From a243b79af85a55f53a35c081849ff4d9746d0e66 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Fri, 27 Feb 2015 14:51:19 -0800 Subject: [PATCH] 4. Use XPCOMUtils for Bug 1136358 - Preprocessing and file includes make it difficult to debug app update tests. r=spohl --- .../update/tests/data/xpcshellUtilsAUS.js | 63 ++++--------------- .../downloadCompleteAfterPartialFailure.js | 8 +-- .../downloadFileTooBig_gonk.js | 33 +++++----- .../downloadInterruptedRecovery.js | 2 +- .../unit_aus_update/uiOnlyAllowOneWindow.js | 16 +---- .../tests/unit_aus_update/uiSilentPref.js | 8 +-- .../uiUnsupportedAlreadyNotified.js | 16 +---- .../consumerNotifications.js | 54 ++++++++-------- 8 files changed, 63 insertions(+), 137 deletions(-) diff --git a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js index dd09b080edf..b66e2c40336 100644 --- a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js +++ b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js @@ -3061,14 +3061,8 @@ xhr.prototype = { } throw Cr.NS_ERROR_NO_AGGREGATION; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIClassInfo) || - aIID.equals(Ci.nsISupports)) { - return gXHR; - } - throw Cr.NS_ERROR_NO_INTERFACE; - }, - get wrappedJSObject() { return this; } + get wrappedJSObject() { return this; }, + QueryInterface: XPCOMUtils.generateQI([Ci.nsIClassInfo]) }; /** @@ -3125,14 +3119,7 @@ UpdatePrompt.prototype = { } throw Cr.NS_ERROR_NO_AGGREGATION; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIClassInfo) || - aIID.equals(Ci.nsIUpdatePrompt) || - aIID.equals(Ci.nsISupports)) { - return gUpdatePrompt; - } - throw Cr.NS_ERROR_NO_INTERFACE; - }, + QueryInterface: XPCOMUtils.generateQI([Ci.nsIClassInfo, Ci.nsIUpdatePrompt]) }; /* Update check listener */ @@ -3164,13 +3151,7 @@ const updateCheckListener = { do_execute_soon(gCheckFunc.bind(null, aRequest, aUpdate)); }, - QueryInterface: function(aIID) { - if (!aIID.equals(Ci.nsIUpdateCheckListener) && - !aIID.equals(Ci.nsISupports)) { - throw Cr.NS_ERROR_NO_INTERFACE; - } - return this; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdateCheckListener]) }; /* Update download listener - nsIRequestObserver */ @@ -3190,14 +3171,8 @@ const downloadListener = { do_execute_soon(gCheckFunc); }, - QueryInterface: function DL_QueryInterface(aIID) { - if (!aIID.equals(Ci.nsIRequestObserver) && - !aIID.equals(Ci.nsIProgressEventSink) && - !aIID.equals(Ci.nsISupports)) { - throw Cr.NS_ERROR_NO_INTERFACE; - } - return this; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIRequestObserver, + Ci.nsIProgressEventSink]) }; /** @@ -3247,6 +3222,10 @@ function stop_httpserver(aCallback) { function createAppInfo(aID, aName, aVersion, aPlatformVersion) { const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"); + let ifaces = [Ci.nsIXULAppInfo, Ci.nsIXULRuntime]; + if (IS_WIN) { + ifaces.push(Ci.nsIWinAppHelper); + } const XULAppInfo = { vendor: APP_INFO_VENDOR, name: aName, @@ -3260,21 +3239,11 @@ function createAppInfo(aID, aName, aVersion, aPlatformVersion) { OS: "XPCShell", XPCOMABI: "noarch-spidermonkey", - QueryInterface: function QueryInterface(aIID) { - if (aIID.equals(Ci.nsIXULAppInfo) || - aIID.equals(Ci.nsIXULRuntime) || - aIID.equals(Ci.nsISupports)) { - return this; - } - if (IS_WIN && aIID.equals(Ci.nsIWinAppHelper)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI(ifaces) }; const XULAppInfoFactory = { - createInstance: function (aOuter, aIID) { + createInstance: function(aOuter, aIID) { if (aOuter == null) { return XULAppInfo.QueryInterface(aIID); } @@ -3400,13 +3369,7 @@ function adjustGeneralPaths() { } return null; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIDirectoryServiceProvider) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]) }; let ds = Services.dirsvc.QueryInterface(Ci.nsIDirectoryService); ds.QueryInterface(Ci.nsIProperties).undefine(NS_GRE_DIR); diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js index 73328a44820..e6eee6e4c38 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadCompleteAfterPartialFailure.js @@ -62,13 +62,7 @@ const WindowWatcher = { }; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowWatcher) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; const WindowWatcherFactory = { 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 2d12b05722b..bd542737255 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js @@ -10,21 +10,6 @@ let gDirService; let gDirProvider; let gOldProviders; -function FakeDirProvider() {} -FakeDirProvider.prototype = { - classID: Components.ID("{f30b43a7-2bfa-4e5f-8c4f-abc7dd4ac486}"), - QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]), - - getFile: function(prop, persistent) { - if (prop == KEY_UPDATE_ARCHIVE_DIR) { - if (gActiveUpdate) { - gActiveUpdate.errorCode = Cr.NS_ERROR_FILE_TOO_BIG; - } - } - return null; - } -}; - function run_test() { setupTestCommon(); @@ -49,7 +34,7 @@ function run_test() { gDirService = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties); - gOldProviders.forEach(function (p) { + gOldProviders.forEach(function(p) { gDirService.unregisterProvider(p); }); gDirService.registerProvider(gDirProvider); @@ -99,10 +84,24 @@ function check_test_pt1() { function end_test() { gDirService.unregisterProvider(gDirProvider); - gOldProviders.forEach(function (p) { + gOldProviders.forEach(function(p) { gDirService.registerProvider(p); }); gActiveUpdate = null; gDirService = null; gDirProvider = null; } + +function FakeDirProvider() {} +FakeDirProvider.prototype = { + getFile: function(prop, persistent) { + if (prop == KEY_UPDATE_ARCHIVE_DIR) { + if (gActiveUpdate) { + gActiveUpdate.errorCode = Cr.NS_ERROR_FILE_TOO_BIG; + } + } + return null; + }, + classID: Components.ID("{f30b43a7-2bfa-4e5f-8c4f-abc7dd4ac486}"), + QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]) +}; diff --git a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js index 1b78da237c7..8570cd3e145 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/downloadInterruptedRecovery.js @@ -240,7 +240,7 @@ IncrementalDownload.prototype = { get status() { return this._status; }, - QueryInterface: XPCOMUtils.generateQI([Ci.nsIIncrementalDownload]), + QueryInterface: XPCOMUtils.generateQI([Ci.nsIIncrementalDownload]) }; // Test disconnecting during an update diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js b/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js index 3a9ca915b18..6a01875f2be 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js @@ -74,13 +74,7 @@ const WindowWatcher = { gCheckFunc(); }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowWatcher) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; const WindowWatcherFactory = { @@ -97,13 +91,7 @@ const WindowMediator = { return { getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow]) }; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowMediator) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator]) } const WindowMediatorFactory = { diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js b/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js index 7cb7e2e72ae..eb55cf6e1f4 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiSilentPref.js @@ -85,13 +85,7 @@ const WindowWatcher = { gCheckFunc(); }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowWatcher) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; const WindowWatcherFactory = { diff --git a/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js b/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js index 88930530270..e29c6a3f4b7 100644 --- a/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiUnsupportedAlreadyNotified.js @@ -82,13 +82,7 @@ const WindowWatcher = { check_showUpdateAvailable(); }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowWatcher) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowWatcher]) }; const WindowWatcherFactory = { @@ -105,13 +99,7 @@ const WindowMediator = { return null; }, - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIWindowMediator) || - aIID.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediator]) }; const WindowMediatorFactory = { diff --git a/toolkit/mozapps/update/tests/unit_timermanager/consumerNotifications.js b/toolkit/mozapps/update/tests/unit_timermanager/consumerNotifications.js index 6c665b275af..6a3f7b5b803 100644 --- a/toolkit/mozapps/update/tests/unit_timermanager/consumerNotifications.js +++ b/toolkit/mozapps/update/tests/unit_timermanager/consumerNotifications.js @@ -314,9 +314,9 @@ const gTest1TimerCallback = { }; const gTest1Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest1TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest1TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -330,9 +330,9 @@ const gTest2TimerCallback = { }; const gTest2Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest2TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest2TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -346,9 +346,9 @@ const gTest3TimerCallback = { }; const gTest3Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest3TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest3TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -359,9 +359,9 @@ const gTest4TimerCallback = { }; const gTest4Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest4TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest4TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -377,9 +377,9 @@ const gTest5TimerCallback = { }; const gTest5Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest5TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest5TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -395,9 +395,9 @@ const gTest6TimerCallback = { }; const gTest6Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest6TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest6TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -413,9 +413,9 @@ const gTest7TimerCallback = { }; const gTest7Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest7TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest7TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -433,9 +433,9 @@ const gTest8TimerCallback = { }; const gTest8Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest8TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest8TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; } @@ -453,9 +453,9 @@ const gTest9TimerCallback = { }; const gTest9Factory = { - createInstance: function (outer, iid) { - if (outer == null) { - return gTest9TimerCallback.QueryInterface(iid); + createInstance: function(aOuter, aIID) { + if (aOuter == null) { + return gTest9TimerCallback.QueryInterface(aIID); } throw Cr.NS_ERROR_NO_AGGREGATION; }