|
1 // ---------------------------------------------------------------------------- |
|
2 // Test whether a request for auth for an XPI switches to the appropriate tab |
|
3 var gNewTab; |
|
4 |
|
5 function test() { |
|
6 Harness.authenticationCallback = get_auth_info; |
|
7 Harness.downloadFailedCallback = download_failed; |
|
8 Harness.installEndedCallback = install_ended; |
|
9 Harness.installsCompletedCallback = finish_test; |
|
10 Harness.setup(); |
|
11 |
|
12 var pm = Services.perms; |
|
13 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
14 |
|
15 var triggers = encodeURIComponent(JSON.stringify({ |
|
16 "Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi" |
|
17 })); |
|
18 gNewTab = gBrowser.addTab(); |
|
19 gBrowser.getBrowserForTab(gNewTab).loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
20 } |
|
21 |
|
22 function get_auth_info() { |
|
23 is(gBrowser.selectedTab, gNewTab, "Should have focused the tab loading the XPI"); |
|
24 return [ "testuser", "testpass" ]; |
|
25 } |
|
26 |
|
27 function download_failed(install) { |
|
28 ok(false, "Install should not have failed"); |
|
29 } |
|
30 |
|
31 function install_ended(install, addon) { |
|
32 install.cancel(); |
|
33 } |
|
34 |
|
35 function finish_test(count) { |
|
36 is(count, 1, "1 Add-on should have been successfully installed"); |
|
37 var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] |
|
38 .getService(Components.interfaces.nsIHttpAuthManager); |
|
39 authMgr.clearAll(); |
|
40 |
|
41 Services.perms.remove("example.com", "install"); |
|
42 |
|
43 gBrowser.removeTab(gNewTab); |
|
44 Harness.finish(); |
|
45 } |