toolkit/mozapps/extensions/test/xpinstall/browser_httphash2.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_httphash2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +// ----------------------------------------------------------------------------
     1.5 +// Test whether an install fails when a invalid hash is included in the HTTPS
     1.6 +// request
     1.7 +// This verifies bug 591070
     1.8 +function test() {
     1.9 +  Harness.downloadFailedCallback = download_failed;
    1.10 +  Harness.installsCompletedCallback = finish_test;
    1.11 +  Harness.setup();
    1.12 +
    1.13 +  var pm = Services.perms;
    1.14 +  pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    1.15 +  Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
    1.16 +
    1.17 +  var url = "https://example.com/browser/" + RELATIVE_DIR + "hashRedirect.sjs";
    1.18 +  url += "?sha1:foobar|" + TESTROOT + "unsigned.xpi";
    1.19 +
    1.20 +  var triggers = encodeURIComponent(JSON.stringify({
    1.21 +    "Unsigned XPI": {
    1.22 +      URL: url,
    1.23 +      toString: function() { return this.URL; }
    1.24 +    }
    1.25 +  }));
    1.26 +  gBrowser.selectedTab = gBrowser.addTab();
    1.27 +  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    1.28 +}
    1.29 +
    1.30 +function download_failed(install) {
    1.31 +  is(install.error, AddonManager.ERROR_INCORRECT_HASH, "Download should fail");
    1.32 +}
    1.33 +
    1.34 +function finish_test(count) {
    1.35 +  is(count, 0, "0 Add-ons should have been successfully installed");
    1.36 +
    1.37 +  Services.perms.remove("example.com", "install");
    1.38 +  Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
    1.39 +
    1.40 +  gBrowser.removeCurrentTab();
    1.41 +  Harness.finish();
    1.42 +}

mercurial