1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +/** 1.9 + * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled and 1.10 + * showUpdateAvailable when there is already an application update window open. 1.11 + */ 1.12 + 1.13 +function run_test() { 1.14 + setupTestCommon(); 1.15 + 1.16 + logTestInfo("testing nsIUpdatePrompt notifications should not be seen when " + 1.17 + "there is already an application update window open"); 1.18 + 1.19 + Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false); 1.20 + 1.21 + let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); 1.22 + registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.23 + "Fake Window Watcher", 1.24 + "@mozilla.org/embedcomp/window-watcher;1", 1.25 + WindowWatcherFactory); 1.26 + registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), 1.27 + "Fake Window Mediator", 1.28 + "@mozilla.org/appshell/window-mediator;1", 1.29 + WindowMediatorFactory); 1.30 + 1.31 + standardInit(); 1.32 + 1.33 + logTestInfo("testing showUpdateInstalled should not call openWindow"); 1.34 + Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true); 1.35 + 1.36 + gCheckFunc = check_showUpdateInstalled; 1.37 + gUP.showUpdateInstalled(); 1.38 + // Report a successful check after the call to showUpdateInstalled since it 1.39 + // didn't throw and otherwise it would report no tests run. 1.40 + do_check_true(true); 1.41 + 1.42 + logTestInfo("testing showUpdateAvailable should not call openWindow"); 1.43 + writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false); 1.44 + let patches = getLocalPatchString(null, null, null, null, null, null, 1.45 + STATE_FAILED); 1.46 + let updates = getLocalUpdateString(patches); 1.47 + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); 1.48 + writeStatusFile(STATE_FAILED); 1.49 + reloadUpdateManagerData(); 1.50 + 1.51 + gCheckFunc = check_showUpdateAvailable; 1.52 + let update = gUpdateManager.activeUpdate; 1.53 + gUP.showUpdateAvailable(update); 1.54 + // Report a successful check after the call to showUpdateAvailable since it 1.55 + // didn't throw and otherwise it would report no tests run. 1.56 + do_check_true(true); 1.57 + 1.58 + let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar); 1.59 + registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), 1.60 + WindowWatcherFactory); 1.61 + registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"), 1.62 + WindowMediatorFactory); 1.63 + 1.64 + doTestFinish(); 1.65 +} 1.66 + 1.67 +function check_showUpdateInstalled() { 1.68 + do_throw("showUpdateInstalled should not have called openWindow!"); 1.69 +} 1.70 + 1.71 +function check_showUpdateAvailable() { 1.72 + do_throw("showUpdateAvailable should not have called openWindow!"); 1.73 +} 1.74 + 1.75 +var WindowWatcher = { 1.76 + openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) { 1.77 + gCheckFunc(); 1.78 + }, 1.79 + 1.80 + QueryInterface: function(aIID) { 1.81 + if (aIID.equals(AUS_Ci.nsIWindowWatcher) || 1.82 + aIID.equals(AUS_Ci.nsISupports)) 1.83 + return this; 1.84 + 1.85 + throw AUS_Cr.NS_ERROR_NO_INTERFACE; 1.86 + } 1.87 +} 1.88 + 1.89 +var WindowWatcherFactory = { 1.90 + createInstance: function createInstance(aOuter, aIID) { 1.91 + if (aOuter != null) 1.92 + throw AUS_Cr.NS_ERROR_NO_AGGREGATION; 1.93 + return WindowWatcher.QueryInterface(aIID); 1.94 + } 1.95 +}; 1.96 + 1.97 +var WindowMediator = { 1.98 + getMostRecentWindow: function(aWindowType) { 1.99 + return { getInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDOMWindow]) }; 1.100 + }, 1.101 + 1.102 + QueryInterface: function(aIID) { 1.103 + if (aIID.equals(AUS_Ci.nsIWindowMediator) || 1.104 + aIID.equals(AUS_Ci.nsISupports)) 1.105 + return this; 1.106 + 1.107 + throw AUS_Cr.NS_ERROR_NO_INTERFACE; 1.108 + } 1.109 +} 1.110 + 1.111 +var WindowMediatorFactory = { 1.112 + createInstance: function createInstance(aOuter, aIID) { 1.113 + if (aOuter != null) 1.114 + throw AUS_Cr.NS_ERROR_NO_AGGREGATION; 1.115 + return WindowMediator.QueryInterface(aIID); 1.116 + } 1.117 +};