toolkit/mozapps/extensions/test/xpcshell/test_bug335238.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d8e5401ecb26
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
5
6 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
7 const PREF_SELECTED_LOCALE = "general.useragent.locale";
8
9 // Disables security checking our updates which haven't been signed
10 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
11
12 const Ci = Components.interfaces;
13 const Cu = Components.utils;
14
15 Cu.import("resource://testing-common/httpd.js");
16
17 // This is the data we expect to see sent as part of the update url.
18 var EXPECTED = [
19 {
20 id: "bug335238_1@tests.mozilla.org",
21 version: "1.3.4",
22 maxAppVersion: "5",
23 status: "userEnabled",
24 appId: "xpcshell@tests.mozilla.org",
25 appVersion: "1",
26 appOs: "XPCShell",
27 appAbi: "noarch-spidermonkey",
28 locale: "en-US",
29 reqVersion: "2"
30 },
31 {
32 id: "bug335238_2@tests.mozilla.org",
33 version: "28at",
34 maxAppVersion: "7",
35 status: "userDisabled",
36 appId: "xpcshell@tests.mozilla.org",
37 appVersion: "1",
38 appOs: "XPCShell",
39 appAbi: "noarch-spidermonkey",
40 locale: "en-US",
41 reqVersion: "2"
42 },
43 {
44 id: "bug335238_3@tests.mozilla.org",
45 version: "58",
46 maxAppVersion: "*",
47 status: "userDisabled,softblocked",
48 appId: "xpcshell@tests.mozilla.org",
49 appVersion: "1",
50 appOs: "XPCShell",
51 appAbi: "noarch-spidermonkey",
52 locale: "en-US",
53 reqVersion: "2"
54 },
55 {
56 id: "bug335238_4@tests.mozilla.org",
57 version: "4",
58 maxAppVersion: "2+",
59 status: "userEnabled,blocklisted",
60 appId: "xpcshell@tests.mozilla.org",
61 appVersion: "1",
62 appOs: "XPCShell",
63 appAbi: "noarch-spidermonkey",
64 locale: "en-US",
65 reqVersion: "2"
66 }
67 ];
68
69 var ADDONS = [
70 {id: "bug335238_1@tests.mozilla.org",
71 addon: "test_bug335238_1"},
72 {id: "bug335238_2@tests.mozilla.org",
73 addon: "test_bug335238_2"},
74 {id: "bug335238_3@tests.mozilla.org",
75 addon: "test_bug335238_3"},
76 {id: "bug335238_4@tests.mozilla.org",
77 addon: "test_bug335238_4"}
78 ];
79
80 // This is a replacement for the blocklist service
81 var BlocklistService = {
82 getAddonBlocklistState: function(aAddon, aAppVersion, aToolkitVersion) {
83 if (aAddon.id == "bug335238_3@tests.mozilla.org")
84 return Ci.nsIBlocklistService.STATE_SOFTBLOCKED;
85 if (aAddon.id == "bug335238_4@tests.mozilla.org")
86 return Ci.nsIBlocklistService.STATE_BLOCKED;
87 return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
88 },
89
90 getPluginBlocklistState: function(aPlugin, aVersion, aAppVersion, aToolkitVersion) {
91 return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
92 },
93
94 isAddonBlocklisted: function(aAddon, aAppVersion, aToolkitVersion) {
95 return this.getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) ==
96 Ci.nsIBlocklistService.STATE_BLOCKED;
97 },
98
99 QueryInterface: function(iid) {
100 if (iid.equals(Ci.nsIBlocklistService)
101 || iid.equals(Ci.nsISupports))
102 return this;
103
104 throw Components.results.NS_ERROR_NO_INTERFACE;
105 }
106 };
107
108 var BlocklistServiceFactory = {
109 createInstance: function (outer, iid) {
110 if (outer != null)
111 throw Components.results.NS_ERROR_NO_AGGREGATION;
112 return BlocklistService.QueryInterface(iid);
113 }
114 };
115 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
116 registrar.registerFactory(Components.ID("{61189e7a-6b1b-44b8-ac81-f180a6105085}"), "BlocklistService",
117 "@mozilla.org/extensions/blocklist;1", BlocklistServiceFactory);
118
119 var server;
120
121 var updateListener = {
122 pendingCount: 0,
123
124 onUpdateAvailable: function(aAddon) {
125 do_throw("Should not have seen an update for " + aAddon.id);
126 },
127
128 onUpdateFinished: function() {
129 if (--this.pendingCount == 0)
130 server.stop(do_test_finished);
131 }
132 }
133
134 var requestHandler = {
135 handle: function(metadata, response)
136 {
137 var expected = EXPECTED[metadata.path.substring(1)];
138 var params = metadata.queryString.split("&");
139 do_check_eq(params.length, 10);
140 for (var k in params) {
141 var pair = params[k].split("=");
142 var name = decodeURIComponent(pair[0]);
143 var value = decodeURIComponent(pair[1]);
144 do_check_eq(expected[name], value);
145 }
146 response.setStatusLine(metadata.httpVersion, 404, "Not Found");
147 }
148 }
149
150 function run_test() {
151 do_test_pending();
152 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
153
154 server = new HttpServer();
155 server.registerPathHandler("/0", requestHandler);
156 server.registerPathHandler("/1", requestHandler);
157 server.registerPathHandler("/2", requestHandler);
158 server.registerPathHandler("/3", requestHandler);
159 server.start(4444);
160
161 Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
162 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "en-US");
163
164 startupManager();
165 installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
166
167 restartManager();
168 AddonManager.getAddonByID(ADDONS[1].id, callback_soon(function(addon) {
169 do_check_true(!(!addon));
170 addon.userDisabled = true;
171 restartManager();
172
173 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(installedItems) {
174 installedItems.forEach(function(item) {
175 updateListener.pendingCount++;
176 item.findUpdates(updateListener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
177 });
178 });
179 }));
180 });
181 }

mercurial