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