toolkit/components/passwordmgr/test/test_prompt.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/passwordmgr/test/test_prompt.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1109 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for Login Manager</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>  
     1.9 +  <script type="text/javascript" src="pwmgr_common.js"></script>
    1.10 +  <script type="text/javascript" src="prompt_common.js"></script>
    1.11 +  <script type="text/javascript" src="notification_common.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +Login Manager test: username/password prompts
    1.16 +<p id="display"></p>
    1.17 +
    1.18 +<div id="content" style="display: none">
    1.19 +  <iframe id="iframe"></iframe>
    1.20 +</div>
    1.21 +
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +
    1.26 +/** Test for Login Manager: username / password prompts. **/
    1.27 +var pwmgr, ioService, observerService;
    1.28 +var tmplogin, login1, login2A, login2B, login2C, login2D, login2E, login3A, login3B, login4, proxyLogin;
    1.29 +var mozproxy, proxiedHost = "http://mochi.test:8888";
    1.30 +var proxyChannel;
    1.31 +var testNum = 1;
    1.32 +
    1.33 +function initLogins(pi) {
    1.34 +  observerService = Cc["@mozilla.org/observer-service;1"].
    1.35 +                      getService(Ci.nsIObserverService);
    1.36 +  observerService.addObserver(storageObserver, "passwordmgr-storage-changed", false);
    1.37 +
    1.38 +  pwmgr = Cc["@mozilla.org/login-manager;1"].
    1.39 +          getService(Ci.nsILoginManager);
    1.40 +  ioService = Cc["@mozilla.org/network/io-service;1"].
    1.41 +              getService(Ci.nsIIOService);
    1.42 +
    1.43 +  mozproxy = "moz-proxy://" + SpecialPowers.wrap(pi).host + ":" +
    1.44 +              SpecialPowers.wrap(pi).port;
    1.45 +
    1.46 +  tmpLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.47 +             createInstance(Ci.nsILoginInfo);
    1.48 +
    1.49 +  login1  = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.50 +            createInstance(Ci.nsILoginInfo);
    1.51 +  login2A = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.52 +            createInstance(Ci.nsILoginInfo);
    1.53 +  login2B = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.54 +            createInstance(Ci.nsILoginInfo);
    1.55 +  login2C = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.56 +            createInstance(Ci.nsILoginInfo);
    1.57 +  login2D = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.58 +            createInstance(Ci.nsILoginInfo);
    1.59 +  login2E = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.60 +            createInstance(Ci.nsILoginInfo);
    1.61 +  login3A = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.62 +            createInstance(Ci.nsILoginInfo);
    1.63 +  login3B = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.64 +            createInstance(Ci.nsILoginInfo);
    1.65 +  login4  = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.66 +            createInstance(Ci.nsILoginInfo);
    1.67 +  proxyLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
    1.68 +               createInstance(Ci.nsILoginInfo);
    1.69 +
    1.70 +  login1.init("http://example.com", null, "http://example.com",
    1.71 +              "", "examplepass", "", "");
    1.72 +  login2A.init("http://example2.com", null, "http://example2.com",
    1.73 +               "user1name", "user1pass", "", "");
    1.74 +  login2B.init("http://example2.com", null, "http://example2.com",
    1.75 +               "user2name", "user2pass", "", "");
    1.76 +  login2C.init("http://example2.com", null, "http://example2.com",
    1.77 +               "user3.name@host", "user3pass", "", "");
    1.78 +  login2D.init("http://example2.com", null, "http://example2.com",
    1.79 +               "100@beef", "user3pass", "", "");
    1.80 +  login2E.init("http://example2.com", null, "http://example2.com",
    1.81 +               "100%beef", "user3pass", "", "");
    1.82 +  login3A.init("http://mochi.test:8888", null, "mochitest",
    1.83 +               "mochiuser1", "mochipass1", "", "");
    1.84 +  login3B.init("http://mochi.test:8888", null, "mochitest2",
    1.85 +               "mochiuser2", "mochipass2", "", "");
    1.86 +  login4.init("http://mochi.test:8888", null, "mochitest3",
    1.87 +               "mochiuser3", "mochipass3-old", "", "");
    1.88 +  proxyLogin.init(mozproxy, null, "Proxy Realm",
    1.89 +                  "proxuser", "proxpass", "", "");
    1.90 +
    1.91 +  pwmgr.addLogin(login1);
    1.92 +  pwmgr.addLogin(login2A);
    1.93 +  pwmgr.addLogin(login2B);
    1.94 +  pwmgr.addLogin(login2C);
    1.95 +  pwmgr.addLogin(login2D);
    1.96 +  pwmgr.addLogin(login2E);
    1.97 +  pwmgr.addLogin(login3A);
    1.98 +  pwmgr.addLogin(login3B);
    1.99 +  pwmgr.addLogin(login4);
   1.100 +  pwmgr.addLogin(proxyLogin);
   1.101 +}
   1.102 +
   1.103 +function finishTest() {
   1.104 +  try {
   1.105 +    ok(true, "finishTest removing testing logins...");
   1.106 +    observerService.removeObserver(storageObserver, "passwordmgr-storage-changed");
   1.107 +
   1.108 +    dumpLogins(pwmgr);
   1.109 +    ok(true, "removing login 1...");
   1.110 +      pwmgr.removeLogin(login1);
   1.111 +    ok(true, "removing login 2A...");
   1.112 +      pwmgr.removeLogin(login2A);
   1.113 +    ok(true, "removing login 2B...");
   1.114 +      pwmgr.removeLogin(login2B);
   1.115 +    ok(true, "removing login 2C...");
   1.116 +      pwmgr.removeLogin(login2C);
   1.117 +    ok(true, "removing login 2D...");
   1.118 +      pwmgr.removeLogin(login2D);
   1.119 +    ok(true, "removing login 2E...");
   1.120 +      pwmgr.removeLogin(login2E);
   1.121 +    ok(true, "removing login 3A...");
   1.122 +      pwmgr.removeLogin(login3A);
   1.123 +    ok(true, "removing login 3B...");
   1.124 +      pwmgr.removeLogin(login3B);
   1.125 +    ok(true, "removing login 4...");
   1.126 +      pwmgr.removeLogin(login4);
   1.127 +    ok(true, "removing proxyLogin...");
   1.128 +      pwmgr.removeLogin(proxyLogin);
   1.129 +  } catch (e) {
   1.130 +    ok(false, "finishTest FAILED: " + e);
   1.131 +  }
   1.132 +  ok(true, "whee, done!");
   1.133 +
   1.134 +  SimpleTest.finish();
   1.135 +}
   1.136 +
   1.137 +function proxyChannelListener() { }
   1.138 +proxyChannelListener.prototype = {
   1.139 +  onStartRequest: function(request, context) {
   1.140 +    doTests();
   1.141 +  },
   1.142 +  onStopRequest: function(request, context, status) { }
   1.143 +};
   1.144 +
   1.145 +var resolveCallback = SpecialPowers.wrapCallbackObject({
   1.146 +  QueryInterface : function (iid) {
   1.147 +    const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports];
   1.148 +
   1.149 +    if (!interfaces.some( function(v) { return iid.equals(v) } ))
   1.150 +      throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
   1.151 +    return this;
   1.152 +  },
   1.153 +
   1.154 +  onProxyAvailable : function (req, uri, pi, status) {
   1.155 +    initLogins(pi);
   1.156 +
   1.157 +    // I'm cheating a bit here... We should probably do some magic foo to get
   1.158 +    // something implementing nsIProxiedProtocolHandler and then call
   1.159 +    // NewProxiedChannel(), so we have something that's definately a proxied
   1.160 +    // channel. But Mochitests use a proxy for a number of hosts, so just
   1.161 +    // requesting a normal channel will give us a channel that's proxied.
   1.162 +    // The proxyChannel needs to move to at least on-modify-request to
   1.163 +    // have valid ProxyInfo, but we use OnStartRequest during startup()
   1.164 +    // for simplicity.
   1.165 +    proxyChannel = ioService.newChannel(proxiedHost, null, null);
   1.166 +    proxyChannel.asyncOpen(SpecialPowers.wrapCallbackObject(new proxyChannelListener()), null);
   1.167 +  }
   1.168 +});
   1.169 +
   1.170 +function startup() {
   1.171 +  //need to allow for arbitrary network servers defined in PAC instead of a hardcoded moz-proxy.
   1.172 +  var ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
   1.173 +    getService(SpecialPowers.Ci.nsIIOService);
   1.174 +
   1.175 +  var pps = SpecialPowers.Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
   1.176 +
   1.177 +  var uri = ios.newURI("http://example.com", null, null);
   1.178 +  pps.asyncResolve(uri, 0, resolveCallback);
   1.179 +}
   1.180 +
   1.181 +function addNotificationCallback(cb) {
   1.182 +  storageObserver.notificationCallbacks.push(cb);
   1.183 +}
   1.184 +
   1.185 +var storageObserver = SpecialPowers.wrapCallbackObject({
   1.186 +  notificationCallbacks: [],
   1.187 +
   1.188 +  QueryInterface : function (iid) {
   1.189 +    const interfaces = [Ci.nsIObserver,
   1.190 +                        Ci.nsISupports, Ci.nsISupportsWeakReference];
   1.191 +
   1.192 +    if (!interfaces.some( function(v) { return iid.equals(v) } ))
   1.193 +      throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
   1.194 +    return this;
   1.195 +  },
   1.196 +
   1.197 +  observe : function (subject, topic, data) {
   1.198 +    ok(true, ".");
   1.199 +    ok(true, "observer for " + topic + " / " + data);
   1.200 +    ok(true, "Time is " + (new Date()).toUTCString());
   1.201 +    var wrapped = SpecialPowers.wrap(subject);
   1.202 +    try {
   1.203 +      switch (data) {
   1.204 +        case "addLogin":
   1.205 +          ok(wrapped.QueryInterface(Ci.nsILoginInfo), "subject QI 1");
   1.206 +          ok(wrapped.QueryInterface(Ci.nsILoginMetaInfo), "subject QI 2");
   1.207 +          dumpLogin("added: ", subject);
   1.208 +          break;
   1.209 +        case "modifyLogin":
   1.210 +          var arr = wrapped.QueryInterface(Ci.nsIArray);
   1.211 +          ok(arr, "subject QI");
   1.212 +          is(arr.length, 2, "should be 2 items");
   1.213 +          var oldLogin = arr.queryElementAt(0, Ci.nsILoginInfo);
   1.214 +          var newLogin = arr.queryElementAt(1, Ci.nsILoginInfo);
   1.215 +          dumpLogin("oldLogin: ", oldLogin);
   1.216 +          dumpLogin("newLogin: ", newLogin);
   1.217 +          break;
   1.218 +        case "removeLogin":
   1.219 +          ok(wrapped.QueryInterface(Ci.nsILoginInfo), "subject QI 1");
   1.220 +          ok(wrapped.QueryInterface(Ci.nsILoginMetaInfo), "subject QI 2");
   1.221 +          dumpLogin("removed: ", subject);
   1.222 +          break;
   1.223 +        case "removeAllLogins":
   1.224 +          is(subject, null, "no subject");
   1.225 +          break;
   1.226 +        case "hostSavingEnabled":
   1.227 +        case "hostSavingDisabled":
   1.228 +          ok(subject instanceof Ci.nsISupportsString, "subject QI");
   1.229 +          ok(true, "state is: " + subject.data);
   1.230 +          break;
   1.231 +        default:
   1.232 +          do_throw("Unhandled notification: " + data + " / " + topic);
   1.233 +      }
   1.234 +
   1.235 +      if (this.notificationCallbacks.length)
   1.236 +        this.notificationCallbacks.splice(0, 1)[0]();
   1.237 +    } catch (e) {
   1.238 +      ok(false, "OBSERVER FAILED: " + e);
   1.239 +    }
   1.240 +  }
   1.241 +});
   1.242 +
   1.243 +/*
   1.244 + * handleDialog
   1.245 + *
   1.246 + * Invoked a short period of time after calling startCallbackTimer(), and
   1.247 + * allows testing the actual auth dialog while it's being displayed. Tests
   1.248 + * should call startCallbackTimer() each time the auth dialog is expected (the
   1.249 + * timer is a one-shot).
   1.250 + */
   1.251 +function handleDialog(doc, testNum) {
   1.252 +  ok(true, "."); // make it easier to see next line in logs.
   1.253 +  ok(true, "handleDialog running for test " + testNum);
   1.254 +  ok(true, "Time is " + (new Date()).toUTCString());
   1.255 +  dumpNotifications();
   1.256 +
   1.257 +  var clickOK = true;
   1.258 +  var body = doc.getElementById("info.body");
   1.259 +  var userfield = doc.getElementById("loginTextbox");
   1.260 +  var passfield = doc.getElementById("password1Textbox");
   1.261 +  var username = userfield.getAttribute("value");
   1.262 +  var password = passfield.getAttribute("value");
   1.263 +  var dialog    = doc.getElementById("commonDialog");
   1.264 +
   1.265 +  switch(testNum) {
   1.266 +    case 1:
   1.267 +      is(username, "abc", "Checking provided username");
   1.268 +      userfield.setAttribute("value", "xyz");
   1.269 +      // Temporarily commented out because of Bug #718543
   1.270 +      // is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum);
   1.271 +      // doc.commandDispatcher.rewindFocus();
   1.272 +      // is(doc.activeElement, body, "description focusable");
   1.273 +      break;
   1.274 +    case 2:
   1.275 +      clickOK = false;
   1.276 +      break;
   1.277 +    case 10:
   1.278 +      is(password, "inputpw", "Checking provided password");
   1.279 +      passfield.setAttribute("value", "secret");
   1.280 +      // Temporarily commented out because of Bug #718543
   1.281 +      // is(doc.activeElement, passfield.inputField, "focus correct for test" + testNum);
   1.282 +      break;
   1.283 +    case 11:
   1.284 +      is(password, "inputpw", "Checking provided password");
   1.285 +      clickOK = false;
   1.286 +      break;
   1.287 +    case 12:
   1.288 +      is(password, "", "Checking provided password");
   1.289 +      passfield.setAttribute("value", "secret");
   1.290 +      break;
   1.291 +    case 14:
   1.292 +      is(password, "", "Checking provided password");
   1.293 +      passfield.setAttribute("value", "secret");
   1.294 +      break;
   1.295 +    case 30:
   1.296 +    case 31:
   1.297 +      is(password, "", "Checking provided password");
   1.298 +      passfield.setAttribute("value", "fill2pass");
   1.299 +      break;
   1.300 +    case 100:
   1.301 +      is(username, "inuser", "Checking provided username");
   1.302 +      is(password, "inpass", "Checking provided password");
   1.303 +      userfield.setAttribute("value", "outuser");
   1.304 +      passfield.setAttribute("value", "outpass");
   1.305 +      break;
   1.306 +    case 101:
   1.307 +      clickOK = false;
   1.308 +      break;
   1.309 +    case 102:
   1.310 +      is(username, "", "Checking provided username");
   1.311 +      is(password, "examplepass", "Checking provided password");
   1.312 +      break;
   1.313 +    case 103:
   1.314 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.315 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.316 +      break;
   1.317 +    case 104:
   1.318 +      is(username, "user1name", "Checking filled username");
   1.319 +      is(password, "user1pass", "Checking filled password");
   1.320 +      break;
   1.321 +    case 105:
   1.322 +      is(username, "user2name", "Checking filled username");
   1.323 +      is(password, "user2pass", "Checking filled password");
   1.324 +      break;
   1.325 +    case 106:
   1.326 +      is(username, "user2name", "Checking filled username");
   1.327 +      is(password, "user2pass", "Checking filled password");
   1.328 +      passfield.setAttribute("value", "NEWuser2pass");
   1.329 +      break;
   1.330 +    case 107:
   1.331 +      is(username, "user2name", "Checking filled username");
   1.332 +      is(password, "NEWuser2pass", "Checking filled password");
   1.333 +      passfield.setAttribute("value", "user2pass");
   1.334 +      break;
   1.335 +    case 120:
   1.336 +    case 121:
   1.337 +      is(username, "", "Checking filled username");
   1.338 +      is(password, "", "Checking filled password");
   1.339 +      userfield.setAttribute("value", "fill2user");
   1.340 +      passfield.setAttribute("value", "fill2pass");
   1.341 +      break;
   1.342 +    case 500:
   1.343 +      is(username, "inuser", "Checking unfilled username");
   1.344 +      is(password, "inpass", "Checking unfilled password");
   1.345 +      userfield.setAttribute("value", "outuser");
   1.346 +      passfield.setAttribute("value", "outpass");
   1.347 +      break;
   1.348 +    case 501:
   1.349 +      clickOK = false;
   1.350 +      break;
   1.351 +    case 502:
   1.352 +      is(username, "", "Checking filled username");
   1.353 +      is(password, "examplepass", "Checking filled password");
   1.354 +      break;
   1.355 +    case 503:
   1.356 +      // either of the two logins might have been filled in
   1.357 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.358 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.359 +      break;
   1.360 +    case 504:
   1.361 +      // either of the two logins might have been filled in
   1.362 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.363 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.364 +      // enter one of the known logins, test 504+505 exercise the two possible states.
   1.365 +      userfield.setAttribute("value", "user1name");
   1.366 +      passfield.setAttribute("value", "user1pass");
   1.367 +      break;
   1.368 +    case 505:
   1.369 +      // either of the two logins might have been filled in
   1.370 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.371 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.372 +      // enter one of the known logins, test 504+505 exercise the two possible states.
   1.373 +      userfield.setAttribute("value", "user2name");
   1.374 +      passfield.setAttribute("value", "user2pass");
   1.375 +      break;
   1.376 +    case 506:
   1.377 +      // either of the two logins might have been filled in
   1.378 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.379 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.380 +      // force to user2, and change the password
   1.381 +      userfield.setAttribute("value", "user2name");
   1.382 +      passfield.setAttribute("value", "NEWuser2pass");
   1.383 +      break;
   1.384 +    case 507:
   1.385 +      // either of the two logins might have been filled in
   1.386 +      ok(username == "user1name" || username == "user2name", "Checking filled username");
   1.387 +      ok(password == "user1pass" || password == "user2pass", "Checking filled password");
   1.388 +      // force to user2, and change the password back
   1.389 +      userfield.setAttribute("value", "user2name");
   1.390 +      passfield.setAttribute("value", "user2pass");
   1.391 +      break;
   1.392 +    case 508:
   1.393 +      is(username, "proxuser", "Checking filled username");
   1.394 +      is(password, "proxpass", "Checking filled password");
   1.395 +      break;
   1.396 +    // No case 509, it's unprompted.
   1.397 +    case 510:
   1.398 +      is(username, "proxuser", "Checking filled username");
   1.399 +      is(password, "proxpass", "Checking filled password");
   1.400 +      break;
   1.401 +    case 511:
   1.402 +      is(username, "proxuser", "Checking filled username");
   1.403 +      is(password, "proxpass", "Checking filled password");
   1.404 +      break;
   1.405 +    case 1000:
   1.406 +      is(username, "mochiuser1", "Checking filled username");
   1.407 +      is(password, "mochipass1", "Checking filled password");
   1.408 +      break;
   1.409 +    case 1001:
   1.410 +      is(username, "mochiuser2", "Checking filled username");
   1.411 +      is(password, "mochipass2", "Checking filled password");
   1.412 +      break;
   1.413 +    // (1002 doesn't trigger a dialog)
   1.414 +    case 1003:
   1.415 +      is(username, "mochiuser1", "Checking filled username");
   1.416 +      is(password, "mochipass1", "Checking filled password");
   1.417 +      passfield.setAttribute("value", "mochipass1-new");
   1.418 +      break;
   1.419 +    case 1004:
   1.420 +      is(username, "mochiuser3", "Checking filled username");
   1.421 +      is(password, "mochipass3-old", "Checking filled password");
   1.422 +      passfield.setAttribute("value", "mochipass3-new");
   1.423 +      break;
   1.424 +    case 1005:
   1.425 +      is(username, "", "Checking filled username");
   1.426 +      is(password, "", "Checking filled password");
   1.427 +      userfield.setAttribute("value", "mochiuser3");
   1.428 +      passfield.setAttribute("value", "mochipass3-old");
   1.429 +      break;
   1.430 +    default:
   1.431 +      ok(false, "Uhh, unhandled switch for testNum #" + testNum);
   1.432 +      break;
   1.433 +  }
   1.434 +
   1.435 +  if (clickOK)
   1.436 +    dialog.acceptDialog();
   1.437 +  else
   1.438 +    dialog.cancelDialog();
   1.439 +
   1.440 +  ok(true, "handleDialog done");
   1.441 +  didDialog = true;
   1.442 +}
   1.443 +
   1.444 +/*
   1.445 + * handleLoad
   1.446 + *
   1.447 + * Called when a load event is fired at the subtest's iframe.
   1.448 + */
   1.449 +function handleLoad() {
   1.450 +  ok(true, "."); // make it easier to see next line in logs.
   1.451 +  ok(true, "handleLoad running for test " + testNum);
   1.452 +  ok(true, "Time is " + (new Date()).toUTCString());
   1.453 +  dumpNotifications();
   1.454 +
   1.455 +  if (testNum != 1002)
   1.456 +    ok(didDialog, "handleDialog was invoked");
   1.457 +
   1.458 +  // The server echos back the user/pass it received.
   1.459 +  var username = iframe.contentDocument.getElementById("user").textContent;
   1.460 +  var password = iframe.contentDocument.getElementById("pass").textContent;
   1.461 +  var authok = iframe.contentDocument.getElementById("ok").textContent;
   1.462 +
   1.463 +  switch(testNum) {
   1.464 +    case 1000:
   1.465 +      testNum++;
   1.466 +      is(authok, "PASS", "Checking for successful authentication");
   1.467 +      is(username, "mochiuser1", "Checking for echoed username");
   1.468 +      is(password, "mochipass1", "Checking for echoed password");
   1.469 +      startCallbackTimer();
   1.470 +      // We've already authenticated to this host:port. For this next
   1.471 +      // request, the existing auth should be sent, we'll get a 401 reply,
   1.472 +      // and we should prompt for new auth.
   1.473 +      iframe.src = "authenticate.sjs?user=mochiuser2&pass=mochipass2&realm=mochitest2";
   1.474 +      break;
   1.475 +    case 1001:
   1.476 +      testNum++;
   1.477 +      is(authok, "PASS", "Checking for successful authentication");
   1.478 +      is(username, "mochiuser2", "Checking for echoed username");
   1.479 +      is(password, "mochipass2", "Checking for echoed password");
   1.480 +      // Now make a load that requests the realm from test 1000. It was
   1.481 +      // already provided there, so auth will *not* be prompted for -- the
   1.482 +      // networking layer already knows it!
   1.483 +      iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
   1.484 +      break;
   1.485 +    case 1002:
   1.486 +      testNum++;
   1.487 +      is(authok, "PASS", "Checking for successful authentication");
   1.488 +      is(username, "mochiuser1", "Checking for echoed username");
   1.489 +      is(password, "mochipass1", "Checking for echoed password");
   1.490 +
   1.491 +      // Same realm we've already authenticated to, but with a different
   1.492 +      // expected password (to trigger an auth prompt, and change-password
   1.493 +      // popup notification).
   1.494 +      startCallbackTimer();
   1.495 +      iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1-new";
   1.496 +      break;
   1.497 +    case 1003:
   1.498 +      testNum++;
   1.499 +      is(authok, "PASS", "Checking for successful authentication");
   1.500 +      is(username, "mochiuser1", "Checking for echoed username");
   1.501 +      is(password, "mochipass1-new", "Checking for echoed password");
   1.502 +
   1.503 +      // Housekeeping: change it back
   1.504 +      function resetIt() {
   1.505 +        tmpLogin.init("http://mochi.test:8888", null, "mochitest",
   1.506 +                      "mochiuser1", "mochipass1-new", "", "");
   1.507 +        pwmgr.modifyLogin(tmpLogin, login3A);
   1.508 +      }
   1.509 +      addNotificationCallback(resetIt);
   1.510 +
   1.511 +      // Check for the popup notification, and change the password.
   1.512 +      popupNotifications = getPopupNotifications(window.top);
   1.513 +      popup = getPopup(popupNotifications, "password-change");
   1.514 +      ok(popup, "got popup notification");
   1.515 +      clickPopupButton(popup, kChangeButton);
   1.516 +      popup.remove();
   1.517 +
   1.518 +      // Same as last test, but for a realm we haven't already authenticated
   1.519 +      // to (but have an existing saved login for, so that we'll trigger
   1.520 +      // a change-password popup notification.
   1.521 +      startCallbackTimer();
   1.522 +      iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-new&realm=mochitest3";
   1.523 +      break;
   1.524 +    case 1004:
   1.525 +      testNum++;
   1.526 +      is(authok, "PASS", "Checking for successful authentication");
   1.527 +      is(username, "mochiuser3", "Checking for echoed username");
   1.528 +      is(password, "mochipass3-new", "Checking for echoed password");
   1.529 +
   1.530 +      // Housekeeping: change it back to the original login4. Actually,
   1.531 +      // just delete it and we'll re-add it as the next test.
   1.532 +      function clearIt() {
   1.533 +        ok(true, "1004's clearIt() called.");
   1.534 +       try {
   1.535 +        tmpLogin.init("http://mochi.test:8888", null, "mochitest3",
   1.536 +                      "mochiuser3", "mochipass3-new", "", "");
   1.537 +        pwmgr.removeLogin(tmpLogin);
   1.538 +
   1.539 +        // Trigger a new prompt, so we can test adding a new login.
   1.540 +        startCallbackTimer();
   1.541 +        iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-old&realm=mochitest3";
   1.542 +       } catch (e) { ok(false, "clearIt GOT EXCEPTION: " + e); }
   1.543 +      }
   1.544 +      addNotificationCallback(clearIt);
   1.545 +
   1.546 +      // Check for the popup notification, and change the password.
   1.547 +      popup = getPopup(popupNotifications, "password-change");
   1.548 +      ok(popup, "got popup notification");
   1.549 +      clickPopupButton(popup, kChangeButton);
   1.550 +      popup.remove();
   1.551 +
   1.552 +      // Clear cached auth from this subtest, and avoid leaking due to bug 459620.
   1.553 +      var authMgr = Cc['@mozilla.org/network/http-auth-manager;1'].
   1.554 +                    getService(Ci.nsIHttpAuthManager);
   1.555 +      authMgr.clearAll();
   1.556 +      ok(true, "authMgr cleared cached auth");
   1.557 +      break;
   1.558 +    case 1005:
   1.559 +      testNum++;
   1.560 +      is(authok, "PASS", "Checking for successful authentication");
   1.561 +      is(username, "mochiuser3", "Checking for echoed username");
   1.562 +      is(password, "mochipass3-old", "Checking for echoed password");
   1.563 +
   1.564 +      function finishIt() {
   1.565 +        finishTest();
   1.566 +      }
   1.567 +      addNotificationCallback(finishIt);
   1.568 +
   1.569 +      // Check for the popup notification, and change the password.
   1.570 +      popup = getPopup(popupNotifications, "password-save");
   1.571 +      ok(popup, "got popup notification");
   1.572 +      clickPopupButton(popup, kRememberButton);
   1.573 +      popup.remove();
   1.574 +      break;
   1.575 +    default:
   1.576 +      ok(false, "Uhh, unhandled switch for testNum #" + testNum);
   1.577 +      break;
   1.578 +  }
   1.579 +}
   1.580 +
   1.581 +startup();
   1.582 +
   1.583 +function doTests() {
   1.584 +  var authinfo = {
   1.585 +    username : "",
   1.586 +    password : "",
   1.587 +    domain   : "",
   1.588 +
   1.589 +    flags : Ci.nsIAuthInformation.AUTH_HOST,
   1.590 +    authenticationScheme : "basic",
   1.591 +    realm : ""
   1.592 +  };
   1.593 +
   1.594 +  var proxyAuthinfo = {
   1.595 +    username : "",
   1.596 +    password : "",
   1.597 +    domain   : "",
   1.598 +
   1.599 +    flags : Ci.nsIAuthInformation.AUTH_PROXY,
   1.600 +    authenticationScheme : "basic",
   1.601 +    realm : ""
   1.602 +  };
   1.603 +
   1.604 +  var prefs = Cc["@mozilla.org/preferences-service;1"].
   1.605 +              getService(Ci.nsIPrefBranch);
   1.606 +
   1.607 +  const Cc_promptFac= Cc["@mozilla.org/passwordmanager/authpromptfactory;1"];
   1.608 +  ok(Cc_promptFac != null, "Access Cc[@mozilla.org/passwordmanager/authpromptfactory;1]");
   1.609 +
   1.610 +  const Ci_promptFac = Ci.nsIPromptFactory;
   1.611 +  ok(Ci_promptFac != null, "Access Ci.nsIPromptFactory");
   1.612 +
   1.613 +  const promptFac = Cc_promptFac.getService(Ci_promptFac);
   1.614 +  ok(promptFac != null, "promptFac getService()");
   1.615 +
   1.616 +  var prompter1 = promptFac.getPrompt(window, Ci.nsIAuthPrompt);
   1.617 +  var prompter2 = promptFac.getPrompt(window, Ci.nsIAuthPrompt2);
   1.618 +
   1.619 +  function dialogTitle() { return "nsILoginManagerPrompter test #" + testNum; }
   1.620 +  var dialogText  = "This dialog should be modified and dismissed by the test.";
   1.621 +  var uname  = { value : null };
   1.622 +  var pword  = { value : null };
   1.623 +  var result = { value : null };
   1.624 +  var isOk;
   1.625 +
   1.626 +  // popupNotifications (not *popup*) is a constant, per-tab container. So, we
   1.627 +  // only need to fetch it once.
   1.628 +  var popupNotifications = getPopupNotifications(window.top);
   1.629 +  ok(popupNotifications, "Got popupNotifications");
   1.630 +
   1.631 +  // ===== test 1 =====
   1.632 +  testNum = 1;
   1.633 +  startCallbackTimer();
   1.634 +  isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com",
   1.635 +                          Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
   1.636 +
   1.637 +  ok(isOk, "Checking dialog return value (accept)");
   1.638 +  ok(didDialog, "handleDialog was invoked");
   1.639 +  is(result.value, "xyz", "Checking prompt() returned value");
   1.640 +
   1.641 +  // ===== test 2 =====
   1.642 +  testNum++;
   1.643 +  startCallbackTimer();
   1.644 +  isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com",
   1.645 +                          Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
   1.646 +  ok(didDialog, "handleDialog was invoked");
   1.647 +  ok(!isOk, "Checking dialog return value (cancel)");
   1.648 +
   1.649 +  // ===== test 10 =====
   1.650 +  // Default password provided, existing logins are ignored.
   1.651 +  testNum = 10;
   1.652 +  pword.value = "inputpw";
   1.653 +  startCallbackTimer();
   1.654 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
   1.655 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.656 +  ok(isOk, "Checking dialog return value (accept)");
   1.657 +  ok(didDialog, "handleDialog was invoked");
   1.658 +  is(pword.value, "secret", "Checking returned password");
   1.659 +
   1.660 +  // ===== test 11 =====
   1.661 +  // Default password provided, existing logins are ignored.
   1.662 +  testNum++;
   1.663 +  pword.value = "inputpw";
   1.664 +  startCallbackTimer();
   1.665 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
   1.666 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.667 +  ok(!isOk, "Checking dialog return value (cancel)");
   1.668 +  ok(didDialog, "handleDialog was invoked");
   1.669 +
   1.670 +  // ===== test 12 =====
   1.671 +  // No default password provided, realm does not match existing login.
   1.672 +  testNum++;
   1.673 +  pword.value = null;
   1.674 +  startCallbackTimer();
   1.675 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://nonexample.com",
   1.676 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.677 +  ok(isOk, "Checking dialog return value (accept)");
   1.678 +  ok(didDialog, "handleDialog was invoked");
   1.679 +  is(pword.value, "secret", "Checking returned password");
   1.680 +
   1.681 +  // ===== test 13 =====
   1.682 +  // No default password provided, matching login is returned w/o prompting.
   1.683 +  testNum++;
   1.684 +  pword.value = null;
   1.685 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
   1.686 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.687 +  ok(isOk, "Checking dialog return value (accept)");
   1.688 +  is(pword.value, "examplepass", "Checking returned password");
   1.689 +
   1.690 +  // ===== test 14 =====
   1.691 +  // No default password provided, none of the logins from this host are
   1.692 +  // password-only so the user is prompted.
   1.693 +  testNum++;
   1.694 +  pword.value = null;
   1.695 +  startCallbackTimer();
   1.696 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example2.com",
   1.697 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.698 +  ok(isOk, "Checking dialog return value (accept)");
   1.699 +  ok(didDialog, "handleDialog was invoked");
   1.700 +  is(pword.value, "secret", "Checking returned password");
   1.701 +
   1.702 +  // ===== test 15 =====
   1.703 +  // No default password provided, matching login is returned w/o prompting.
   1.704 +  testNum++;
   1.705 +  pword.value = null;
   1.706 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user1name@example2.com",
   1.707 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.708 +  ok(isOk, "Checking dialog return value (accept)");
   1.709 +  is(pword.value, "user1pass", "Checking returned password");
   1.710 +
   1.711 +  // ===== test 16 =====
   1.712 +  // No default password provided, matching login is returned w/o prompting.
   1.713 +  testNum++;
   1.714 +  pword.value = null;
   1.715 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user2name@example2.com",
   1.716 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.717 +  ok(isOk, "Checking dialog return value (accept)");
   1.718 +  is(pword.value, "user2pass", "Checking returned password");
   1.719 +
   1.720 +  // ===== test 17 =====
   1.721 +  // No default password provided, matching login is returned w/o prompting.
   1.722 +  testNum++;
   1.723 +  pword.value = null;
   1.724 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user3%2Ename%40host@example2.com",
   1.725 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.726 +  ok(isOk, "Checking dialog return value (accept)");
   1.727 +  is(pword.value, "user3pass", "Checking returned password");
   1.728 +
   1.729 +  // ===== test 18 =====
   1.730 +  // No default password provided, matching login is returned w/o prompting.
   1.731 +  testNum++;
   1.732 +  pword.value = null;
   1.733 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100@beef@example2.com",
   1.734 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.735 +  ok(isOk, "Checking dialog return value (accept)");
   1.736 +  is(pword.value, "user3pass", "Checking returned password");
   1.737 +
   1.738 +  // ===== test 19 =====
   1.739 +  // No default password provided, matching login is returned w/o prompting.
   1.740 +  testNum++;
   1.741 +  pword.value = null;
   1.742 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100%25beef@example2.com",
   1.743 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.744 +  ok(isOk, "Checking dialog return value (accept)");
   1.745 +  is(pword.value, "user3pass", "Checking returned password");
   1.746 +
   1.747 +  // XXX test saving a password with  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY
   1.748 +
   1.749 +  // ===== test 30 =====
   1.750 +  // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
   1.751 +  testNum = 30;
   1.752 +  pword.value = null;
   1.753 +  startCallbackTimer();
   1.754 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
   1.755 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
   1.756 +  ok(isOk, "Checking dialog return value (accept)");
   1.757 +  ok(didDialog, "handleDialog was invoked");
   1.758 +  is(pword.value, "fill2pass", "Checking returned password");
   1.759 +
   1.760 +  // ===== test 31 =====
   1.761 +  // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
   1.762 +  testNum++;
   1.763 +  pword.value = null;
   1.764 +  startCallbackTimer();
   1.765 +  isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
   1.766 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, pword);
   1.767 +  ok(isOk, "Checking dialog return value (accept)");
   1.768 +  ok(didDialog, "handleDialog was invoked");
   1.769 +  is(pword.value, "fill2pass", "Checking returned password");
   1.770 +
   1.771 +  // ===== test 100 =====
   1.772 +  testNum = 100;
   1.773 +  uname.value = "inuser";
   1.774 +  pword.value = "inpass";
   1.775 +  startCallbackTimer();
   1.776 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com",
   1.777 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
   1.778 +  ok(isOk, "Checking dialog return value (accept)");
   1.779 +  ok(didDialog, "handleDialog was invoked");
   1.780 +  is(uname.value, "outuser", "Checking returned username");
   1.781 +  is(pword.value, "outpass", "Checking returned password");
   1.782 +
   1.783 +  // ===== test 101 =====
   1.784 +  testNum++;
   1.785 +  uname.value = "inuser";
   1.786 +  pword.value = "inpass";
   1.787 +  startCallbackTimer();
   1.788 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com",
   1.789 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
   1.790 +  ok(!isOk, "Checking dialog return value (cancel)");
   1.791 +  ok(didDialog, "handleDialog was invoked");
   1.792 +
   1.793 +  // ===== test 102 =====
   1.794 +  // test filling in existing password-only login
   1.795 +  testNum++;
   1.796 +  uname.value = null;
   1.797 +  pword.value = null;
   1.798 +  startCallbackTimer();
   1.799 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example.com",
   1.800 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.801 +  ok(isOk, "Checking dialog return value (accept)");
   1.802 +  ok(didDialog, "handleDialog was invoked");
   1.803 +  is(uname.value, "", "Checking returned username");
   1.804 +  is(pword.value, "examplepass", "Checking returned password");
   1.805 +
   1.806 +  // ===== test 103 =====
   1.807 +  // test filling in existing login (undetermined from multiple selection)
   1.808 +  testNum++;
   1.809 +  uname.value = null;
   1.810 +  pword.value = null;
   1.811 +  startCallbackTimer();
   1.812 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
   1.813 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.814 +  ok(isOk, "Checking dialog return value (accept)");
   1.815 +  ok(didDialog, "handleDialog was invoked");
   1.816 +  ok(uname.value == "user1name" || uname.value == "user2name", "Checking returned username");
   1.817 +  ok(pword.value == "user1pass" || uname.value == "user2pass", "Checking returned password");
   1.818 +
   1.819 +  // ===== test 104 =====
   1.820 +  // test filling in existing login (user1 from multiple selection)
   1.821 +  testNum++;
   1.822 +  uname.value = "user1name";
   1.823 +  pword.value = null;
   1.824 +  startCallbackTimer();
   1.825 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
   1.826 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.827 +  ok(isOk, "Checking dialog return value (accept)");
   1.828 +  ok(didDialog, "handleDialog was invoked");
   1.829 +  is(uname.value, "user1name", "Checking returned username");
   1.830 +  is(pword.value, "user1pass", "Checking returned password");
   1.831 +
   1.832 +  // ===== test 105 =====
   1.833 +  // test filling in existing login (user2 from multiple selection)
   1.834 +  testNum++;
   1.835 +  uname.value = "user2name";
   1.836 +  pword.value = null;
   1.837 +  startCallbackTimer();
   1.838 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
   1.839 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.840 +  ok(isOk, "Checking dialog return value (accept)");
   1.841 +  ok(didDialog, "handleDialog was invoked");
   1.842 +  is(uname.value, "user2name", "Checking returned username");
   1.843 +  is(pword.value, "user2pass", "Checking returned password");
   1.844 +
   1.845 +  // ===== test 106 =====
   1.846 +  // test changing password
   1.847 +  testNum++;
   1.848 +  uname.value = "user2name";
   1.849 +  pword.value = null;
   1.850 +  startCallbackTimer();
   1.851 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
   1.852 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.853 +  ok(isOk, "Checking dialog return value (accept)");
   1.854 +  ok(didDialog, "handleDialog was invoked");
   1.855 +  is(uname.value, "user2name", "Checking returned username");
   1.856 +  is(pword.value, "NEWuser2pass", "Checking returned password");
   1.857 +
   1.858 +  // ===== test 107 =====
   1.859 +  // test changing password (back to original value)
   1.860 +  testNum++;
   1.861 +  uname.value = "user2name";
   1.862 +  pword.value = null;
   1.863 +  startCallbackTimer();
   1.864 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
   1.865 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.866 +  ok(isOk, "Checking dialog return value (accept)");
   1.867 +  ok(didDialog, "handleDialog was invoked");
   1.868 +  is(uname.value, "user2name", "Checking returned username");
   1.869 +  is(pword.value, "user2pass", "Checking returned password");
   1.870 +
   1.871 +  // ===== test 120 =====
   1.872 +  // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
   1.873 +  testNum = 120;
   1.874 +  uname.value = null;
   1.875 +  pword.value = null;
   1.876 +  startCallbackTimer();
   1.877 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
   1.878 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
   1.879 +  ok(isOk, "Checking dialog return value (accept)");
   1.880 +  ok(didDialog, "handleDialog was invoked");
   1.881 +  is(uname.value, "fill2user", "Checking returned username");
   1.882 +  is(pword.value, "fill2pass", "Checking returned password");
   1.883 +
   1.884 +  // ===== test 121 =====
   1.885 +  // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
   1.886 +  testNum++;
   1.887 +  uname.value = null;
   1.888 +  pword.value = null;
   1.889 +  startCallbackTimer();
   1.890 +  isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
   1.891 +                                  Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
   1.892 +  ok(isOk, "Checking dialog return value (accept)");
   1.893 +  ok(didDialog, "handleDialog was invoked");
   1.894 +  is(uname.value, "fill2user", "Checking returned username");
   1.895 +  is(pword.value, "fill2pass", "Checking returned password");
   1.896 +
   1.897 +  var channel1 = ioService.newChannel("http://example.com", null, null);
   1.898 +  var channel2 = ioService.newChannel("http://example2.com", null, null);
   1.899 +
   1.900 +  var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
   1.901 +
   1.902 +  // ===== test 500 =====
   1.903 +  testNum = 500;
   1.904 +  authinfo.username = "inuser";
   1.905 +  authinfo.password = "inpass";
   1.906 +  authinfo.realm    = "some realm";
   1.907 +
   1.908 +  startCallbackTimer();
   1.909 +  isOk = prompter2.promptAuth(channel1, level, authinfo);
   1.910 +
   1.911 +  ok(isOk, "Checking dialog return value (accept)");
   1.912 +  ok(didDialog, "handleDialog was invoked");
   1.913 +  is(authinfo.username, "outuser", "Checking returned username");
   1.914 +  is(authinfo.password, "outpass", "Checking returned password");
   1.915 +
   1.916 +  // ===== test 501 =====
   1.917 +  testNum++;
   1.918 +  startCallbackTimer();
   1.919 +  isOk = prompter2.promptAuth(channel1, level, authinfo);
   1.920 +
   1.921 +  ok(!isOk, "Checking dialog return value (cancel)");
   1.922 +  ok(didDialog, "handleDialog was invoked");
   1.923 +
   1.924 +  // ===== test 502 =====
   1.925 +  // test filling in password-only login
   1.926 +  testNum++;
   1.927 +  authinfo.username = "";
   1.928 +  authinfo.password = "";
   1.929 +  authinfo.realm    = "http://example.com";
   1.930 +
   1.931 +  startCallbackTimer();
   1.932 +  isOk = prompter2.promptAuth(channel1, level, authinfo);
   1.933 +
   1.934 +  ok(isOk, "Checking dialog return value (accept)");
   1.935 +  ok(didDialog, "handleDialog was invoked");
   1.936 +  is(authinfo.username, "", "Checking returned username");
   1.937 +  is(authinfo.password, "examplepass", "Checking returned password");
   1.938 +
   1.939 +  // ===== test 503 =====
   1.940 +  // test filling in existing login (undetermined from multiple selection)
   1.941 +  testNum++;
   1.942 +  authinfo.username = "";
   1.943 +  authinfo.password = "";
   1.944 +  authinfo.realm    = "http://example2.com";
   1.945 +
   1.946 +  startCallbackTimer();
   1.947 +  isOk = prompter2.promptAuth(channel2, level, authinfo);
   1.948 +
   1.949 +  ok(isOk, "Checking dialog return value (accept)");
   1.950 +  ok(didDialog, "handleDialog was invoked");
   1.951 +  ok(authinfo.username == "user1name" || authinfo.username == "user2name", "Checking returned username");
   1.952 +  ok(authinfo.password == "user1pass" || authinfo.password == "user2pass", "Checking returned password");
   1.953 +
   1.954 +  // ===== test 504 =====
   1.955 +  // test filling in existing login (undetermined --> user1)
   1.956 +  testNum++;
   1.957 +  authinfo.username = "";
   1.958 +  authinfo.password = "";
   1.959 +  authinfo.realm    = "http://example2.com";
   1.960 +
   1.961 +  startCallbackTimer();
   1.962 +  isOk = prompter2.promptAuth(channel2, level, authinfo);
   1.963 +
   1.964 +  ok(isOk, "Checking dialog return value (accept)");
   1.965 +  ok(didDialog, "handleDialog was invoked");
   1.966 +  is(authinfo.username, "user1name", "Checking returned username");
   1.967 +  is(authinfo.password, "user1pass", "Checking returned password");
   1.968 +
   1.969 +  // ===== test 505 =====
   1.970 +  // test filling in existing login (undetermined --> user2)
   1.971 +  testNum++;
   1.972 +  authinfo.username = "";
   1.973 +  authinfo.password = "";
   1.974 +  authinfo.realm    = "http://example2.com";
   1.975 +
   1.976 +  dumpNotifications();
   1.977 +  startCallbackTimer();
   1.978 +  isOk = prompter2.promptAuth(channel2, level, authinfo);
   1.979 +
   1.980 +  ok(isOk, "Checking dialog return value (accept)");
   1.981 +  ok(didDialog, "handleDialog was invoked");
   1.982 +  is(authinfo.username, "user2name", "Checking returned username");
   1.983 +  is(authinfo.password, "user2pass", "Checking returned password");
   1.984 +
   1.985 +  // ===== test 506 =====
   1.986 +  // test changing a password (undetermined --> user2 w/ newpass)
   1.987 +  testNum++;
   1.988 +  authinfo.username = "";
   1.989 +  authinfo.password = "";
   1.990 +  authinfo.realm    = "http://example2.com";
   1.991 +
   1.992 +  dumpNotifications();
   1.993 +  startCallbackTimer();
   1.994 +  isOk = prompter2.promptAuth(channel2, level, authinfo);
   1.995 +
   1.996 +  ok(isOk, "Checking dialog return value (accept)");
   1.997 +  ok(didDialog, "handleDialog was invoked");
   1.998 +  is(authinfo.username, "user2name", "Checking returned username");
   1.999 +  is(authinfo.password, "NEWuser2pass", "Checking returned password");
  1.1000 +
  1.1001 +  // ===== test 507 =====
  1.1002 +  // test changing a password (undetermined --> user2 w/ origpass)
  1.1003 +  testNum++;
  1.1004 +  authinfo.username = "";
  1.1005 +  authinfo.password = "";
  1.1006 +  authinfo.realm    = "http://example2.com";
  1.1007 +
  1.1008 +  dumpNotifications();
  1.1009 +  startCallbackTimer();
  1.1010 +  isOk = prompter2.promptAuth(channel2, level, authinfo);
  1.1011 +
  1.1012 +  ok(isOk, "Checking dialog return value (accept)");
  1.1013 +  ok(didDialog, "handleDialog was invoked");
  1.1014 +  is(authinfo.username, "user2name", "Checking returned username");
  1.1015 +  is(authinfo.password, "user2pass", "Checking returned password");
  1.1016 +
  1.1017 +  // ===== test 508 =====
  1.1018 +  // test proxy login (default = no autologin), make sure it prompts.
  1.1019 +  testNum++;
  1.1020 +  proxyAuthinfo.username = "";
  1.1021 +  proxyAuthinfo.password = "";
  1.1022 +  proxyAuthinfo.realm    = "Proxy Realm";
  1.1023 +  proxyAuthinfo.flags    = Ci.nsIAuthInformation.AUTH_PROXY;
  1.1024 +
  1.1025 +  dumpNotifications();
  1.1026 +  var time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1027 +  startCallbackTimer();
  1.1028 +  isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
  1.1029 +  var time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1030 +
  1.1031 +  ok(isOk, "Checking dialog return value (accept)");
  1.1032 +  ok(didDialog, "handleDialog was invoked");
  1.1033 +  isnot(time1, time2, "Checking that timeLastUsed was updated");
  1.1034 +  is(proxyAuthinfo.username, "proxuser", "Checking returned username");
  1.1035 +  is(proxyAuthinfo.password, "proxpass", "Checking returned password");
  1.1036 +
  1.1037 +  // ===== test 509 =====
  1.1038 +  // test proxy login (with autologin)
  1.1039 +  testNum++;
  1.1040 +
  1.1041 +  // Enable the autologin pref.
  1.1042 +  prefs.setBoolPref("signon.autologin.proxy", true);
  1.1043 +
  1.1044 +  proxyAuthinfo.username = "";
  1.1045 +  proxyAuthinfo.password = "";
  1.1046 +  proxyAuthinfo.realm    = "Proxy Realm";
  1.1047 +  proxyAuthinfo.flags    = Ci.nsIAuthInformation.AUTH_PROXY;
  1.1048 +
  1.1049 +  time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1050 +  isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
  1.1051 +  time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1052 +
  1.1053 +  ok(isOk, "Checking dialog return value (accept)");
  1.1054 +  isnot(time1, time2, "Checking that timeLastUsed was updated");
  1.1055 +  is(proxyAuthinfo.username, "proxuser", "Checking returned username");
  1.1056 +  is(proxyAuthinfo.password, "proxpass", "Checking returned password");
  1.1057 +
  1.1058 +  // ===== test 510 =====
  1.1059 +  // test proxy login (with autologin), ensure it prompts after a failed auth.
  1.1060 +  testNum++;
  1.1061 +
  1.1062 +  proxyAuthinfo.username = "";
  1.1063 +  proxyAuthinfo.password = "";
  1.1064 +  proxyAuthinfo.realm    = "Proxy Realm";
  1.1065 +  proxyAuthinfo.flags    = (Ci.nsIAuthInformation.AUTH_PROXY | Ci.nsIAuthInformation.PREVIOUS_FAILED);
  1.1066 +
  1.1067 +  time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1068 +  startCallbackTimer();
  1.1069 +  isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
  1.1070 +  time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
  1.1071 +
  1.1072 +  ok(isOk, "Checking dialog return value (accept)");
  1.1073 +  ok(didDialog, "handleDialog was invoked");
  1.1074 +  isnot(time1, time2, "Checking that timeLastUsed was updated");
  1.1075 +  is(proxyAuthinfo.username, "proxuser", "Checking returned username");
  1.1076 +  is(proxyAuthinfo.password, "proxpass", "Checking returned password");
  1.1077 +
  1.1078 +  // ===== test 511 =====
  1.1079 +  // test proxy login (with autologin), ensure it prompts in Private Browsing mode.
  1.1080 +  testNum++;
  1.1081 +
  1.1082 +  proxyAuthinfo.username = "";
  1.1083 +  proxyAuthinfo.password = "";
  1.1084 +  proxyAuthinfo.realm    = "Proxy Realm";
  1.1085 +  proxyAuthinfo.flags    = Ci.nsIAuthInformation.AUTH_PROXY;
  1.1086 +
  1.1087 +  prefs.clearUserPref("signon.autologin.proxy");
  1.1088 +
  1.1089 +  // XXX check for and kill popup notification??
  1.1090 +  // XXX check for checkbox / checkstate on old prompts?
  1.1091 +  // XXX check NTLM domain stuff
  1.1092 +
  1.1093 +  var iframe = document.getElementById("iframe");
  1.1094 +  iframe.onload = handleLoad;
  1.1095 +
  1.1096 +  // clear plain HTTP auth sessions before the test, to allow
  1.1097 +  // running them more than once.
  1.1098 +  var authMgr = Cc['@mozilla.org/network/http-auth-manager;1'].
  1.1099 +                getService(Ci.nsIHttpAuthManager);
  1.1100 +  authMgr.clearAll();
  1.1101 +
  1.1102 +  // ===== test 1000 =====
  1.1103 +  testNum = 1000;
  1.1104 +  startCallbackTimer();
  1.1105 +  iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
  1.1106 +
  1.1107 +  // ...remaining tests are driven by handleLoad()...
  1.1108 +}
  1.1109 +</script>
  1.1110 +</pre>
  1.1111 +</body>
  1.1112 +</html>

mercurial