test_donottrack.html (1799B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=629535 5 --> 6 <head> 7 <title>Test for Bug 629535</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629535">Mozilla Bug 629535</a> 13 14 <script type="application/javascript"> 15 16 const dntPref = 'privacy.donottrackheader.enabled'; 17 18 SimpleTest.waitForExplicitFinish(); 19 20 var currentTestIdx = -1; 21 var tests = []; 22 function nextTest() { 23 currentTestIdx++; 24 if (currentTestIdx >= tests.length) { 25 SimpleTest.finish(); 26 return; 27 } 28 29 tests[currentTestIdx](); 30 } 31 32 tests.push(function testDefaultValues() { 33 // The default pref values depend on the OS it seems. 34 var isAndroid = !!navigator.userAgent.includes("Android"); 35 var isB2G = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent); 36 37 is(SpecialPowers.getBoolPref(dntPref), false, 38 'DNT should be disabled by default'); 39 is(navigator.doNotTrack, 'unspecified', 40 'navigator.doNotTrack should initially be "unspecified".'); 41 42 nextTest(); 43 }); 44 45 tests.push(function clearedEnabled() { 46 SpecialPowers.pushPrefEnv({"clear": [[dntPref]]}, function() { 47 is(navigator.doNotTrack, "unspecified", 'after clearing pref'); 48 nextTest(); 49 }); 50 }); 51 52 tests.push(function setEnabled() { 53 SpecialPowers.pushPrefEnv({"set": [[dntPref, true]]}, function() { 54 is(navigator.doNotTrack, "1", 'after setting pref to true'); 55 nextTest(); 56 }); 57 }); 58 59 tests.push(function setDisabled() { 60 SpecialPowers.pushPrefEnv({"set": [[dntPref, false]]}, function() { 61 is(navigator.doNotTrack, "unspecified", 'after setting pref to false'); 62 nextTest(); 63 }); 64 }); 65 66 nextTest(); 67 68 </script> 69 70 </body> 71 </html>