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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // ----------------------------------------------------------------------------
     2 // Test whether an install fails when authentication is required and bad
     3 // credentials are given
     4 // This verifies bug 312473
     5 function test() {
     6   requestLongerTimeout(2);
     7   Harness.authenticationCallback = get_auth_info;
     8   Harness.downloadFailedCallback = download_failed;
     9   Harness.installEndedCallback = install_ended;
    10   Harness.installsCompletedCallback = finish_test;
    11   Harness.setup();
    13   var pm = Services.perms;
    14   pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
    16   var triggers = encodeURIComponent(JSON.stringify({
    17     "Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
    18   }));
    19   gBrowser.selectedTab = gBrowser.addTab();
    20   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
    21 }
    23 function get_auth_info() {
    24   return [ "baduser", "badpass" ];
    25 }
    27 function download_failed(install) {
    28   is(install.error, AddonManager.ERROR_NETWORK_FAILURE, "Install should have failed");
    29 }
    31 function install_ended(install, addon) {
    32   ok(false, "Add-on should not have installed");
    33   install.cancel();
    34 }
    36 function finish_test(count) {
    37   is(count, 0, "No add-ons should have been installed");
    38   var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
    39                           .getService(Components.interfaces.nsIHttpAuthManager);
    40   authMgr.clearAll();
    42   Services.perms.remove("example.com", "install");
    44   gBrowser.removeCurrentTab();
    45   Harness.finish();
    46 }

mercurial