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
174
175
176
177
178
|
/* 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/.
*/
// Disables security checking our updates which haven't been signed
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
// Get the HTTP server.
Components.utils.import("resource://testing-common/httpd.js");
var testserver;
var next_test = null;
var gItemsNotChecked =[];
var ADDONS = [ {id: "bug324121_1@tests.mozilla.org",
addon: "test_bug324121_1",
shouldCheck: false },
{id: "bug324121_2@tests.mozilla.org",
addon: "test_bug324121_2",
shouldCheck: true },
{id: "bug324121_3@tests.mozilla.org",
addon: "test_bug324121_3",
shouldCheck: true },
{id: "bug324121_4@tests.mozilla.org",
addon: "test_bug324121_4",
shouldCheck: true },
{id: "bug324121_5@tests.mozilla.org",
addon: "test_bug324121_5",
shouldCheck: false },
{id: "bug324121_6@tests.mozilla.org",
addon: "test_bug324121_6",
shouldCheck: true },
{id: "bug324121_7@tests.mozilla.org",
addon: "test_bug324121_7",
shouldCheck: true },
{id: "bug324121_8@tests.mozilla.org",
addon: "test_bug324121_8",
shouldCheck: true },
{id: "bug324121_9@tests.mozilla.org",
addon: "test_bug324121_9",
shouldCheck: false } ];
// nsIAddonUpdateCheckListener
var updateListener = {
pendingCount: 0,
onUpdateAvailable: function onAddonUpdateEnded(aAddon) {
switch (aAddon.id) {
// add-on disabled - should not happen
case "bug324121_1@tests.mozilla.org":
// app id already compatible - should not happen
case "bug324121_5@tests.mozilla.org":
// toolkit id already compatible - should not happen
case "bug324121_9@tests.mozilla.org":
do_throw("Should not have seen an update check for " + aAddon.id);
break;
// app id incompatible update available
case "bug324121_3@tests.mozilla.org":
// update rdf not found
case "bug324121_4@tests.mozilla.org":
// toolkit id incompatible update available
case "bug324121_7@tests.mozilla.org":
// update rdf not found
case "bug324121_8@tests.mozilla.org":
do_throw("Should be no update available for " + aAddon.id);
break;
// Updates available
case "bug324121_2@tests.mozilla.org":
case "bug324121_6@tests.mozilla.org":
break;
default:
do_throw("Update check for unknown " + aAddon.id);
}
// pos should always be >= 0 so just let this throw if this fails
var pos = gItemsNotChecked.indexOf(aAddon.id);
gItemsNotChecked.splice(pos, 1);
},
onNoUpdateAvailable: function onNoUpdateAvailable(aAddon) {
switch (aAddon.id) {
// add-on disabled - should not happen
case "bug324121_1@tests.mozilla.org":
// app id already compatible - should not happen
case "bug324121_5@tests.mozilla.org":
// toolkit id already compatible - should not happen
case "bug324121_9@tests.mozilla.org":
do_throw("Should not have seen an update check for " + aAddon.id);
break;
// app id incompatible update available
case "bug324121_3@tests.mozilla.org":
// update rdf not found
case "bug324121_4@tests.mozilla.org":
// toolkit id incompatible update available
case "bug324121_7@tests.mozilla.org":
// update rdf not found
case "bug324121_8@tests.mozilla.org":
break;
// Updates available
case "bug324121_2@tests.mozilla.org":
case "bug324121_6@tests.mozilla.org":
do_throw("Should be an update available for " + aAddon.id);
break;
default:
do_throw("Update check for unknown " + aAddon.id);
}
// pos should always be >= 0 so just let this throw if this fails
var pos = gItemsNotChecked.indexOf(aAddon.id);
gItemsNotChecked.splice(pos, 1);
},
onUpdateFinished: function onUpdateFinished(aAddon) {
if (--this.pendingCount == 0)
test_complete();
}
};
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
const dataDir = do_get_file("data");
// Create and configure the HTTP server.
testserver = new HttpServer();
testserver.registerDirectory("/data/", dataDir);
testserver.start(4444);
startupManager();
installAllFiles(ADDONS.map(a => do_get_addon(a.addon)), function() {
restartManager();
AddonManager.getAddonByID(ADDONS[0].id, callback_soon(function(firstAddon) {
do_check_true(firstAddon);
firstAddon.userDisabled = true;
restartManager();
AddonManager.getAddonsByTypes(["extension"], function(installedItems) {
var items = [];
for (let addon of ADDONS) {
for (let installedItem of installedItems) {
if (addon.id != installedItem.id)
continue;
if (installedItem.userDisabled)
continue;
if (addon.shouldCheck == installedItem.isCompatibleWith("3", "3")) {
do_throw(installedItem.id + " had the wrong compatibility: " +
installedItem.isCompatibleWith("3", "3"));
}
if (addon.shouldCheck) {
gItemsNotChecked.push(addon.id);
updateListener.pendingCount++;
installedItem.findUpdates(updateListener,
AddonManager.UPDATE_WHEN_USER_REQUESTED,
"3", "3");
}
}
}
});
}));
});
}
function test_complete() {
do_check_eq(gItemsNotChecked.length, 0);
testserver.stop(do_test_finished);
}
|