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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a2a62915df20
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,
7 * showUpdateAvailable, and showUpdateError when the app.update.silent
8 * preference is true.
9 */
10
11 function run_test() {
12 setupTestCommon();
13
14 logTestInfo("testing nsIUpdatePrompt notifications should not be seen " +
15 "when the " + PREF_APP_UPDATE_SILENT + " preference is true");
16
17 Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true);
18
19 let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
20 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
21 "Fake Window Watcher",
22 "@mozilla.org/embedcomp/window-watcher;1",
23 WindowWatcherFactory);
24
25 standardInit();
26
27 logTestInfo("testing showUpdateInstalled should not call openWindow");
28 Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, true);
29
30 gCheckFunc = check_showUpdateInstalled;
31 gUP.showUpdateInstalled();
32 // Report a successful check after the call to showUpdateInstalled since it
33 // didn't throw and otherwise it would report no tests run.
34 do_check_true(true);
35
36 logTestInfo("testing showUpdateAvailable should not call openWindow");
37 writeUpdatesToXMLFile(getLocalUpdatesXMLString(""), false);
38 let patches = getLocalPatchString(null, null, null, null, null, null,
39 STATE_FAILED);
40 let updates = getLocalUpdateString(patches);
41 writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
42 writeStatusFile(STATE_FAILED);
43 reloadUpdateManagerData();
44
45 gCheckFunc = check_showUpdateAvailable;
46 let update = gUpdateManager.activeUpdate;
47 gUP.showUpdateAvailable(update);
48 // Report a successful check after the call to showUpdateAvailable since it
49 // didn't throw and otherwise it would report no tests run.
50 do_check_true(true);
51
52 logTestInfo("testing showUpdateError should not call getNewPrompter");
53 gCheckFunc = check_showUpdateError;
54 update.errorCode = WRITE_ERROR;
55 gUP.showUpdateError(update);
56 // Report a successful check after the call to showUpdateError since it
57 // didn't throw and otherwise it would report no tests run.
58 do_check_true(true);
59
60 let registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
61 registrar.unregisterFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
62 WindowWatcherFactory);
63
64 doTestFinish();
65 }
66
67 function check_showUpdateInstalled() {
68 do_throw("showUpdateInstalled should not have called openWindow!");
69 }
70
71 function check_showUpdateAvailable() {
72 do_throw("showUpdateAvailable should not have called openWindow!");
73 }
74
75 function check_showUpdateError() {
76 do_throw("showUpdateError should not have seen getNewPrompter!");
77 }
78
79 var WindowWatcher = {
80 openWindow: function(aParent, aUrl, aName, aFeatures, aArgs) {
81 gCheckFunc();
82 },
83
84 getNewPrompter: function(aParent) {
85 gCheckFunc();
86 },
87
88 QueryInterface: function(aIID) {
89 if (aIID.equals(AUS_Ci.nsIWindowWatcher) ||
90 aIID.equals(AUS_Ci.nsISupports))
91 return this;
92
93 throw AUS_Cr.NS_ERROR_NO_INTERFACE;
94 }
95 }
96
97 var WindowWatcherFactory = {
98 createInstance: function createInstance(aOuter, aIID) {
99 if (aOuter != null)
100 throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
101 return WindowWatcher.QueryInterface(aIID);
102 }
103 };

mercurial