toolkit/mozapps/plugins/tests/browser_bug435788.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const TEST_ROOT = "http://example.com/browser/toolkit/mozapps/plugins/tests/";
     3 let tmp = {};
     4 Components.utils.import("resource://gre/modules/AddonManager.jsm", tmp);
     5 let AddonManager = tmp.AddonManager;
     7 var gPFS;
     9 function test() {
    10   waitForExplicitFinish();
    12   prepare_test_1();
    13 }
    15 function finishTest() {
    16   Services.prefs.clearUserPref("pfs.datasource.url");
    17   finish();
    18 }
    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 }
    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 }
    37 // Gets the number of plugin results
    38 function getResultCount() {
    39   var list = gPFS.document.getElementById("pluginResultList");
    40   return list.childNodes.length;
    41 }
    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 }
    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   }
    70   info("Page shown: " +
    71        gPFS.document.documentElement.currentPage.getAttribute("label"));
    72   show_button_state("next");
    73   show_button_state("finish");
    74 }
    76 function pfs_loaded() {
    77   info("PFS loaded");
    78   var docEle = gPFS.document.documentElement;
    80   var onwizardfinish = function () {
    81     info("wizardfinish event");
    82   };
    83   var onwizardnext = function () {
    84     info("wizardnext event");
    85   };
    87   docEle.addEventListener("pageshow", page_shown, false);
    88   docEle.addEventListener("wizardfinish", onwizardfinish, false);
    89   docEle.addEventListener("wizardnext", onwizardnext, false);
    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);
    99   page_shown();
   100 }
   102 function startTest(num, missingPluginsArray) {
   103   info("Test " + num);
   105   gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
   106                            "PFSWindow", "chrome,centerscreen,resizable=yes",
   107                            {plugins: missingPluginsArray});
   109   var testScope = this;
   111   gPFS.addEventListener("load", function () {
   112     gPFS.removeEventListener("load", arguments.callee, false);
   114     pfs_loaded();
   116     var seenAvailable = false;
   117     var expectAvailable = typeof testScope["test_" + num + "_available"] == "function";
   119     function availableListener() {
   120       seenAvailable = true;
   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     }
   132     function completeListener() {
   133       if (expectAvailable)
   134         ok(seenAvailable, "Should have seen the list of available plugins");
   136       executeSoon(testScope["test_" + num + "_complete"]);
   137     }
   139     gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", availableListener);
   140     gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", completeListener);
   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);
   147       num++;
   148       if (typeof testScope["prepare_test_" + num] == "function")
   149         testScope["prepare_test_" + num]();
   150       else
   151         finishTest();
   152     });
   153   });
   154 }
   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 }
   163 // Test a working installer
   164 function prepare_test_1() {
   165   Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf");
   167   var missingPluginsArray = {
   168     "application/x-working-plugin": {
   169       mimetype: "application/x-working-plugin",
   170       pluginsPage: ""
   171     }
   172   };
   174   startTest(1, missingPluginsArray);
   175 }
   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 }
   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");
   188   clickFinish();
   189 }
   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   };
   200   startTest(2, missingPluginsArray);
   201 }
   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 }
   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");
   214   clickFinish();
   215 }
   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   };
   230   startTest(3, missingPluginsArray);
   231 }
   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 }
   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");
   248   clickFinish();
   249 }
   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   };
   260   startTest(4, missingPluginsArray);
   261 }
   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 }
   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");
   274   clickFinish();
   275 }
   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   };
   286   startTest(5, missingPluginsArray);
   287 }
   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 }
   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");
   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();
   306     clickFinish();
   307   });
   308 }
   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   };
   319   startTest(6, missingPluginsArray);
   320 }
   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 }
   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");
   333   clickFinish();
   334 }
   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   };
   349   startTest(7, missingPluginsArray);
   350 }
   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 }
   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");
   367   AddonManager.getAllInstalls(function(installs) {
   368     is(installs.length, 1, "Should be one active installs");
   369     installs[0].cancel();
   371     clickFinish();
   372   });
   373 }
   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   };
   384   startTest(8, missingPluginsArray);
   385 }
   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 }
   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");
   398   AddonManager.getAllInstalls(function(installs) {
   399     is(installs.length, 0, "Should not be any installs");
   401     clickFinish();
   402   });
   403 }
   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   };
   414   startTest(9, missingPluginsArray);
   415 }
   417 function test_9_complete() {
   418   is(getResultCount(), 0, "Should have found no plugins");
   420   clickFinish();
   421 }
   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");
   427   var missingPluginsArray = {
   428     "application/x-broken-xml": {
   429       mimetype: "application/x-broken-xml",
   430       pluginsPage: ""
   431     }
   432   };
   434   startTest(10, missingPluginsArray);
   435 }
   437 function test_10_complete() {
   438   is(getResultCount(), 0, "Should have found no plugins");
   440   clickFinish();
   441 }
   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");
   447   var missingPluginsArray = {
   448     "application/x-missing-xml": {
   449       mimetype: "application/x-missing-xml",
   450       pluginsPage: ""
   451     }
   452   };
   454   startTest(11, missingPluginsArray);
   455 }
   457 function test_11_complete() {
   458   is(getResultCount(), 0, "Should have found no plugins");
   460   clickFinish();
   461 }

mercurial