toolkit/mozapps/extensions/test/xpinstall/browser_whitelist.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_whitelist.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +// ----------------------------------------------------------------------------
     1.5 +// Tests installing an unsigned add-on through an InstallTrigger call in web
     1.6 +// content. This should be blocked by the whitelist check.
     1.7 +// This verifies bug 252830
     1.8 +function test() {
     1.9 +  Harness.installConfirmCallback = confirm_install;
    1.10 +  Harness.installBlockedCallback = allow_blocked;
    1.11 +  Harness.installEndedCallback = install_ended;
    1.12 +  Harness.installsCompletedCallback = finish_test;
    1.13 +  Harness.setup();
    1.14 +
    1.15 +  var triggers = encodeURIComponent(JSON.stringify({
    1.16 +    "Unsigned XPI": TESTROOT + "unsigned.xpi"
    1.17 +  }));
    1.18 +  gBrowser.selectedTab = gBrowser.addTab();
    1.19 +  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    1.20 +}
    1.21 +
    1.22 +function allow_blocked(installInfo) {
    1.23 +  is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
    1.24 +  is(installInfo.originatingURI.spec, gBrowser.currentURI.spec, "Install should have been triggered by the right uri");
    1.25 +  return true;
    1.26 +}
    1.27 +
    1.28 +function confirm_install(window) {
    1.29 +  var items = window.document.getElementById("itemList").childNodes;
    1.30 +  is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
    1.31 +  is(items[0].name, "XPI Test", "Should have seen the name from the trigger list");
    1.32 +  is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
    1.33 +  is(items[0].signed, "false", "Should have listed the item as unsigned");
    1.34 +  return true;
    1.35 +}
    1.36 +
    1.37 +function install_ended(install, addon) {
    1.38 +  install.cancel();
    1.39 +}
    1.40 +
    1.41 +function finish_test(count) {
    1.42 +  is(count, 1, "1 Add-on should have been successfully installed");
    1.43 +
    1.44 +  var doc = gBrowser.contentDocument;
    1.45 +  is(doc.getElementById("return").textContent, "false", "installTrigger should seen a failure");
    1.46 +  gBrowser.removeCurrentTab();
    1.47 +  Harness.finish();
    1.48 +}
    1.49 +// ----------------------------------------------------------------------------

mercurial