toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7 <script type="text/javascript" src="pwmgr_common.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 Login Manager test: multiple login autocomplete
michael@0 12
michael@0 13 <script>
michael@0 14 commonInit();
michael@0 15 SimpleTest.waitForExplicitFinish();
michael@0 16
michael@0 17 // Get the pwmgr service
michael@0 18 var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"]
michael@0 19 .getService(SpecialPowers.Ci.nsILoginManager);
michael@0 20 ok(pwmgr != null, "nsLoginManager service");
michael@0 21
michael@0 22 // Create some logins just for this form, since we'll be deleting them.
michael@0 23 var nsLoginInfo =
michael@0 24 SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
michael@0 25 SpecialPowers.Ci.nsILoginInfo, "init");
michael@0 26 ok(nsLoginInfo != null, "nsLoginInfo constructor");
michael@0 27
michael@0 28
michael@0 29 // login0 has no username, so should be filtered out from the autocomplete list.
michael@0 30 var login0 = new nsLoginInfo(
michael@0 31 "http://mochi.test:8888", "http://autocomplete:8888", null,
michael@0 32 "", "user0pass", "", "pword");
michael@0 33
michael@0 34 var login1 = new nsLoginInfo(
michael@0 35 "http://mochi.test:8888", "http://autocomplete:8888", null,
michael@0 36 "tempuser1", "temppass1", "uname", "pword");
michael@0 37
michael@0 38 var login2 = new nsLoginInfo(
michael@0 39 "http://mochi.test:8888", "http://autocomplete:8888", null,
michael@0 40 "testuser2", "testpass2", "uname", "pword");
michael@0 41
michael@0 42 var login3 = new nsLoginInfo(
michael@0 43 "http://mochi.test:8888", "http://autocomplete:8888", null,
michael@0 44 "testuser3", "testpass3", "uname", "pword");
michael@0 45
michael@0 46 var login4 = new nsLoginInfo(
michael@0 47 "http://mochi.test:8888", "http://autocomplete:8888", null,
michael@0 48 "zzzuser4", "zzzpass4", "uname", "pword");
michael@0 49
michael@0 50 // login 5 only used in the single-user forms
michael@0 51 var login5 = new nsLoginInfo(
michael@0 52 "http://mochi.test:8888", "http://autocomplete2", null,
michael@0 53 "singleuser5", "singlepass5", "uname", "pword");
michael@0 54
michael@0 55 var login6A = new nsLoginInfo(
michael@0 56 "http://mochi.test:8888", "http://autocomplete3", null,
michael@0 57 "form7user1", "form7pass1", "uname", "pword");
michael@0 58 var login6B = new nsLoginInfo(
michael@0 59 "http://mochi.test:8888", "http://autocomplete3", null,
michael@0 60 "form7user2", "form7pass2", "uname", "pword");
michael@0 61
michael@0 62 var login7 = new nsLoginInfo(
michael@0 63 "http://mochi.test:8888", "http://autocomplete4", null,
michael@0 64 "form8user", "form8pass", "uname", "pword");
michael@0 65
michael@0 66 var login8A = new nsLoginInfo(
michael@0 67 "http://mochi.test:8888", "http://autocomplete5", null,
michael@0 68 "form9userAB", "form9pass", "uname", "pword");
michael@0 69
michael@0 70 var login8B = new nsLoginInfo(
michael@0 71 "http://mochi.test:8888", "http://autocomplete5", null,
michael@0 72 "form9userAAB", "form9pass", "uname", "pword");
michael@0 73
michael@0 74 // login8C is added later
michael@0 75 var login8C = new nsLoginInfo(
michael@0 76 "http://mochi.test:8888", "http://autocomplete5", null,
michael@0 77 "form9userAABz", "form9pass", "uname", "pword");
michael@0 78 // try/catch in case someone runs the tests manually, twice.
michael@0 79 try {
michael@0 80 pwmgr.addLogin(login0);
michael@0 81 pwmgr.addLogin(login1);
michael@0 82 pwmgr.addLogin(login2);
michael@0 83 pwmgr.addLogin(login3);
michael@0 84 pwmgr.addLogin(login4);
michael@0 85 pwmgr.addLogin(login5);
michael@0 86 pwmgr.addLogin(login6A);
michael@0 87 pwmgr.addLogin(login6B);
michael@0 88 pwmgr.addLogin(login7);
michael@0 89 pwmgr.addLogin(login8A);
michael@0 90 pwmgr.addLogin(login8B);
michael@0 91 } catch (e) {
michael@0 92 ok(false, "addLogin threw: " + e);
michael@0 93 }
michael@0 94
michael@0 95 </script>
michael@0 96 <p id="display"></p>
michael@0 97
michael@0 98 <!-- we presumably can't hide the content for this test. -->
michael@0 99 <div id="content">
michael@0 100
michael@0 101 <!-- form1 tests multiple matching logins -->
michael@0 102 <form id="form1" action="http://autocomplete:8888/formtest.js" onsubmit="return false;">
michael@0 103 <input type="text" name="uname">
michael@0 104 <input type="password" name="pword">
michael@0 105 <button type="submit">Submit</button>
michael@0 106 </form>
michael@0 107
michael@0 108 <!-- other forms test single logins, with autocomplete=off set -->
michael@0 109 <form id="form2" action="http://autocomplete2" onsubmit="return false;">
michael@0 110 <input type="text" name="uname">
michael@0 111 <input type="password" name="pword" autocomplete="off">
michael@0 112 <button type="submit">Submit</button>
michael@0 113 </form>
michael@0 114
michael@0 115 <form id="form3" action="http://autocomplete2" onsubmit="return false;">
michael@0 116 <input type="text" name="uname" autocomplete="off">
michael@0 117 <input type="password" name="pword">
michael@0 118 <button type="submit">Submit</button>
michael@0 119 </form>
michael@0 120
michael@0 121 <form id="form4" action="http://autocomplete2" onsubmit="return false;" autocomplete="off">
michael@0 122 <input type="text" name="uname">
michael@0 123 <input type="password" name="pword">
michael@0 124 <button type="submit">Submit</button>
michael@0 125 </form>
michael@0 126
michael@0 127 <form id="form5" action="http://autocomplete2" onsubmit="return false;">
michael@0 128 <input type="text" name="uname" autocomplete="off">
michael@0 129 <input type="password" name="pword" autocomplete="off">
michael@0 130 <button type="submit">Submit</button>
michael@0 131 </form>
michael@0 132
michael@0 133 <!-- control -->
michael@0 134 <form id="form6" action="http://autocomplete2" onsubmit="return false;">
michael@0 135 <input type="text" name="uname">
michael@0 136 <input type="password" name="pword">
michael@0 137 <button type="submit">Submit</button>
michael@0 138 </form>
michael@0 139
michael@0 140 <!-- This form will be manipulated to insert a different username field. -->
michael@0 141 <form id="form7" action="http://autocomplete3" onsubmit="return false;">
michael@0 142 <input type="text" name="uname">
michael@0 143 <input type="password" name="pword">
michael@0 144 <button type="submit">Submit</button>
michael@0 145 </form>
michael@0 146
michael@0 147 <!-- test for no autofill after onblur with blank username -->
michael@0 148 <form id="form8" action="http://autocomplete4" onsubmit="return false;">
michael@0 149 <input type="text" name="uname">
michael@0 150 <input type="password" name="pword">
michael@0 151 <button type="submit">Submit</button>
michael@0 152 </form>
michael@0 153
michael@0 154 <!-- test autocomplete dropdown -->
michael@0 155 <form id="form9" action="http://autocomplete5" onsubmit="return false;">
michael@0 156 <input type="text" name="uname">
michael@0 157 <input type="password" name="pword">
michael@0 158 <button type="submit">Submit</button>
michael@0 159 </form>
michael@0 160 </div>
michael@0 161
michael@0 162 <pre id="test">
michael@0 163 <script class="testbody" type="text/javascript">
michael@0 164
michael@0 165 /** Test for Login Manager: multiple login autocomplete. **/
michael@0 166
michael@0 167
michael@0 168 var uname = $_(1, "uname");
michael@0 169 var pword = $_(1, "pword");
michael@0 170 const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
michael@0 171
michael@0 172 // Restore the form to the default state.
michael@0 173 function restoreForm() {
michael@0 174 uname.value = "";
michael@0 175 pword.value = "";
michael@0 176 uname.focus();
michael@0 177 }
michael@0 178
michael@0 179
michael@0 180 // Check for expected username/password in form.
michael@0 181 function checkACForm(expectedUsername, expectedPassword) {
michael@0 182 var formID = uname.parentNode.id;
michael@0 183 is(uname.value, expectedUsername, "Checking " + formID + " username");
michael@0 184 is(pword.value, expectedPassword, "Checking " + formID + " password");
michael@0 185 }
michael@0 186
michael@0 187
michael@0 188 function sendFakeAutocompleteEvent(element) {
michael@0 189 var acEvent = document.createEvent("HTMLEvents");
michael@0 190 acEvent.initEvent("DOMAutoComplete", true, false);
michael@0 191 element.dispatchEvent(acEvent);
michael@0 192 }
michael@0 193
michael@0 194 function hitEventLoop(func, times) {
michael@0 195 if (times > 0) {
michael@0 196 setTimeout(hitEventLoop, 0, func, times - 1);
michael@0 197 } else {
michael@0 198 setTimeout(func, 0);
michael@0 199 }
michael@0 200 }
michael@0 201
michael@0 202 var gNextTestWillOpenPopup = true;
michael@0 203 var gLastTest = 704;
michael@0 204
michael@0 205 function addPopupListener(eventName, func, capture) {
michael@0 206 autocompletePopup.addEventListener(eventName, func, capture);
michael@0 207 }
michael@0 208
michael@0 209 function removePopupListener(eventName, func, capture) {
michael@0 210 autocompletePopup.removeEventListener(eventName, func, capture);
michael@0 211 }
michael@0 212
michael@0 213 /*
michael@0 214 * Main section of test...
michael@0 215 *
michael@0 216 * This is a bit hacky, because the events are either being sent or
michael@0 217 * processes asynchronously, so we need to interrupt our flow with lots of
michael@0 218 * setTimeout() calls. The case statements are executed in order, one per
michael@0 219 * timeout.
michael@0 220 */
michael@0 221 function runTest(testNum) {
michael@0 222 ok(true, "Starting test #" + testNum);
michael@0 223
michael@0 224 if (gNextTestWillOpenPopup) {
michael@0 225 addPopupListener("popupshown", function() {
michael@0 226 removePopupListener("popupshown", arguments.callee, false);
michael@0 227
michael@0 228 if (testNum != gLastTest) {
michael@0 229 window.setTimeout(runTest, 0, testNum + 1);
michael@0 230 }
michael@0 231 }, false);
michael@0 232 } else {
michael@0 233 var unexpectedPopup = function() {
michael@0 234 removePopupListener("popupshown", arguments.callee, false);
michael@0 235
michael@0 236 ok(false, "Test " + testNum + " should not show a popup");
michael@0 237 };
michael@0 238 addPopupListener("popupshown", unexpectedPopup, false);
michael@0 239 if (testNum == gLastTest) {
michael@0 240 removePopupListener("popupshown", unexpectedPopup, false);
michael@0 241 } else {
michael@0 242 hitEventLoop(function() {
michael@0 243 removePopupListener("popupshown", unexpectedPopup, false);
michael@0 244 runTest(testNum + 1);
michael@0 245 }, 100);
michael@0 246 }
michael@0 247 }
michael@0 248
michael@0 249 switch(testNum) {
michael@0 250 case 1:
michael@0 251 // Make sure initial form is empty.
michael@0 252 checkACForm("", "");
michael@0 253 // Trigger autocomplete popup
michael@0 254 restoreForm();
michael@0 255 doKey("down");
michael@0 256 break;
michael@0 257
michael@0 258 case 2:
michael@0 259 // Check first entry
michael@0 260 doKey("down");
michael@0 261 checkACForm("", ""); // value shouldn't update
michael@0 262 doKey("return"); // not "enter"!
michael@0 263 checkACForm("tempuser1", "temppass1");
michael@0 264
michael@0 265 // Trigger autocomplete popup
michael@0 266 restoreForm();
michael@0 267 doKey("down");
michael@0 268 break;
michael@0 269
michael@0 270 case 3:
michael@0 271 // Check second entry
michael@0 272 doKey("down");
michael@0 273 doKey("down");
michael@0 274 doKey("return"); // not "enter"!
michael@0 275 checkACForm("testuser2", "testpass2");
michael@0 276
michael@0 277 // Trigger autocomplete popup
michael@0 278 restoreForm();
michael@0 279 doKey("down");
michael@0 280 break;
michael@0 281
michael@0 282 case 4:
michael@0 283 // Check third entry
michael@0 284 doKey("down");
michael@0 285 doKey("down");
michael@0 286 doKey("down");
michael@0 287 doKey("return");
michael@0 288 checkACForm("testuser3", "testpass3");
michael@0 289
michael@0 290 // Trigger autocomplete popup
michael@0 291 restoreForm();
michael@0 292 doKey("down");
michael@0 293 break;
michael@0 294
michael@0 295 case 5:
michael@0 296 // Check fourth entry
michael@0 297 doKey("down");
michael@0 298 doKey("down");
michael@0 299 doKey("down");
michael@0 300 doKey("down");
michael@0 301 doKey("return");
michael@0 302 checkACForm("zzzuser4", "zzzpass4");
michael@0 303
michael@0 304 // Trigger autocomplete popup
michael@0 305 restoreForm();
michael@0 306 doKey("down");
michael@0 307 break;
michael@0 308
michael@0 309 case 6:
michael@0 310 // Check first entry (wraparound)
michael@0 311 doKey("down");
michael@0 312 doKey("down");
michael@0 313 doKey("down");
michael@0 314 doKey("down");
michael@0 315 doKey("down"); // deselects
michael@0 316 doKey("down");
michael@0 317 doKey("return");
michael@0 318 checkACForm("tempuser1", "temppass1");
michael@0 319
michael@0 320 // Trigger autocomplete popup
michael@0 321 restoreForm();
michael@0 322 doKey("down");
michael@0 323 break;
michael@0 324
michael@0 325 case 7:
michael@0 326 // Check the last entry via arrow-up
michael@0 327 doKey("up");
michael@0 328 doKey("return");
michael@0 329 checkACForm("zzzuser4", "zzzpass4");
michael@0 330
michael@0 331 // Trigger autocomplete popup
michael@0 332 restoreForm();
michael@0 333 doKey("down");
michael@0 334 break;
michael@0 335
michael@0 336 case 8:
michael@0 337 // Check the last entry via arrow-up
michael@0 338 doKey("down"); // select first entry
michael@0 339 doKey("up"); // selects nothing!
michael@0 340 doKey("up"); // select last entry
michael@0 341 doKey("return");
michael@0 342 checkACForm("zzzuser4", "zzzpass4");
michael@0 343
michael@0 344 // Trigger autocomplete popup
michael@0 345 restoreForm();
michael@0 346 doKey("down");
michael@0 347 break;
michael@0 348
michael@0 349 case 9:
michael@0 350 // Check the last entry via arrow-up (wraparound)
michael@0 351 doKey("down");
michael@0 352 doKey("up"); // deselects
michael@0 353 doKey("up"); // last entry
michael@0 354 doKey("up");
michael@0 355 doKey("up");
michael@0 356 doKey("up"); // first entry
michael@0 357 doKey("up"); // deselects
michael@0 358 doKey("up"); // last entry
michael@0 359 doKey("return");
michael@0 360 checkACForm("zzzuser4", "zzzpass4");
michael@0 361
michael@0 362 // Trigger autocomplete popup
michael@0 363 restoreForm();
michael@0 364 doKey("down");
michael@0 365 break;
michael@0 366
michael@0 367 case 10:
michael@0 368 // Set first entry w/o triggering autocomplete
michael@0 369 doKey("down");
michael@0 370 doKey("right");
michael@0 371 checkACForm("tempuser1", ""); // empty password
michael@0 372
michael@0 373 // Trigger autocomplete popup
michael@0 374 restoreForm();
michael@0 375 doKey("down");
michael@0 376 break;
michael@0 377
michael@0 378 case 11:
michael@0 379 // Set first entry w/o triggering autocomplete
michael@0 380 doKey("down");
michael@0 381 doKey("left");
michael@0 382 checkACForm("tempuser1", ""); // empty password
michael@0 383
michael@0 384 // Trigger autocomplete popup
michael@0 385 restoreForm();
michael@0 386 doKey("down");
michael@0 387 break;
michael@0 388
michael@0 389 case 12:
michael@0 390 // Check first entry (page up)
michael@0 391 doKey("down");
michael@0 392 doKey("down");
michael@0 393 doKey("page_up");
michael@0 394 doKey("return");
michael@0 395 checkACForm("tempuser1", "temppass1");
michael@0 396
michael@0 397 // Trigger autocomplete popup
michael@0 398 restoreForm();
michael@0 399 doKey("down");
michael@0 400 gNextTestWillOpenPopup = false;
michael@0 401 break;
michael@0 402
michael@0 403 case 13:
michael@0 404 // Check last entry (page down)
michael@0 405 doKey("down");
michael@0 406 doKey("page_down");
michael@0 407 doKey("return");
michael@0 408 checkACForm("zzzuser4", "zzzpass4");
michael@0 409 restoreForm();
michael@0 410 gNextTestWillOpenPopup = false;
michael@0 411 break;
michael@0 412
michael@0 413 case 14:
michael@0 414 // Send a fake (untrusted) event.
michael@0 415 checkACForm("", "");
michael@0 416 uname.value = "zzzuser4";
michael@0 417 sendFakeAutocompleteEvent(uname);
michael@0 418 checkACForm("zzzuser4", "");
michael@0 419 gNextTestWillOpenPopup = true;
michael@0 420 break;
michael@0 421
michael@0 422 case 15:
michael@0 423 //checkACForm("zzzuser4", "");
michael@0 424
michael@0 425 // Trigger autocomplete popup
michael@0 426 restoreForm();
michael@0 427 doKey("down");
michael@0 428 testNum = 49;
michael@0 429 break;
michael@0 430
michael@0 431 // XXX tried sending character "t" before/during dropdown to test
michael@0 432 // filtering, but had no luck. Seemed like the character was getting lost.
michael@0 433 // Setting uname.value didn't seem to work either. This works with a human
michael@0 434 // driver, so I'm not sure what's up.
michael@0 435
michael@0 436
michael@0 437 case 50:
michael@0 438 // Delete the first entry (of 4), "tempuser1"
michael@0 439 doKey("down");
michael@0 440 var numLogins;
michael@0 441 numLogins = pwmgr.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
michael@0 442 is(numLogins, 5, "Correct number of logins before deleting one");
michael@0 443
michael@0 444 // On OS X, shift-backspace and shift-delete work, just delete does not.
michael@0 445 // On Win/Linux, shift-backspace does not work, delete and shift-delete do.
michael@0 446 doKey("delete", shiftModifier);
michael@0 447
michael@0 448 checkACForm("", "");
michael@0 449 numLogins = pwmgr.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
michael@0 450 is(numLogins, 4, "Correct number of logins after deleting one");
michael@0 451 doKey("return");
michael@0 452 checkACForm("testuser2", "testpass2");
michael@0 453
michael@0 454 // Trigger autocomplete popup
michael@0 455 restoreForm();
michael@0 456 doKey("down");
michael@0 457 break;
michael@0 458
michael@0 459 case 51:
michael@0 460 // Check the new first entry (of 3)
michael@0 461 doKey("down");
michael@0 462 doKey("return");
michael@0 463 checkACForm("testuser2", "testpass2");
michael@0 464
michael@0 465 // Trigger autocomplete popup
michael@0 466 restoreForm();
michael@0 467 doKey("down");
michael@0 468 break;
michael@0 469
michael@0 470 case 52:
michael@0 471 // Delete the second entry (of 3), "testuser3"
michael@0 472 doKey("down");
michael@0 473 doKey("down");
michael@0 474 doKey("delete", shiftModifier);
michael@0 475 checkACForm("", "");
michael@0 476 numLogins = pwmgr.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
michael@0 477 is(numLogins, 3, "Correct number of logins after deleting one");
michael@0 478 doKey("return");
michael@0 479 checkACForm("zzzuser4", "zzzpass4");
michael@0 480
michael@0 481 // Trigger autocomplete popup
michael@0 482 restoreForm();
michael@0 483 doKey("down");
michael@0 484 break;
michael@0 485
michael@0 486 case 53:
michael@0 487 // Check the new second entry (of 2)
michael@0 488 doKey("down");
michael@0 489 doKey("return");
michael@0 490 checkACForm("testuser2", "testpass2");
michael@0 491
michael@0 492 // Trigger autocomplete popup
michael@0 493 restoreForm();
michael@0 494 doKey("down");
michael@0 495 break;
michael@0 496
michael@0 497 case 54:
michael@0 498 // Delete the last entry (of 2), "zzzuser4"
michael@0 499 doKey("down");
michael@0 500 doKey("down");
michael@0 501 doKey("delete", shiftModifier);
michael@0 502 checkACForm("", "");
michael@0 503 numLogins = pwmgr.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
michael@0 504 is(numLogins, 2, "Correct number of logins after deleting one");
michael@0 505 doKey("return");
michael@0 506 checkACForm("testuser2", "testpass2");
michael@0 507
michael@0 508 // Trigger autocomplete popup
michael@0 509 restoreForm();
michael@0 510 doKey("down");
michael@0 511 break;
michael@0 512
michael@0 513 case 55:
michael@0 514 // Check the new second entry (of 2)
michael@0 515 doKey("down");
michael@0 516 doKey("return");
michael@0 517 checkACForm("testuser2", "testpass2");
michael@0 518
michael@0 519 // Trigger autocomplete popup
michael@0 520 restoreForm();
michael@0 521 doKey("down");
michael@0 522 gNextTestWillOpenPopup = false;
michael@0 523 break;
michael@0 524
michael@0 525 case 56:
michael@0 526 // Delete the only remaining entry, "testuser2"
michael@0 527 doKey("down");
michael@0 528 doKey("delete", shiftModifier);
michael@0 529 //doKey("return");
michael@0 530 checkACForm("", "");
michael@0 531 numLogins = pwmgr.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
michael@0 532 is(numLogins, 1, "Correct number of logins after deleting one");
michael@0 533 pwmgr.removeLogin(login0); // remove the login that's not shown in the list.
michael@0 534 testNum = 99;
michael@0 535 gNextTestWillOpenPopup = true;
michael@0 536 break;
michael@0 537
michael@0 538
michael@0 539 /* Tests for single-user forms with autocomplete=off */
michael@0 540
michael@0 541 case 100:
michael@0 542 // Turn our attention to form2
michael@0 543 uname = $_(2, "uname");
michael@0 544 pword = $_(2, "pword");
michael@0 545 checkACForm("", "");
michael@0 546
michael@0 547 // Trigger autocomplete popup
michael@0 548 restoreForm();
michael@0 549 doKey("down");
michael@0 550 gNextTestWillOpenPopup = false;
michael@0 551 break;
michael@0 552
michael@0 553 case 101:
michael@0 554 // Check first entry
michael@0 555 doKey("down");
michael@0 556 checkACForm("", ""); // value shouldn't update
michael@0 557 doKey("return"); // not "enter"!
michael@0 558 checkACForm("singleuser5", "singlepass5");
michael@0 559 restoreForm(); // clear field, so reloading test doesn't fail
michael@0 560 gNextTestWillOpenPopup = true;
michael@0 561 break;
michael@0 562
michael@0 563 case 102:
michael@0 564 // Turn our attention to form3
michael@0 565 uname = $_(3, "uname");
michael@0 566 pword = $_(3, "pword");
michael@0 567 checkACForm("", "");
michael@0 568
michael@0 569 // Trigger autocomplete popup
michael@0 570 restoreForm();
michael@0 571 doKey("down");
michael@0 572 gNextTestWillOpenPopup = false;
michael@0 573 break;
michael@0 574
michael@0 575 case 103:
michael@0 576 // Check first entry
michael@0 577 doKey("down");
michael@0 578 checkACForm("", ""); // value shouldn't update
michael@0 579 doKey("return"); // not "enter"!
michael@0 580 checkACForm("singleuser5", "singlepass5");
michael@0 581 gNextTestWillOpenPopup = true;
michael@0 582 break;
michael@0 583
michael@0 584 case 104:
michael@0 585 // Turn our attention to form4
michael@0 586 uname = $_(4, "uname");
michael@0 587 pword = $_(4, "pword");
michael@0 588 checkACForm("", "");
michael@0 589
michael@0 590 // Trigger autocomplete popup
michael@0 591 restoreForm();
michael@0 592 doKey("down");
michael@0 593 gNextTestWillOpenPopup = false;
michael@0 594 break;
michael@0 595
michael@0 596 case 105:
michael@0 597 // Check first entry
michael@0 598 doKey("down");
michael@0 599 checkACForm("", ""); // value shouldn't update
michael@0 600 doKey("return"); // not "enter"!
michael@0 601 checkACForm("singleuser5", "singlepass5");
michael@0 602 gNextTestWillOpenPopup = true;
michael@0 603 break;
michael@0 604
michael@0 605 case 106:
michael@0 606 // Turn our attention to form5
michael@0 607 uname = $_(5, "uname");
michael@0 608 pword = $_(5, "pword");
michael@0 609 checkACForm("", "");
michael@0 610
michael@0 611 // Trigger autocomplete popup
michael@0 612 restoreForm();
michael@0 613 doKey("down");
michael@0 614 gNextTestWillOpenPopup = false;
michael@0 615 break;
michael@0 616
michael@0 617 case 107:
michael@0 618 // Check first entry
michael@0 619 doKey("down");
michael@0 620 checkACForm("", ""); // value shouldn't update
michael@0 621 doKey("return"); // not "enter"!
michael@0 622 checkACForm("singleuser5", "singlepass5");
michael@0 623 gNextTestWillOpenPopup = false;
michael@0 624 break;
michael@0 625
michael@0 626 case 108:
michael@0 627 // Turn our attention to form6
michael@0 628 // (this is a control, w/o autocomplete=off, to ensure the login
michael@0 629 // that was being suppressed would have been filled in otherwise)
michael@0 630 uname = $_(6, "uname");
michael@0 631 pword = $_(6, "pword");
michael@0 632 checkACForm("singleuser5", "singlepass5");
michael@0 633 gNextTestWillOpenPopup = false;
michael@0 634 break;
michael@0 635
michael@0 636 case 109:
michael@0 637 // Test that the password field remains filled in after changing
michael@0 638 // the username.
michael@0 639 uname.focus();
michael@0 640 doKey("right");
michael@0 641 sendChar("X");
michael@0 642 // Trigger the 'blur' event on uname
michael@0 643 pword.focus();
michael@0 644 checkACForm("sXingleuser5", "singlepass5");
michael@0 645
michael@0 646 pwmgr.removeLogin(login5);
michael@0 647 testNum = 499;
michael@0 648 gNextTestWillOpenPopup = true;
michael@0 649 break;
michael@0 650
michael@0 651 case 500:
michael@0 652 // Turn our attention to form7
michael@0 653 uname = $_(7, "uname");
michael@0 654 pword = $_(7, "pword");
michael@0 655 checkACForm("", "");
michael@0 656
michael@0 657 // Insert a new username field into the form. We'll then make sure
michael@0 658 // that invoking the autocomplete doesn't try to fill the form.
michael@0 659 var newField = document.createElement("input");
michael@0 660 newField.setAttribute("type", "text");
michael@0 661 newField.setAttribute("name", "uname2");
michael@0 662 pword.parentNode.insertBefore(newField, pword);
michael@0 663 is($_(7, "uname2").value, "", "Verifying empty uname2");;
michael@0 664
michael@0 665 // Delete login6B. It was created just to prevent filling in a login
michael@0 666 // automatically, removing it makes it more likely that we'll catch a
michael@0 667 // future regression with form filling here.
michael@0 668 pwmgr.removeLogin(login6B);
michael@0 669
michael@0 670 // Trigger autocomplete popup
michael@0 671 restoreForm();
michael@0 672 doKey("down");
michael@0 673 gNextTestWillOpenPopup = false;
michael@0 674 break;
michael@0 675
michael@0 676 case 501:
michael@0 677 // Check first entry
michael@0 678 doKey("down");
michael@0 679 checkACForm("", ""); // value shouldn't update
michael@0 680 doKey("return"); // not "enter"!
michael@0 681 // The form changes, so we expect the old username field to get the
michael@0 682 // selected autocomplete value, but neither the new username field nor
michael@0 683 // the password field should have any values filled in.
michael@0 684 checkACForm("form7user1", "");
michael@0 685 is($_(7, "uname2").value, "", "Verifying empty uname2");;
michael@0 686 restoreForm(); // clear field, so reloading test doesn't fail
michael@0 687
michael@0 688 pwmgr.removeLogin(login6A);
michael@0 689 testNum = 599;
michael@0 690 gNextTestWillOpenPopup = false;
michael@0 691 break;
michael@0 692
michael@0 693 case 600:
michael@0 694 // Turn our attention to form8
michael@0 695 uname = $_(8, "uname");
michael@0 696 pword = $_(8, "pword");
michael@0 697 checkACForm("form8user", "form8pass");
michael@0 698 restoreForm();
michael@0 699 gNextTestWillOpenPopup = false;
michael@0 700 break;
michael@0 701
michael@0 702 case 601:
michael@0 703 checkACForm("", "");
michael@0 704 // Focus the previous form to trigger a blur.
michael@0 705 $_(7, "uname").focus();
michael@0 706 gNextTestWillOpenPopup = false;
michael@0 707 break;
michael@0 708
michael@0 709 case 602:
michael@0 710 checkACForm("", "");
michael@0 711 restoreForm();
michael@0 712 gNextTestWillOpenPopup = false;
michael@0 713 break;
michael@0 714
michael@0 715 case 603:
michael@0 716 checkACForm("", "");
michael@0 717 pwmgr.removeLogin(login7);
michael@0 718
michael@0 719 testNum = 699;
michael@0 720 gNextTestWillOpenPopup = true;
michael@0 721 break;
michael@0 722
michael@0 723 case 700:
michael@0 724 // Turn our attention to form9 to test the dropdown - bug 497541
michael@0 725 uname = $_(9, "uname");
michael@0 726 pword = $_(9, "pword");
michael@0 727 uname.focus();
michael@0 728 sendString("form9userAB");
michael@0 729 gNextTestWillOpenPopup = true;
michael@0 730 break;
michael@0 731
michael@0 732 case 701:
michael@0 733 checkACForm("form9userAB", "");
michael@0 734 uname.focus();
michael@0 735 doKey("left");
michael@0 736 sendChar("A");
michael@0 737 gNextTestWillOpenPopup = false;
michael@0 738 break;
michael@0 739
michael@0 740 case 702:
michael@0 741 // check dropdown is updated after inserting "A"
michael@0 742 checkACForm("form9userAAB", "");
michael@0 743 checkMenuEntries(["form9userAAB"]);
michael@0 744 doKey("down");
michael@0 745 doKey("return");
michael@0 746 checkACForm("form9userAAB", "form9pass");
michael@0 747 gNextTestWillOpenPopup = false;
michael@0 748 break;
michael@0 749
michael@0 750 case 703:
michael@0 751 pwmgr.addLogin(login8C);
michael@0 752 uname.focus();
michael@0 753 sendChar("z");
michael@0 754 gNextTestWillOpenPopup = false;
michael@0 755 break;
michael@0 756
michael@0 757 case 704:
michael@0 758 // check that empty results are cached - bug 496466
michael@0 759 checkMenuEntries([]);
michael@0 760
michael@0 761 SimpleTest.finish();
michael@0 762 return;
michael@0 763
michael@0 764 default:
michael@0 765 ok(false, "Unexpected invocation of test #" + testNum);
michael@0 766 SimpleTest.finish();
michael@0 767 return;
michael@0 768 }
michael@0 769 }
michael@0 770
michael@0 771
michael@0 772 function checkMenuEntries(expectedValues) {
michael@0 773 var actualValues = getMenuEntries();
michael@0 774 is(actualValues.length, expectedValues.length, "Checking length of expected menu");
michael@0 775 for (var i = 0; i < expectedValues.length; i++)
michael@0 776 is(actualValues[i], expectedValues[i], "Checking menu entry #"+i);
michael@0 777 }
michael@0 778
michael@0 779 var autocompletePopup;
michael@0 780 function getMenuEntries() {
michael@0 781 var entries = [];
michael@0 782
michael@0 783 // Could perhaps pull values directly from the controller, but it seems
michael@0 784 // more reliable to test the values that are actually in the tree?
michael@0 785 var column = autocompletePopup.tree.columns[0];
michael@0 786 var numRows = autocompletePopup.tree.view.rowCount;
michael@0 787 for (var i = 0; i < numRows; i++) {
michael@0 788 entries.push(autocompletePopup.tree.view.getValueAt(i, column));
michael@0 789 }
michael@0 790 return entries;
michael@0 791 }
michael@0 792
michael@0 793 function startTest() {
michael@0 794 var Ci = SpecialPowers.Ci;
michael@0 795 chromeWin = SpecialPowers.wrap(window)
michael@0 796 .QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 797 .getInterface(Ci.nsIWebNavigation)
michael@0 798 .QueryInterface(Ci.nsIDocShellTreeItem)
michael@0 799 .rootTreeItem
michael@0 800 .QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 801 .getInterface(Ci.nsIDOMWindow)
michael@0 802 .QueryInterface(Ci.nsIDOMChromeWindow);
michael@0 803 // shouldn't reach into browser internals like this and
michael@0 804 // shouldn't assume ID is consistent across products
michael@0 805 autocompletePopup = chromeWin.document.getElementById("PopupAutoComplete");
michael@0 806 ok(autocompletePopup, "Got autocomplete popup");
michael@0 807 runTest(1);
michael@0 808 }
michael@0 809
michael@0 810 window.onload = startTest;
michael@0 811 </script>
michael@0 812 </pre>
michael@0 813 </body>
michael@0 814 </html>
michael@0 815

mercurial