toolkit/mozapps/extensions/test/xpinstall/browser_auth3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_auth3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,45 @@
     1.4 +// ----------------------------------------------------------------------------
     1.5 +// Test whether an install fails when authentication is required and it is
     1.6 +// canceled
     1.7 +// This verifies bug 312473
     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 +  gBrowser.selectedTab = gBrowser.addTab();
    1.22 +  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    1.23 +}
    1.24 +
    1.25 +function get_auth_info() {
    1.26 +  return null;
    1.27 +}
    1.28 +
    1.29 +function download_failed(install) {
    1.30 +  is(install.error, AddonManager.ERROR_NETWORK_FAILURE, "Install should have failed");
    1.31 +}
    1.32 +
    1.33 +function install_ended(install, addon) {
    1.34 +  ok(false, "Add-on should not have installed");
    1.35 +  install.cancel();
    1.36 +}
    1.37 +
    1.38 +function finish_test(count) {
    1.39 +  is(count, 0, "No add-ons should have been 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.removeCurrentTab();
    1.47 +  Harness.finish();
    1.48 +}

mercurial