michael@0: // ---------------------------------------------------------------------------- michael@0: // Tests that a new hash is accepted when restarting a failed download michael@0: // This verifies bug 593535 michael@0: function setup_redirect(aSettings) { michael@0: var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=setup"; michael@0: for (var name in aSettings) { michael@0: url += "&" + name + "=" + aSettings[name]; michael@0: } michael@0: michael@0: var req = new XMLHttpRequest(); michael@0: req.open("GET", url, false); michael@0: req.send(null); michael@0: } michael@0: michael@0: var gInstall = null; michael@0: michael@0: function test() { michael@0: Harness.downloadFailedCallback = download_failed; michael@0: Harness.installsCompletedCallback = finish_failed_download; michael@0: Harness.setup(); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); michael@0: michael@0: // Set up the redirect to give a bad hash michael@0: setup_redirect({ michael@0: "X-Target-Digest": "sha1:foo", michael@0: "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi" michael@0: }); michael@0: michael@0: var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=redirect"; michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Unsigned XPI": { michael@0: URL: url, michael@0: toString: function() { return this.URL; } michael@0: } michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: } michael@0: michael@0: function download_failed(install) { michael@0: is(install.error, AddonManager.ERROR_INCORRECT_HASH, "Should have seen a hash failure"); michael@0: // Stash the failed download while the harness cleans itself up michael@0: gInstall = install; michael@0: } michael@0: michael@0: function finish_failed_download() { michael@0: // Setup to track the successful re-download michael@0: Harness.installEndedCallback = install_ended; michael@0: Harness.installsCompletedCallback = finish_test; michael@0: Harness.setup(); michael@0: michael@0: // Give it the right hash this time michael@0: setup_redirect({ michael@0: "X-Target-Digest": "sha1:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f", michael@0: "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi" michael@0: }); michael@0: michael@0: // The harness expects onNewInstall events for all installs that are about to start michael@0: Harness.onNewInstall(gInstall); michael@0: michael@0: // Restart the install as a regular webpage install so the harness tracks it michael@0: AddonManager.installAddonsFromWebpage("application/x-xpinstall", michael@0: gBrowser.contentWindow, michael@0: gBrowser.currentURI, [gInstall]); michael@0: } michael@0: michael@0: function install_ended(install, addon) { michael@0: install.cancel(); michael@0: } michael@0: michael@0: function finish_test(count) { michael@0: is(count, 1, "1 Add-on should have been successfully installed"); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: Harness.finish(); michael@0: }