Bug 1333933 - Part 2: Add a test case to test whether prefs can be modified and restored correctly when flipping 'privacy.resistFingerprinting'. r?Ehsan,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Mon, 15 May 2017 11:10:17 +0800
changeset 579398 8632c459a00f72d8881066aa89ac34677cf654f9
parent 579397 737d6d3a65a93bc4d7561ed35d1d43c898c539db
child 628995 0d5fdaf00c0f2c2eee47a84d2a0a42e2d166b531
push id59239
push userbmo:tihuang@mozilla.com
push dateWed, 17 May 2017 09:25:55 +0000
reviewersEhsan, arthuredelstein
bugs1333933
milestone55.0a1
Bug 1333933 - Part 2: Add a test case to test whether prefs can be modified and restored correctly when flipping 'privacy.resistFingerprinting'. r?Ehsan,arthuredelstein This patch add a test case for modification and restoration of fingerprinting prefs when flipping 'privacy.resistFingerprinting'. In addition, this patch also fixes some test cases that affect by prefs changes. MozReview-Commit-ID: 4M98nK18XQv
browser/components/resistfingerprinting/test/browser/browser.ini
browser/components/resistfingerprinting/test/browser/browser_prefs.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
--- a/browser/components/resistfingerprinting/test/browser/browser.ini
+++ b/browser/components/resistfingerprinting/test/browser/browser.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 tags = resistfingerprinting
 support-files =
   file_dummy.html
   head.js
 
