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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* import-globals-from testHelpers.js */
runTestInFirstAndThirdPartyContexts(
"ServiceWorkers - Ensure the fingerprinting WebCompat overrides the fingerprinting protection in third-party context.",
async win => {
let SPOOFED_HW_CONCURRENCY = 2;
// Register service worker for the first-party window.
if (!win.sw) {
win.sw = await registerServiceWorker(win, "serviceWorker.js");
}
// Check navigator HW concurrency from the first-party service worker.
let res = await sendAndWaitWorkerMessage(
win.sw,
win.navigator.serviceWorker,
{ type: "GetHWConcurrency" }
);
is(
res.value,
SPOOFED_HW_CONCURRENCY,
"HW Concurrency should be spoofed in the first-party context"
);
},
async win => {
// Quickly unset and reset these prefs so we can get the real navigator.hardwareConcurrency
// It can't be set externally and then captured because this function gets stringified and
// then evaled in a new scope.
await SpecialPowers.pushPrefEnv({
set: [["privacy.fingerprintingProtection", false]],
});
var DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency;
await SpecialPowers.popPrefEnv();
// Register service worker for the third-party window.
if (!win.sw) {
win.sw = await registerServiceWorker(win, "serviceWorker.js");
}
// Check navigator HW concurrency from the third-party service worker.
let res = await sendAndWaitWorkerMessage(
win.sw,
win.navigator.serviceWorker,
{ type: "GetHWConcurrency" }
);
is(
res.value,
DEFAULT_HARDWARE_CONCURRENCY,
"HW Concurrency should not be spoofed in the third-party context"
);
},
async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () =>
resolve()
);
});
},
[
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.ipc.processCount", 1],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["privacy.fingerprintingProtection", true],
["privacy.fingerprintingProtection.overrides", "+NavigatorHWConcurrency"],
[
"privacy.fingerprintingProtection.granularOverrides",
JSON.stringify([
{
id: "1",
last_modified: 1000000000000001,
overrides: "-NavigatorHWConcurrency",
firstPartyDomain: "example.net",
thirdPartyDomain: "example.com",
},
]),
],
]
);
runTestInFirstAndThirdPartyContexts(
"ServiceWorkers - Ensure the fingerprinting WebCompat overrides the fingerprinting protection in third-party context with FPI enabled.",
async win => {
let SPOOFED_HW_CONCURRENCY = 2;
// Register service worker for the first-party window.
if (!win.sw) {
win.sw = await registerServiceWorker(win, "serviceWorker.js");
}
// Check navigator HW concurrency from the first-party service worker.
let res = await sendAndWaitWorkerMessage(
win.sw,
win.navigator.serviceWorker,
{ type: "GetHWConcurrency" }
);
is(
res.value,
SPOOFED_HW_CONCURRENCY,
"HW Concurrency should be spoofed in the first-party context"
);
},
async win => {
// Quickly unset and reset these prefs so we can get the real navigator.hardwareConcurrency
// It can't be set enternally and then captured because this function gets stringified and
// then evaled in a new scope.
await SpecialPowers.pushPrefEnv({
set: [["privacy.fingerprintingProtection", false]],
});
var DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency;
await SpecialPowers.popPrefEnv();
// Register service worker for the third-party window.
if (!win.sw) {
win.sw = await registerServiceWorker(win, "serviceWorker.js");
}
// Check navigator HW concurrency from the third-party service worker.
let res = await sendAndWaitWorkerMessage(
win.sw,
win.navigator.serviceWorker,
{ type: "GetHWConcurrency" }
);
is(
res.value,
DEFAULT_HARDWARE_CONCURRENCY,
"HW Concurrency should not be spoofed in the third-party context"
);
},
async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () =>
resolve()
);
});
},
[
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.ipc.processCount", 1],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["privacy.firstparty.isolate", true],
["privacy.fingerprintingProtection", true],
["privacy.fingerprintingProtection.overrides", "+NavigatorHWConcurrency"],
[
"privacy.fingerprintingProtection.granularOverrides",
JSON.stringify([
{
id: "1",
last_modified: 1000000000000001,
overrides: "-NavigatorHWConcurrency",
firstPartyDomain: "example.net",
thirdPartyDomain: "example.com",
},
]),
],
]
);
|