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
|
/**
* Bug 1372072 - A test case for check whether network information API has been
* spoofed correctly when 'privacy.resistFingerprinting' is true;
*/
async function testWindow() {
// Open a tab to test network information in a content.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_dummy.html"
);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
ok("connection" in content.navigator, "navigator.connection should exist");
is(
content.navigator.connection.type,
"unknown",
"The connection type is spoofed correctly"
);
});
BrowserTestUtils.removeTab(tab);
}
async function testWorker() {
// Open a tab to test network information in a worker.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_dummy.html"
);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
await new Promise(resolve => {
let worker = new content.Worker("file_workerNetInfo.js");
worker.onmessage = function (e) {
if (e.data.type == "status") {
ok(e.data.status, e.data.msg);
} else if (e.data.type == "finish") {
resolve();
} else {
ok(false, "Unknown message type");
resolve();
}
};
worker.postMessage({ type: "runTests" });
});
});
BrowserTestUtils.removeTab(tab);
}
add_task(async function runTest() {
await SpecialPowers.pushPrefEnv({
set: [
["privacy.resistFingerprinting", true],
["dom.netinfo.enabled", true],
],
});
await testWindow();
await testWorker();
});
|