browser/base/content/test/general/browser_bug561636.js

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

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

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

michael@0 1 var gInvalidFormPopup = document.getElementById('invalid-form-popup');
michael@0 2 ok(gInvalidFormPopup,
michael@0 3 "The browser should have a popup to show when a form is invalid");
michael@0 4
michael@0 5 function checkPopupShow()
michael@0 6 {
michael@0 7 ok(gInvalidFormPopup.state == 'showing' || gInvalidFormPopup.state == 'open',
michael@0 8 "[Test " + testId + "] The invalid form popup should be shown");
michael@0 9 }
michael@0 10
michael@0 11 function checkPopupHide()
michael@0 12 {
michael@0 13 ok(gInvalidFormPopup.state != 'showing' && gInvalidFormPopup.state != 'open',
michael@0 14 "[Test " + testId + "] The invalid form popup should not be shown");
michael@0 15 }
michael@0 16
michael@0 17 function checkPopupMessage(doc)
michael@0 18 {
michael@0 19 is(gInvalidFormPopup.firstChild.textContent,
michael@0 20 doc.getElementById('i').validationMessage,
michael@0 21 "[Test " + testId + "] The panel should show the message from validationMessage");
michael@0 22 }
michael@0 23
michael@0 24 let gObserver = {
michael@0 25 QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver]),
michael@0 26
michael@0 27 notifyInvalidSubmit : function (aFormElement, aInvalidElements)
michael@0 28 {
michael@0 29 }
michael@0 30 };
michael@0 31
michael@0 32 var testId = -1;
michael@0 33
michael@0 34 function nextTest()
michael@0 35 {
michael@0 36 testId++;
michael@0 37 if (testId >= tests.length) {
michael@0 38 finish();
michael@0 39 return;
michael@0 40 }
michael@0 41 executeSoon(tests[testId]);
michael@0 42 }
michael@0 43
michael@0 44 function test()
michael@0 45 {
michael@0 46 waitForExplicitFinish();
michael@0 47 waitForFocus(nextTest);
michael@0 48 }
michael@0 49
michael@0 50 var tests = [
michael@0 51
michael@0 52 /**
michael@0 53 * In this test, we check that no popup appears if the form is valid.
michael@0 54 */
michael@0 55 function()
michael@0 56 {
michael@0 57 let uri = "data:text/html,<html><body><iframe name='t'></iframe><form target='t' action='data:text/html,'><input><input id='s' type='submit'></form></body></html>";
michael@0 58 let tab = gBrowser.addTab();
michael@0 59
michael@0 60 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 61 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 62 let doc = gBrowser.contentDocument;
michael@0 63
michael@0 64 doc.getElementById('s').click();
michael@0 65
michael@0 66 executeSoon(function() {
michael@0 67 checkPopupHide();
michael@0 68
michael@0 69 // Clean-up
michael@0 70 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 71 nextTest();
michael@0 72 });
michael@0 73 }, true);
michael@0 74
michael@0 75 gBrowser.selectedTab = tab;
michael@0 76 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 77 },
michael@0 78
michael@0 79 /**
michael@0 80 * In this test, we check that, when an invalid form is submitted,
michael@0 81 * the invalid element is focused and a popup appears.
michael@0 82 */
michael@0 83 function()
michael@0 84 {
michael@0 85 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input required id='i'><input id='s' type='submit'></form>";
michael@0 86 let tab = gBrowser.addTab();
michael@0 87
michael@0 88 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 89 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 90
michael@0 91 let doc = gBrowser.contentDocument;
michael@0 92 is(doc.activeElement, doc.getElementById('i'),
michael@0 93 "First invalid element should be focused");
michael@0 94
michael@0 95 checkPopupShow();
michael@0 96 checkPopupMessage(doc);
michael@0 97
michael@0 98 // Clean-up and next test.
michael@0 99 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 100 nextTest();
michael@0 101 }, false);
michael@0 102
michael@0 103 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 104 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 105
michael@0 106 gBrowser.contentDocument.getElementById('s').click();
michael@0 107 }, true);
michael@0 108
michael@0 109 gBrowser.selectedTab = tab;
michael@0 110 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 111 },
michael@0 112
michael@0 113 /**
michael@0 114 * In this test, we check that, when an invalid form is submitted,
michael@0 115 * the first invalid element is focused and a popup appears.
michael@0 116 */
michael@0 117 function()
michael@0 118 {
michael@0 119 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input><input id='i' required><input required><input id='s' type='submit'></form>";
michael@0 120 let tab = gBrowser.addTab();
michael@0 121
michael@0 122 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 123 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 124
michael@0 125 let doc = gBrowser.contentDocument;
michael@0 126 is(doc.activeElement, doc.getElementById('i'),
michael@0 127 "First invalid element should be focused");
michael@0 128
michael@0 129 checkPopupShow();
michael@0 130 checkPopupMessage(doc);
michael@0 131
michael@0 132 // Clean-up and next test.
michael@0 133 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 134 nextTest();
michael@0 135 }, false);
michael@0 136
michael@0 137 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 138 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 139
michael@0 140 gBrowser.contentDocument.getElementById('s').click();
michael@0 141 }, true);
michael@0 142
michael@0 143 gBrowser.selectedTab = tab;
michael@0 144 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 145 },
michael@0 146
michael@0 147 /**
michael@0 148 * In this test, we check that, we hide the popup by interacting with the
michael@0 149 * invalid element if the element becomes valid.
michael@0 150 */
michael@0 151 function()
michael@0 152 {
michael@0 153 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input id='i' required><input id='s' type='submit'></form>";
michael@0 154 let tab = gBrowser.addTab();
michael@0 155
michael@0 156 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 157 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 158
michael@0 159 let doc = gBrowser.contentDocument;
michael@0 160 is(doc.activeElement, doc.getElementById('i'),
michael@0 161 "First invalid element should be focused");
michael@0 162
michael@0 163 checkPopupShow();
michael@0 164 checkPopupMessage(doc);
michael@0 165
michael@0 166 EventUtils.synthesizeKey("a", {});
michael@0 167
michael@0 168 executeSoon(function () {
michael@0 169 checkPopupHide();
michael@0 170
michael@0 171 // Clean-up and next test.
michael@0 172 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 173 nextTest();
michael@0 174 });
michael@0 175 }, false);
michael@0 176
michael@0 177 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 178 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 179
michael@0 180 gBrowser.contentDocument.getElementById('s').click();
michael@0 181 }, true);
michael@0 182
michael@0 183 gBrowser.selectedTab = tab;
michael@0 184 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 185 },
michael@0 186
michael@0 187 /**
michael@0 188 * In this test, we check that, we don't hide the popup by interacting with the
michael@0 189 * invalid element if the element is still invalid.
michael@0 190 */
michael@0 191 function()
michael@0 192 {
michael@0 193 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input type='email' id='i' required><input id='s' type='submit'></form>";
michael@0 194 let tab = gBrowser.addTab();
michael@0 195
michael@0 196 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 197 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 198
michael@0 199 let doc = gBrowser.contentDocument;
michael@0 200 is(doc.activeElement, doc.getElementById('i'),
michael@0 201 "First invalid element should be focused");
michael@0 202
michael@0 203 checkPopupShow();
michael@0 204 checkPopupMessage(doc);
michael@0 205
michael@0 206 EventUtils.synthesizeKey("a", {});
michael@0 207
michael@0 208 executeSoon(function () {
michael@0 209 checkPopupShow();
michael@0 210
michael@0 211 // Clean-up and next test.
michael@0 212 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 213 nextTest();
michael@0 214 });
michael@0 215 }, false);
michael@0 216
michael@0 217 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 218 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 219
michael@0 220 gBrowser.contentDocument.getElementById('s').click();
michael@0 221 }, true);
michael@0 222
michael@0 223 gBrowser.selectedTab = tab;
michael@0 224 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 225 },
michael@0 226
michael@0 227 /**
michael@0 228 * In this test, we check that we can hide the popup by blurring the invalid
michael@0 229 * element.
michael@0 230 */
michael@0 231 function()
michael@0 232 {
michael@0 233 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input id='i' required><input id='s' type='submit'></form>";
michael@0 234 let tab = gBrowser.addTab();
michael@0 235
michael@0 236 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 237 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 238
michael@0 239 let doc = gBrowser.contentDocument;
michael@0 240 is(doc.activeElement, doc.getElementById('i'),
michael@0 241 "First invalid element should be focused");
michael@0 242
michael@0 243 checkPopupShow();
michael@0 244 checkPopupMessage(doc);
michael@0 245
michael@0 246 doc.getElementById('i').blur();
michael@0 247
michael@0 248 executeSoon(function () {
michael@0 249 checkPopupHide();
michael@0 250
michael@0 251 // Clean-up and next test.
michael@0 252 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 253 nextTest();
michael@0 254 });
michael@0 255 }, false);
michael@0 256
michael@0 257 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 258 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 259
michael@0 260 gBrowser.contentDocument.getElementById('s').click();
michael@0 261 }, true);
michael@0 262
michael@0 263 gBrowser.selectedTab = tab;
michael@0 264 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 265 },
michael@0 266
michael@0 267 /**
michael@0 268 * In this test, we check that we can hide the popup by pressing TAB.
michael@0 269 */
michael@0 270 function()
michael@0 271 {
michael@0 272 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input id='i' required><input id='s' type='submit'></form>";
michael@0 273 let tab = gBrowser.addTab();
michael@0 274
michael@0 275 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 276 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 277
michael@0 278 let doc = gBrowser.contentDocument;
michael@0 279 is(doc.activeElement, doc.getElementById('i'),
michael@0 280 "First invalid element should be focused");
michael@0 281
michael@0 282 checkPopupShow();
michael@0 283 checkPopupMessage(doc);
michael@0 284
michael@0 285 EventUtils.synthesizeKey("VK_TAB", {});
michael@0 286
michael@0 287 executeSoon(function () {
michael@0 288 checkPopupHide();
michael@0 289
michael@0 290 // Clean-up and next test.
michael@0 291 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 292 nextTest();
michael@0 293 });
michael@0 294 }, false);
michael@0 295
michael@0 296 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 297 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 298
michael@0 299 gBrowser.contentDocument.getElementById('s').click();
michael@0 300 }, true);
michael@0 301
michael@0 302 gBrowser.selectedTab = tab;
michael@0 303 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 304 },
michael@0 305
michael@0 306 /**
michael@0 307 * In this test, we check that the popup will hide if we move to another tab.
michael@0 308 */
michael@0 309 function()
michael@0 310 {
michael@0 311 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input id='i' required><input id='s' type='submit'></form>";
michael@0 312 let tab = gBrowser.addTab();
michael@0 313
michael@0 314 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 315 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 316
michael@0 317 let doc = gBrowser.contentDocument;
michael@0 318 is(doc.activeElement, doc.getElementById('i'),
michael@0 319 "First invalid element should be focused");
michael@0 320
michael@0 321 checkPopupShow();
michael@0 322 checkPopupMessage(doc);
michael@0 323
michael@0 324 // Create a new tab and move to it.
michael@0 325 gBrowser.selectedTab = gBrowser.addTab("about:blank", {skipAnimation: true});
michael@0 326
michael@0 327 executeSoon(function() {
michael@0 328 checkPopupHide();
michael@0 329
michael@0 330 // Clean-up and next test.
michael@0 331 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 332 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 333 nextTest();
michael@0 334 });
michael@0 335 }, false);
michael@0 336
michael@0 337 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 338 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 339
michael@0 340 gBrowser.contentDocument.getElementById('s').click();
michael@0 341 }, true);
michael@0 342
michael@0 343 gBrowser.selectedTab = tab;
michael@0 344 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 345 },
michael@0 346
michael@0 347 /**
michael@0 348 * In this test, we check that nothing happen (no focus nor popup) if the
michael@0 349 * invalid form is submitted in another tab than the current focused one
michael@0 350 * (submitted in background).
michael@0 351 */
michael@0 352 function()
michael@0 353 {
michael@0 354 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input id='i' required><input id='s' type='submit'></form>";
michael@0 355 let tab = gBrowser.addTab();
michael@0 356
michael@0 357 gObserver.notifyInvalidSubmit = function() {
michael@0 358 executeSoon(function() {
michael@0 359 let doc = tab.linkedBrowser.contentDocument;
michael@0 360 isnot(doc.activeElement, doc.getElementById('i'),
michael@0 361 "We should not focus the invalid element when the form is submitted in background");
michael@0 362
michael@0 363 checkPopupHide();
michael@0 364
michael@0 365 // Clean-up
michael@0 366 Services.obs.removeObserver(gObserver, "invalidformsubmit");
michael@0 367 gObserver.notifyInvalidSubmit = function () {};
michael@0 368 gBrowser.removeTab(tab);
michael@0 369
michael@0 370 nextTest();
michael@0 371 });
michael@0 372 };
michael@0 373
michael@0 374 Services.obs.addObserver(gObserver, "invalidformsubmit", false);
michael@0 375
michael@0 376 tab.linkedBrowser.addEventListener("load", function(e) {
michael@0 377 // Ignore load events from the iframe.
michael@0 378 if (tab.linkedBrowser.contentDocument == e.target) {
michael@0 379 let browser = e.currentTarget;
michael@0 380 browser.removeEventListener("load", arguments.callee, true);
michael@0 381
michael@0 382 isnot(gBrowser.selectedTab.linkedBrowser, browser,
michael@0 383 "This tab should have been loaded in background");
michael@0 384 browser.contentDocument.getElementById('s').click();
michael@0 385 }
michael@0 386 }, true);
michael@0 387
michael@0 388 tab.linkedBrowser.loadURI(uri);
michael@0 389 },
michael@0 390
michael@0 391 /**
michael@0 392 * In this test, we check that the author defined error message is shown.
michael@0 393 */
michael@0 394 function()
michael@0 395 {
michael@0 396 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input x-moz-errormessage='foo' required id='i'><input id='s' type='submit'></form>";
michael@0 397 let tab = gBrowser.addTab();
michael@0 398
michael@0 399 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 400 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 401
michael@0 402 let doc = gBrowser.contentDocument;
michael@0 403 is(doc.activeElement, doc.getElementById('i'),
michael@0 404 "First invalid element should be focused");
michael@0 405
michael@0 406 checkPopupShow();
michael@0 407
michael@0 408 is(gInvalidFormPopup.firstChild.textContent, "foo",
michael@0 409 "The panel should show the author defined error message");
michael@0 410
michael@0 411 // Clean-up and next test.
michael@0 412 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 413 nextTest();
michael@0 414 }, false);
michael@0 415
michael@0 416 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 417 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 418
michael@0 419 gBrowser.contentDocument.getElementById('s').click();
michael@0 420 }, true);
michael@0 421
michael@0 422 gBrowser.selectedTab = tab;
michael@0 423 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 424 },
michael@0 425
michael@0 426 /**
michael@0 427 * In this test, we check that the message is correctly updated when it changes.
michael@0 428 */
michael@0 429 function()
michael@0 430 {
michael@0 431 let uri = "data:text/html,<iframe name='t'></iframe><form target='t' action='data:text/html,'><input type='email' required id='i'><input id='s' type='submit'></form>";
michael@0 432 let tab = gBrowser.addTab();
michael@0 433
michael@0 434 gInvalidFormPopup.addEventListener("popupshown", function() {
michael@0 435 gInvalidFormPopup.removeEventListener("popupshown", arguments.callee, false);
michael@0 436
michael@0 437 let doc = gBrowser.contentDocument;
michael@0 438 let input = doc.getElementById('i');
michael@0 439 is(doc.activeElement, input, "First invalid element should be focused");
michael@0 440
michael@0 441 checkPopupShow();
michael@0 442
michael@0 443 is(gInvalidFormPopup.firstChild.textContent, input.validationMessage,
michael@0 444 "The panel should show the current validation message");
michael@0 445
michael@0 446 input.addEventListener('input', function() {
michael@0 447 input.removeEventListener('input', arguments.callee, false);
michael@0 448
michael@0 449 executeSoon(function() {
michael@0 450 // Now, the element suffers from another error, the message should have
michael@0 451 // been updated.
michael@0 452 is(gInvalidFormPopup.firstChild.textContent, input.validationMessage,
michael@0 453 "The panel should show the current validation message");
michael@0 454
michael@0 455 // Clean-up and next test.
michael@0 456 gBrowser.removeTab(gBrowser.selectedTab);
michael@0 457 nextTest();
michael@0 458 });
michael@0 459 }, false);
michael@0 460
michael@0 461 EventUtils.synthesizeKey('f', {});
michael@0 462 }, false);
michael@0 463
michael@0 464 tab.linkedBrowser.addEventListener("load", function(aEvent) {
michael@0 465 tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 466
michael@0 467 gBrowser.contentDocument.getElementById('s').click();
michael@0 468 }, true);
michael@0 469
michael@0 470 gBrowser.selectedTab = tab;
michael@0 471 gBrowser.selectedTab.linkedBrowser.loadURI(uri);
michael@0 472 },
michael@0 473
michael@0 474 ];

mercurial