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