|
1 // ---------------------------------------------------------------------------- |
|
2 // Test whether an install fails when authentication is required and bad |
|
3 // credentials are given |
|
4 // This verifies bug 312473 |
|
5 function test() { |
|
6 requestLongerTimeout(2); |
|
7 Harness.authenticationCallback = get_auth_info; |
|
8 Harness.downloadFailedCallback = download_failed; |
|
9 Harness.installEndedCallback = install_ended; |
|
10 Harness.installsCompletedCallback = finish_test; |
|
11 Harness.setup(); |
|
12 |
|
13 var pm = Services.perms; |
|
14 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
15 |
|
16 var triggers = encodeURIComponent(JSON.stringify({ |
|
17 "Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi" |
|
18 })); |
|
19 gBrowser.selectedTab = gBrowser.addTab(); |
|
20 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
21 } |
|
22 |
|
23 function get_auth_info() { |
|
24 return [ "baduser", "badpass" ]; |
|
25 } |
|
26 |
|
27 function download_failed(install) { |
|
28 is(install.error, AddonManager.ERROR_NETWORK_FAILURE, "Install should have failed"); |
|
29 } |
|
30 |
|
31 function install_ended(install, addon) { |
|
32 ok(false, "Add-on should not have installed"); |
|
33 install.cancel(); |
|
34 } |
|
35 |
|
36 function finish_test(count) { |
|
37 is(count, 0, "No add-ons should have been installed"); |
|
38 var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] |
|
39 .getService(Components.interfaces.nsIHttpAuthManager); |
|
40 authMgr.clearAll(); |
|
41 |
|
42 Services.perms.remove("example.com", "install"); |
|
43 |
|
44 gBrowser.removeCurrentTab(); |
|
45 Harness.finish(); |
|
46 } |