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