Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for Login Manager</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="pwmgr_common.js"></script> |
michael@0 | 7 | <script type="text/javascript" src="prompt_common.js"></script> |
michael@0 | 8 | <script type="text/javascript" src="notification_common.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | Login Manager test: username/password prompts |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | <iframe id="iframe"></iframe> |
michael@0 | 17 | </div> |
michael@0 | 18 | |
michael@0 | 19 | <pre id="test"> |
michael@0 | 20 | <script class="testbody" type="text/javascript"> |
michael@0 | 21 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | /** Test for Login Manager: username / password prompts. **/ |
michael@0 | 24 | var pwmgr, ioService, observerService; |
michael@0 | 25 | var tmplogin, login1, login2A, login2B, login2C, login2D, login2E, login3A, login3B, login4, proxyLogin; |
michael@0 | 26 | var mozproxy, proxiedHost = "http://mochi.test:8888"; |
michael@0 | 27 | var proxyChannel; |
michael@0 | 28 | var testNum = 1; |
michael@0 | 29 | |
michael@0 | 30 | function initLogins(pi) { |
michael@0 | 31 | observerService = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 32 | getService(Ci.nsIObserverService); |
michael@0 | 33 | observerService.addObserver(storageObserver, "passwordmgr-storage-changed", false); |
michael@0 | 34 | |
michael@0 | 35 | pwmgr = Cc["@mozilla.org/login-manager;1"]. |
michael@0 | 36 | getService(Ci.nsILoginManager); |
michael@0 | 37 | ioService = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 38 | getService(Ci.nsIIOService); |
michael@0 | 39 | |
michael@0 | 40 | mozproxy = "moz-proxy://" + SpecialPowers.wrap(pi).host + ":" + |
michael@0 | 41 | SpecialPowers.wrap(pi).port; |
michael@0 | 42 | |
michael@0 | 43 | tmpLogin = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 44 | createInstance(Ci.nsILoginInfo); |
michael@0 | 45 | |
michael@0 | 46 | login1 = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 47 | createInstance(Ci.nsILoginInfo); |
michael@0 | 48 | login2A = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 49 | createInstance(Ci.nsILoginInfo); |
michael@0 | 50 | login2B = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 51 | createInstance(Ci.nsILoginInfo); |
michael@0 | 52 | login2C = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 53 | createInstance(Ci.nsILoginInfo); |
michael@0 | 54 | login2D = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 55 | createInstance(Ci.nsILoginInfo); |
michael@0 | 56 | login2E = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 57 | createInstance(Ci.nsILoginInfo); |
michael@0 | 58 | login3A = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 59 | createInstance(Ci.nsILoginInfo); |
michael@0 | 60 | login3B = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 61 | createInstance(Ci.nsILoginInfo); |
michael@0 | 62 | login4 = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 63 | createInstance(Ci.nsILoginInfo); |
michael@0 | 64 | proxyLogin = Cc["@mozilla.org/login-manager/loginInfo;1"]. |
michael@0 | 65 | createInstance(Ci.nsILoginInfo); |
michael@0 | 66 | |
michael@0 | 67 | login1.init("http://example.com", null, "http://example.com", |
michael@0 | 68 | "", "examplepass", "", ""); |
michael@0 | 69 | login2A.init("http://example2.com", null, "http://example2.com", |
michael@0 | 70 | "user1name", "user1pass", "", ""); |
michael@0 | 71 | login2B.init("http://example2.com", null, "http://example2.com", |
michael@0 | 72 | "user2name", "user2pass", "", ""); |
michael@0 | 73 | login2C.init("http://example2.com", null, "http://example2.com", |
michael@0 | 74 | "user3.name@host", "user3pass", "", ""); |
michael@0 | 75 | login2D.init("http://example2.com", null, "http://example2.com", |
michael@0 | 76 | "100@beef", "user3pass", "", ""); |
michael@0 | 77 | login2E.init("http://example2.com", null, "http://example2.com", |
michael@0 | 78 | "100%beef", "user3pass", "", ""); |
michael@0 | 79 | login3A.init("http://mochi.test:8888", null, "mochitest", |
michael@0 | 80 | "mochiuser1", "mochipass1", "", ""); |
michael@0 | 81 | login3B.init("http://mochi.test:8888", null, "mochitest2", |
michael@0 | 82 | "mochiuser2", "mochipass2", "", ""); |
michael@0 | 83 | login4.init("http://mochi.test:8888", null, "mochitest3", |
michael@0 | 84 | "mochiuser3", "mochipass3-old", "", ""); |
michael@0 | 85 | proxyLogin.init(mozproxy, null, "Proxy Realm", |
michael@0 | 86 | "proxuser", "proxpass", "", ""); |
michael@0 | 87 | |
michael@0 | 88 | pwmgr.addLogin(login1); |
michael@0 | 89 | pwmgr.addLogin(login2A); |
michael@0 | 90 | pwmgr.addLogin(login2B); |
michael@0 | 91 | pwmgr.addLogin(login2C); |
michael@0 | 92 | pwmgr.addLogin(login2D); |
michael@0 | 93 | pwmgr.addLogin(login2E); |
michael@0 | 94 | pwmgr.addLogin(login3A); |
michael@0 | 95 | pwmgr.addLogin(login3B); |
michael@0 | 96 | pwmgr.addLogin(login4); |
michael@0 | 97 | pwmgr.addLogin(proxyLogin); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function finishTest() { |
michael@0 | 101 | try { |
michael@0 | 102 | ok(true, "finishTest removing testing logins..."); |
michael@0 | 103 | observerService.removeObserver(storageObserver, "passwordmgr-storage-changed"); |
michael@0 | 104 | |
michael@0 | 105 | dumpLogins(pwmgr); |
michael@0 | 106 | ok(true, "removing login 1..."); |
michael@0 | 107 | pwmgr.removeLogin(login1); |
michael@0 | 108 | ok(true, "removing login 2A..."); |
michael@0 | 109 | pwmgr.removeLogin(login2A); |
michael@0 | 110 | ok(true, "removing login 2B..."); |
michael@0 | 111 | pwmgr.removeLogin(login2B); |
michael@0 | 112 | ok(true, "removing login 2C..."); |
michael@0 | 113 | pwmgr.removeLogin(login2C); |
michael@0 | 114 | ok(true, "removing login 2D..."); |
michael@0 | 115 | pwmgr.removeLogin(login2D); |
michael@0 | 116 | ok(true, "removing login 2E..."); |
michael@0 | 117 | pwmgr.removeLogin(login2E); |
michael@0 | 118 | ok(true, "removing login 3A..."); |
michael@0 | 119 | pwmgr.removeLogin(login3A); |
michael@0 | 120 | ok(true, "removing login 3B..."); |
michael@0 | 121 | pwmgr.removeLogin(login3B); |
michael@0 | 122 | ok(true, "removing login 4..."); |
michael@0 | 123 | pwmgr.removeLogin(login4); |
michael@0 | 124 | ok(true, "removing proxyLogin..."); |
michael@0 | 125 | pwmgr.removeLogin(proxyLogin); |
michael@0 | 126 | } catch (e) { |
michael@0 | 127 | ok(false, "finishTest FAILED: " + e); |
michael@0 | 128 | } |
michael@0 | 129 | ok(true, "whee, done!"); |
michael@0 | 130 | |
michael@0 | 131 | SimpleTest.finish(); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function proxyChannelListener() { } |
michael@0 | 135 | proxyChannelListener.prototype = { |
michael@0 | 136 | onStartRequest: function(request, context) { |
michael@0 | 137 | doTests(); |
michael@0 | 138 | }, |
michael@0 | 139 | onStopRequest: function(request, context, status) { } |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | var resolveCallback = SpecialPowers.wrapCallbackObject({ |
michael@0 | 143 | QueryInterface : function (iid) { |
michael@0 | 144 | const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports]; |
michael@0 | 145 | |
michael@0 | 146 | if (!interfaces.some( function(v) { return iid.equals(v) } )) |
michael@0 | 147 | throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 148 | return this; |
michael@0 | 149 | }, |
michael@0 | 150 | |
michael@0 | 151 | onProxyAvailable : function (req, uri, pi, status) { |
michael@0 | 152 | initLogins(pi); |
michael@0 | 153 | |
michael@0 | 154 | // I'm cheating a bit here... We should probably do some magic foo to get |
michael@0 | 155 | // something implementing nsIProxiedProtocolHandler and then call |
michael@0 | 156 | // NewProxiedChannel(), so we have something that's definately a proxied |
michael@0 | 157 | // channel. But Mochitests use a proxy for a number of hosts, so just |
michael@0 | 158 | // requesting a normal channel will give us a channel that's proxied. |
michael@0 | 159 | // The proxyChannel needs to move to at least on-modify-request to |
michael@0 | 160 | // have valid ProxyInfo, but we use OnStartRequest during startup() |
michael@0 | 161 | // for simplicity. |
michael@0 | 162 | proxyChannel = ioService.newChannel(proxiedHost, null, null); |
michael@0 | 163 | proxyChannel.asyncOpen(SpecialPowers.wrapCallbackObject(new proxyChannelListener()), null); |
michael@0 | 164 | } |
michael@0 | 165 | }); |
michael@0 | 166 | |
michael@0 | 167 | function startup() { |
michael@0 | 168 | //need to allow for arbitrary network servers defined in PAC instead of a hardcoded moz-proxy. |
michael@0 | 169 | var ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 170 | getService(SpecialPowers.Ci.nsIIOService); |
michael@0 | 171 | |
michael@0 | 172 | var pps = SpecialPowers.Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(); |
michael@0 | 173 | |
michael@0 | 174 | var uri = ios.newURI("http://example.com", null, null); |
michael@0 | 175 | pps.asyncResolve(uri, 0, resolveCallback); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | function addNotificationCallback(cb) { |
michael@0 | 179 | storageObserver.notificationCallbacks.push(cb); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | var storageObserver = SpecialPowers.wrapCallbackObject({ |
michael@0 | 183 | notificationCallbacks: [], |
michael@0 | 184 | |
michael@0 | 185 | QueryInterface : function (iid) { |
michael@0 | 186 | const interfaces = [Ci.nsIObserver, |
michael@0 | 187 | Ci.nsISupports, Ci.nsISupportsWeakReference]; |
michael@0 | 188 | |
michael@0 | 189 | if (!interfaces.some( function(v) { return iid.equals(v) } )) |
michael@0 | 190 | throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 191 | return this; |
michael@0 | 192 | }, |
michael@0 | 193 | |
michael@0 | 194 | observe : function (subject, topic, data) { |
michael@0 | 195 | ok(true, "."); |
michael@0 | 196 | ok(true, "observer for " + topic + " / " + data); |
michael@0 | 197 | ok(true, "Time is " + (new Date()).toUTCString()); |
michael@0 | 198 | var wrapped = SpecialPowers.wrap(subject); |
michael@0 | 199 | try { |
michael@0 | 200 | switch (data) { |
michael@0 | 201 | case "addLogin": |
michael@0 | 202 | ok(wrapped.QueryInterface(Ci.nsILoginInfo), "subject QI 1"); |
michael@0 | 203 | ok(wrapped.QueryInterface(Ci.nsILoginMetaInfo), "subject QI 2"); |
michael@0 | 204 | dumpLogin("added: ", subject); |
michael@0 | 205 | break; |
michael@0 | 206 | case "modifyLogin": |
michael@0 | 207 | var arr = wrapped.QueryInterface(Ci.nsIArray); |
michael@0 | 208 | ok(arr, "subject QI"); |
michael@0 | 209 | is(arr.length, 2, "should be 2 items"); |
michael@0 | 210 | var oldLogin = arr.queryElementAt(0, Ci.nsILoginInfo); |
michael@0 | 211 | var newLogin = arr.queryElementAt(1, Ci.nsILoginInfo); |
michael@0 | 212 | dumpLogin("oldLogin: ", oldLogin); |
michael@0 | 213 | dumpLogin("newLogin: ", newLogin); |
michael@0 | 214 | break; |
michael@0 | 215 | case "removeLogin": |
michael@0 | 216 | ok(wrapped.QueryInterface(Ci.nsILoginInfo), "subject QI 1"); |
michael@0 | 217 | ok(wrapped.QueryInterface(Ci.nsILoginMetaInfo), "subject QI 2"); |
michael@0 | 218 | dumpLogin("removed: ", subject); |
michael@0 | 219 | break; |
michael@0 | 220 | case "removeAllLogins": |
michael@0 | 221 | is(subject, null, "no subject"); |
michael@0 | 222 | break; |
michael@0 | 223 | case "hostSavingEnabled": |
michael@0 | 224 | case "hostSavingDisabled": |
michael@0 | 225 | ok(subject instanceof Ci.nsISupportsString, "subject QI"); |
michael@0 | 226 | ok(true, "state is: " + subject.data); |
michael@0 | 227 | break; |
michael@0 | 228 | default: |
michael@0 | 229 | do_throw("Unhandled notification: " + data + " / " + topic); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | if (this.notificationCallbacks.length) |
michael@0 | 233 | this.notificationCallbacks.splice(0, 1)[0](); |
michael@0 | 234 | } catch (e) { |
michael@0 | 235 | ok(false, "OBSERVER FAILED: " + e); |
michael@0 | 236 | } |
michael@0 | 237 | } |
michael@0 | 238 | }); |
michael@0 | 239 | |
michael@0 | 240 | /* |
michael@0 | 241 | * handleDialog |
michael@0 | 242 | * |
michael@0 | 243 | * Invoked a short period of time after calling startCallbackTimer(), and |
michael@0 | 244 | * allows testing the actual auth dialog while it's being displayed. Tests |
michael@0 | 245 | * should call startCallbackTimer() each time the auth dialog is expected (the |
michael@0 | 246 | * timer is a one-shot). |
michael@0 | 247 | */ |
michael@0 | 248 | function handleDialog(doc, testNum) { |
michael@0 | 249 | ok(true, "."); // make it easier to see next line in logs. |
michael@0 | 250 | ok(true, "handleDialog running for test " + testNum); |
michael@0 | 251 | ok(true, "Time is " + (new Date()).toUTCString()); |
michael@0 | 252 | dumpNotifications(); |
michael@0 | 253 | |
michael@0 | 254 | var clickOK = true; |
michael@0 | 255 | var body = doc.getElementById("info.body"); |
michael@0 | 256 | var userfield = doc.getElementById("loginTextbox"); |
michael@0 | 257 | var passfield = doc.getElementById("password1Textbox"); |
michael@0 | 258 | var username = userfield.getAttribute("value"); |
michael@0 | 259 | var password = passfield.getAttribute("value"); |
michael@0 | 260 | var dialog = doc.getElementById("commonDialog"); |
michael@0 | 261 | |
michael@0 | 262 | switch(testNum) { |
michael@0 | 263 | case 1: |
michael@0 | 264 | is(username, "abc", "Checking provided username"); |
michael@0 | 265 | userfield.setAttribute("value", "xyz"); |
michael@0 | 266 | // Temporarily commented out because of Bug #718543 |
michael@0 | 267 | // is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum); |
michael@0 | 268 | // doc.commandDispatcher.rewindFocus(); |
michael@0 | 269 | // is(doc.activeElement, body, "description focusable"); |
michael@0 | 270 | break; |
michael@0 | 271 | case 2: |
michael@0 | 272 | clickOK = false; |
michael@0 | 273 | break; |
michael@0 | 274 | case 10: |
michael@0 | 275 | is(password, "inputpw", "Checking provided password"); |
michael@0 | 276 | passfield.setAttribute("value", "secret"); |
michael@0 | 277 | // Temporarily commented out because of Bug #718543 |
michael@0 | 278 | // is(doc.activeElement, passfield.inputField, "focus correct for test" + testNum); |
michael@0 | 279 | break; |
michael@0 | 280 | case 11: |
michael@0 | 281 | is(password, "inputpw", "Checking provided password"); |
michael@0 | 282 | clickOK = false; |
michael@0 | 283 | break; |
michael@0 | 284 | case 12: |
michael@0 | 285 | is(password, "", "Checking provided password"); |
michael@0 | 286 | passfield.setAttribute("value", "secret"); |
michael@0 | 287 | break; |
michael@0 | 288 | case 14: |
michael@0 | 289 | is(password, "", "Checking provided password"); |
michael@0 | 290 | passfield.setAttribute("value", "secret"); |
michael@0 | 291 | break; |
michael@0 | 292 | case 30: |
michael@0 | 293 | case 31: |
michael@0 | 294 | is(password, "", "Checking provided password"); |
michael@0 | 295 | passfield.setAttribute("value", "fill2pass"); |
michael@0 | 296 | break; |
michael@0 | 297 | case 100: |
michael@0 | 298 | is(username, "inuser", "Checking provided username"); |
michael@0 | 299 | is(password, "inpass", "Checking provided password"); |
michael@0 | 300 | userfield.setAttribute("value", "outuser"); |
michael@0 | 301 | passfield.setAttribute("value", "outpass"); |
michael@0 | 302 | break; |
michael@0 | 303 | case 101: |
michael@0 | 304 | clickOK = false; |
michael@0 | 305 | break; |
michael@0 | 306 | case 102: |
michael@0 | 307 | is(username, "", "Checking provided username"); |
michael@0 | 308 | is(password, "examplepass", "Checking provided password"); |
michael@0 | 309 | break; |
michael@0 | 310 | case 103: |
michael@0 | 311 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 312 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 313 | break; |
michael@0 | 314 | case 104: |
michael@0 | 315 | is(username, "user1name", "Checking filled username"); |
michael@0 | 316 | is(password, "user1pass", "Checking filled password"); |
michael@0 | 317 | break; |
michael@0 | 318 | case 105: |
michael@0 | 319 | is(username, "user2name", "Checking filled username"); |
michael@0 | 320 | is(password, "user2pass", "Checking filled password"); |
michael@0 | 321 | break; |
michael@0 | 322 | case 106: |
michael@0 | 323 | is(username, "user2name", "Checking filled username"); |
michael@0 | 324 | is(password, "user2pass", "Checking filled password"); |
michael@0 | 325 | passfield.setAttribute("value", "NEWuser2pass"); |
michael@0 | 326 | break; |
michael@0 | 327 | case 107: |
michael@0 | 328 | is(username, "user2name", "Checking filled username"); |
michael@0 | 329 | is(password, "NEWuser2pass", "Checking filled password"); |
michael@0 | 330 | passfield.setAttribute("value", "user2pass"); |
michael@0 | 331 | break; |
michael@0 | 332 | case 120: |
michael@0 | 333 | case 121: |
michael@0 | 334 | is(username, "", "Checking filled username"); |
michael@0 | 335 | is(password, "", "Checking filled password"); |
michael@0 | 336 | userfield.setAttribute("value", "fill2user"); |
michael@0 | 337 | passfield.setAttribute("value", "fill2pass"); |
michael@0 | 338 | break; |
michael@0 | 339 | case 500: |
michael@0 | 340 | is(username, "inuser", "Checking unfilled username"); |
michael@0 | 341 | is(password, "inpass", "Checking unfilled password"); |
michael@0 | 342 | userfield.setAttribute("value", "outuser"); |
michael@0 | 343 | passfield.setAttribute("value", "outpass"); |
michael@0 | 344 | break; |
michael@0 | 345 | case 501: |
michael@0 | 346 | clickOK = false; |
michael@0 | 347 | break; |
michael@0 | 348 | case 502: |
michael@0 | 349 | is(username, "", "Checking filled username"); |
michael@0 | 350 | is(password, "examplepass", "Checking filled password"); |
michael@0 | 351 | break; |
michael@0 | 352 | case 503: |
michael@0 | 353 | // either of the two logins might have been filled in |
michael@0 | 354 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 355 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 356 | break; |
michael@0 | 357 | case 504: |
michael@0 | 358 | // either of the two logins might have been filled in |
michael@0 | 359 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 360 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 361 | // enter one of the known logins, test 504+505 exercise the two possible states. |
michael@0 | 362 | userfield.setAttribute("value", "user1name"); |
michael@0 | 363 | passfield.setAttribute("value", "user1pass"); |
michael@0 | 364 | break; |
michael@0 | 365 | case 505: |
michael@0 | 366 | // either of the two logins might have been filled in |
michael@0 | 367 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 368 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 369 | // enter one of the known logins, test 504+505 exercise the two possible states. |
michael@0 | 370 | userfield.setAttribute("value", "user2name"); |
michael@0 | 371 | passfield.setAttribute("value", "user2pass"); |
michael@0 | 372 | break; |
michael@0 | 373 | case 506: |
michael@0 | 374 | // either of the two logins might have been filled in |
michael@0 | 375 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 376 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 377 | // force to user2, and change the password |
michael@0 | 378 | userfield.setAttribute("value", "user2name"); |
michael@0 | 379 | passfield.setAttribute("value", "NEWuser2pass"); |
michael@0 | 380 | break; |
michael@0 | 381 | case 507: |
michael@0 | 382 | // either of the two logins might have been filled in |
michael@0 | 383 | ok(username == "user1name" || username == "user2name", "Checking filled username"); |
michael@0 | 384 | ok(password == "user1pass" || password == "user2pass", "Checking filled password"); |
michael@0 | 385 | // force to user2, and change the password back |
michael@0 | 386 | userfield.setAttribute("value", "user2name"); |
michael@0 | 387 | passfield.setAttribute("value", "user2pass"); |
michael@0 | 388 | break; |
michael@0 | 389 | case 508: |
michael@0 | 390 | is(username, "proxuser", "Checking filled username"); |
michael@0 | 391 | is(password, "proxpass", "Checking filled password"); |
michael@0 | 392 | break; |
michael@0 | 393 | // No case 509, it's unprompted. |
michael@0 | 394 | case 510: |
michael@0 | 395 | is(username, "proxuser", "Checking filled username"); |
michael@0 | 396 | is(password, "proxpass", "Checking filled password"); |
michael@0 | 397 | break; |
michael@0 | 398 | case 511: |
michael@0 | 399 | is(username, "proxuser", "Checking filled username"); |
michael@0 | 400 | is(password, "proxpass", "Checking filled password"); |
michael@0 | 401 | break; |
michael@0 | 402 | case 1000: |
michael@0 | 403 | is(username, "mochiuser1", "Checking filled username"); |
michael@0 | 404 | is(password, "mochipass1", "Checking filled password"); |
michael@0 | 405 | break; |
michael@0 | 406 | case 1001: |
michael@0 | 407 | is(username, "mochiuser2", "Checking filled username"); |
michael@0 | 408 | is(password, "mochipass2", "Checking filled password"); |
michael@0 | 409 | break; |
michael@0 | 410 | // (1002 doesn't trigger a dialog) |
michael@0 | 411 | case 1003: |
michael@0 | 412 | is(username, "mochiuser1", "Checking filled username"); |
michael@0 | 413 | is(password, "mochipass1", "Checking filled password"); |
michael@0 | 414 | passfield.setAttribute("value", "mochipass1-new"); |
michael@0 | 415 | break; |
michael@0 | 416 | case 1004: |
michael@0 | 417 | is(username, "mochiuser3", "Checking filled username"); |
michael@0 | 418 | is(password, "mochipass3-old", "Checking filled password"); |
michael@0 | 419 | passfield.setAttribute("value", "mochipass3-new"); |
michael@0 | 420 | break; |
michael@0 | 421 | case 1005: |
michael@0 | 422 | is(username, "", "Checking filled username"); |
michael@0 | 423 | is(password, "", "Checking filled password"); |
michael@0 | 424 | userfield.setAttribute("value", "mochiuser3"); |
michael@0 | 425 | passfield.setAttribute("value", "mochipass3-old"); |
michael@0 | 426 | break; |
michael@0 | 427 | default: |
michael@0 | 428 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 429 | break; |
michael@0 | 430 | } |
michael@0 | 431 | |
michael@0 | 432 | if (clickOK) |
michael@0 | 433 | dialog.acceptDialog(); |
michael@0 | 434 | else |
michael@0 | 435 | dialog.cancelDialog(); |
michael@0 | 436 | |
michael@0 | 437 | ok(true, "handleDialog done"); |
michael@0 | 438 | didDialog = true; |
michael@0 | 439 | } |
michael@0 | 440 | |
michael@0 | 441 | /* |
michael@0 | 442 | * handleLoad |
michael@0 | 443 | * |
michael@0 | 444 | * Called when a load event is fired at the subtest's iframe. |
michael@0 | 445 | */ |
michael@0 | 446 | function handleLoad() { |
michael@0 | 447 | ok(true, "."); // make it easier to see next line in logs. |
michael@0 | 448 | ok(true, "handleLoad running for test " + testNum); |
michael@0 | 449 | ok(true, "Time is " + (new Date()).toUTCString()); |
michael@0 | 450 | dumpNotifications(); |
michael@0 | 451 | |
michael@0 | 452 | if (testNum != 1002) |
michael@0 | 453 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 454 | |
michael@0 | 455 | // The server echos back the user/pass it received. |
michael@0 | 456 | var username = iframe.contentDocument.getElementById("user").textContent; |
michael@0 | 457 | var password = iframe.contentDocument.getElementById("pass").textContent; |
michael@0 | 458 | var authok = iframe.contentDocument.getElementById("ok").textContent; |
michael@0 | 459 | |
michael@0 | 460 | switch(testNum) { |
michael@0 | 461 | case 1000: |
michael@0 | 462 | testNum++; |
michael@0 | 463 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 464 | is(username, "mochiuser1", "Checking for echoed username"); |
michael@0 | 465 | is(password, "mochipass1", "Checking for echoed password"); |
michael@0 | 466 | startCallbackTimer(); |
michael@0 | 467 | // We've already authenticated to this host:port. For this next |
michael@0 | 468 | // request, the existing auth should be sent, we'll get a 401 reply, |
michael@0 | 469 | // and we should prompt for new auth. |
michael@0 | 470 | iframe.src = "authenticate.sjs?user=mochiuser2&pass=mochipass2&realm=mochitest2"; |
michael@0 | 471 | break; |
michael@0 | 472 | case 1001: |
michael@0 | 473 | testNum++; |
michael@0 | 474 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 475 | is(username, "mochiuser2", "Checking for echoed username"); |
michael@0 | 476 | is(password, "mochipass2", "Checking for echoed password"); |
michael@0 | 477 | // Now make a load that requests the realm from test 1000. It was |
michael@0 | 478 | // already provided there, so auth will *not* be prompted for -- the |
michael@0 | 479 | // networking layer already knows it! |
michael@0 | 480 | iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1"; |
michael@0 | 481 | break; |
michael@0 | 482 | case 1002: |
michael@0 | 483 | testNum++; |
michael@0 | 484 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 485 | is(username, "mochiuser1", "Checking for echoed username"); |
michael@0 | 486 | is(password, "mochipass1", "Checking for echoed password"); |
michael@0 | 487 | |
michael@0 | 488 | // Same realm we've already authenticated to, but with a different |
michael@0 | 489 | // expected password (to trigger an auth prompt, and change-password |
michael@0 | 490 | // popup notification). |
michael@0 | 491 | startCallbackTimer(); |
michael@0 | 492 | iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1-new"; |
michael@0 | 493 | break; |
michael@0 | 494 | case 1003: |
michael@0 | 495 | testNum++; |
michael@0 | 496 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 497 | is(username, "mochiuser1", "Checking for echoed username"); |
michael@0 | 498 | is(password, "mochipass1-new", "Checking for echoed password"); |
michael@0 | 499 | |
michael@0 | 500 | // Housekeeping: change it back |
michael@0 | 501 | function resetIt() { |
michael@0 | 502 | tmpLogin.init("http://mochi.test:8888", null, "mochitest", |
michael@0 | 503 | "mochiuser1", "mochipass1-new", "", ""); |
michael@0 | 504 | pwmgr.modifyLogin(tmpLogin, login3A); |
michael@0 | 505 | } |
michael@0 | 506 | addNotificationCallback(resetIt); |
michael@0 | 507 | |
michael@0 | 508 | // Check for the popup notification, and change the password. |
michael@0 | 509 | popupNotifications = getPopupNotifications(window.top); |
michael@0 | 510 | popup = getPopup(popupNotifications, "password-change"); |
michael@0 | 511 | ok(popup, "got popup notification"); |
michael@0 | 512 | clickPopupButton(popup, kChangeButton); |
michael@0 | 513 | popup.remove(); |
michael@0 | 514 | |
michael@0 | 515 | // Same as last test, but for a realm we haven't already authenticated |
michael@0 | 516 | // to (but have an existing saved login for, so that we'll trigger |
michael@0 | 517 | // a change-password popup notification. |
michael@0 | 518 | startCallbackTimer(); |
michael@0 | 519 | iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-new&realm=mochitest3"; |
michael@0 | 520 | break; |
michael@0 | 521 | case 1004: |
michael@0 | 522 | testNum++; |
michael@0 | 523 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 524 | is(username, "mochiuser3", "Checking for echoed username"); |
michael@0 | 525 | is(password, "mochipass3-new", "Checking for echoed password"); |
michael@0 | 526 | |
michael@0 | 527 | // Housekeeping: change it back to the original login4. Actually, |
michael@0 | 528 | // just delete it and we'll re-add it as the next test. |
michael@0 | 529 | function clearIt() { |
michael@0 | 530 | ok(true, "1004's clearIt() called."); |
michael@0 | 531 | try { |
michael@0 | 532 | tmpLogin.init("http://mochi.test:8888", null, "mochitest3", |
michael@0 | 533 | "mochiuser3", "mochipass3-new", "", ""); |
michael@0 | 534 | pwmgr.removeLogin(tmpLogin); |
michael@0 | 535 | |
michael@0 | 536 | // Trigger a new prompt, so we can test adding a new login. |
michael@0 | 537 | startCallbackTimer(); |
michael@0 | 538 | iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-old&realm=mochitest3"; |
michael@0 | 539 | } catch (e) { ok(false, "clearIt GOT EXCEPTION: " + e); } |
michael@0 | 540 | } |
michael@0 | 541 | addNotificationCallback(clearIt); |
michael@0 | 542 | |
michael@0 | 543 | // Check for the popup notification, and change the password. |
michael@0 | 544 | popup = getPopup(popupNotifications, "password-change"); |
michael@0 | 545 | ok(popup, "got popup notification"); |
michael@0 | 546 | clickPopupButton(popup, kChangeButton); |
michael@0 | 547 | popup.remove(); |
michael@0 | 548 | |
michael@0 | 549 | // Clear cached auth from this subtest, and avoid leaking due to bug 459620. |
michael@0 | 550 | var authMgr = Cc['@mozilla.org/network/http-auth-manager;1']. |
michael@0 | 551 | getService(Ci.nsIHttpAuthManager); |
michael@0 | 552 | authMgr.clearAll(); |
michael@0 | 553 | ok(true, "authMgr cleared cached auth"); |
michael@0 | 554 | break; |
michael@0 | 555 | case 1005: |
michael@0 | 556 | testNum++; |
michael@0 | 557 | is(authok, "PASS", "Checking for successful authentication"); |
michael@0 | 558 | is(username, "mochiuser3", "Checking for echoed username"); |
michael@0 | 559 | is(password, "mochipass3-old", "Checking for echoed password"); |
michael@0 | 560 | |
michael@0 | 561 | function finishIt() { |
michael@0 | 562 | finishTest(); |
michael@0 | 563 | } |
michael@0 | 564 | addNotificationCallback(finishIt); |
michael@0 | 565 | |
michael@0 | 566 | // Check for the popup notification, and change the password. |
michael@0 | 567 | popup = getPopup(popupNotifications, "password-save"); |
michael@0 | 568 | ok(popup, "got popup notification"); |
michael@0 | 569 | clickPopupButton(popup, kRememberButton); |
michael@0 | 570 | popup.remove(); |
michael@0 | 571 | break; |
michael@0 | 572 | default: |
michael@0 | 573 | ok(false, "Uhh, unhandled switch for testNum #" + testNum); |
michael@0 | 574 | break; |
michael@0 | 575 | } |
michael@0 | 576 | } |
michael@0 | 577 | |
michael@0 | 578 | startup(); |
michael@0 | 579 | |
michael@0 | 580 | function doTests() { |
michael@0 | 581 | var authinfo = { |
michael@0 | 582 | username : "", |
michael@0 | 583 | password : "", |
michael@0 | 584 | domain : "", |
michael@0 | 585 | |
michael@0 | 586 | flags : Ci.nsIAuthInformation.AUTH_HOST, |
michael@0 | 587 | authenticationScheme : "basic", |
michael@0 | 588 | realm : "" |
michael@0 | 589 | }; |
michael@0 | 590 | |
michael@0 | 591 | var proxyAuthinfo = { |
michael@0 | 592 | username : "", |
michael@0 | 593 | password : "", |
michael@0 | 594 | domain : "", |
michael@0 | 595 | |
michael@0 | 596 | flags : Ci.nsIAuthInformation.AUTH_PROXY, |
michael@0 | 597 | authenticationScheme : "basic", |
michael@0 | 598 | realm : "" |
michael@0 | 599 | }; |
michael@0 | 600 | |
michael@0 | 601 | var prefs = Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 602 | getService(Ci.nsIPrefBranch); |
michael@0 | 603 | |
michael@0 | 604 | const Cc_promptFac= Cc["@mozilla.org/passwordmanager/authpromptfactory;1"]; |
michael@0 | 605 | ok(Cc_promptFac != null, "Access Cc[@mozilla.org/passwordmanager/authpromptfactory;1]"); |
michael@0 | 606 | |
michael@0 | 607 | const Ci_promptFac = Ci.nsIPromptFactory; |
michael@0 | 608 | ok(Ci_promptFac != null, "Access Ci.nsIPromptFactory"); |
michael@0 | 609 | |
michael@0 | 610 | const promptFac = Cc_promptFac.getService(Ci_promptFac); |
michael@0 | 611 | ok(promptFac != null, "promptFac getService()"); |
michael@0 | 612 | |
michael@0 | 613 | var prompter1 = promptFac.getPrompt(window, Ci.nsIAuthPrompt); |
michael@0 | 614 | var prompter2 = promptFac.getPrompt(window, Ci.nsIAuthPrompt2); |
michael@0 | 615 | |
michael@0 | 616 | function dialogTitle() { return "nsILoginManagerPrompter test #" + testNum; } |
michael@0 | 617 | var dialogText = "This dialog should be modified and dismissed by the test."; |
michael@0 | 618 | var uname = { value : null }; |
michael@0 | 619 | var pword = { value : null }; |
michael@0 | 620 | var result = { value : null }; |
michael@0 | 621 | var isOk; |
michael@0 | 622 | |
michael@0 | 623 | // popupNotifications (not *popup*) is a constant, per-tab container. So, we |
michael@0 | 624 | // only need to fetch it once. |
michael@0 | 625 | var popupNotifications = getPopupNotifications(window.top); |
michael@0 | 626 | ok(popupNotifications, "Got popupNotifications"); |
michael@0 | 627 | |
michael@0 | 628 | // ===== test 1 ===== |
michael@0 | 629 | testNum = 1; |
michael@0 | 630 | startCallbackTimer(); |
michael@0 | 631 | isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 632 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result); |
michael@0 | 633 | |
michael@0 | 634 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 635 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 636 | is(result.value, "xyz", "Checking prompt() returned value"); |
michael@0 | 637 | |
michael@0 | 638 | // ===== test 2 ===== |
michael@0 | 639 | testNum++; |
michael@0 | 640 | startCallbackTimer(); |
michael@0 | 641 | isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 642 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result); |
michael@0 | 643 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 644 | ok(!isOk, "Checking dialog return value (cancel)"); |
michael@0 | 645 | |
michael@0 | 646 | // ===== test 10 ===== |
michael@0 | 647 | // Default password provided, existing logins are ignored. |
michael@0 | 648 | testNum = 10; |
michael@0 | 649 | pword.value = "inputpw"; |
michael@0 | 650 | startCallbackTimer(); |
michael@0 | 651 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 652 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 653 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 654 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 655 | is(pword.value, "secret", "Checking returned password"); |
michael@0 | 656 | |
michael@0 | 657 | // ===== test 11 ===== |
michael@0 | 658 | // Default password provided, existing logins are ignored. |
michael@0 | 659 | testNum++; |
michael@0 | 660 | pword.value = "inputpw"; |
michael@0 | 661 | startCallbackTimer(); |
michael@0 | 662 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 663 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 664 | ok(!isOk, "Checking dialog return value (cancel)"); |
michael@0 | 665 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 666 | |
michael@0 | 667 | // ===== test 12 ===== |
michael@0 | 668 | // No default password provided, realm does not match existing login. |
michael@0 | 669 | testNum++; |
michael@0 | 670 | pword.value = null; |
michael@0 | 671 | startCallbackTimer(); |
michael@0 | 672 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://nonexample.com", |
michael@0 | 673 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 674 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 675 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 676 | is(pword.value, "secret", "Checking returned password"); |
michael@0 | 677 | |
michael@0 | 678 | // ===== test 13 ===== |
michael@0 | 679 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 680 | testNum++; |
michael@0 | 681 | pword.value = null; |
michael@0 | 682 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 683 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 684 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 685 | is(pword.value, "examplepass", "Checking returned password"); |
michael@0 | 686 | |
michael@0 | 687 | // ===== test 14 ===== |
michael@0 | 688 | // No default password provided, none of the logins from this host are |
michael@0 | 689 | // password-only so the user is prompted. |
michael@0 | 690 | testNum++; |
michael@0 | 691 | pword.value = null; |
michael@0 | 692 | startCallbackTimer(); |
michael@0 | 693 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 694 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 695 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 696 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 697 | is(pword.value, "secret", "Checking returned password"); |
michael@0 | 698 | |
michael@0 | 699 | // ===== test 15 ===== |
michael@0 | 700 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 701 | testNum++; |
michael@0 | 702 | pword.value = null; |
michael@0 | 703 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user1name@example2.com", |
michael@0 | 704 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 705 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 706 | is(pword.value, "user1pass", "Checking returned password"); |
michael@0 | 707 | |
michael@0 | 708 | // ===== test 16 ===== |
michael@0 | 709 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 710 | testNum++; |
michael@0 | 711 | pword.value = null; |
michael@0 | 712 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user2name@example2.com", |
michael@0 | 713 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 714 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 715 | is(pword.value, "user2pass", "Checking returned password"); |
michael@0 | 716 | |
michael@0 | 717 | // ===== test 17 ===== |
michael@0 | 718 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 719 | testNum++; |
michael@0 | 720 | pword.value = null; |
michael@0 | 721 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user3%2Ename%40host@example2.com", |
michael@0 | 722 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 723 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 724 | is(pword.value, "user3pass", "Checking returned password"); |
michael@0 | 725 | |
michael@0 | 726 | // ===== test 18 ===== |
michael@0 | 727 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 728 | testNum++; |
michael@0 | 729 | pword.value = null; |
michael@0 | 730 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100@beef@example2.com", |
michael@0 | 731 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 732 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 733 | is(pword.value, "user3pass", "Checking returned password"); |
michael@0 | 734 | |
michael@0 | 735 | // ===== test 19 ===== |
michael@0 | 736 | // No default password provided, matching login is returned w/o prompting. |
michael@0 | 737 | testNum++; |
michael@0 | 738 | pword.value = null; |
michael@0 | 739 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100%25beef@example2.com", |
michael@0 | 740 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 741 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 742 | is(pword.value, "user3pass", "Checking returned password"); |
michael@0 | 743 | |
michael@0 | 744 | // XXX test saving a password with Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY |
michael@0 | 745 | |
michael@0 | 746 | // ===== test 30 ===== |
michael@0 | 747 | // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt |
michael@0 | 748 | testNum = 30; |
michael@0 | 749 | pword.value = null; |
michael@0 | 750 | startCallbackTimer(); |
michael@0 | 751 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)", |
michael@0 | 752 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword); |
michael@0 | 753 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 754 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 755 | is(pword.value, "fill2pass", "Checking returned password"); |
michael@0 | 756 | |
michael@0 | 757 | // ===== test 31 ===== |
michael@0 | 758 | // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt |
michael@0 | 759 | testNum++; |
michael@0 | 760 | pword.value = null; |
michael@0 | 761 | startCallbackTimer(); |
michael@0 | 762 | isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)", |
michael@0 | 763 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, pword); |
michael@0 | 764 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 765 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 766 | is(pword.value, "fill2pass", "Checking returned password"); |
michael@0 | 767 | |
michael@0 | 768 | // ===== test 100 ===== |
michael@0 | 769 | testNum = 100; |
michael@0 | 770 | uname.value = "inuser"; |
michael@0 | 771 | pword.value = "inpass"; |
michael@0 | 772 | startCallbackTimer(); |
michael@0 | 773 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com", |
michael@0 | 774 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword); |
michael@0 | 775 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 776 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 777 | is(uname.value, "outuser", "Checking returned username"); |
michael@0 | 778 | is(pword.value, "outpass", "Checking returned password"); |
michael@0 | 779 | |
michael@0 | 780 | // ===== test 101 ===== |
michael@0 | 781 | testNum++; |
michael@0 | 782 | uname.value = "inuser"; |
michael@0 | 783 | pword.value = "inpass"; |
michael@0 | 784 | startCallbackTimer(); |
michael@0 | 785 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com", |
michael@0 | 786 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword); |
michael@0 | 787 | ok(!isOk, "Checking dialog return value (cancel)"); |
michael@0 | 788 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 789 | |
michael@0 | 790 | // ===== test 102 ===== |
michael@0 | 791 | // test filling in existing password-only login |
michael@0 | 792 | testNum++; |
michael@0 | 793 | uname.value = null; |
michael@0 | 794 | pword.value = null; |
michael@0 | 795 | startCallbackTimer(); |
michael@0 | 796 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example.com", |
michael@0 | 797 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 798 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 799 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 800 | is(uname.value, "", "Checking returned username"); |
michael@0 | 801 | is(pword.value, "examplepass", "Checking returned password"); |
michael@0 | 802 | |
michael@0 | 803 | // ===== test 103 ===== |
michael@0 | 804 | // test filling in existing login (undetermined from multiple selection) |
michael@0 | 805 | testNum++; |
michael@0 | 806 | uname.value = null; |
michael@0 | 807 | pword.value = null; |
michael@0 | 808 | startCallbackTimer(); |
michael@0 | 809 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 810 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 811 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 812 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 813 | ok(uname.value == "user1name" || uname.value == "user2name", "Checking returned username"); |
michael@0 | 814 | ok(pword.value == "user1pass" || uname.value == "user2pass", "Checking returned password"); |
michael@0 | 815 | |
michael@0 | 816 | // ===== test 104 ===== |
michael@0 | 817 | // test filling in existing login (user1 from multiple selection) |
michael@0 | 818 | testNum++; |
michael@0 | 819 | uname.value = "user1name"; |
michael@0 | 820 | pword.value = null; |
michael@0 | 821 | startCallbackTimer(); |
michael@0 | 822 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 823 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 824 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 825 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 826 | is(uname.value, "user1name", "Checking returned username"); |
michael@0 | 827 | is(pword.value, "user1pass", "Checking returned password"); |
michael@0 | 828 | |
michael@0 | 829 | // ===== test 105 ===== |
michael@0 | 830 | // test filling in existing login (user2 from multiple selection) |
michael@0 | 831 | testNum++; |
michael@0 | 832 | uname.value = "user2name"; |
michael@0 | 833 | pword.value = null; |
michael@0 | 834 | startCallbackTimer(); |
michael@0 | 835 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 836 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 837 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 838 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 839 | is(uname.value, "user2name", "Checking returned username"); |
michael@0 | 840 | is(pword.value, "user2pass", "Checking returned password"); |
michael@0 | 841 | |
michael@0 | 842 | // ===== test 106 ===== |
michael@0 | 843 | // test changing password |
michael@0 | 844 | testNum++; |
michael@0 | 845 | uname.value = "user2name"; |
michael@0 | 846 | pword.value = null; |
michael@0 | 847 | startCallbackTimer(); |
michael@0 | 848 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 849 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 850 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 851 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 852 | is(uname.value, "user2name", "Checking returned username"); |
michael@0 | 853 | is(pword.value, "NEWuser2pass", "Checking returned password"); |
michael@0 | 854 | |
michael@0 | 855 | // ===== test 107 ===== |
michael@0 | 856 | // test changing password (back to original value) |
michael@0 | 857 | testNum++; |
michael@0 | 858 | uname.value = "user2name"; |
michael@0 | 859 | pword.value = null; |
michael@0 | 860 | startCallbackTimer(); |
michael@0 | 861 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com", |
michael@0 | 862 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 863 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 864 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 865 | is(uname.value, "user2name", "Checking returned username"); |
michael@0 | 866 | is(pword.value, "user2pass", "Checking returned password"); |
michael@0 | 867 | |
michael@0 | 868 | // ===== test 120 ===== |
michael@0 | 869 | // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt |
michael@0 | 870 | testNum = 120; |
michael@0 | 871 | uname.value = null; |
michael@0 | 872 | pword.value = null; |
michael@0 | 873 | startCallbackTimer(); |
michael@0 | 874 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)", |
michael@0 | 875 | Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword); |
michael@0 | 876 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 877 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 878 | is(uname.value, "fill2user", "Checking returned username"); |
michael@0 | 879 | is(pword.value, "fill2pass", "Checking returned password"); |
michael@0 | 880 | |
michael@0 | 881 | // ===== test 121 ===== |
michael@0 | 882 | // We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt |
michael@0 | 883 | testNum++; |
michael@0 | 884 | uname.value = null; |
michael@0 | 885 | pword.value = null; |
michael@0 | 886 | startCallbackTimer(); |
michael@0 | 887 | isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)", |
michael@0 | 888 | Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword); |
michael@0 | 889 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 890 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 891 | is(uname.value, "fill2user", "Checking returned username"); |
michael@0 | 892 | is(pword.value, "fill2pass", "Checking returned password"); |
michael@0 | 893 | |
michael@0 | 894 | var channel1 = ioService.newChannel("http://example.com", null, null); |
michael@0 | 895 | var channel2 = ioService.newChannel("http://example2.com", null, null); |
michael@0 | 896 | |
michael@0 | 897 | var level = Ci.nsIAuthPrompt2.LEVEL_NONE; |
michael@0 | 898 | |
michael@0 | 899 | // ===== test 500 ===== |
michael@0 | 900 | testNum = 500; |
michael@0 | 901 | authinfo.username = "inuser"; |
michael@0 | 902 | authinfo.password = "inpass"; |
michael@0 | 903 | authinfo.realm = "some realm"; |
michael@0 | 904 | |
michael@0 | 905 | startCallbackTimer(); |
michael@0 | 906 | isOk = prompter2.promptAuth(channel1, level, authinfo); |
michael@0 | 907 | |
michael@0 | 908 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 909 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 910 | is(authinfo.username, "outuser", "Checking returned username"); |
michael@0 | 911 | is(authinfo.password, "outpass", "Checking returned password"); |
michael@0 | 912 | |
michael@0 | 913 | // ===== test 501 ===== |
michael@0 | 914 | testNum++; |
michael@0 | 915 | startCallbackTimer(); |
michael@0 | 916 | isOk = prompter2.promptAuth(channel1, level, authinfo); |
michael@0 | 917 | |
michael@0 | 918 | ok(!isOk, "Checking dialog return value (cancel)"); |
michael@0 | 919 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 920 | |
michael@0 | 921 | // ===== test 502 ===== |
michael@0 | 922 | // test filling in password-only login |
michael@0 | 923 | testNum++; |
michael@0 | 924 | authinfo.username = ""; |
michael@0 | 925 | authinfo.password = ""; |
michael@0 | 926 | authinfo.realm = "http://example.com"; |
michael@0 | 927 | |
michael@0 | 928 | startCallbackTimer(); |
michael@0 | 929 | isOk = prompter2.promptAuth(channel1, level, authinfo); |
michael@0 | 930 | |
michael@0 | 931 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 932 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 933 | is(authinfo.username, "", "Checking returned username"); |
michael@0 | 934 | is(authinfo.password, "examplepass", "Checking returned password"); |
michael@0 | 935 | |
michael@0 | 936 | // ===== test 503 ===== |
michael@0 | 937 | // test filling in existing login (undetermined from multiple selection) |
michael@0 | 938 | testNum++; |
michael@0 | 939 | authinfo.username = ""; |
michael@0 | 940 | authinfo.password = ""; |
michael@0 | 941 | authinfo.realm = "http://example2.com"; |
michael@0 | 942 | |
michael@0 | 943 | startCallbackTimer(); |
michael@0 | 944 | isOk = prompter2.promptAuth(channel2, level, authinfo); |
michael@0 | 945 | |
michael@0 | 946 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 947 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 948 | ok(authinfo.username == "user1name" || authinfo.username == "user2name", "Checking returned username"); |
michael@0 | 949 | ok(authinfo.password == "user1pass" || authinfo.password == "user2pass", "Checking returned password"); |
michael@0 | 950 | |
michael@0 | 951 | // ===== test 504 ===== |
michael@0 | 952 | // test filling in existing login (undetermined --> user1) |
michael@0 | 953 | testNum++; |
michael@0 | 954 | authinfo.username = ""; |
michael@0 | 955 | authinfo.password = ""; |
michael@0 | 956 | authinfo.realm = "http://example2.com"; |
michael@0 | 957 | |
michael@0 | 958 | startCallbackTimer(); |
michael@0 | 959 | isOk = prompter2.promptAuth(channel2, level, authinfo); |
michael@0 | 960 | |
michael@0 | 961 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 962 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 963 | is(authinfo.username, "user1name", "Checking returned username"); |
michael@0 | 964 | is(authinfo.password, "user1pass", "Checking returned password"); |
michael@0 | 965 | |
michael@0 | 966 | // ===== test 505 ===== |
michael@0 | 967 | // test filling in existing login (undetermined --> user2) |
michael@0 | 968 | testNum++; |
michael@0 | 969 | authinfo.username = ""; |
michael@0 | 970 | authinfo.password = ""; |
michael@0 | 971 | authinfo.realm = "http://example2.com"; |
michael@0 | 972 | |
michael@0 | 973 | dumpNotifications(); |
michael@0 | 974 | startCallbackTimer(); |
michael@0 | 975 | isOk = prompter2.promptAuth(channel2, level, authinfo); |
michael@0 | 976 | |
michael@0 | 977 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 978 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 979 | is(authinfo.username, "user2name", "Checking returned username"); |
michael@0 | 980 | is(authinfo.password, "user2pass", "Checking returned password"); |
michael@0 | 981 | |
michael@0 | 982 | // ===== test 506 ===== |
michael@0 | 983 | // test changing a password (undetermined --> user2 w/ newpass) |
michael@0 | 984 | testNum++; |
michael@0 | 985 | authinfo.username = ""; |
michael@0 | 986 | authinfo.password = ""; |
michael@0 | 987 | authinfo.realm = "http://example2.com"; |
michael@0 | 988 | |
michael@0 | 989 | dumpNotifications(); |
michael@0 | 990 | startCallbackTimer(); |
michael@0 | 991 | isOk = prompter2.promptAuth(channel2, level, authinfo); |
michael@0 | 992 | |
michael@0 | 993 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 994 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 995 | is(authinfo.username, "user2name", "Checking returned username"); |
michael@0 | 996 | is(authinfo.password, "NEWuser2pass", "Checking returned password"); |
michael@0 | 997 | |
michael@0 | 998 | // ===== test 507 ===== |
michael@0 | 999 | // test changing a password (undetermined --> user2 w/ origpass) |
michael@0 | 1000 | testNum++; |
michael@0 | 1001 | authinfo.username = ""; |
michael@0 | 1002 | authinfo.password = ""; |
michael@0 | 1003 | authinfo.realm = "http://example2.com"; |
michael@0 | 1004 | |
michael@0 | 1005 | dumpNotifications(); |
michael@0 | 1006 | startCallbackTimer(); |
michael@0 | 1007 | isOk = prompter2.promptAuth(channel2, level, authinfo); |
michael@0 | 1008 | |
michael@0 | 1009 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 1010 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1011 | is(authinfo.username, "user2name", "Checking returned username"); |
michael@0 | 1012 | is(authinfo.password, "user2pass", "Checking returned password"); |
michael@0 | 1013 | |
michael@0 | 1014 | // ===== test 508 ===== |
michael@0 | 1015 | // test proxy login (default = no autologin), make sure it prompts. |
michael@0 | 1016 | testNum++; |
michael@0 | 1017 | proxyAuthinfo.username = ""; |
michael@0 | 1018 | proxyAuthinfo.password = ""; |
michael@0 | 1019 | proxyAuthinfo.realm = "Proxy Realm"; |
michael@0 | 1020 | proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY; |
michael@0 | 1021 | |
michael@0 | 1022 | dumpNotifications(); |
michael@0 | 1023 | var time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1024 | startCallbackTimer(); |
michael@0 | 1025 | isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo); |
michael@0 | 1026 | var time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1027 | |
michael@0 | 1028 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 1029 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1030 | isnot(time1, time2, "Checking that timeLastUsed was updated"); |
michael@0 | 1031 | is(proxyAuthinfo.username, "proxuser", "Checking returned username"); |
michael@0 | 1032 | is(proxyAuthinfo.password, "proxpass", "Checking returned password"); |
michael@0 | 1033 | |
michael@0 | 1034 | // ===== test 509 ===== |
michael@0 | 1035 | // test proxy login (with autologin) |
michael@0 | 1036 | testNum++; |
michael@0 | 1037 | |
michael@0 | 1038 | // Enable the autologin pref. |
michael@0 | 1039 | prefs.setBoolPref("signon.autologin.proxy", true); |
michael@0 | 1040 | |
michael@0 | 1041 | proxyAuthinfo.username = ""; |
michael@0 | 1042 | proxyAuthinfo.password = ""; |
michael@0 | 1043 | proxyAuthinfo.realm = "Proxy Realm"; |
michael@0 | 1044 | proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY; |
michael@0 | 1045 | |
michael@0 | 1046 | time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1047 | isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo); |
michael@0 | 1048 | time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1049 | |
michael@0 | 1050 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 1051 | isnot(time1, time2, "Checking that timeLastUsed was updated"); |
michael@0 | 1052 | is(proxyAuthinfo.username, "proxuser", "Checking returned username"); |
michael@0 | 1053 | is(proxyAuthinfo.password, "proxpass", "Checking returned password"); |
michael@0 | 1054 | |
michael@0 | 1055 | // ===== test 510 ===== |
michael@0 | 1056 | // test proxy login (with autologin), ensure it prompts after a failed auth. |
michael@0 | 1057 | testNum++; |
michael@0 | 1058 | |
michael@0 | 1059 | proxyAuthinfo.username = ""; |
michael@0 | 1060 | proxyAuthinfo.password = ""; |
michael@0 | 1061 | proxyAuthinfo.realm = "Proxy Realm"; |
michael@0 | 1062 | proxyAuthinfo.flags = (Ci.nsIAuthInformation.AUTH_PROXY | Ci.nsIAuthInformation.PREVIOUS_FAILED); |
michael@0 | 1063 | |
michael@0 | 1064 | time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1065 | startCallbackTimer(); |
michael@0 | 1066 | isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo); |
michael@0 | 1067 | time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed; |
michael@0 | 1068 | |
michael@0 | 1069 | ok(isOk, "Checking dialog return value (accept)"); |
michael@0 | 1070 | ok(didDialog, "handleDialog was invoked"); |
michael@0 | 1071 | isnot(time1, time2, "Checking that timeLastUsed was updated"); |
michael@0 | 1072 | is(proxyAuthinfo.username, "proxuser", "Checking returned username"); |
michael@0 | 1073 | is(proxyAuthinfo.password, "proxpass", "Checking returned password"); |
michael@0 | 1074 | |
michael@0 | 1075 | // ===== test 511 ===== |
michael@0 | 1076 | // test proxy login (with autologin), ensure it prompts in Private Browsing mode. |
michael@0 | 1077 | testNum++; |
michael@0 | 1078 | |
michael@0 | 1079 | proxyAuthinfo.username = ""; |
michael@0 | 1080 | proxyAuthinfo.password = ""; |
michael@0 | 1081 | proxyAuthinfo.realm = "Proxy Realm"; |
michael@0 | 1082 | proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY; |
michael@0 | 1083 | |
michael@0 | 1084 | prefs.clearUserPref("signon.autologin.proxy"); |
michael@0 | 1085 | |
michael@0 | 1086 | // XXX check for and kill popup notification?? |
michael@0 | 1087 | // XXX check for checkbox / checkstate on old prompts? |
michael@0 | 1088 | // XXX check NTLM domain stuff |
michael@0 | 1089 | |
michael@0 | 1090 | var iframe = document.getElementById("iframe"); |
michael@0 | 1091 | iframe.onload = handleLoad; |
michael@0 | 1092 | |
michael@0 | 1093 | // clear plain HTTP auth sessions before the test, to allow |
michael@0 | 1094 | // running them more than once. |
michael@0 | 1095 | var authMgr = Cc['@mozilla.org/network/http-auth-manager;1']. |
michael@0 | 1096 | getService(Ci.nsIHttpAuthManager); |
michael@0 | 1097 | authMgr.clearAll(); |
michael@0 | 1098 | |
michael@0 | 1099 | // ===== test 1000 ===== |
michael@0 | 1100 | testNum = 1000; |
michael@0 | 1101 | startCallbackTimer(); |
michael@0 | 1102 | iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1"; |
michael@0 | 1103 | |
michael@0 | 1104 | // ...remaining tests are driven by handleLoad()... |
michael@0 | 1105 | } |
michael@0 | 1106 | </script> |
michael@0 | 1107 | </pre> |
michael@0 | 1108 | </body> |
michael@0 | 1109 | </html> |