+[browser_prefs.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]
 [browser_roundedWindow_windowSetting_min.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/resistfingerprinting/test/browser/browser_prefs.js
@@ -0,0 +1,157 @@
+/**
+ * Bug 1333933 - A test case for testing prefs changes when flipping
+ *   'privacy.resistFingerprinting'
+ */
+
+const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
+
+var gPrefService;
+
+var gPrefsList = [
+  { name: "geo.enabled", value: false},
+  { name: "browser.search.countryCode", value: "US"},
+  { name: "browser.search.geoip.url", value: ""},
+  { name: "browser.search.geoSpecificDefaults", value: false},
+  { name: "intl.locale.matchOS", value: false},
+  { name: "general.useragent.locale", value: "en-US"},
+  { name: "webgl.min_capability_mode", value: true},
+  { name: "webgl.disable-extensions", value: true},
+  { name: "webgl.disable-fail-if-major-performance-caveat", value: true},
+  { name: "dom.battery.enabled", value: false},
+  { name: "dom.network.enabled", value: false},
+  { name: "gfx.downloadable_fonts.fallback_delay", value: -1},
+  { name: "general.appname.override", value: "Netscape"},
+  { name: "general.appversion.override", value: "5.0 (Windows)"},
+  { name: "general.oscpu.override", value: "Windows NT 6.1"},
+  { name: "general.platform.override", value: "Win32"},
+  { name: "general.productSub.override", value: "20100101"},
+  { name: "general.buildID.override", value: "20100101"},
+  { name: "browser.startup.homepage_override.buildID", value: "20100101"},
+  { name: "general.useragent.vendor", value: ""},
+  { name: "general.useragent.vendorSub", value: ""},
+  { name: "dom.enable_performance", value: false},
+  { name: "plugin.expose_full_path", value: false},
+  { name: "browser.zoom.siteSpecific", value: false},
+  { name: "intl.charset.default", value: "windows-1252"},
+  { name: "browser.link.open_newwindow.restriction", value: 0},
+  { name: "dom.gamepad.enabled", value: false},
+  { name: "javascript.use_us_english_locale", value: true},
+  { name: "media.video_stats.enabled", value: false},
+  { name: "device.sensors.enabled", value: false},
+  { name: "dom.enable_resource_timing", value: false},
+  { name: "dom.enable_user_timing", value: false},
+  { name: "privacy.resistFingerprinting", value: true},
+  { name: "dom.event.highrestimestamp.enabled", value: true},
+  { name: "privacy.suppressModifierKeyEvents", value: true},
+  { name: "ui.use_standins_for_native_colors", value: true},
+  { name: "browser.reader.detectedFirstArticle", value: true},
+  { name: "reader.parse-on-load.enabled", value: false},
+];
+
+function getPrefValue(name) {
+  let prefType = gPrefService.getPrefType(name);
+  let prefValue;
+
+  switch (prefType) {
+    case gPrefService.PREF_STRING:
+      prefValue = gPrefService.getStringPref(name);
+      break;
+    case gPrefService.PREF_INT:
+      prefValue = gPrefService.getIntPref(name);
+      break;
+    case gPrefService.PREF_BOOL:
+      prefValue = gPrefService.getBoolPref(name);
+      break;
+    default:
+      prefValue = undefined;
+  }
+
+  return prefValue;
+}
+
+add_task(async function setup() {
+  gPrefService = Cc["@mozilla.org/preferences-service;1"]
+                   .getService(Ci.nsIPrefBranch);
+
+  // Generate spoofed UA string and add it into the prefs list.
+  let version = Services.appinfo.version;
+  let spoofedVersion = version.slice(0, version.indexOf(".")) + ".0";
+  let spoofedUA = "Mozilla/5.0 (Windows NT 6.1; rv:" + spoofedVersion +
+                  ") Gecko/20100101 Firefox/" + spoofedVersion;
+
+  gPrefsList.push({ name: "general.useragent.override", value: spoofedUA});
+});
+
+// Testing that whether prefs can be overridden and restored correctly.
+add_task(async function test_prefs_values() {
+  // First, store original values of prefs.
+  let originPrefValues = {};
+
+  for (let pref of gPrefsList) {
+    let prefValue = getPrefValue(pref.name);
+    originPrefValues[pref.name] = prefValue;
+  }
+
+  // Second, turn on the 'privacy.resistFingerprinting'
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", true]]
+  });
+
+  // Then, verify does every pref has the correct value.
+  for (let pref of gPrefsList) {
+    let prefValue = getPrefValue(pref.name);
+    is(prefValue, pref.value, "Pref '" + pref.name + "' has correct value: " + prefValue);
+  }
+
+  // Turn off the 'privacy.resistFingerprinting' and verify does all prefs be
+  // restored back to its original values.
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", false]]
+  });
+
+  for (let pref of gPrefsList) {
+    let prefValue = getPrefValue(pref.name);
+    is(prefValue, originPrefValues[pref.name], "Pref '" + pref.name + "' has been restored successfully.");
+  }
+});
+
+// Testing that whether a user setting value can be restored correctly.
+add_task(async function test_prefs_restoreUserValues() {
+  // First, we set one pref with non-default value.
+  gPrefService.setStringPref("general.buildID.override", "20170101");
+
+  // Turn on 'privacy.resistFingerprinting' and check whether this pref has been
+  // set properly.
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", true]]
+  });
+
+  is(getPrefValue("general.buildID.override"), "20100101", "This pref has been set properly");
+
+  // Turn off 'privacy.resistFingerprinting' and check whether this pref has been
+  // restored properly.
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", false]]
+  });
+
+  is(getPrefValue("general.buildID.override"), "20170101", "This pref has been restored properly");
+});
+
+// Testing the behavior of change a pref when 'privacy.resistFingerprinting' is on.
+add_task(async function test_prefs_changePrefs() {
+  // First, turn on the 'privacy.resistFingerprinting'.
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", true]]
+  });
+
+  // Second, set a user value to one pref.
+  gPrefService.setStringPref("general.buildID.override", "20170101");
+
+  // Turn off 'privacy.resistFingerprinting' and check whether the pref still remains
+  // the user setting value.
+  await SpecialPowers.pushPrefEnv({"set":
+    [["privacy.resistFingerprinting", false]]
+  });
+
+  is(getPrefValue("general.buildID.override"), "20170101", "This pref has been restored properly");
+});
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_newWindow.js
@@ -11,16 +11,22 @@ const TEST_PATH = TEST_DOMAIN + "browser
 let gMaxAvailWidth;
 let gMaxAvailHeight;
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize();
 
   gMaxAvailWidth = maxAvailSize.maxAvailWidth;
   gMaxAvailHeight = maxAvailSize.maxAvailHeight;
 });
 
 add_task(function* test_new_window() {
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_max.js
@@ -22,16 +22,22 @@ const TESTCASES = [
   { settingWidth: 999, settingHeight: 999, targetWidth: 1000, targetHeight: 1000 },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_mid.js
@@ -22,16 +22,22 @@ const TESTCASES = [
   { settingWidth: 401, settingHeight: 501, targetWidth: 600, targetHeight: 600 },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_open_min.js
@@ -21,16 +21,22 @@ const TESTCASES = [
   { settingWidth: 10, settingHeight: 10, targetWidth: 200, targetHeight: 100 },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_max.js
@@ -25,16 +25,22 @@ const TESTCASES = [
     initWidth: 200, initHeight: 100  },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_mid.js
@@ -25,16 +25,22 @@ const TESTCASES = [
     initWidth: 200, initHeight: 100  },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,
--- a/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_roundedWindow_windowSetting_min.js
@@ -23,16 +23,22 @@ const TESTCASES = [
     initWidth: 1000, initHeight: 1000  },
 ];
 
 add_task(function* setup() {
   yield SpecialPowers.pushPrefEnv({"set":
     [["privacy.resistFingerprinting", true]]
   });
 
+  // This pref will be overridden when fingerprinting resistance is enabled, but
+  // we need this to open new window for testing.
+  Cc["@mozilla.org/preferences-service;1"]
+     .getService(Ci.nsIPrefBranch)
+     .clearUserPref("browser.link.open_newwindow.restriction");
+
   // Calculate the popup window's chrome UI size for tests of outerWidth/Height.
   let popUpChromeUISize = yield calcPopUpWindowChromeUISize();
 
   gPopupChromeUIWidth = popUpChromeUISize.chromeWidth;
   gPopupChromeUIHeight = popUpChromeUISize.chromeHeight;
 
   // Calculate the maximum available size.
   let maxAvailSize = yield calcMaximumAvailSize(gPopupChromeUIWidth,