Bug 723953 - Fennec chrome scripts and tests leak global variables. r=mbrubeck
authorDão Gottwald <dao@mozilla.com>
Fri, 06 Apr 2012 22:02:15 +0200
changeset 94507 bb1eebb47fc30f69e1091b3fc4f3ceac71460da2
parent 94506 bc1ecf41f4003829824d93eb4c72c06dcb9f1f5e
child 94508 79662b6e372a61932ce555440a00d93a35311af7
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs723953
milestone14.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 723953 - Fennec chrome scripts and tests leak global variables. r=mbrubeck
mobile/xul/chrome/content/browser-scripts.js
mobile/xul/chrome/content/browser-ui.js
mobile/xul/chrome/content/browser.xul
mobile/xul/chrome/content/downloads.js
mobile/xul/chrome/content/extensions.js
mobile/xul/chrome/tests/browser_addons.js
mobile/xul/chrome/tests/browser_addons_locales.js
mobile/xul/chrome/tests/browser_contacts.js
mobile/xul/chrome/tests/browser_localerepository.js
mobile/xul/chrome/tests/browser_localerepository_buildid.js
mobile/xul/chrome/tests/browser_localerepository_pref.js
mobile/xul/chrome/tests/browser_vkb.js
testing/mochitest/browser-test.js
--- a/mobile/xul/chrome/content/browser-scripts.js
+++ b/mobile/xul/chrome/content/browser-scripts.js
@@ -37,25 +37,27 @@
  * ***** END LICENSE BLOCK ***** */
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 /**
  * Delay load some JS modules
  */
-XPCOMUtils.defineLazyGetter(this, "PluralForm", function() {
-  Cu.import("resource://gre/modules/PluralForm.jsm");
-  return PluralForm;
-});
+XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
+                                  "resource://gre/modules/PluralForm.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
 
