Bug 1372072 - Part 2: Add a test case for check whether network information API has been spoofed correctly when 'privacy.resistFingerprinting' is true. r?baku,arthuredelstein
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
--- a/browser/components/resistfingerprinting/test/browser/browser.ini
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -1,18 +1,20 @@
[DEFAULT]
tags = resistfingerprinting
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]
[browser_roundedWindow_open_max.js]
[browser_roundedWindow_open_mid.js]
[browser_roundedWindow_open_min.js]
[browser_roundedWindow_windowSetting_max.js]
[browser_roundedWindow_windowSetting_mid.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_netInfo.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();
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/file_workerNetInfo.js
@@ -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");
+ }
+}