123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <!DOCTYPE HTML>
- <html>
- <!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=558788
- -->
- <head>
- <title>Test for Bug 558788</title>
- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
- </head>
- <body>
- <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=558788">Mozilla Bug 558788</a>
- <p id="display"></p>
- <div id="content">
- </div>
- <pre id="test">
- <script type="application/javascript">
- /** Test for Bug 558788 **/
- var validElementsDescription = [
- /* element type value required pattern maxlength minlength */
- /* <input> */
- [ "input", null, null, null, null, null, null ],
- /* <input required value='foo'> */
- [ "input", null, "foo", true, null, null, null ],
- /* <input type='email'> */
- [ "input", "email", null, null, null, null, null ],
- /* <input type='email' value='foo@mozilla.org'> */
- [ "input", "email", "foo@mozilla.org", null, null, null, null ],
- /* <input type='url'> */
- [ "input", "url", null, null, null, null, null ],
- /* <input type='url' value='http://mozilla.org'> */
- [ "input", "url", "http://mozilla.org", null, null, null, null ],
- /* <input pattern='\\d\\d'> */
- [ "input", null, null, null, "\\d\\d", null, null ],
- /* <input pattern='\\d\\d' value='42'> */
- [ "input", null, "42", null, "\\d\\d", null, null ],
- /* <input maxlength='3'> - still valid until user interaction */
- [ "input", null, null, null, null, "3", null ],
- /* <input maxlength='3'> */
- [ "input", null, "fooo", null, null, "3", null ],
- /* <input minlength='3'> - still valid until user interaction */
- [ "input", null, null, null, null, null, "3" ],
- /* <input minlength='3'> */
- [ "input", null, "fo", null, null, null, "3" ],
- /* <textarea></textarea> */
- [ "textarea", null, null, null, null, null, null ],
- /* <textarea required>foo</textarea> */
- [ "textarea", null, "foo", true, null, null, null ]
- ];
- var invalidElementsDescription = [
- /* element type value required pattern maxlength minlength valid-value */
- /* <input required> */
- [ "input", null, null, true, null, null, null, "foo" ],
- /* <input type='email' value='foo'> */
- [ "input", "email", "foo", null, null, null, null, "foo@mozilla.org" ],
- /* <input type='url' value='foo'> */
- [ "input", "url", "foo", null, null, null, null, "http://mozilla.org" ],
- /* <input pattern='\\d\\d' value='foo'> */
- [ "input", null, "foo", null, "\\d\\d", null, null, "42" ],
- /* <input maxlength='3'> - still valid until user interaction */
- [ "input", null, "foooo", null, null, "3", null, "foo" ],
- /* <input minlength='3'> - still valid until user interaction */
- [ "input", null, "foo", null, null, null, "3", "foo" ],
- /* <textarea required></textarea> */
- [ "textarea", null, null, true, null, null, null, "foo" ],
- ];
- var validElements = [];
- var invalidElements = [];
- function appendElements(aElementsDesc, aElements)
- {
- var content = document.getElementById('content');
- var length = aElementsDesc.length;
- for (var i=0; i<length; ++i) {
- var e = document.createElement(aElementsDesc[i][0]);
- if (aElementsDesc[i][1]) {
- e.type = aElementsDesc[i][1];
- }
- if (aElementsDesc[i][2]) {
- e.value = aElementsDesc[i][2];
- }
- if (aElementsDesc[i][3]) {
- e.required = true;
- }
- if (aElementsDesc[i][4]) {
- e.pattern = aElementsDesc[i][4];
- }
- if (aElementsDesc[i][5]) {
- e.maxLength = aElementsDesc[i][5];
- }
- if (aElementsDesc[i][6]) {
- e.minLength = aElementsDesc[i][6];
- }
- content.appendChild(e);
- // Adding the element to the appropriate list.
- aElements.push(e);
- }
- }
- function compareArrayWithSelector(aElements, aSelector)
- {
- var aSelectorElements = document.querySelectorAll(aSelector);
- is(aSelectorElements.length, aElements.length,
- aSelector + " selector should return the correct number of elements");
- if (aSelectorElements.length != aElements.length) {
- return;
- }
- var length = aElements.length;
- for (var i=0; i<length; ++i) {
- is(aSelectorElements[i], aElements[i],
- aSelector + " should return the correct elements");
- }
- }
- function makeMinMaxLengthElementsActuallyInvalid(aInvalidElements,
- aInvalidElementsDesc)
- {
- // min/maxlength elements are not invalid until user edits them
- var length = aInvalidElementsDesc.length;
- for (var i=0; i<length; ++i) {
- var e = aInvalidElements[i];
- if (aInvalidElementsDesc[i][5]) { // maxlength
- e.focus();
- synthesizeKey("VK_BACK_SPACE", {});
- } else if (aInvalidElementsDesc[i][6]) { // minlength
- e.focus();
- synthesizeKey("VK_BACK_SPACE", {});
- }
- }
- }
- function makeInvalidElementsValid(aInvalidElements,
- aInvalidElementsDesc,
- aValidElements)
- {
- var length = aInvalidElementsDesc.length;
- for (var i=0; i<length; ++i) {
- var e = aInvalidElements.shift();
- e.value = aInvalidElementsDesc[i][7];
- aValidElements.push(e);
- }
- }
- appendElements(validElementsDescription, validElements);
- appendElements(invalidElementsDescription, invalidElements);
- makeMinMaxLengthElementsActuallyInvalid(invalidElements, invalidElementsDescription);
- compareArrayWithSelector(validElements, ":valid");
- compareArrayWithSelector(invalidElements, ":invalid");
- makeInvalidElementsValid(invalidElements, invalidElementsDescription,
- validElements);
- compareArrayWithSelector(validElements, ":valid");
- compareArrayWithSelector(invalidElements, ":invalid");
- </script>
- </pre>
- </body>
- </html>
|