bug418986-1.js (2575B)
1 /* globals chromeWindow */ 2 3 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */ 4 5 // The main test function. 6 var test = function (isContent) { 7 SimpleTest.waitForExplicitFinish(); 8 9 SpecialPowers.pushPrefEnv({ 10 set: [["security.allow_eval_with_system_principal", true]], 11 }); 12 13 if (!isContent) { 14 let { ww } = SpecialPowers.Services; 15 window.chromeWindow = ww.activeWindow; 16 } 17 18 // The pairs of values expected to be the same when 19 // fingerprinting resistance is enabled. 20 let pairs = [ 21 ["screenX", 0], 22 ["screenY", 0], 23 ["mozInnerScreenX", 0], 24 ["mozInnerScreenY", 0], 25 ["screen.pixelDepth", 24], 26 ["screen.colorDepth", 24], 27 ["screen.availWidth", "outerWidth"], 28 ["screen.availHeight", "outerHeight"], 29 ["screen.left", 0], 30 ["screen.top", 0], 31 ["screen.availLeft", 0], 32 ["screen.availTop", 0], 33 ["screen.width", "outerWidth"], 34 ["screen.height", "outerHeight"], 35 ["devicePixelRatio", 2], 36 ]; 37 38 // checkPair: tests if members of pair [a, b] are equal when evaluated. 39 let checkPair = function (a, b) { 40 // eslint-disable-next-line no-eval 41 is(eval(a), eval(b), a + " should be equal to " + b); 42 }; 43 44 // Returns generator object that iterates through pref values. 45 let prefVals = (function* () { 46 yield false; 47 yield true; 48 })(); 49 50 // The main test function, runs until all pref values are exhausted. 51 let nextTest = function () { 52 let { value: prefValue, done } = prefVals.next(); 53 if (done) { 54 SimpleTest.finish(); 55 return; 56 } 57 SpecialPowers.pushPrefEnv( 58 { set: [["privacy.resistFingerprinting", prefValue]] }, 59 function () { 60 // We will be resisting fingerprinting if the pref is enabled, 61 // and we are in a content script (not chrome). 62 let resisting = prefValue && isContent; 63 // Check each of the pairs. 64 pairs.map(function ([item, onVal]) { 65 if (resisting) { 66 checkPair("window." + item, onVal); 67 } else if (!isContent && !item.startsWith("moz")) { 68 checkPair("window." + item, "chromeWindow." + item); 69 } 70 }); 71 if (!isContent && !resisting) { 72 // Hard to predict these values, but we can enforce constraints: 73 ok( 74 window.mozInnerScreenX >= chromeWindow.mozInnerScreenX, 75 "mozInnerScreenX" 76 ); 77 ok( 78 window.mozInnerScreenY >= chromeWindow.mozInnerScreenY, 79 "mozInnerScreenY" 80 ); 81 } 82 nextTest(); 83 } 84 ); 85 }; 86 87 nextTest(); 88 };