1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_httphash6.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +// ---------------------------------------------------------------------------- 1.5 +// Tests that a new hash is accepted when restarting a failed download 1.6 +// This verifies bug 593535 1.7 +function setup_redirect(aSettings) { 1.8 + var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=setup"; 1.9 + for (var name in aSettings) { 1.10 + url += "&" + name + "=" + aSettings[name]; 1.11 + } 1.12 + 1.13 + var req = new XMLHttpRequest(); 1.14 + req.open("GET", url, false); 1.15 + req.send(null); 1.16 +} 1.17 + 1.18 +var gInstall = null; 1.19 + 1.20 +function test() { 1.21 + Harness.downloadFailedCallback = download_failed; 1.22 + Harness.installsCompletedCallback = finish_failed_download; 1.23 + Harness.setup(); 1.24 + 1.25 + var pm = Services.perms; 1.26 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.27 + Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); 1.28 + 1.29 + // Set up the redirect to give a bad hash 1.30 + setup_redirect({ 1.31 + "X-Target-Digest": "sha1:foo", 1.32 + "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi" 1.33 + }); 1.34 + 1.35 + var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=redirect"; 1.36 + 1.37 + var triggers = encodeURIComponent(JSON.stringify({ 1.38 + "Unsigned XPI": { 1.39 + URL: url, 1.40 + toString: function() { return this.URL; } 1.41 + } 1.42 + })); 1.43 + gBrowser.selectedTab = gBrowser.addTab(); 1.44 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.45 +} 1.46 + 1.47 +function download_failed(install) { 1.48 + is(install.error, AddonManager.ERROR_INCORRECT_HASH, "Should have seen a hash failure"); 1.49 + // Stash the failed download while the harness cleans itself up 1.50 + gInstall = install; 1.51 +} 1.52 + 1.53 +function finish_failed_download() { 1.54 + // Setup to track the successful re-download 1.55 + Harness.installEndedCallback = install_ended; 1.56 + Harness.installsCompletedCallback = finish_test; 1.57 + Harness.setup(); 1.58 + 1.59 + // Give it the right hash this time 1.60 + setup_redirect({ 1.61 + "X-Target-Digest": "sha1:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f", 1.62 + "Location": "http://example.com/browser/" + RELATIVE_DIR + "unsigned.xpi" 1.63 + }); 1.64 + 1.65 + // The harness expects onNewInstall events for all installs that are about to start 1.66 + Harness.onNewInstall(gInstall); 1.67 + 1.68 + // Restart the install as a regular webpage install so the harness tracks it 1.69 + AddonManager.installAddonsFromWebpage("application/x-xpinstall", 1.70 + gBrowser.contentWindow, 1.71 + gBrowser.currentURI, [gInstall]); 1.72 +} 1.73 + 1.74 +function install_ended(install, addon) { 1.75 + install.cancel(); 1.76 +} 1.77 + 1.78 +function finish_test(count) { 1.79 + is(count, 1, "1 Add-on should have been successfully installed"); 1.80 + 1.81 + Services.perms.remove("example.com", "install"); 1.82 + Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS); 1.83 + 1.84 + gBrowser.removeCurrentTab(); 1.85 + Harness.finish(); 1.86 +}