michael@0: // ---------------------------------------------------------------------------- michael@0: // Test whether a request for auth for an XPI switches to the appropriate tab michael@0: var gNewTab; michael@0: michael@0: function test() { michael@0: Harness.authenticationCallback = get_auth_info; michael@0: Harness.downloadFailedCallback = download_failed; michael@0: Harness.installEndedCallback = install_ended; michael@0: Harness.installsCompletedCallback = finish_test; michael@0: Harness.setup(); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi" michael@0: })); michael@0: gNewTab = gBrowser.addTab(); michael@0: gBrowser.getBrowserForTab(gNewTab).loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: } michael@0: michael@0: function get_auth_info() { michael@0: is(gBrowser.selectedTab, gNewTab, "Should have focused the tab loading the XPI"); michael@0: return [ "testuser", "testpass" ]; michael@0: } michael@0: michael@0: function download_failed(install) { michael@0: ok(false, "Install should not have failed"); michael@0: } michael@0: michael@0: function install_ended(install, addon) { michael@0: install.cancel(); michael@0: } michael@0: michael@0: function finish_test(count) { michael@0: is(count, 1, "1 Add-on should have been successfully installed"); michael@0: var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] michael@0: .getService(Components.interfaces.nsIHttpAuthManager); michael@0: authMgr.clearAll(); michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: michael@0: gBrowser.removeTab(gNewTab); michael@0: Harness.finish(); michael@0: }