test_bug622597.html (2828B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=622597 5 --> 6 <head> 7 <title>Test for Bug 622597</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=622597">Mozilla Bug 622597</a> 14 <p id="display"></p> 15 <div id="content"> 16 <form> 17 <input required> 18 <textarea required></textarea> 19 <select required><option value="">foo</option><option selected>bar</option></select> 20 <button>submit</button> 21 </form> 22 </div> 23 <pre id="test"> 24 <script type="application/javascript"> 25 26 /** Test for Bug 622597 */ 27 28 var form = document.forms[0]; 29 var input = form.elements[0]; 30 var textarea = form.elements[1]; 31 var select = form.elements[2]; 32 var button = form.elements[3]; 33 34 function checkPseudoClasses(aElement, aValid, aInvalid) 35 { 36 is(aElement.matches(":-moz-ui-valid"), aValid, 37 aValid ? aElement + " should match :-moz-ui-valid" 38 : aElement + " should not match :-moz-ui-valid"); 39 is(aElement.matches(":-moz-ui-invalid"), aInvalid, 40 aInvalid ? aElement + " should match :-moz-ui-invalid" 41 : aElement + " should not match :-moz-ui-invalid"); 42 if (aValid && aInvalid) { 43 ok(false, 44 aElement + " should not match :-moz-ui-valid AND :-moz-ui-invalid"); 45 } 46 } 47 48 select.addEventListener("focus", function() { 49 SimpleTest.executeSoon(function() { 50 form.noValidate = false; 51 SimpleTest.executeSoon(function() { 52 checkPseudoClasses(select, false, true); 53 SimpleTest.finish(); 54 }); 55 }); 56 }, {once: true}); 57 58 textarea.addEventListener("focus", function() { 59 SimpleTest.executeSoon(function() { 60 form.noValidate = false; 61 SimpleTest.executeSoon(function() { 62 checkPseudoClasses(textarea, false, true); 63 form.noValidate = true; 64 select.selectedIndex = 0; 65 select.focus(); 66 }); 67 }); 68 }, {once: true}); 69 70 input.addEventListener("invalid", function() { 71 input.addEventListener("focus", function() { 72 SimpleTest.executeSoon(function() { 73 form.noValidate = false; 74 SimpleTest.executeSoon(function() { 75 checkPseudoClasses(input, false, true); 76 form.noValidate = true; 77 textarea.value = ''; 78 textarea.focus(); 79 }); 80 }); 81 }, {once: true}); 82 83 SimpleTest.executeSoon(function() { 84 form.noValidate = true; 85 input.blur(); 86 input.value = ''; 87 input.focus(); 88 }); 89 }, {once: true}); 90 91 button.addEventListener("focus", function() { 92 SimpleTest.executeSoon(function() { 93 synthesizeKey("KEY_Enter"); 94 }); 95 }, {once: true}); 96 97 SimpleTest.waitForExplicitFinish(); 98 SimpleTest.waitForFocus(function() { 99 button.focus(); 100 }); 101 102 </script> 103 </pre> 104 </body> 105 </html>