1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_auth4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +// ---------------------------------------------------------------------------- 1.5 +// Test whether a request for auth for an XPI switches to the appropriate tab 1.6 +var gNewTab; 1.7 + 1.8 +function test() { 1.9 + Harness.authenticationCallback = get_auth_info; 1.10 + Harness.downloadFailedCallback = download_failed; 1.11 + Harness.installEndedCallback = install_ended; 1.12 + Harness.installsCompletedCallback = finish_test; 1.13 + Harness.setup(); 1.14 + 1.15 + var pm = Services.perms; 1.16 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.17 + 1.18 + var triggers = encodeURIComponent(JSON.stringify({ 1.19 + "Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi" 1.20 + })); 1.21 + gNewTab = gBrowser.addTab(); 1.22 + gBrowser.getBrowserForTab(gNewTab).loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.23 +} 1.24 + 1.25 +function get_auth_info() { 1.26 + is(gBrowser.selectedTab, gNewTab, "Should have focused the tab loading the XPI"); 1.27 + return [ "testuser", "testpass" ]; 1.28 +} 1.29 + 1.30 +function download_failed(install) { 1.31 + ok(false, "Install should not have failed"); 1.32 +} 1.33 + 1.34 +function install_ended(install, addon) { 1.35 + install.cancel(); 1.36 +} 1.37 + 1.38 +function finish_test(count) { 1.39 + is(count, 1, "1 Add-on should have been successfully installed"); 1.40 + var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] 1.41 + .getService(Components.interfaces.nsIHttpAuthManager); 1.42 + authMgr.clearAll(); 1.43 + 1.44 + Services.perms.remove("example.com", "install"); 1.45 + 1.46 + gBrowser.removeTab(gNewTab); 1.47 + Harness.finish(); 1.48 +}