Bug 1372072 - Part 2: Add a test case for check whether network information API has been spoofed correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku

This adds a test case to test that network information is correctly spoofed when
'privacy.resistFingerprinting' is true. This tests not only windows, but also
workers.

MozReview-Commit-ID: Lt6HZlFrcja

--HG--
extra : rebase_source : 6040bc8697be2665f4063df9b24bc8afdc549e32
extra : source : fe711bd124f6e904548b3f4d90fa321deea78615
This commit is contained in:
Tim Huang 2017-06-13 14:10:18 +08:00
parent d53b315de9
commit 17d45bd8e2
3 changed files with 89 additions and 0 deletions

View File

@ -4,10 +4,12 @@ support-files =
file_dummy.html
file_navigator.html
file_navigatorWorker.js
file_workerNetInfo.js
file_workerPerformance.js
head.js
[browser_navigator.js]
[browser_netInfo.js]
[browser_performanceAPI.js]
[browser_roundedWindow_dialogWindow.js]
[browser_roundedWindow_newWindow.js]

View File

@ -0,0 +1,61 @@
/**
* Bug 1372072 - A test case for check whether network information API has been
* spoofed correctly when 'privacy.resistFingerprinting' is true;
*/
const TEST_PATH = "http://example.net/browser/browser/" +
"components/resistfingerprinting/test/browser/"
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 ContentTask.spawn(tab.linkedBrowser, null, async function() {
ok("connection" in content.navigator, "navigator.connection should exist");
is(content.navigator.connection.type, "unknown", "The connection type is spoofed correctly");
});
await 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 ContentTask.spawn(tab.linkedBrowser, null, 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"});
});
});
await BrowserTestUtils.removeTab(tab);
}
add_task(async function runTest() {
await SpecialPowers.pushPrefEnv({"set":
[
["privacy.resistFingerprinting", true],
["dom.netinfo.enabled", true]
]
});
await testWindow();
await testWorker();
});

View File

@ -0,0 +1,26 @@
function ok(a, msg) {
postMessage({type: "status", status: !!a, msg});
}
function is(a, b, msg) {
ok(a === b, msg);
}
function finish() {
postMessage({type: "finish"});
}
function runTests() {
ok("connection" in navigator, "navigator.connection should exist");
is(navigator.connection.type, "unknown", "The connection type is spoofed correctly");
finish();
}
self.onmessage = function(e) {
if (e.data.type === "runTests") {
runTests();
} else {
ok(false, "Unknown message type");
}
}