michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: /** michael@0: * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled, michael@0: * showUpdateAvailable, and showUpdateError when the app.update.silent michael@0: * preference is true. michael@0: */ michael@0: michael@0: function run_test() { michael@0: setupTestCommon(); michael@0: michael@0: logTestInfo("testing nsIUpdatePrompt notifications should not be seen " + michael@0: "when the " + PREF_APP_UPDATE_SILENT + " preference is true"); michael@0: michael@0: Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); michael@0: michael@0: let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: "Fake Window Watcher", michael@0: "@mozilla.org/embedcomp/window-watcher;1", michael@0: WindowWatcherFactory); michael@0: michael@0: standardInit(); michael@0: michael@0: logTestInfo("testing showUpdateInstalled should not call openWindow"); michael@0: Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true); michael@0: michael@0: gCheckFunc = check_showUpdateInstalled; michael@0: gUP.showUpdateInstalled(); michael@0: // Report a successful check after the call to showUpdateInstalled since it michael@0: // didn't throw and otherwise it would report no tests run. michael@0: do_check_true(true); michael@0: michael@0: logTestInfo("testing showUpdateAvailable should not call openWindow"); michael@0: writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); michael@0: let patches = getLocalPatchString(null, null, null, null, null, null, michael@0: STATE_FAILED); michael@0: let updates = getLocalUpdateString(patches); michael@0: writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); michael@0: writeStatusFile(STATE_FAILED); michael@0: reloadUpdateManagerData(); michael@0: michael@0: gCheckFunc = check_showUpdateAvailable; michael@0: let update = gUpdateManager.activeUpdate; michael@0: gUP.showUpdateAvailable(update); michael@0: // Report a successful check after the call to showUpdateAvailable since it michael@0: // didn't throw and otherwise it would report no tests run. michael@0: do_check_true(true); michael@0: michael@0: logTestInfo("testing showUpdateError should not call getNewPrompter"); michael@0: gCheckFunc = check_showUpdateError; michael@0: update.errorCode = WRITE_ERROR; michael@0: gUP.showUpdateError(update); michael@0: // Report a successful check after the call to showUpdateError since it michael@0: // didn't throw and otherwise it would report no tests run. michael@0: do_check_true(true); michael@0: michael@0: let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); michael@0: registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), michael@0: WindowWatcherFactory); michael@0: michael@0: doTestFinish(); michael@0: } michael@0: michael@0: function check_showUpdateInstalled() { michael@0: do_throw("showUpdateInstalled should not have called openWindow!"); michael@0: } michael@0: michael@0: function check_showUpdateAvailable() { michael@0: do_throw("showUpdateAvailable should not have called openWindow!"); michael@0: } michael@0: michael@0: function check_showUpdateError() { michael@0: do_throw("showUpdateError should not have seen getNewPrompter!"); michael@0: } michael@0: michael@0: var WindowWatcher = { michael@0: openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) { michael@0: gCheckFunc(); michael@0: }, michael@0: michael@0: getNewPrompter: function(aParent) { michael@0: gCheckFunc(); michael@0: }, michael@0: michael@0: QueryInterface: function(aIID) { michael@0: if (aIID.equals(AUS_Ci.nsIWindowWatcher) || michael@0: aIID.equals(AUS_Ci.nsISupports)) michael@0: return this; michael@0: michael@0: throw AUS_Cr.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var WindowWatcherFactory = { michael@0: createInstance: function createInstance(aOuter, aIID) { michael@0: if (aOuter != null) michael@0: throw AUS_Cr.NS_ERROR_NO_AGGREGATION; michael@0: return WindowWatcher.QueryInterface(aIID); michael@0: } michael@0: };