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