Bug 1081343 - Create a pref to control Polaris. r=gavin
authorTomasz Kołodziejski <tkolodziejski@mozilla.com>
Thu, 23 Oct 2014 14:43:51 -0700
changeset 212123 54fab44be5f327fdb342eebc8860ce595b3c7c10
parent 212122 c77cb1e0d919d2f8b798b802d8b83ebb02b877a6
child 212124 fa426ab14a9c110e9708884ece5ec5f3fcd83345
push id27698
push usercbook@mozilla.com
push dateFri, 24 Oct 2014 13:53:50 +0000
treeherdermozilla-central@6e35802ae3e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1081343, 100644
milestone36.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 1081343 - Create a pref to control Polaris. r=gavin --- browser/app/profile/firefox.js | 3 ++ browser/components/nsBrowserGlue.js | 14 ++++++ browser/components/test/browser.ini | 2 + browser/components/test/browser_polaris_prefs.js | 57 ++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 browser/components/test/browser_polaris_prefs.js
browser/app/profile/firefox.js
browser/components/nsBrowserGlue.js
browser/components/test/browser.ini
browser/components/test/browser_polaris_prefs.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1756,8 +1756,11 @@ pref("experiments.manifest.fetchInterval
 pref("experiments.manifest.uri", "https://telemetry-experiment.cdn.mozilla.net/manifest/v1/firefox/%VERSION%/%CHANNEL%");
 // Whether experiments are supported by the current application profile.
 pref("experiments.supported", true);
 
 // Enable the OpenH264 plugin support in the addon manager.
 pref("media.gmp-gmpopenh264.provider.enabled", true);
 
 pref("browser.apps.URL", "https://marketplace.firefox.com/discovery/");
+
+pref("browser.polaris.enabled", false);
+pref("privacy.trackingprotection.ui.enabled", false);
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -4,16 +4,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+const POLARIS_ENABLED = "browser.polaris.enabled";
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AboutHome",
                                   "resource:///modules/AboutHome.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
@@ -392,16 +393,23 @@ BrowserGlue.prototype = {
           ss.currentEngine = ss.defaultEngine;
         break;
       case "browser-search-service":
         if (data != "init-complete")
           return;
         Services.obs.removeObserver(this, "browser-search-service");
         this._syncSearchEngines();
         break;
+      case "nsPref:changed":
+        if (data == POLARIS_ENABLED) {
+          let enabled = Services.prefs.getBoolPref(POLARIS_ENABLED);
+          Services.prefs.setBoolPref("privacy.donottrackheader.enabled", enabled);
+          Services.prefs.setBoolPref("privacy.trackingprotection.enabled", enabled);
+          Services.prefs.setBoolPref("privacy.trackingprotection.ui.enabled", enabled);
+        }
     }
   },
 
   _syncSearchEngines: function () {
     // Only do this if the search service is already initialized. This function
     // gets called in finalUIStartup and from a browser-search-service observer,
     // to catch both cases (search service initialization occurring before and
     // after final-ui-startup)
@@ -438,16 +446,19 @@ BrowserGlue.prototype = {
     this._isPlacesShutdownObserver = true;
     os.addObserver(this, "handle-xul-text-link", false);
     os.addObserver(this, "profile-before-change", false);
 #ifdef MOZ_SERVICES_HEALTHREPORT
     os.addObserver(this, "keyword-search", false);
 #endif
     os.addObserver(this, "browser-search-engine-modified", false);
     os.addObserver(this, "browser-search-service", false);
+#ifdef NIGHTLY_BUILD
+    Services.prefs.addObserver(POLARIS_ENABLED, this, false);
+#endif
   },
 
   // cleanup (called on application shutdown)
   _dispose: function BG__dispose() {
     let os = Services.obs;
     os.removeObserver(this, "prefservice:after-app-defaults");
     os.removeObserver(this, "final-ui-startup");
     os.removeObserver(this, "sessionstore-windows-restored");
@@ -478,16 +489,19 @@ BrowserGlue.prototype = {
 #ifdef MOZ_SERVICES_HEALTHREPORT
     os.removeObserver(this, "keyword-search");
 #endif
     os.removeObserver(this, "browser-search-engine-modified");
     try {
       os.removeObserver(this, "browser-search-service");
       // may have already been removed by the observer
     } catch (ex) {}
+#ifdef NIGHTLY_BUILD
+    Services.prefs.removeObserver(POLARIS_ENABLED, this);
+#endif
   },
 
   _onAppDefaults: function BG__onAppDefaults() {
     // apply distribution customizations (prefs)
     // other customizations are applied in _finalUIStartup()
     this._distributionCustomizer.applyPrefDefaults();
   },
 
--- a/browser/components/test/browser.ini
+++ b/browser/components/test/browser.ini
@@ -1,4 +1,6 @@
 [DEFAULT]
 
 [browser_bug538331.js]
 skip-if = e10s # Bug ?????? - child process crash, but only when run as part of the suite (ie, probably not actually this tests fault!?)
+
+[browser_polaris_prefs.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/test/browser_polaris_prefs.js
@@ -0,0 +1,57 @@
+const POLARIS_ENABLED = "browser.polaris.enabled";
+const PREF_DNT = "privacy.donottrackheader.enabled";
+const PREF_TP = "privacy.trackingprotection.enabled";
+const PREF_TPUI = "privacy.trackingprotection.ui.enabled";
+
+let prefs = [PREF_DNT, PREF_TP, PREF_TPUI];
+
+function spinEventLoop() {
+  return new Promise((resolve) => executeSoon(resolve));
+};
+
+// Spin event loop before checking so that polaris pref observer can set
+// dependent prefs.
+function* assertPref(pref, enabled) {
+  yield spinEventLoop();
+  let prefEnabled = Services.prefs.getBoolPref(pref);
+  Assert.equal(prefEnabled, enabled, "Checking state of pref " + pref + ".");
+};
+
+function* testPrefs(test) {
+  for (let pref of prefs) {
+    yield test(pref);
+  }
+}
+
+add_task(function* test_default_values() {
+  Assert.ok(!Services.prefs.getBoolPref(POLARIS_ENABLED), POLARIS_ENABLED + " is disabled by default.");
+  Assert.ok(!Services.prefs.getBoolPref(PREF_TPUI), PREF_TPUI + "is disabled by default.");
+});
+
+add_task(function* test_changing_pref_changes_tracking() {
+  function* testPref(pref) {
+    Services.prefs.setBoolPref(POLARIS_ENABLED, true);
+    yield assertPref(pref, true);
+    Services.prefs.setBoolPref(POLARIS_ENABLED, false);
+    yield assertPref(pref, false);
+    Services.prefs.setBoolPref(POLARIS_ENABLED, true);
+    yield assertPref(pref, true);
+  }
+  yield testPrefs(testPref);
+});
+
+add_task(function* test_prefs_can_be_changed_individually() {
+  function* testPref(pref) {
+    Services.prefs.setBoolPref(POLARIS_ENABLED, true);
+    yield assertPref(pref, true);
+    Services.prefs.setBoolPref(pref, false);
+    yield assertPref(pref, false);
+    yield assertPref(POLARIS_ENABLED, true);
+    Services.prefs.setBoolPref(POLARIS_ENABLED, false);
+    yield assertPref(pref, false);
+    Services.prefs.setBoolPref(pref, true);
+    yield assertPref(pref, true);
+    yield assertPref(POLARIS_ENABLED, false);
+  }
+  yield testPrefs(testPref);
+});