toolkit/mozapps/plugins/tests/browser_bug435788.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial