Bug 1351980 - Initialize and uninitialize UserAgentOverrides.jsm for Firefox; r=mconley
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 02 Apr 2017 11:08:16 -0400
changeset 351291 1f5e8370f845e5bfe8f5d14a69ad3c848cedfe45
parent 351290 141975d40a7c783d4131de3f3e0474f404233198
child 351292 018e8f0f6e804dd39a23cfbb06a4d2f997d70ce0
push id31604
push usercbook@mozilla.com
push dateWed, 05 Apr 2017 12:33:50 +0000
treeherdermozilla-central@3854bcf837a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1351980
milestone55.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 1351980 - Initialize and uninitialize UserAgentOverrides.jsm for Firefox; r=mconley
browser/base/content/test/static/browser_all_files_referenced.js
browser/components/nsBrowserGlue.js
netwerk/test/mochitests/test_user_agent_overrides.html
netwerk/test/mochitests/test_user_agent_updates.html
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -242,18 +242,16 @@ var whitelist = new Set([
   // Bug 1351089
   {file: "resource://gre/modules/PresentationDeviceInfoManager.jsm"},
   // Bug 1351091
   {file: "resource://gre/modules/Profiler.jsm"},
   // Bug 1351658
   {file: "resource://gre/modules/PropertyListUtils.jsm", platforms: ["linux", "win"]},
   // Bug 1351093
   {file: "resource://gre/modules/Sntp.jsm"},
-  // Bug 1351980
-  {file: "resource://gre/modules/UserAgentOverrides.jsm"},
   // Bug 1351097
   {file: "resource://gre/modules/accessibility/AccessFu.jsm"},
   // Bug 1351099
   {file: "resource://gre/modules/addons/AddonLogging.jsm"},
   // Bug 1351637
   {file: "resource://gre/modules/sdk/bootstrap.js"},
   // Bug 1351657
   {file: "resource://gre/res/langGroups.properties", platforms: ["macosx"]},
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -84,16 +84,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
   ["ShellService", "resource:///modules/ShellService.jsm"],
   ["SimpleServiceDiscovery", "resource://gre/modules/SimpleServiceDiscovery.jsm"],
   ["TabCrashHandler", "resource:///modules/ContentCrashHandlers.jsm"],
   ["Task", "resource://gre/modules/Task.jsm"],
   ["UITour", "resource:///modules/UITour.jsm"],
   ["WebChannel", "resource://gre/modules/WebChannel.jsm"],
   ["WindowsRegistry", "resource://gre/modules/WindowsRegistry.jsm"],
   ["webrtcUI", "resource:///modules/webrtcUI.jsm"],
+  ["UserAgentOverrides", "resource://gre/modules/UserAgentOverrides.jsm"],
 ].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource));
 
 if (AppConstants.MOZ_CRASHREPORTER) {
   XPCOMUtils.defineLazyModuleGetter(this, "PluginCrashReporter",
                                     "resource:///modules/ContentCrashHandlers.jsm");
   XPCOMUtils.defineLazyModuleGetter(this, "UnsubmittedCrashHandler",
                                     "resource:///modules/ContentCrashHandlers.jsm");
   XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
@@ -426,16 +427,18 @@ BrowserGlue.prototype = {
     this._flashHangCount = 0;
     this._firstWindowReady = new Promise(resolve => this._firstWindowLoaded = resolve);
 
     if (AppConstants.platform == "macosx") {
       // Handles prompting to inform about incompatibilites when accessibility
       // and e10s are active together.
       E10SAccessibilityCheck.init();
     }
+
+    UserAgentOverrides.init();
   },
 
   // cleanup (called on application shutdown)
   _dispose: function BG__dispose() {
     let os = Services.obs;
     os.removeObserver(this, "notifications-open-settings");
     os.removeObserver(this, "prefservice:after-app-defaults");
     os.removeObserver(this, "final-ui-startup");
@@ -465,16 +468,18 @@ BrowserGlue.prototype = {
     os.removeObserver(this, "handle-xul-text-link");
     os.removeObserver(this, "profile-before-change");
     if (AppConstants.MOZ_TELEMETRY_REPORTING) {
       os.removeObserver(this, "keyword-search");
     }
     os.removeObserver(this, "browser-search-engine-modified");
     os.removeObserver(this, "flash-plugin-hang");
     os.removeObserver(this, "xpi-signature-changed");
+
+    UserAgentOverrides.uninit();
   },
 
   _onAppDefaults: function BG__onAppDefaults() {
     // apply distribution customizations (prefs)
     // other customizations are applied in _finalUIStartup()
     this._distributionCustomizer.applyPrefDefaults();
   },
 
--- a/netwerk/test/mochitests/test_user_agent_overrides.html
+++ b/netwerk/test/mochitests/test_user_agent_overrides.html
@@ -226,21 +226,16 @@ function testPriority(callback) {
 function testOverrides(callback) {
   SpecialPowers.pushPrefEnv({
     set: [[PREF_OVERRIDES_ENABLED, true]]
   }, function nextTest() {
     testUA(tests.shift(), function() { tests.length ? nextTest() : callback() });
   });
 }
 
-SpecialPowers.loadChromeScript(_ => {
-  Components.utils.import("resource://gre/modules/UserAgentOverrides.jsm");
-  UserAgentOverrides.init();
-});
-
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestCompleteLog();
 SimpleTest.requestLongerTimeout(5);
 
 testOverrides(function() {
   testInactive(function() {
     testPriority(SimpleTest.finish)
   });
--- a/netwerk/test/mochitests/test_user_agent_updates.html
+++ b/netwerk/test/mochitests/test_user_agent_updates.html
@@ -195,41 +195,34 @@ function testBadUpdate(callback) {
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("Test sets timeouts to wait for updates to happen.");
 
 SpecialPowers.pushPrefEnv({
   set: [
     [PREF_APP_UPDATE_TIMERMINIMUMDELAY, 0]
   ]
 }, function () {
-  chromeScript.sendSyncMessage("UAO-uninit");
-
   // Sets the OVERRIDES var in the chrome script.
   // We do this to avoid code duplication.
   chromeScript.sendSyncMessage("set-overrides", OVERRIDES);
 
   // testProfileLoad, testDownload, and testProfileSave must run in this order
-  //  because testDownload depends on testProfileLoad to call UAO.init()
-  //  and testProfileSave depends on testDownload to save overrides to the profile
+  // because testDownload depends on testProfileLoad and testProfileSave depends
+  // on testDownload to save overrides to the profile
   chromeScript.sendAsyncMessage("testProfileLoad", location.hostname);
 });
 
 
 const chromeScript = SpecialPowers.loadChromeScript(_ => {
   // Enter update timer manager test mode
   Components.classes["@mozilla.org/updates/timer-manager;1"].getService(
     Components.interfaces.nsIObserver).observe(null, "utm-test-init", "");
 
-  Components.utils.import("resource://gre/modules/UserAgentOverrides.jsm");
-
   var _notifyOnUpdate = false;
 
-  var UAO = UserAgentOverrides;
-  UAO.uninit();
-
   Components.utils.import("resource://gre/modules/FileUtils.jsm");
   var FU = FileUtils;
 
   const { TextDecoder, TextEncoder, OS } = Components.utils.import("resource://gre/modules/osfile.jsm");
   var OSF = OS.File;
 
   const KEY_PREFDIR = "PrefD";
   const KEY_APPDIR = "XCurProcD";
@@ -313,29 +306,24 @@ const chromeScript = SpecialPowers.loadC
       }
     );
   }
 
 
   addMessageListener("testProfileSave", testProfileSave);
   addMessageListener("testProfileLoad", testProfileLoad);
   addMessageListener("set-overrides", function(overrides) { OVERRIDES = overrides});
-  addMessageListener("UAO-init", function() { UAO.init(); });
-  addMessageListener("UAO-uninit", function() { UAO.uninit(); });
   addMessageListener("notify-on-update", () => { _notifyOnUpdate = true });
 });
 
 chromeScript.addMessageListener("testProfileSaveDone", SimpleTest.finish);
 chromeScript.addMessageListener("testProfileLoadDone", function() {
   SpecialPowers.pushPrefEnv({
     set: [[PREF_UPDATES_ENABLED, true]]
   }, function () {
-    // initialize UserAgentOverrides.jsm and
-    // UserAgentUpdates.jsm and load saved file
-    chromeScript.sendSyncMessage("UAO-init");
     (function waitForLoad() {
       var ifr = document.createElement('IFRAME');
       ifr.src = location.origin;
 
       ifr.addEventListener('load', function() {
         var nav = ifr.contentWindow.navigator;
         if (nav.userAgent !== UA_ALT_OVERRIDE) {
           setTimeout(waitForLoad, 100);