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

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

mercurial