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