Bug 723953 - Fennec chrome scripts and tests leak global variables. r=mbrubeck

This commit is contained in:
Dão Gottwald 2012-04-06 22:02:15 +02:00
parent 8e7bf30228
commit 0dbfd85588
13 changed files with 42 additions and 82 deletions

View File

@ -42,15 +42,17 @@ 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.defineLazyGetter(this, "PlacesUtils", function() {
Cu.import("resource://gre/modules/PlacesUtils.jsm");
return PlacesUtils;
});
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
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

View File

@ -37,10 +37,6 @@
*
* ***** 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"],

View File

@ -81,8 +81,8 @@
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-ui.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/Util.js"/>
<script type="application/javascript" src="chrome://browser/content/input.js"/>

View File

@ -35,8 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
#ifdef ANDROID
const URI_GENERIC_ICON_DOWNLOAD = "drawable://alertdownloads";
#else
@ -299,7 +297,7 @@ var DownloadsView = {
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);
}
@ -308,7 +306,7 @@ var DownloadsView = {
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
@ -318,7 +316,7 @@ var DownloadsView = {
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;
@ -492,6 +490,9 @@ var DownloadsView = {
}
};
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() { }

View File

@ -49,21 +49,6 @@ const URI_GENERIC_ICON_XPINSTALL = "chrome://browser/skin/images/alert-addons-30
#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,
@ -565,18 +550,18 @@ var ExtensionsView = {
// 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);
}
},
@ -905,6 +890,9 @@ function searchFailed() {
let failButton = strings.GetStringFromName("addonsSearchFail.retryButton");
ExtensionsView.displaySectionMessage("repo", failLabel, failButton, true);
}
XPCOMUtils.defineLazyModuleGetter(ExtensionsView, "_AddonRepository",
"resource://gre/modules/AddonRepository.jsm", "AddonRepository");
///////////////////////////////////////////////////////////////////////////////
@ -914,7 +902,8 @@ var RecommendedSearchResults = {
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

View File

@ -2,11 +2,6 @@
* 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;

View File

@ -1,9 +1,9 @@
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();

View File

@ -1,6 +1,8 @@
// 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);

View File

@ -1,8 +1,9 @@
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();

View File

@ -1,8 +1,9 @@
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();

View File

@ -1,8 +1,9 @@
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();

View File

@ -43,7 +43,7 @@ let VKBObserver = {
observe: function(aTopic, aSubject, aData) {
if (this._enabled != parseInt(aData)) {
this._enabled = parseInt(aData);
VKBstateHasChanged = true;
VKBStateHasChanged = true;
}
}
};

View File

@ -96,34 +96,6 @@ Tester.prototype = {
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)