toolkit/mozapps/update/tests/unit_aus_update/uiOnlyAllowOneWindow.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 /**
michael@0 6 * Test that nsIUpdatePrompt doesn't display UI for showUpdateInstalled and
michael@0 7 * showUpdateAvailable when there is already an application update window open.
michael@0 8 */
michael@0 9
michael@0 10 function run_test() {
michael@0 11 setupTestCommon();
michael@0 12
michael@0 13 logTestInfo("testing nsIUpdatePrompt notifications should not be seen when " +
michael@0 14 "there is already an application update window open");
michael@0 15
michael@0 16 Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, false);
michael@0 17
michael@0 18 let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
michael@0 19 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
michael@0 20 "Fake Window Watcher",
michael@0 21 "@mozilla.org/embedcomp/window-watcher;1",
michael@0 22 WindowWatcherFactory);
michael@0 23 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
michael@0 24 "Fake Window Mediator",
michael@0 25 "@mozilla.org/appshell/window-mediator;1",
michael@0 26 WindowMediatorFactory);
michael@0 27
michael@0 28 standardInit();
michael@0 29
michael@0 30 logTestInfo("testing showUpdateInstalled should not call openWindow");
michael@0 31 Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
michael@0 32
michael@0 33 gCheckFunc = check_showUpdateInstalled;
michael@0 34 gUP.showUpdateInstalled();
michael@0 35 // Report a successful check after the call to showUpdateInstalled since it
michael@0 36 // didn't throw and otherwise it would report no tests run.
michael@0 37 do_check_true(true);
michael@0 38
michael@0 39 logTestInfo("testing showUpdateAvailable should not call openWindow");
michael@0 40 writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
michael@0 41 let patches = getLocalPatchString(null, null, null, null, null, null,
michael@0 42 STATE_FAILED);
michael@0 43 let updates = getLocalUpdateString(patches);
michael@0 44 writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
michael@0 45 writeStatusFile(STATE_FAILED);
michael@0 46 reloadUpdateManagerData();
michael@0 47
michael@0 48 gCheckFunc = check_showUpdateAvailable;
michael@0 49 let update = gUpdateManager.activeUpdate;
michael@0 50 gUP.showUpdateAvailable(update);
michael@0 51 // Report a successful check after the call to showUpdateAvailable since it
michael@0 52 // didn't throw and otherwise it would report no tests run.
michael@0 53 do_check_true(true);
michael@0 54
michael@0 55 let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
michael@0 56 registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
michael@0 57 WindowWatcherFactory);
michael@0 58 registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af56}"),
michael@0 59 WindowMediatorFactory);
michael@0 60
michael@0 61 doTestFinish();
michael@0 62 }
michael@0 63
michael@0 64 function check_showUpdateInstalled() {
michael@0 65 do_throw("showUpdateInstalled should not have called openWindow!");
michael@0 66 }
michael@0 67
michael@0 68 function check_showUpdateAvailable() {
michael@0 69 do_throw("showUpdateAvailable should not have called openWindow!");
michael@0 70 }
michael@0 71
michael@0 72 var WindowWatcher = {
michael@0 73 openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
michael@0 74 gCheckFunc();
michael@0 75 },
michael@0 76
michael@0 77 QueryInterface: function(aIID) {
michael@0 78 if (aIID.equals(AUS_Ci.nsIWindowWatcher) ||
michael@0 79 aIID.equals(AUS_Ci.nsISupports))
michael@0 80 return this;
michael@0 81
michael@0 82 throw AUS_Cr.NS_ERROR_NO_INTERFACE;
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 var WindowWatcherFactory = {
michael@0 87 createInstance: function createInstance(aOuter, aIID) {
michael@0 88 if (aOuter != null)
michael@0 89 throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
michael@0 90 return WindowWatcher.QueryInterface(aIID);
michael@0 91 }
michael@0 92 };
michael@0 93
michael@0 94 var WindowMediator = {
michael@0 95 getMostRecentWindow: function(aWindowType) {
michael@0 96 return { getInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDOMWindow]) };
michael@0 97 },
michael@0 98
michael@0 99 QueryInterface: function(aIID) {
michael@0 100 if (aIID.equals(AUS_Ci.nsIWindowMediator) ||
michael@0 101 aIID.equals(AUS_Ci.nsISupports))
michael@0 102 return this;
michael@0 103
michael@0 104 throw AUS_Cr.NS_ERROR_NO_INTERFACE;
michael@0 105 }
michael@0 106 }
michael@0 107
michael@0 108 var WindowMediatorFactory = {
michael@0 109 createInstance: function createInstance(aOuter, aIID) {
michael@0 110 if (aOuter != null)
michael@0 111 throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
michael@0 112 return WindowMediator.QueryInterface(aIID);
michael@0 113 }
michael@0 114 };

mercurial