-XPCOMUtils.defineLazyGetter(this, "PlacesUtils", function() {
-  Cu.import("resource://gre/modules/PlacesUtils.jsm");
-  return PlacesUtils;
-});
+XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
+                                  "resource://gre/modules/AddonManager.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
+                                  "resource://gre/modules/NetUtil.jsm");
 
 /* window.Rect is used by http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-Rect
  * so it is not possible to set a lazy getter for Geometry.jsm
  */
 Cu.import("resource://gre/modules/Geometry.jsm");
 
 /**
  * Delay load some objects from a common script. We only load the script once,
--- a/mobile/xul/chrome/content/browser-ui.js
+++ b/mobile/xul/chrome/content/browser-ui.js
@@ -32,20 +32,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AddonManager.jsm");
-
 [
   ["AllPagesList", "popup_autocomplete", "cmd_openLocation"],
   ["HistoryList", "history-items", "cmd_history"],
   ["BookmarkList", "bookmarks-items", "cmd_bookmarks"],
 #ifdef MOZ_SERVICES_SYNC
   ["RemoteTabsList", "remotetabs-items", "cmd_remoteTabs"]
 #endif
 ].forEach(function(aPanel) {
--- a/mobile/xul/chrome/content/browser.xul
+++ b/mobile/xul/chrome/content/browser.xul
@@ -76,18 +76,18 @@
 #endif
 #endif
         onkeypress="onDebugKeyPress(event);"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:svg="http://www.w3.org/2000/svg"
         xmlns:html="http://www.w3.org/1999/xhtml">
 
   <script type="application/javascript" src="chrome://browser/content/browser.js"/>
+  <script type="application/javascript" src="chrome://browser/content/browser-scripts.js"/>
   <script type="application/javascript" src="chrome://browser/content/browser-ui.js"/>
-  <script type="application/javascript" src="chrome://browser/content/browser-scripts.js"/>
   <script type="application/javascript" src="chrome://browser/content/Util.js"/>
   <script type="application/javascript" src="chrome://browser/content/input.js"/>
 
   <broadcasterset id="broadcasterset">
     <broadcaster id="bcast_contentShowing" disabled="false"/>
     <broadcaster id="bcast_urlbarState" mode="view" tablet_sidebar="true" persist="tablet_sidebar"/>
     <broadcaster id="bcast_uidiscovery"/>
   </broadcasterset>
--- a/mobile/xul/chrome/content/downloads.js
+++ b/mobile/xul/chrome/content/downloads.js
@@ -30,18 +30,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
-
 #ifdef ANDROID
 const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads";
 #else
 const URI_GENERIC_ICON_DOWNLOAD = "chrome://browser/skin/images/alert-downloads-30.png";
 #endif
 
 var DownloadsView = {
   _initialized: false,
@@ -294,36 +292,36 @@ var DownloadsView = {
     let strings = Strings.browser;
 
     let status = "";
 
     // Display the file size, but show "Unknown" for negative sizes
     let fileSize = Number(aItem.getAttribute("maxBytes"));
     let sizeText = strings.GetStringFromName("downloadsUnknownSize");
     if (fileSize >= 0) {
-      let [size, unit] = DownloadUtils.convertByteUnits(fileSize);
+      let [size, unit] = this._DownloadUtils.convertByteUnits(fileSize);
       sizeText = this._replaceInsert(strings.GetStringFromName("downloadsKnownSize"), 1, size);
       sizeText = this._replaceInsert(sizeText, 2, unit);
     }
 
     // Insert 1 is the download size
     status = this._replaceInsert(strings.GetStringFromName("downloadsStatus"), 1, sizeText);
 
     // Insert 2 is the eTLD + 1 or other variations of the host
-    let [displayHost, fullHost] = DownloadUtils.getURIHost(this._getReferrerOrSource(aItem));
+    let [displayHost, fullHost] = this._DownloadUtils.getURIHost(this._getReferrerOrSource(aItem));
     status = this._replaceInsert(status, 2, displayHost);
   
     // Insert 3 is the left time if download status is DOWNLOADING
     let currstate = Number(aItem.getAttribute("state"));
     if (currstate == Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING) {
       let downloadSize = Number(aItem.getAttribute("currBytes"));
       let passedTime = (Date.now() - aItem.getAttribute("startTime"))/1000;
       let totalTime = (passedTime / downloadSize) * fileSize;
       let leftTime = totalTime - passedTime;
-      let [time, lastTime] = DownloadUtils.getTimeLeft(leftTime);
+      let [time, lastTime] = this._DownloadUtils.getTimeLeft(leftTime);
 
       let stringTime = this._replaceInsert(strings.GetStringFromName("downloadsTime"), 1, time);
       status = status + " " + stringTime;
     } 
       
     aItem.setAttribute("status", status);
   },
 
@@ -487,16 +485,19 @@ var DownloadsView = {
     if (!aIID.equals(Ci.nsIObserver) &&
         !aIID.equals(Ci.nsISupportsWeakReference) &&
         !aIID.equals(Ci.nsISupports))
       throw Components.results.NS_ERROR_NO_INTERFACE;
     return this;
   }
 };
 
+XPCOMUtils.defineLazyModuleGetter(DownloadsView, "_DownloadUtils",
+                                  "resource://gre/modules/DownloadUtils.jsm", "DownloadUtils");
+
 // DownloadProgressListener is used for managing the DownloadsView UI. This listener
 // is only active if the view has been completely initialized.
 function DownloadProgressListener() { }
 
 DownloadProgressListener.prototype = {
   //////////////////////////////////////////////////////////////////////////////
   //// nsIDownloadProgressListener
   onDownloadStateChange: function dlPL_onDownloadStateChange(aState, aDownload) {
--- a/mobile/xul/chrome/content/extensions.js
+++ b/mobile/xul/chrome/content/extensions.js
@@ -44,31 +44,16 @@ const kAddonPageSize = 5;
 
 #ifdef ANDROID
 const URI_GENERIC_ICON_XPINSTALL = "drawable://alertaddons";
 #else
 const URI_GENERIC_ICON_XPINSTALL = "chrome://browser/skin/images/alert-addons-30.png";
 #endif
 const ADDONS_NOTIFICATION_NAME = "addons";
 
-XPCOMUtils.defineLazyGetter(this, "AddonManager", function() {
-  Cu.import("resource://gre/modules/AddonManager.jsm");
-  return AddonManager;
-});
-
-XPCOMUtils.defineLazyGetter(this, "AddonRepository", function() {
-  Cu.import("resource://gre/modules/AddonRepository.jsm");
-  return AddonRepository;
-});
-
-XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
-  Cu.import("resource://gre/modules/NetUtil.jsm");
-  return NetUtil;
-});
-
 var ExtensionsView = {
   _strings: {},
   _list: null,
   _localItem: null,
   _repoItem: null,
   _msg: null,
   _dloadmgr: null,
   _restartCount: 0,
@@ -560,28 +545,28 @@ var ExtensionsView = {
   },
 
   getAddonsFromRepo: function ev_getAddonsFromRepo(aTerms, aSelectFirstResult) {
     this.clearSection("repo");
 
     // Make sure we're online before attempting to load
     Util.forceOnline();
 
-    if (AddonRepository.isSearching)
-      AddonRepository.cancelSearch();
+    if (this._AddonRepository.isSearching)
+      this._AddonRepository.cancelSearch();
 
     let strings = Strings.browser;
     if (aTerms) {
       AddonSearchResults.selectFirstResult = aSelectFirstResult;
       this.displaySectionMessage("repo", strings.GetStringFromName("addonsSearchStart.label"), strings.GetStringFromName("addonsSearchStart.button"), false);
-      AddonRepository.searchAddons(aTerms, Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), AddonSearchResults);
+      this._AddonRepository.searchAddons(aTerms, Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), AddonSearchResults);
     }
     else {
       this.displaySectionMessage("repo", strings.GetStringFromName("addonsSearchStart.label"), strings.GetStringFromName("addonsSearchStart.button"), false);
-      AddonRepository.retrieveRecommendedAddons(Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), RecommendedSearchResults);
+      this._AddonRepository.retrieveRecommendedAddons(Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), RecommendedSearchResults);
     }
   },
 
   appendSearchResults: function(aAddons, aShowRating, aShowCount) {
     let urlproperties = [ "iconURL", "homepageURL" ];
     let foundItem = false;
     let appendedAddons = [];
     for (let i = 0; i < aAddons.length; i++) {
@@ -900,26 +885,30 @@ function searchFailed() {
   let strings = Strings.browser;
   let brand = Strings.brand;
 
   let failLabel = strings.formatStringFromName("addonsSearchFail.label",
                                              [brand.GetStringFromName("brandShortName")], 1);
   let failButton = strings.GetStringFromName("addonsSearchFail.retryButton");
   ExtensionsView.displaySectionMessage("repo", failLabel, failButton, true);
 }
+ 
+XPCOMUtils.defineLazyModuleGetter(ExtensionsView, "_AddonRepository",
+                                  "resource://gre/modules/AddonRepository.jsm", "AddonRepository");
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // callback for the recommended search
 var RecommendedSearchResults = {
   cache: null,
 
   searchSucceeded: function(aAddons, aAddonCount, aTotalResults) {
     this.cache = aAddons;
-    AddonRepository.searchAddons(" ", Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS), BrowseSearchResults);
+    ExtensionsView._AddonRepository.searchAddons(" ", Services.prefs.getIntPref(PREF_GETADDONS_MAXRESULTS),
+                                                 BrowseSearchResults);
   },
 
   searchFailed: searchFailed
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // callback for the browse search
 var BrowseSearchResults = {
--- a/mobile/xul/chrome/tests/browser_addons.js
+++ b/mobile/xul/chrome/tests/browser_addons.js
@@ -1,17 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-Components.utils.import("resource://gre/modules/AddonManager.jsm");
-Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
-
 const RELATIVE_DIR = "browser/mobile/chrome/tests/";
 const TESTROOT     = "http://example.com/" + RELATIVE_DIR;
 const TESTROOT2    = "http://example.org/" + RELATIVE_DIR;
 const PREF_LOGGING_ENABLED            = "extensions.logging.enabled";
 const PREF_SEARCH_MAXRESULTS          = "extensions.getAddons.maxResults";
 const CHROME_NAME                     = "mochikit";
 const PREF_AUTOUPDATE_DEFAULT         = "extensions.update.autoUpdateDefault"
 const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
--- a/mobile/xul/chrome/tests/browser_addons_locales.js
+++ b/mobile/xul/chrome/tests/browser_addons_locales.js
@@ -1,14 +1,14 @@
 var localeList = serverRoot + "locales_list.sjs";
 var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
-Components.utils.import("resource://gre/modules/AddonManager.jsm");
+let tmp = {};
+Components.utils.import("resource://gre/modules/LocaleRepository.jsm", tmp);
+let LocaleRepository = tmp.LocaleRepository;
 
 function test() {
   waitForExplicitFinish();
   runNextTest();
 }
 
 function end_test() {
   Services.prefs.clearUserPref(PREF_LOCALE_LIST);
--- a/mobile/xul/chrome/tests/browser_contacts.js
+++ b/mobile/xul/chrome/tests/browser_contacts.js
@@ -1,11 +1,13 @@
 
 // pull in the Contacts service
-Components.utils.import("resource:///modules/contacts.jsm");
+let tmp = {};
+Components.utils.import("resource:///modules/contacts.jsm", tmp);
+let Contacts = tmp.Contacts;
 
 let fac = Cc["@mozilla.org/satchel/form-autocomplete;1"].getService(Ci.nsIFormAutoComplete);
 let fh = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
 
 function test() {
   ok(Contacts, "Contacts class exists");
   for (var fname in tests) {
     tests[fname]();
--- a/mobile/xul/chrome/tests/browser_localerepository.js
+++ b/mobile/xul/chrome/tests/browser_localerepository.js
@@ -1,13 +1,14 @@
 var localeList = serverRoot + "locales_list.sjs";
 var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
+let tmp = {};
+Components.utils.import("resource://gre/modules/LocaleRepository.jsm", tmp);
+let LocaleRepository = tmp.LocaleRepository;
 
 function test() {
   waitForExplicitFinish();
   runNextTest();
 }
 
 function end_test() {
   Services.prefs.clearUserPref(PREF_LOCALE_LIST);
--- a/mobile/xul/chrome/tests/browser_localerepository_buildid.js
+++ b/mobile/xul/chrome/tests/browser_localerepository_buildid.js
@@ -1,13 +1,14 @@
 var localeList = serverRoot + "locales_list.sjs";
 var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
+let tmp = {};
+Components.utils.import("resource://gre/modules/LocaleRepository.jsm", tmp);
+let LocaleRepository = tmp.LocaleRepository;
 
 function test() {
   waitForExplicitFinish();
   runNextTest();
 }
 
 function end_test() {
   Services.prefs.clearUserPref(PREF_LOCALE_LIST);
--- a/mobile/xul/chrome/tests/browser_localerepository_pref.js
+++ b/mobile/xul/chrome/tests/browser_localerepository_pref.js
@@ -1,13 +1,14 @@
 var localeList = serverRoot + "locales_list.sjs";
 var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
+let tmp = {};
+Components.utils.import("resource://gre/modules/LocaleRepository.jsm", tmp);
+let LocaleRepository = tmp.LocaleRepository;
 
 function test() {
   waitForExplicitFinish();
   runNextTest();
 }
 
 function end_test() {
   Services.prefs.clearUserPref(PREF_LOCALE_LIST);
--- a/mobile/xul/chrome/tests/browser_vkb.js
+++ b/mobile/xul/chrome/tests/browser_vkb.js
@@ -38,17 +38,17 @@ function test() {
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 let VKBStateHasChanged = false;
 let VKBObserver = {
   _enabled: false,
   observe: function(aTopic, aSubject, aData) {
     if (this._enabled != parseInt(aData)) {
       this._enabled = parseInt(aData);
-      VKBstateHasChanged = true;
+      VKBStateHasChanged = true;
     }
   }
 };
 Services.obs.addObserver(VKBObserver, "ime-enabled-state-changed", false);
 
 function waitForVKBChange(aCallback, aState) {
   waitForAndContinue(aCallback, function() {
     if (VKBStateHasChanged) {
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -91,44 +91,16 @@ Tester.prototype = {
     if (!gConfig)
       gConfig = readConfig();
     this.repeat = gConfig.repeat;
     this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
     this._cs.registerListener(this);
     this._globalProperties = Object.keys(window);
     this._globalPropertyWhitelist = ["navigator", "constructor", "Application",
       "__SS_tabsToRestore", "__SSi", "webConsoleCommandController",
-
-      // Temporarily added to whitelist for Fennec tests:
-      "AddonUpdateChecker",
-      "PlacesAggregatedTransaction",
-      "PlacesCreateFolderTransaction",
-      "PlacesCreateBookmarkTransaction",
-      "PlacesCreateSeparatorTransaction",
-      "PlacesCreateLivemarkTransaction",
-      "PlacesMoveItemTransaction",
-      "PlacesRemoveItemTransaction",
-      "PlacesEditItemTitleTransaction",
-      "PlacesEditBookmarkURITransaction",
-      "PlacesSetItemAnnotationTransaction",
-      "PlacesSetPageAnnotationTransaction",
-      "PlacesEditBookmarkKeywordTransaction",
-      "PlacesEditBookmarkPostDataTransaction",
-      "PlacesEditLivemarkSiteURITransaction",
-      "PlacesEditLivemarkFeedURITransaction",
-      "PlacesEditItemDateAddedTransaction",
-      "PlacesEditItemLastModifiedTransaction",
-      "PlacesSortFolderByNameTransaction",
-      "PlacesTagURITransaction",
-      "PlacesUntagURITransaction",
-      "DownloadUtils",
-      "AddonRepository",
-      "LocaleRepository",
-      "Contacts",
-      "VKBstateHasChanged"
     ];
 
     if (this.tests.length)
       this.nextTest();
     else
       this.finish();
   },