Bug 1333651 - Part 3: Add a test case to verify that Navigator object has been spoofed/disabled correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein,Ehsan
authorTim Huang <tihuang@mozilla.com>
Tue, 06 Jun 2017 17:14:55 +0800
changeset 364971 5131e38858f91107d1d198ffd8a4187be1ed1a87
parent 364970 76040a8fabaaa1484900aa7fa6937e275e5c0bfc
child 364972 58e1d5cd63c0ccaa859d264bfd5196df2ea499aa
push id32058
push userkwierso@gmail.com
push dateWed, 21 Jun 2017 01:24:44 +0000
treeherdermozilla-central@c55e582aee5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarthuredelstein, Ehsan
bugs1333651
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 1333651 - Part 3: Add a test case to verify that Navigator object has been spoofed/disabled correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein,Ehsan This patch adds a brower chrome test to verify the navigator object when 'privacy.resistFingerprinting' is true. This test will also test worker navigator to check that whether it has been correctly spoofed/disabled. MozReview-Commit-ID: 17FvdlmLMjP
browser/components/resistfingerprinting/test/browser/browser.ini
browser/components/resistfingerprinting/test/browser/browser_navigator.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
browser/components/resistfingerprinting/test/browser/browser_timezone.js
browser/components/resistfingerprinting/test/browser/file_navigator.html
browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js
browser/components/resistfingerprinting/test/browser/head.js
--- a/browser/components/resistfingerprinting/test/browser/browser.ini
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -1,15 +1,18 @@
 [DEFAULT]
 tags = resistfingerprinting
 support-files =
   file_dummy.html
+  file_navigator.html
+  file_navigatorWorker.js
   file_workerPerformance.js
   head.js
 
+[browser_navigator.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_navigator.js
@@ -0,0 +1,122 @@
+/**
+ * Bug 1333651 - A test case for making sure the navigator object has been
+ *   spoofed/disabled correctly.
+ */
+
+const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
+
+const TEST_PATH = "http://example.net/browser/browser/" +
+                  "components/resistfingerprinting/test/browser/"
+
+var spoofedUserAgent;
+
+const SPOOFED_APPNAME        = "Netscape";
+const SPOOFED_APPVERSION     = "5.0 (Windows)";
+const SPOOFED_PLATFORM       = "Win32";
+const SPOOFED_OSCPU          = "Windows NT 6.1";
+const SPOOFED_BUILDID        = "20100101";
+const SPOOFED_HW_CONCURRENCY = 2;
+
+const CONST_APPCODENAME = "Mozilla";
+const CONST_PRODUCT     = "Gecko";
+const CONST_PRODUCTSUB  = "20100101";
+const CONST_VENDOR      = "";
+const CONST_VENDORSUB   = "";
+
+async function testNavigator() {
+  // Open a tab to collect result.
+  let tab = await BrowserTestUtils.openNewForegroundTab(
+    gBrowser, TEST_PATH + "file_navigator.html");
+
+  let result = await ContentTask.spawn(tab.linkedBrowser, null, function() {
+    return content.document.getElementById("result").innerHTML;
+  });
+
+  result = JSON.parse(result);
+
+  is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
+  is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
+  is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
+  is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
+  is(result.mimeTypesLength, 0, "Navigator.mimeTypes has a length of 0.");
+  is(result.pluginsLength, 0, "Navigator.plugins has a length of 0.");
+  is(result.oscpu, SPOOFED_OSCPU, "Navigator.oscpu is correctly spoofed.");
+  is(result.buildID, SPOOFED_BUILDID, "Navigator.buildID is correctly spoofed.");
+  is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.")
+
+  is(result.appCodeName, CONST_APPCODENAME, "Navigator.appCodeName reports correct constant value.");
+  is(result.product, CONST_PRODUCT, "Navigator.product reports correct constant value.");
+  is(result.productSub, CONST_PRODUCTSUB, "Navigator.productSub reports correct constant value.");
+  is(result.vendor, CONST_VENDOR, "Navigator.vendor reports correct constant value.");
+  is(result.vendorSub, CONST_VENDORSUB, "Navigator.vendorSub reports correct constant value.");
+
+  await BrowserTestUtils.removeTab(tab);
+}
+
+async function testWorkerNavigator() {
+  // Open a tab to collect result from worker.
+  let tab = await BrowserTestUtils.openNewForegroundTab(
+    gBrowser, TEST_PATH + "file_dummy.html");
+
+  let result = await ContentTask.spawn(tab.linkedBrowser, null, async function() {
+    let worker = new content.SharedWorker("file_navigatorWorker.js", "WorkerNavigatorTest");
+
+    let res = await new Promise(resolve => {
+      worker.port.onmessage = function(e) {
+        resolve(e.data);
+      };
+    });
+
+    return res;
+  });
+
+  result = JSON.parse(result);
+
+  is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
+  is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
+  is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
+  is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
+  is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.")
+
+  is(result.appCodeName, CONST_APPCODENAME, "Navigator.appCodeName reports correct constant value.");
+  is(result.product, CONST_PRODUCT, "Navigator.product reports correct constant value.");
+
+  await BrowserTestUtils.removeTab(tab);
+}
+
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", true]]
+  });
+
+  let appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
+  let appVersion = parseInt(appInfo.version);
+  let spoofedVersion = appVersion - (appVersion % 10);
+  spoofedUserAgent = `Mozilla/5.0 (Windows NT 6.1; rv:${spoofedVersion}.0) Gecko/20100101 Firefox/${spoofedVersion}.0`;
+});
+
+add_task(async function runNavigatorTest() {
+  await testNavigator();
+});
+
+add_task(async function runWorkerNavigatorTest() {
+  await testWorkerNavigator();
+});
+
+// This tests that 'general.*.override' should not override spoofed values.
+add_task(async function runOverrideTest() {
+  await SpecialPowers.pushPrefEnv({"set":
+    [
+      ["general.appname.override", "appName overridden"],
+      ["general.appversion.override", "appVersion overridden"],
+      ["general.platform.override", "platform overridden"],
+      ["general.useragent.override", "userAgent overridden"],
+      ["general.oscpu.override", "oscpu overridden"],
+      ["general.buildID.override", "buildID overridden"],
+    ]
+  });
+
+  await testNavigator();
+
+  await testWorkerNavigator();
+});
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
@@ -1,17 +1,17 @@
 /*
  * Bug 1330882 - A test case for opening new windows as rounded size when
  *   fingerprinting resistance is enabled.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for opening new windows through window.open() as
  *   rounded size when fingerprinting resistance is enabled. This test is for
  *   maximum values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for opening new windows through window.open() as
  *   rounded size when fingerprinting resistance is enabled. This test is for
  *   middle values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for opening new windows through window.open() as
  *   rounded size when fingerprinting resistance is enabled. This test is for
  *   minimum values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
  *   and window.outerWidth/Height when fingerprinting resistance is enabled. This
  *   test is for maximum values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
  *   and window.outerWidth/Height when fingerprinting resistance is enabled. This
  *   test is for middle values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
@@ -2,17 +2,17 @@
  * Bug 1330882 - A test case for setting window size through window.innerWidth/Height
  *   and window.outerWidth/Height when fingerprinting resistance is enabled. This
  *   test is for minimum values.
  */
 
 const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 // We need the chrome UI size of popup windows for testing outerWidth/Height.
 let gPopupChromeUIWidth;
 let gPopupChromeUIHeight;
 
