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
authorTim Huang <tihuang@mozilla.com>
Tue, 13 Jun 2017 14:10:18 +0800
changeset 366735 12f8c79dabb4b267f5f033c644295544ed82ad0c
parent 366734 69970dbe2b5ac4221205c77660b9cc5f38bf5241
child 366736 d71a65e4af01d6d640755c9ba49a2638acd6b66d
push id32108
push usercbook@mozilla.com
push dateFri, 30 Jun 2017 10:57:12 +0000
treeherdermozilla-central@a578ce873d80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarthuredelstein, baku
bugs1372072
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/components/resistfingerprinting/test/browser/browser.ini
browser/components/resistfingerprinting/test/browser/browser_netInfo.js
browser/components/resistfingerprinting/test/browser/file_workerNetInfo.js
--- 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");
+  }
+}