toolkit/mozapps/extensions/test/xpinstall/browser_httphash6.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:da157e9109aa
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 }
9
10 var req = new XMLHttpRequest();
11 req.open("GET", url, false);
12 req.send(null);
13 }
14
15 var gInstall = null;
16
17 function test() {
18 Harness.downloadFailedCallback = download_failed;
19 Harness.installsCompletedCallback = finish_failed_download;
20 Harness.setup();
21
22 var pm = Services.perms;
23 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
24 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
25
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 });
31
32 var url = "https://example.com/browser/" + RELATIVE_DIR + "redirect.sjs?mode=redirect";
33
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 }
43
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 }
49
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();
55
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 });
61
62 // The harness expects onNewInstall events for all installs that are about to start
63 Harness.onNewInstall(gInstall);
64
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 }
70
71 function install_ended(install, addon) {
72 install.cancel();
73 }
74
75 function finish_test(count) {
76 is(count, 1, "1 Add-on should have been successfully installed");
77
78 Services.perms.remove("example.com", "install");
79 Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS);
80
81 gBrowser.removeCurrentTab();
82 Harness.finish();
83 }

mercurial