--- a/browser/components/resistfingerprinting/test/browser/browser_timezone.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_timezone.js
@@ -1,15 +1,15 @@
 /**
  * Bug 1330890 - A test case for verifying Date() object of javascript will use
  *               UTC timezone after fingerprinting resistance is enabled.
  */
 
 const TEST_DOMAIN = "http://example.net/";
-const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistFingerprinting/test/browser/";
+const TEST_PATH = TEST_DOMAIN + "browser/browser/components/resistfingerprinting/test/browser/";
 
 add_task(async function setup() {
   await SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 });
 
 add_task(async function test_timezone() {
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/file_navigator.html
@@ -0,0 +1,33 @@
+<html>
+<head>
+<title>Test page for navigator object</title>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
+<script>
+  // This page will collect information from the navigator object and store
+  // the result at a paragraph in the page.
+  function collect() {
+    let result = {};
+
+    result["appCodeName"] = navigator.appCodeName;
+    result["appName"] = navigator.appName;
+    result["appVersion"] = navigator.appVersion;
+    result["platform"] = navigator.platform;
+    result["userAgent"] = navigator.userAgent;
+    result["product"] = navigator.product;
+    result["productSub"] = navigator.productSub;
+    result["vendor"] = navigator.vendor;
+    result["vendorSub"] = navigator.vendorSub;
+    result["mimeTypesLength"] = navigator.mimeTypes.length;
+    result["pluginsLength"] = navigator.plugins.length;
+    result["oscpu"] = navigator.oscpu;
+    result["buildID"] = navigator.buildID;
+    result["hardwareConcurrency"] = navigator.hardwareConcurrency;
+
+    document.getElementById("result").innerHTML = JSON.stringify(result);
+  }
+</script>
+</head>
+<body onload="collect();">
+<p id="result"></p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/file_navigatorWorker.js
@@ -0,0 +1,19 @@
+/* eslint-env worker */
+
+onconnect = function(e) {
+  let port = e.ports[0];
+
+  let navigatorObj = self.navigator;
+  let result = {};
+
+  result["appCodeName"] = navigatorObj.appCodeName;
+  result["appName"] = navigatorObj.appName;
+  result["appVersion"] = navigatorObj.appVersion;
+  result["platform"] = navigatorObj.platform;
+  result["userAgent"] = navigatorObj.userAgent;
+  result["product"] = navigatorObj.product;
+  result["hardwareConcurrency"] = navigatorObj.hardwareConcurrency;
+
+  port.postMessage(JSON.stringify(result));
+  port.start();
+};
--- a/browser/components/resistfingerprinting/test/browser/head.js
+++ b/browser/components/resistfingerprinting/test/browser/head.js
@@ -6,17 +6,17 @@
 
 
 // This function calculates the maximum available window dimensions and returns
 // them as an object.
 async function calcMaximumAvailSize(aChromeWidth, aChromeHeight) {
   let chromeUIWidth;
   let chromeUIHeight;
   let testPath = "http://example.net/browser/browser/" +
-                 "components/resistFingerprinting/test/browser/"
+                 "components/resistfingerprinting/test/browser/"
 
   // If the chrome UI dimensions is not given, we will calculate it.
   if (!aChromeWidth || !aChromeHeight) {
     let win = await BrowserTestUtils.openNewBrowserWindow();
 
     let tab = await BrowserTestUtils.openNewForegroundTab(
       win.gBrowser, testPath + "file_dummy.html");