toolkit/mozapps/plugins/tests/browser_bug435788.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:888ccf08963d
1 const TEST_ROOT = "http://example.com/browser/toolkit/mozapps/plugins/tests/";
2
3 let tmp = {};
4 Components.utils.import("resource://gre/modules/AddonManager.jsm", tmp);
5 let AddonManager = tmp.AddonManager;
6
7 var gPFS;
8
9 function test() {
10 waitForExplicitFinish();
11
12 prepare_test_1();
13 }
14
15 function finishTest() {
16 Services.prefs.clearUserPref("pfs.datasource.url");
17 finish();
18 }
19
20 // Gets the number of plugin items in the detected list
21 function getListCount() {
22 var list = gPFS.document.getElementById("pluginList");
23 return list.childNodes.length;
24 }
25
26 // Gets wether the list contains a particular plugin name
27 function hasListItem(name, version) {
28 var label = name + " " + (version ? version : "");
29 var list = gPFS.document.getElementById("pluginList");
30 for (var i = 0; i < list.childNodes.length; i++) {
31 if (list.childNodes[i].label == label)
32 return true;
33 }
34 return false;
35 }
36
37 // Gets the number of plugin results
38 function getResultCount() {
39 var list = gPFS.document.getElementById("pluginResultList");
40 return list.childNodes.length;
41 }
42
43 // Gets the plugin result for a particular plugin name
44 function getResultItem(name, version) {
45 var label = name + " " + (version ? version : "");
46 var list = gPFS.document.getElementById("pluginResultList");
47 for (var i = 0; i < list.childNodes.length; i++) {
48 if (list.childNodes[i].childNodes[1].value == label) {
49 var item = {
50 name: name,
51 version: version,
52 status: null
53 };
54 if (list.childNodes[i].childNodes[2].tagName == "label")
55 item.status = list.childNodes[i].childNodes[2].value;
56 return item;
57 }
58 }
59 return null;
60 }
61
62 // Logs the currently displaying wizard page
63 function page_shown() {
64 function show_button_state(name) {
65 var button = gPFS.document.documentElement.getButton(name);
66 info("Button " + name + ". hidden: " + button.hidden +
67 ", disabled: " + button.disabled);
68 }
69
70 info("Page shown: " +
71 gPFS.document.documentElement.currentPage.getAttribute("label"));
72 show_button_state("next");
73 show_button_state("finish");
74 }
75
76 function pfs_loaded() {
77 info("PFS loaded");
78 var docEle = gPFS.document.documentElement;
79
80 var onwizardfinish = function () {
81 info("wizardfinish event");
82 };
83 var onwizardnext = function () {
84 info("wizardnext event");
85 };
86
87 docEle.addEventListener("pageshow", page_shown, false);
88 docEle.addEventListener("wizardfinish", onwizardfinish, false);
89 docEle.addEventListener("wizardnext", onwizardnext, false);
90
91 gPFS.addEventListener("unload", function() {
92 info("unload event");
93 gPFS.removeEventListener("unload", arguments.callee, false);
94 docEle.removeEventListener("pageshow", page_shown, false);
95 docEle.removeEventListener("wizardfinish", onwizardfinish, false);
96 docEle.removeEventListener("wizardnext", onwizardnext, false);
97 }, false);
98
99 page_shown();
100 }
101
102 function startTest(num, missingPluginsArray) {
103 info("Test " + num);
104
105 gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
106 "PFSWindow", "chrome,centerscreen,resizable=yes",
107 {plugins: missingPluginsArray});
108
109 var testScope = this;
110
111 gPFS.addEventListener("load", function () {
112 gPFS.removeEventListener("load", arguments.callee, false);
113
114 pfs_loaded();
115
116 var seenAvailable = false;
117 var expectAvailable = typeof testScope["test_" + num + "_available"] == "function";
118
119 function availableListener() {
120 seenAvailable = true;
121
122 if (expectAvailable) {
123 executeSoon(function () {
124 testScope["test_" + num + "_available"]();
125 gPFS.document.documentElement.getButton("next").click();
126 });
127 } else {
128 ok(false, "Should not have found plugins to install");
129 }
130 }
131
132 function completeListener() {
133 if (expectAvailable)
134 ok(seenAvailable, "Should have seen the list of available plugins");
135
136 executeSoon(testScope["test_" + num + "_complete"]);
137 }
138
139 gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", availableListener);
140 gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", completeListener);
141
142 gPFS.addEventListener("unload", function () {
143 gPFS.removeEventListener("unload", arguments.callee, false);
144 gPFS.document.documentElement.wizardPages[1].removeEventListener("pageshow", availableListener, false);
145 gPFS.document.documentElement.wizardPages[4].removeEventListener("pageshow", completeListener, false);
146
147 num++;
148 if (typeof testScope["prepare_test_" + num] == "function")
149 testScope["prepare_test_" + num]();
150 else
151 finishTest();
152 });
153 });
154 }
155
156 function clickFinish() {
157 var finish = gPFS.document.documentElement.getButton("finish");
158 ok(!finish.hidden, "Finish button should not be hidden");
159 ok(!finish.disabled, "Finish button should not be disabled");
160 finish.click();
161 }
162
163 // Test a working installer
164 function prepare_test_1() {
165 Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf");
166
167 var missingPluginsArray = {
168 "application/x-working-plugin": {
169 mimetype: "application/x-working-plugin",
170 pluginsPage: ""
171 }
172 };
173
174 startTest(1, missingPluginsArray);
175 }
176
177 function test_1_available() {
178 is(getListCount(), 1, "Should have found 1 plugin to install");
179 ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name");
180 }
181
182 function test_1_complete() {
183 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
184 var item = getResultItem("Test plugin 1", null);
185 ok(item, "Should have seen the installed item");
186 is(item.status, "Installed", "Should have been a successful install");
187
188 clickFinish();
189 }
190
191 // Test a broken installer (returns exit code 1)
192 function prepare_test_2() {
193 var missingPluginsArray = {
194 "application/x-broken-installer": {
195 mimetype: "application/x-broken-installer",
196 pluginsPage: ""
197 }
198 };
199
200 startTest(2, missingPluginsArray);
201 }
202
203 function test_2_available() {
204 is(getListCount(), 1, "Should have found 1 plugin to install");
205 ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name");
206 }
207
208 function test_2_complete() {
209 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
210 var item = getResultItem("Test plugin 2", null);
211 ok(item, "Should have seen the installed item");
212 is(item.status, "Failed", "Should have been a failed install");
213
214 clickFinish();
215 }
216
217 // Test both working and broken together
218 function prepare_test_3() {
219 var missingPluginsArray = {
220 "application/x-working-plugin": {
221 mimetype: "application/x-working-plugin",
222 pluginsPage: ""
223 },
224 "application/x-broken-installer": {
225 mimetype: "application/x-broken-installer",
226 pluginsPage: ""
227 }
228 };
229
230 startTest(3, missingPluginsArray);
231 }
232
233 function test_3_available() {
234 is(getListCount(), 2, "Should have found 2 plugins to install");
235 ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name");
236 ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name");
237 }
238
239 function test_3_complete() {
240 is(getResultCount(), 2, "Should have attempted to install 2 plugins");
241 var item = getResultItem("Test plugin 1", null);
242 ok(item, "Should have seen the installed item");
243 is(item.status, "Installed", "Should have been a successful install");
244 item = getResultItem("Test plugin 2", null);
245 ok(item, "Should have seen the installed item");
246 is(item.status, "Failed", "Should have been a failed install");
247
248 clickFinish();
249 }
250
251 // Test an installer with a bad hash
252 function prepare_test_4() {
253 var missingPluginsArray = {
254 "application/x-broken-plugin-hash": {
255 mimetype: "application/x-broken-plugin-hash",
256 pluginsPage: ""
257 }
258 };
259
260 startTest(4, missingPluginsArray);
261 }
262
263 function test_4_available() {
264 is(getListCount(), 1, "Should have found 1 plugin to install");
265 ok(hasListItem("Test plugin 3", null), "Should have seen the right plugin name");
266 }
267
268 function test_4_complete() {
269 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
270 var item = getResultItem("Test plugin 3", null);
271 ok(item, "Should have seen the installed item");
272 is(item.status, "Failed", "Should have not been a successful install");
273
274 clickFinish();
275 }
276
277 // Test a working xpi
278 function prepare_test_5() {
279 var missingPluginsArray = {
280 "application/x-working-extension": {
281 mimetype: "application/x-working-extension",
282 pluginsPage: ""
283 }
284 };
285
286 startTest(5, missingPluginsArray);
287 }
288
289 function test_5_available() {
290 is(getListCount(), 1, "Should have found 1 plugin to install");
291 ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name");
292 }
293
294 function test_5_complete() {
295 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
296 var item = getResultItem("Test extension 1", null);
297 ok(item, "Should have seen the installed item");
298 is(item.status, "Installed", "Should have been a successful install");
299
300 AddonManager.getAllInstalls(function(installs) {
301 is(installs.length, 1, "Should be just one install");
302 is(installs[0].state, AddonManager.STATE_INSTALLED, "Should be fully installed");
303 is(installs[0].addon.id, "bug435788_1@tests.mozilla.org", "Should have installed the extension");
304 installs[0].cancel();
305
306 clickFinish();
307 });
308 }
309
310 // Test a broke xpi (no install.rdf)
311 function prepare_test_6() {
312 var missingPluginsArray = {
313 "application/x-broken-extension": {
314 mimetype: "application/x-broken-extension",
315 pluginsPage: ""
316 }
317 };
318
319 startTest(6, missingPluginsArray);
320 }
321
322 function test_6_available() {
323 is(getListCount(), 1, "Should have found 1 plugin to install");
324 ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name");
325 }
326
327 function test_6_complete() {
328 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
329 var item = getResultItem("Test extension 2", null);
330 ok(item, "Should have seen the installed item");
331 is(item.status, "Failed", "Should have been a failed install");
332
333 clickFinish();
334 }
335
336 // Test both working and broken xpi
337 function prepare_test_7() {
338 var missingPluginsArray = {
339 "application/x-working-extension": {
340 mimetype: "application/x-working-extension",
341 pluginsPage: ""
342 },
343 "application/x-broken-extension": {
344 mimetype: "application/x-broken-extension",
345 pluginsPage: ""
346 }
347 };
348
349 startTest(7, missingPluginsArray);
350 }
351
352 function test_7_available() {
353 is(getListCount(), 2, "Should have found 2 plugins to install");
354 ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name");
355 ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name");
356 }
357
358 function test_7_complete() {
359 is(getResultCount(), 2, "Should have attempted to install 2 plugins");
360 var item = getResultItem("Test extension 1", null);
361 ok(item, "Should have seen the installed item");
362 is(item.status, "Installed", "Should have been a failed install");
363 item = getResultItem("Test extension 2", null);
364 ok(item, "Should have seen the installed item");
365 is(item.status, "Failed", "Should have been a failed install");
366
367 AddonManager.getAllInstalls(function(installs) {
368 is(installs.length, 1, "Should be one active installs");
369 installs[0].cancel();
370
371 clickFinish();
372 });
373 }
374
375 // Test an xpi with a bad hash
376 function prepare_test_8() {
377 var missingPluginsArray = {
378 "application/x-broken-extension-hash": {
379 mimetype: "application/x-broken-extension-hash",
380 pluginsPage: ""
381 }
382 };
383
384 startTest(8, missingPluginsArray);
385 }
386
387 function test_8_available() {
388 is(getListCount(), 1, "Should have found 1 plugin to install");
389 ok(hasListItem("Test extension 3", null), "Should have seen the right plugin name");
390 }
391
392 function test_8_complete() {
393 is(getResultCount(), 1, "Should have attempted to install 1 plugin");
394 var item = getResultItem("Test extension 3", null);
395 ok(item, "Should have seen the installed item");
396 is(item.status, "Failed", "Should have not been a successful install");
397
398 AddonManager.getAllInstalls(function(installs) {
399 is(installs.length, 0, "Should not be any installs");
400
401 clickFinish();
402 });
403 }
404
405 // Test when no plugin exists in the datasource
406 function prepare_test_9() {
407 var missingPluginsArray = {
408 "application/x-unknown-plugin": {
409 mimetype: "application/x-unknown-plugin",
410 pluginsPage: ""
411 }
412 };
413
414 startTest(9, missingPluginsArray);
415 }
416
417 function test_9_complete() {
418 is(getResultCount(), 0, "Should have found no plugins");
419
420 clickFinish();
421 }
422
423 // Test when the datasource is invalid xml
424 function prepare_test_10() {
425 Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_2.rdf");
426
427 var missingPluginsArray = {
428 "application/x-broken-xml": {
429 mimetype: "application/x-broken-xml",
430 pluginsPage: ""
431 }
432 };
433
434 startTest(10, missingPluginsArray);
435 }
436
437 function test_10_complete() {
438 is(getResultCount(), 0, "Should have found no plugins");
439
440 clickFinish();
441 }
442
443 // Test when no datasource is returned
444 function prepare_test_11() {
445 Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_foo.rdf");
446
447 var missingPluginsArray = {
448 "application/x-missing-xml": {
449 mimetype: "application/x-missing-xml",
450 pluginsPage: ""
451 }
452 };
453
454 startTest(11, missingPluginsArray);
455 }
456
457 function test_11_complete() {
458 is(getResultCount(), 0, "Should have found no plugins");
459
460 clickFinish();
461 }

mercurial