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 : 70d44115532549814af9fce3af9fe379e36bca80
This commit is contained in:
Tim Huang 2017-06-13 14:10:18 +08:00
Родитель db3305baa3
Коммит 425a0fbd11
3 изменённых файлов: 89 добавлений и 0 удалений

Просмотреть файл

@ -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]

Просмотреть файл

@ -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();
});

Просмотреть файл

@ -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");
}
}