toolkit/mozapps/extensions/test/xpinstall/browser_httphash6.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 // ----------------------------------------------------------------------------
     2 // Tests that a new hash is accepted when restarting a failed download
     3 // This verifies bug 593535
     4 function setup_redirect(aSettings) {
     5   var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=setup";
     6   for (var name in aSettings) {
     7     url += "&" + name + "=" + aSettings[name];
     8   }
    10   var req = new XMLHttpRequest();
    11   req.open("GET", url, false);
    12   req.send(null);
    13 }
    15 var gInstall = null;
    17 function test() {
    18   Harness.downloadFailedCallback = download_failed;
    19   Harness.installsCompletedCallback = finish_failed_download;
    20   Harness.setup();
    22   var pm = Services.perms;
    23   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    24   Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
    26   // Set up the redirect to give a bad hash
    27   setup_redirect({
    28     "X-Target-Digest": "sha1:foo",
    29     "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi"
    30   });
    32   var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=redirect";
    34   var triggers = encodeURIComponent(JSON.stringify({
    35     "Unsigned XPI": {
    36       URL: url,
    37       toString: function() { return this.URL; }
    38     }
    39   }));
    40   gBrowser.selectedTab = gBrowser.addTab();
    41   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    42 }
    44 function download_failed(install) {
    45   is(install.error, AddonManager.ERROR_INCORRECT_HASH, "Should have seen a hash failure");
    46   // Stash the failed download while the harness cleans itself up
    47   gInstall = install;
    48 }
    50 function finish_failed_download() {
    51   // Setup to track the successful re-download
    52   Harness.installEndedCallback = install_ended;
    53   Harness.installsCompletedCallback = finish_test;
    54   Harness.setup();
    56   // Give it the right hash this time
    57   setup_redirect({
    58     "X-Target-Digest": "sha1:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f",
    59     "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi"
    60   });
    62   // The harness expects onNewInstall events for all installs that are about to start
    63   Harness.onNewInstall(gInstall);
    65   // Restart the install as a regular webpage install so the harness tracks it
    66   AddonManager.installAddonsFromWebpage("application/x-xpinstall",
    67                                         gBrowser.contentWindow,
    68                                         gBrowser.currentURI, [gInstall]);
    69 }
    71 function install_ended(install, addon) {
    72   install.cancel();
    73 }
    75 function finish_test(count) {
    76   is(count, 1, "1 Add-on should have been successfully installed");
    78   Services.perms.remove("example.com", "install");
    79   Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
    81   gBrowser.removeCurrentTab();
    82   Harness.finish();
    83 }

mercurial