From 2cb5a25170b8705b002a24a408224446b012fada Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Mon, 30 Mar 2015 02:14:00 -0400 Subject: [PATCH] Bug 1139254 - Use MockRegistrar in toolkit/mozapps. r=Unfocused --- .../extensions/test/xpcshell/head_addons.js | 16 +-- .../test_blocklist_metadata_filters.js | 16 +-- .../test/xpcshell/test_blocklist_prefs.js | 15 +-- .../test/xpcshell/test_blocklist_regexp.js | 15 +-- .../test/xpcshell/test_blocklistchange.js | 12 +- .../test/xpcshell/test_bug335238.js | 12 +- .../test/xpcshell/test_bug393285.js | 15 +-- .../test/xpcshell/test_bug406118.js | 16 +-- .../test/xpcshell/test_bug430120.js | 12 +- .../test/xpcshell/test_bug449027.js | 25 +--- .../test/xpcshell/test_bug455906.js | 25 +--- .../test/xpcshell/test_bug514327_3.js | 26 +---- .../test/xpcshell/test_bug542391.js | 14 +-- .../test/xpcshell/test_bug594058.js | 15 +-- .../test/xpcshell/test_bug596343.js | 15 +-- .../test/xpcshell/test_duplicateplugins.js | 15 +-- .../test/xpcshell/test_metadata_update.js | 14 +-- .../test/xpcshell/test_pluginchange.js | 13 +-- .../update/tests/data/xpcshellUtilsAUS.js | 108 ++++++------------ .../downloadAndHashCheckMar.js | 12 +- .../downloadCompleteAfterPartialFailure.js | 28 ++--- .../downloadFileTooBig_gonk.js | 14 +-- .../downloadInterruptedByOfflineRetry.js | 21 ++-- .../downloadInterruptedRecovery.js | 53 ++------- .../tests/unit_aus_update/remoteUpdateXML.js | 14 +-- .../unit_aus_update/uiOnlyAllowOneWindow.js | 45 ++------ .../tests/unit_aus_update/uiSilentPref.js | 26 ++--- .../uiUnsupportedAlreadyNotified.js | 59 +++------- .../updateCheckOnLoadOnErrorStatusText.js | 8 +- .../tests/unit_aus_update/urlConstruction.js | 8 +- 30 files changed, 172 insertions(+), 515 deletions(-) diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index 4b0f68459a8f..1cf1a4187ba7 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -27,6 +27,7 @@ Components.utils.import("resource://gre/modules/Promise.jsm"); Components.utils.import("resource://gre/modules/Task.jsm"); Components.utils.import("resource://gre/modules/osfile.jsm"); Components.utils.import("resource://gre/modules/AsyncShutdown.jsm"); +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); // We need some internal bits of AddonManager let AMscope = Components.utils.import("resource://gre/modules/AddonManager.jsm"); @@ -1405,20 +1406,7 @@ if ("nsIWindowsRegKey" in AM_Ci) { } }; - var WinRegFactory = { - createInstance: function(aOuter, aIid) { - if (aOuter != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - var key = new MockWindowsRegKey(); - return key.QueryInterface(aIid); - } - }; - - var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{0478de5b-0f38-4edb-851d-4c99f1ed8eba}"), - "Mock Windows Registry Implementation", - "@mozilla.org/windows-registry-key;1", WinRegFactory); + MockRegistrar.register("@mozilla.org/windows-registry-key;1", MockWindowsRegKey); } // Get the profile directory for tests to use. diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js index 15e951bce3a1..172ae9eb25a3 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_metadata_filters.js @@ -10,6 +10,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver = new HttpServer(); testserver.start(-1); gPort = testserver.identity.primaryPort; @@ -48,20 +49,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); - +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function load_blocklist(aFile, aCallback) { Services.obs.addObserver(function() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js index 71112387b4c3..afef16d2593a 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_prefs.js @@ -15,6 +15,7 @@ XPCOMUtils.defineLazyGetter(this, "gPref", function bls_gPref() { }); Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver = new HttpServer(); testserver.start(-1); gPort = testserver.identity.primaryPort; @@ -54,19 +55,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function load_blocklist(aFile, aCallback) { Services.obs.addObserver(function() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js index d9acf7170d4b..d51c07be049b 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_regexp.js @@ -11,6 +11,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver = new HttpServer(); testserver.start(-1); gPort = testserver.identity.primaryPort; @@ -49,19 +50,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function load_blocklist(aFile, aCallback) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js index dfd86a31b793..79682f184495 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.js @@ -35,6 +35,7 @@ const Cr = Components.results; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://gre/modules/NetUtil.jsm"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); // Allow insecure updates Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false) @@ -360,13 +361,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); var InstallConfirm = { confirm: function(aWindow, aUrl, aInstalls, aInstallCount) { @@ -393,9 +388,6 @@ var InstallConfirmFactory = { }; var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); registrar.registerFactory(Components.ID("{f0863905-4dde-42e2-991c-2dc8209bc9ca}"), "Fake Install Prompt", "@mozilla.org/addons/web-install-prompt;1", InstallConfirmFactory); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js index e691bb5708ec..05173037e636 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js @@ -13,6 +13,7 @@ const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); // This is the data we expect to see sent as part of the update url. var EXPECTED = [ @@ -105,16 +106,7 @@ var BlocklistService = { } }; -var BlocklistServiceFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return BlocklistService.QueryInterface(iid); - } -}; -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService", - "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory); +MockRegistrar.register("@mozilla.org/extensions/blocklist;1", BlocklistService); var server; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js index 90cf29753301..8165b01935ce 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js @@ -8,6 +8,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver = new HttpServer(); testserver.start(-1); gPort = testserver.identity.primaryPort; @@ -61,19 +62,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function load_blocklist(aFile, aCallback) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js index 724b48dd5bf9..b885696bc1bc 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug406118.js @@ -13,6 +13,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver = new HttpServer(); testserver.start(-1); gPort = testserver.identity.primaryPort; @@ -50,20 +51,7 @@ var WindowWatcher = { } }; -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); - +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function load_blocklist(aFile, aCallback) { Services.obs.addObserver(function() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js index 74080dba9d20..583186a84449 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug430120.js @@ -14,6 +14,7 @@ const CATEGORY_UPDATE_TIMER = "update-timer"; // Get the HTTP server. Components.utils.import("resource://testing-common/httpd.js"); +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); var testserver; var gOSVersion; var gBlocklist; @@ -49,16 +50,7 @@ var timerService = { } }; -var TimerServiceFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return timerService.QueryInterface(iid); - } -}; -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "TimerService", - "@mozilla.org/updates/timer-manager;1", TimerServiceFactory); +MockRegistrar.register("@mozilla.org/updates/timer-manager;1", timerService); function failHandler(metadata, response) { do_throw("Should not have attempted to retrieve the blocklist when it is disabled"); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js index 623a6a14ac0e..a306aff65c17 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug449027.js @@ -8,6 +8,7 @@ const Ci = Components.interfaces; const Cu = Components.utils; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var ADDONS = [{ id: "test_bug449027_1@tests.mozilla.org", @@ -249,14 +250,6 @@ var PluginHost = { } } -var PluginHostFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return PluginHost.QueryInterface(iid); - } -}; - // Don't need the full interface, attempts to call other methods will just // throw which is just fine var WindowWatcher = { @@ -285,20 +278,8 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), - "Fake Plugin Host", - "@mozilla.org/plugin/host;1", PluginHostFactory); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function create_addon(addon) { var installrdf = "\n" + diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js index 9a41e827c498..7aa590d3bea2 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js @@ -11,6 +11,7 @@ const Cr = Components.results; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var gTestserver = new HttpServer(); gTestserver.start(-1); gPort = gTestserver.identity.primaryPort; @@ -132,14 +133,6 @@ var PluginHost = { } } -var PluginHostFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return PluginHost.QueryInterface(iid); - } -}; - // Don't need the full interface, attempts to call other methods will just // throw which is just fine var WindowWatcher = { @@ -168,20 +161,8 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), - "Fake Plugin Host", - "@mozilla.org/plugin/host;1", PluginHostFactory); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function create_addon(addon) { var installrdf = "\n" + diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js index 1267a877264b..7621bc546c80 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js @@ -8,6 +8,7 @@ const Cu = Components.utils; const Cr = Components.results; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); const nsIBLS = Ci.nsIBlocklistService; const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; @@ -56,14 +57,6 @@ var PluginHost = { } } -var PluginHostFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return PluginHost.QueryInterface(iid); - } -}; - // Don't need the full interface, attempts to call other methods will just // throw which is just fine var WindowWatcher = { @@ -90,21 +83,8 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), - "Fake Plugin Host", - "@mozilla.org/plugin/host;1", PluginHostFactory); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function do_update_blocklist(aDatafile, aNextPart) { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js index ceb472f98fee..a60c59fa45bc 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug542391.js @@ -15,6 +15,7 @@ const Cu = Components.utils; const Cr = Components.results; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver; const profileDir = gProfD.clone(); @@ -77,18 +78,7 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); function check_state_v1([a1, a2, a3, a4, a5, a6]) { do_check_neq(a1, null); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js index 9bbda59a8ff0..3b26c8d74f73 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug594058.js @@ -10,6 +10,8 @@ Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); // Allow the mismatch UI to show Services.prefs.setBoolPref("extensions.showMismatchUI", true); +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + const Ci = Components.interfaces; const extDir = gProfD.clone(); extDir.append("extensions"); @@ -31,18 +33,7 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); /** * Start the test by installing extensions. diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js index 96e95c5ad756..9ed033711185 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug596343.js @@ -8,6 +8,8 @@ const URI_EXTENSION_UPDATE_DIALOG = "chrome://mozapps/content/extensions/upd const PREF_EM_SHOW_MISMATCH_UI = "extensions.showMismatchUI"; const PREF_SHOWN_SELECTION_UI = "extensions.shownSelectionUI"; +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + const profileDir = gProfD.clone(); profileDir.append("extensions"); @@ -29,18 +31,7 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); // Tests that the selection UI is displayed when upgrading an existing profile function run_test() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js b/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js index bad560306aa6..ec4ec47aa233 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js @@ -2,6 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + const Ci = Components.interfaces; // This verifies that duplicate plugins are coalesced and maintain their ID @@ -84,18 +86,7 @@ var PluginHost = { } } -var PluginHostFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return PluginHost.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), - "Fake Plugin Host", - "@mozilla.org/plugin/host;1", PluginHostFactory); +MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost); var gPluginIDs = [null, null, null, null, null]; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_metadata_update.js b/toolkit/mozapps/extensions/test/xpcshell/test_metadata_update.js index a87b3f45b11e..ed74c80cbe66 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_metadata_update.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_metadata_update.js @@ -29,6 +29,7 @@ const Cu = Components.utils; const Cr = Components.results; Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); var testserver; const profileDir = gProfD.clone(); @@ -55,18 +56,7 @@ var WindowWatcher = { } } -var WindowWatcherFactory = { - createInstance: function createInstance(outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return WindowWatcher.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); +MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher); // Return Date.now() in seconds, rounded function now() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js b/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js index d3e33dac3c80..dc0f508d886d 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_pluginchange.js @@ -6,6 +6,7 @@ const LIST_UPDATED_TOPIC = "plugins-list-updated"; // We need to use the same algorithm for generating IDs for plugins var { getIDHashForString } = Components.utils.import("resource://gre/modules/addons/PluginProvider.jsm"); +var { MockRegistrar } = Components.utils.import("resource://testing-common/MockRegistrar.jsm"); function PluginTag(name, description) { this.name = name; @@ -49,17 +50,7 @@ gPluginHost = { QueryInterface: XPCOMUtils.generateQI([AM_Ci.nsIPluginHost]) }; -var PluginHostFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return gPluginHost.QueryInterface(iid); - } -}; - -var registrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar); -registrar.registerFactory(Components.ID("{aa6f9fef-cbe2-4d55-a2fa-dcf5482068b9}"), "PluginHost", - "@mozilla.org/plugin/host;1", PluginHostFactory); +MockRegistrar.register("@mozilla.org/plugin/host;1", gPluginHost); // This verifies that when the list of plugins changes the add-ons manager // correctly updates diff --git a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js index 6146ddabaedc..1289f0e57f60 100644 --- a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js +++ b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js @@ -85,12 +85,6 @@ var gTestserver; var gRegisteredServiceCleanup; -var gXHR; -var gXHRCallback; - -var gUpdatePrompt; -var gUpdatePromptCallback; - var gCheckFunc; var gResponseBody; var gResponseStatusCode = 200; @@ -831,18 +825,6 @@ function cleanupTestCommon() { // tests to fail. gAUS.observe(null, "xpcom-shutdown", ""); - if (gXHR) { - gXHRCallback = null; - - gXHR.responseXML = null; - // null out the event handlers to prevent a mFreeCount leak of 1 - gXHR.onerror = null; - gXHR.onload = null; - gXHR.onprogress = null; - - gXHR = null; - } - gTestserver = null; if (IS_UNIX) { @@ -2987,18 +2969,15 @@ function checkFilesInDirRecursive(aDir, aCallback) { * * Example of the callback function * - * function callHandleEvent() { - * gXHR.status = gExpectedStatus; - * let e = { target: gXHR }; - * gXHR.onload.handleEvent(e); + * function callHandleEvent(aXHR) { + * aXHR.status = gExpectedStatus; + * let e = { target: aXHR }; + * aXHR.onload.handleEvent(e); * } */ function overrideXHR(aCallback) { - gXHRCallback = aCallback; - gXHR = new xhr(); - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(gXHR.classID, gXHR.classDescription, - gXHR.contractID, gXHR); + Cu.import("resource://testing-common/MockRegistrar.jsm"); + MockRegistrar.register("@mozilla.org/xmlextras/xmlhttprequest;1", xhr, [aCallback]); } @@ -3012,35 +2991,41 @@ function makeHandler(aVal) { } return aVal; } -function xhr() { +function xhr(aCallback) { + this._callback = aCallback; } xhr.prototype = { overrideMimeType: function(aMimetype) { }, setRequestHeader: function(aHeader, aValue) { }, status: null, - channel: { set notificationCallbacks(aVal) { } }, + channel: { + set notificationCallbacks(aVal) { }, + QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel]) + }, _url: null, _method: null, open: function(aMethod, aUrl) { - gXHR.channel.originalURI = Services.io.newURI(aUrl, null, null); - gXHR._method = aMethod; gXHR._url = aUrl; + this.channel.originalURI = Services.io.newURI(aUrl, null, null); + this._method = aMethod; this._url = aUrl; }, responseXML: null, responseText: null, send: function(aBody) { - do_execute_soon(gXHRCallback); // Use a timeout so the XHR completes + do_execute_soon(function() { + this._callback(this); + }.bind(this)); // Use a timeout so the XHR completes }, _onprogress: null, - set onprogress(aValue) { gXHR._onprogress = makeHandler(aValue); }, - get onprogress() { return gXHR._onprogress; }, + set onprogress(aValue) { this._onprogress = makeHandler(aValue); }, + get onprogress() { return this._onprogress; }, _onerror: null, - set onerror(aValue) { gXHR._onerror = makeHandler(aValue); }, - get onerror() { return gXHR._onerror; }, + set onerror(aValue) { this._onerror = makeHandler(aValue); }, + get onerror() { return this._onerror; }, _onload: null, - set onload(aValue) { gXHR._onload = makeHandler(aValue); }, - get onload() { return gXHR._onload; }, + set onload(aValue) { this._onload = makeHandler(aValue); }, + get onload() { return this._onload; }, addEventListener: function(aEvent, aValue, aCapturing) { - eval("gXHR._on" + aEvent + " = aValue"); + eval("this._on" + aEvent + " = aValue"); }, flags: Ci.nsIClassInfo.SINGLETON, implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT, @@ -3050,15 +3035,6 @@ xhr.prototype = { aCount.value = interfaces.length; return interfaces; }, - classDescription: "XMLHttpRequest", - contractID: "@mozilla.org/xmlextras/xmlhttprequest;1", - classID: Components.ID("{c9b37f43-4278-4304-a5e0-600991ab08cb}"), - createInstance: function(aOuter, aIID) { - if (aOuter == null) { - return gXHR.QueryInterface(aIID); - } - throw Cr.NS_ERROR_NO_AGGREGATION; - }, get wrappedJSObject() { return this; }, QueryInterface: XPCOMUtils.generateQI([Ci.nsIClassInfo]) }; @@ -3071,29 +3047,28 @@ xhr.prototype = { * The callback to call if the update prompt component is called. */ function overrideUpdatePrompt(aCallback) { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - gUpdatePrompt = new UpdatePrompt(); - gUpdatePromptCallback = aCallback; - registrar.registerFactory(gUpdatePrompt.classID, gUpdatePrompt.classDescription, - gUpdatePrompt.contractID, gUpdatePrompt); + Cu.import("resource://testing-common/MockRegistrar.jsm"); + MockRegistrar.register("@mozilla.org/updates/update-prompt;1", UpdatePrompt, [aCallback]); } -function UpdatePrompt() { +function UpdatePrompt(aCallback) { + this._callback = aCallback; + let fns = ["checkForUpdates", "showUpdateAvailable", "showUpdateDownloaded", "showUpdateError", "showUpdateHistory", "showUpdateInstalled"]; fns.forEach(function(aPromptFn) { UpdatePrompt.prototype[aPromptFn] = function() { - if (!gUpdatePromptCallback) { + if (!this._callback) { return; } - let callback = gUpdatePromptCallback[aPromptFn]; + let callback = this._callback[aPromptFn]; if (!callback) { return; } - callback.apply(gUpdatePromptCallback, + callback.apply(this._callback, Array.prototype.slice.call(arguments)); } }); @@ -3108,15 +3083,6 @@ UpdatePrompt.prototype = { aCount.value = interfaces.length; return interfaces; }, - classDescription: "UpdatePrompt", - contractID: "@mozilla.org/updates/update-prompt;1", - classID: Components.ID("{8c350a15-9b90-4622-93a1-4d320308664b}"), - createInstance: function(aOuter, aIID) { - if (aOuter == null) { - return gUpdatePrompt.QueryInterface(aIID); - } - throw Cr.NS_ERROR_NO_AGGREGATION; - }, QueryInterface: XPCOMUtils.generateQI([Ci.nsIClassInfo, Ci.nsIUpdatePrompt]) }; @@ -3126,10 +3092,7 @@ const updateCheckListener = { }, onCheckComplete: function UCL_onCheckComplete(aRequest, aUpdates, aUpdateCount) { - // The mock xmlhttprequest used by tests doesn't have a real nsIRequest so - // use _url to get the url to prevent the following error: - // ReferenceError: reference to undefined property "QueryInterface" - gRequestURL = gXHR._url; + gRequestURL = aRequest.channel.originalURI.spec; gUpdateCount = aUpdateCount; gUpdates = aUpdates; debugDump("url = " + gRequestURL + ", " + @@ -3140,10 +3103,7 @@ const updateCheckListener = { }, onError: function UCL_onError(aRequest, aUpdate) { - // The mock xmlhttprequest used by tests doesn't have a real nsIRequest so - // use _url to get the url to prevent the following error: - // ReferenceError: reference to undefined property "QueryInterface" - gRequestURL = gXHR._url; + gRequestURL = aRequest.channel.originalURI.spec; gStatusCode = aRequest.status; gStatusText = aUpdate.statusText ? aUpdate.statusText : null; debugDump("url = " + gRequestURL + ", " + diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadAndHashCheckMar.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadAndHashCheckMar.js index 8ad7d99b7bbd..0a6cbfe637b4 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadAndHashCheckMar.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadAndHashCheckMar.js @@ -33,17 +33,17 @@ function finish_test() { // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { - gXHR.status = 400; - gXHR.responseText = gResponseBody; +function callHandleEvent(aXHR) { + aXHR.status = 400; + aXHR.responseText = gResponseBody; try { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); } catch(e) { } - let e = { target: gXHR }; - gXHR.onload(e); + let e = { target: aXHR }; + aXHR.onload(e); } // Helper function for testing mar downloads that have the correct size diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js index ab96935d5901..ead40ab15b49 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js @@ -2,6 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + function run_test() { setupTestCommon(); @@ -13,11 +15,12 @@ function run_test() { Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false); - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); + let windowWatcherCID = + MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", + WindowWatcher); + do_register_cleanup(() => { + MockRegistrar.unregister(windowWatcherCID); + }); standardInit(); @@ -39,12 +42,6 @@ function run_test() { prompter.showUpdateError(update); } -function end_test() { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - WindowWatcherFactory); -} - const WindowWatcher = { getNewPrompter: function(aParent) { do_check_eq(aParent, null); @@ -64,12 +61,3 @@ const WindowWatcher = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; - -const WindowWatcherFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowWatcher.QueryInterface(aIID); - } -}; diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js index e8c29b8470ba..929a511206ff 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js @@ -43,18 +43,18 @@ function run_test() { do_execute_soon(run_test_pt1); } -function xhr_pt1() { - gXHR.status = 200; - gXHR.responseText = gResponseBody; +function xhr_pt1(aXHR) { + aXHR.status = 200; + aXHR.responseText = gResponseBody; try { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); } catch (e) { - gXHR.responseXML = null; + aXHR.responseXML = null; } - let e = { target: gXHR }; - gXHR.onload(e); + let e = { target: aXHR }; + aXHR.onload(e); } function run_test_pt1() { diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedByOfflineRetry.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedByOfflineRetry.js index aca022ded0ee..36181d9d86b5 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedByOfflineRetry.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedByOfflineRetry.js @@ -16,7 +16,7 @@ function run_test() { setUpdateURLOverride(); Services.prefs.setBoolPref(PREF_APP_UPDATE_AUTO, false); - overrideXHR(null); + overrideXHR(xhr_pt1); overrideUpdatePrompt(updatePrompt); standardInit(); @@ -26,13 +26,12 @@ function run_test() { function run_test_pt1() { gResponseBody = null; gCheckFunc = check_test_pt1; - gXHRCallback = xhr_pt1; gUpdateChecker.checkForUpdates(updateCheckListener, true); } -function xhr_pt1() { - gXHR.status = Cr.NS_ERROR_OFFLINE; - gXHR.onerror({ target: gXHR }); +function xhr_pt1(aXHR) { + aXHR.status = Cr.NS_ERROR_OFFLINE; + aXHR.onerror({ target: aXHR }); } function check_test_pt1(request, update) { @@ -43,7 +42,7 @@ function check_test_pt1(request, update) { gAUS.onError(request, update); // Trigger another check by notifying the offline status observer - gXHRCallback = xhr_pt2; + overrideXHR(xhr_pt2); Services.obs.notifyObservers(gAUS, "network:offline-status-changed", "online"); } @@ -53,20 +52,20 @@ const updatePrompt = { } }; -function xhr_pt2() { +function xhr_pt2(aXHR) { let patches = getLocalPatchString(); let updates = getLocalUpdateString(patches); let responseBody = getLocalUpdatesXMLString(updates); - gXHR.status = 200; - gXHR.responseText = responseBody; + aXHR.status = 200; + aXHR.responseText = responseBody; try { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(responseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(responseBody, "application/xml"); } catch (e) { } - gXHR.onload({ target: gXHR }); + aXHR.onload({ target: aXHR }); } function check_test_pt2(update) { diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js index bd34f04417ec..5f3e21d825d7 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js @@ -5,9 +5,9 @@ /* General MAR File Download Tests */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); const INC_CONTRACT_ID = "@mozilla.org/network/incremental-download;1"; -var gIncrementalDownloadClassID, gIncOldFactory; // gIncrementalDownloadErrorType is used to loop through each of the connection // error types in the Mock incremental downloader. var gIncrementalDownloadErrorType = 0; @@ -36,23 +36,19 @@ function finish_test() { stop_httpserver(doTestFinish); } -function end_test() { - cleanupMockIncrementalDownload(); -} - // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { - gXHR.status = 400; - gXHR.responseText = gResponseBody; +function callHandleEvent(aXHR) { + aXHR.status = 400; + aXHR.responseText = gResponseBody; try { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); } catch (e) { } - let e = { target: gXHR }; - gXHR.onload(e); + let e = { target: aXHR }; + aXHR.onload(e); } // Helper function for testing mar downloads that have the correct size @@ -92,37 +88,12 @@ function setResponseBody(aHashFunction, aHashValue, aSize) { gResponseBody = getRemoteUpdatesXMLString(updates); } -const newFactory = { - createInstance: function(aOuter, aIID) { - if (aOuter) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return new IncrementalDownload().QueryInterface(aIID); - }, - lockFactory: function(aLock) { - throw Cr.NS_ERROR_NOT_IMPLEMENTED; - }, - QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]) -}; - function initMockIncrementalDownload() { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - gIncrementalDownloadClassID = registrar.contractIDToCID(INC_CONTRACT_ID); - gIncOldFactory = Cm.getClassObject(Cc[INC_CONTRACT_ID], Ci.nsIFactory); - registrar.unregisterFactory(gIncrementalDownloadClassID, gIncOldFactory); - let components = [IncrementalDownload]; - registrar.registerFactory(gIncrementalDownloadClassID, "", - INC_CONTRACT_ID, newFactory); -} - -function cleanupMockIncrementalDownload() { - if (gIncOldFactory) { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(gIncrementalDownloadClassID, newFactory); - registrar.registerFactory(gIncrementalDownloadClassID, "", - INC_CONTRACT_ID, gIncOldFactory); - } - gIncOldFactory = null; + let incrementalDownloadCID = + MockRegistrar.register(INC_CONTRACT_ID, IncrementalDownload); + do_register_cleanup(() => { + MockRegistrar.unregister(incrementalDownloadCID); + }); } /* This Mock incremental downloader is used to verify that connection diff --git a/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js b/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js index 53ed132ca2c8..09588e52be92 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js @@ -37,20 +37,20 @@ function check_test_helper_pt1() { // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { - gXHR.status = 400; - gXHR.responseText = gResponseBody; +function callHandleEvent(aXHR) { + aXHR.status = 400; + aXHR.responseText = gResponseBody; try { if (gResponseBody) { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); } } catch (e) { - gXHR.responseXML = null; + aXHR.responseXML = null; } - let e = { target: gXHR }; - gXHR.onload(e); + let e = { target: aXHR }; + aXHR.onload(e); } // update xml not found diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js b/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js index 3855a4929504..57b87fb6e945 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js @@ -2,6 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + /** * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled and * showUpdateAvailable when there is already an application update window open. @@ -15,15 +17,16 @@ function run_test() { Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false); - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), - "Fake Window Mediator", - "@mozilla.org/appshell/window-mediator;1", - WindowMediatorFactory); + let windowWatcherCID = + MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", + WindowWatcher); + let windowMediatorCID = + MockRegistrar.register("@mozilla.org/appshell/window-mediator;1", + WindowMediator); + do_register_cleanup(() => { + MockRegistrar.unregister(windowWatcherCID); + MockRegistrar.unregister(windowMediatorCID); + }); standardInit(); @@ -52,12 +55,6 @@ function run_test() { // didn't throw and otherwise it would report no tests run. do_check_true(true); - registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - WindowWatcherFactory); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), - WindowMediatorFactory); - doTestFinish(); } @@ -77,15 +74,6 @@ const WindowWatcher = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; -const WindowWatcherFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowWatcher.QueryInterface(aIID); - } -}; - const WindowMediator = { getMostRecentWindow: function(aWindowType) { return { getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow]) }; @@ -93,12 +81,3 @@ const WindowMediator = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator]) } - -const WindowMediatorFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowMediator.QueryInterface(aIID); - } -}; diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js b/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js index 071fe091d812..93b92b32fc99 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js @@ -2,6 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + /** * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled, * showUpdateAvailable, and showUpdateError when the app.update.silent @@ -16,11 +18,12 @@ function run_test() { Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); + let windowWatcherCID = + MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", + WindowWatcher); + do_register_cleanup(() => { + MockRegistrar.unregister(windowWatcherCID); + }); standardInit(); @@ -57,10 +60,6 @@ function run_test() { // didn't throw and otherwise it would report no tests run. do_check_true(true); - registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - WindowWatcherFactory); - doTestFinish(); } @@ -87,12 +86,3 @@ const WindowWatcher = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; - -const WindowWatcherFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowWatcher.QueryInterface(aIID); - } -}; diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js b/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js index b47a57cbc73d..aa77fc11e5c6 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js @@ -2,6 +2,8 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ +Components.utils.import("resource://testing-common/MockRegistrar.jsm"); + function run_test() { setupTestCommon(); @@ -15,15 +17,16 @@ function run_test() { overrideXHR(callHandleEvent); standardInit(); - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - "Fake Window Watcher", - "@mozilla.org/embedcomp/window-watcher;1", - WindowWatcherFactory); - registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), - "Fake Window Mediator", - "@mozilla.org/appshell/window-mediator;1", - WindowMediatorFactory); + let windowWatcherCID = + MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", + WindowWatcher); + let windowMediatorCID = + MockRegistrar.register("@mozilla.org/appshell/window-mediator;1", + WindowMediator); + do_register_cleanup(() => { + MockRegistrar.unregister(windowWatcherCID); + MockRegistrar.unregister(windowMediatorCID); + }); Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false); Services.prefs.setBoolPref(PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED, true); @@ -50,27 +53,19 @@ function check_test() { doTestFinish(); } -function end_test() { - let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), - WindowWatcherFactory); - registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), - WindowMediatorFactory); -} - // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { - gXHR.status = 400; - gXHR.responseText = gResponseBody; +function callHandleEvent(aXHR) { + aXHR.status = 400; + aXHR.responseText = gResponseBody; try { let parser = Cc["@mozilla.org/xmlextras/domparser;1"]. createInstance(Ci.nsIDOMParser); - gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); + aXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); } catch (e) { } - let e = { target: gXHR }; - gXHR.onload(e); + let e = { target: aXHR }; + aXHR.onload(e); } function check_showUpdateAvailable() { @@ -85,15 +80,6 @@ const WindowWatcher = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; -const WindowWatcherFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowWatcher.QueryInterface(aIID); - } -}; - const WindowMediator = { getMostRecentWindow: function(aWindowType) { return null; @@ -101,12 +87,3 @@ const WindowMediator = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator]) }; - -const WindowMediatorFactory = { - createInstance: function createInstance(aOuter, aIID) { - if (aOuter != null) { - throw Cr.NS_ERROR_NO_AGGREGATION; - } - return WindowMediator.QueryInterface(aIID); - } -}; diff --git a/toolkit/mozapps/update/tests/unit_aus_update/updateCheckOnLoadOnErrorStatusText.js b/toolkit/mozapps/update/tests/unit_aus_update/updateCheckOnLoadOnErrorStatusText.js index 9ad1d8763924..ad94d0b90ded 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/updateCheckOnLoadOnErrorStatusText.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/updateCheckOnLoadOnErrorStatusText.js @@ -27,10 +27,10 @@ function run_test() { // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { - gXHR.status = gExpectedStatusCode; - let e = { target: gXHR }; - gXHR.onload(e); +function callHandleEvent(aXHR) { + aXHR.status = gExpectedStatusCode; + var e = { target: aXHR }; + aXHR.onload(e); } // Helper functions for testing nsIUpdateCheckListener statusText diff --git a/toolkit/mozapps/update/tests/unit_aus_update/urlConstruction.js b/toolkit/mozapps/update/tests/unit_aus_update/urlConstruction.js index 206d8be92e03..f2d8e6b4cc78 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/urlConstruction.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/urlConstruction.js @@ -28,12 +28,12 @@ function run_test() { // Callback function used by the custom XMLHttpRequest implementation to // call the nsIDOMEventListener's handleEvent method for onload. -function callHandleEvent() { +function callHandleEvent(aXHR) { // The mock xmlhttprequest needs a status code to return to the consumer and // the value is not important for this test. - gXHR.status = 404; - let e = { target: gXHR }; - gXHR.onload(e); + aXHR.status = 404; + var e = { target: aXHR }; + aXHR.onload(e); } // Helper function for parsing the result from the contructed url