Changeset 73494 in webkit
- Timestamp:
- Dec 8, 2010 12:43:36 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r73493 r73494 1 2010-12-08 Dai Mikurube <dmikurube@google.com> 2 3 Reviewed by Kent Tamura. 4 5 Implement "required" attribute for select tags 6 https://bugs.webkit.org/show_bug.cgi?id=50380 7 8 Added tests for require attributes, valueMissing and vadility check for select elements. 9 10 * fast/forms/ValidityState-valueMissing-001-expected.txt: 11 * fast/forms/ValidityState-valueMissing-001.html: 12 * fast/forms/ValidityState-valueMissing-002-expected.txt: 13 * fast/forms/ValidityState-valueMissing-002.html: 14 * fast/forms/ValidityState-valueMissing-003-expected.txt: 15 * fast/forms/ValidityState-valueMissing-003.html: 16 * fast/forms/checkValidity-002-expected.txt: 17 * fast/forms/checkValidity-002.html: 18 * fast/forms/required-attribute-001-expected.txt: 19 * fast/forms/required-attribute-001.html: 20 * fast/forms/required-attribute-002-expected.txt: 21 * fast/forms/required-attribute-002.html: 22 * fast/forms/resources/select-live-pseudo-selectors.js: Added. 23 (makeInvalid): 24 (appendOption): 25 (backgroundOf): 26 * fast/forms/script-tests/validationMessage.js: 27 * fast/forms/select-live-pseudo-selectors-expected.txt: Added. 28 * fast/forms/select-live-pseudo-selectors.html: Added. 29 * fast/forms/validationMessage-expected.txt: 30 * platform/mac/fast/objc/dom-html-select-live-pseudo-selectors.html: Added. 31 * platform/mac/fast/objc/dom-html-select-live-pseudo-selectors-expected.txt: Added. 32 1 33 2010-12-08 Yuta Kitamura <yutak@chromium.org> 2 34 -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-001-expected.txt
r46062 r73494 1 Th ere are two form control elements below, both required and blank: validity.valueMissing should be true in both cases.1 This test checks validity.valueMissing with blank values, blank options selected, or nothing selected. 2 2 3 4 SUCCESS 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 5 6 PASS valueMissingFor("input") is true 7 PASS valueMissingFor("textarea") is true 8 PASS valueMissingFor("select-no-option") is true 9 PASS valueMissingFor("select-placeholder-selected") is true 10 PASS valueMissingFor("select-without-placeholder") is false 11 PASS valueMissingFor("select-placeholder-selected-size2") is false 12 PASS valueMissingFor("select-without-placeholder-size2") is false 13 PASS valueMissingFor("select-none-selected-multiple") is true 14 PASS valueMissingFor("select-fake-placeholder-selected-multiple") is false 15 PASS valueMissingFor("select-without-fake-placeholder-multiple") is false 16 PASS valueMissingFor("select-none-selected-size2-multiple") is true 17 PASS valueMissingFor("select-fake-placeholder-selected-size2-multiple") is false 18 PASS valueMissingFor("select-without-fake-placeholder-size2-multiple") is false 19 PASS valueMissingFor("select-optgroup") is false 20 PASS valueMissingFor("select-disabled-option") is false 21 PASS successfullyParsed is true 22 23 TEST COMPLETE 24 -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-001.html
r46062 r73494 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <head> 3 4 <title>required and basic valueMissing</title> 5 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 6 <script src="../../fast/js/resources/js-test-pre.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <input id="input" name="victim" required/> 12 <textarea id="textarea" name="victim" required></textarea> 13 <select id="select-no-option" name="victim" required> 14 </select> 15 <select id="select-placeholder-selected" name="victim" required> 16 <option value="" selected /> 17 <option value="X">X</option> 18 </select> 19 <select id="select-without-placeholder" name="victim" required> 20 <option value="X">X</option> 21 <option value="" selected /> 22 </select> 23 <select id="select-placeholder-selected-size2" name="victim" size="2" required> 24 <option value="" selected /> 25 <option value="X">X</option> 26 </select> 27 <select id="select-without-placeholder-size2" name="victim" size="2" required> 28 <option value="X">X</option> 29 <option value="" selected /> 30 </select> 31 <select id="select-none-selected-multiple" name="victim" multiple required> 32 <option value="" /> 33 <option value="X">X</option> 34 </select> 35 <select id="select-fake-placeholder-selected-multiple" name="victim" multiple required> 36 <option value="" selected /> 37 <option value="X">X</option> 38 </select> 39 <select id="select-without-fake-placeholder-multiple" name="victim" multiple required> 40 <option value="X">X</option> 41 <option value="" selected /> 42 </select> 43 <select id="select-none-selected-size2-multiple" name="victim" multiple size="2" required> 44 <option value="" /> 45 <option value="X">X</option> 46 </select> 47 <select id="select-fake-placeholder-selected-size2-multiple" name="victim" multiple size="2" required> 48 <option value="" selected /> 49 <option value="X">X</option> 50 </select> 51 <select id="select-without-fake-placeholder-size2-multiple" name="victim" multiple size="2" required> 52 <option value="X">X</option> 53 <option value="" selected /> 54 </select> 55 <select id="select-optgroup" name="victim" required> 56 <optgroup label="1"> 57 <option value="" selected /> 58 </optgroup> 59 <option value="X">X</option> 60 </select> 61 <select id="select-disabled-option" name="victim" required> 62 <option value="" disabled selected /> 63 <option value="X">X</option> 64 </select> 4 65 <script language="JavaScript" type="text/javascript"> 5 function log(message) {6 document.getElementById("console").innerHTML += "<li>"+message+"</li>";66 function valueMissingFor(id) { 67 return document.getElementById(id).validity.valueMissing; 7 68 } 8 69 9 function test() { 10 if (window.layoutTestController) 11 layoutTestController.dumpAsText(); 70 description("This test checks validity.valueMissing with blank values, blank options selected, or nothing selected."); 12 71 13 72 v = document.getElementsByName("victim"); 14 73 15 log((v[0].validity.valueMissing && v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE"); 16 } 74 shouldBeTrue('valueMissingFor("input")'); 75 shouldBeTrue('valueMissingFor("textarea")'); 76 shouldBeTrue('valueMissingFor("select-no-option")'); 77 shouldBeTrue('valueMissingFor("select-placeholder-selected")'); 78 shouldBeFalse('valueMissingFor("select-without-placeholder")'); 79 shouldBeFalse('valueMissingFor("select-placeholder-selected-size2")'); 80 shouldBeFalse('valueMissingFor("select-without-placeholder-size2")'); 81 shouldBeTrue('valueMissingFor("select-none-selected-multiple")'); 82 shouldBeFalse('valueMissingFor("select-fake-placeholder-selected-multiple")'); 83 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-multiple")'); 84 shouldBeTrue('valueMissingFor("select-none-selected-size2-multiple")'); 85 shouldBeFalse('valueMissingFor("select-fake-placeholder-selected-size2-multiple")'); 86 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-size2-multiple")'); 87 shouldBeFalse('valueMissingFor("select-optgroup")'); 88 shouldBeFalse('valueMissingFor("select-disabled-option")'); 89 90 var successfullyParsed = true; 17 91 </script> 18 </head> 19 <body onload="test()"> 20 <p>There are two form control elements below, both required and blank: 21 validity.valueMissing should be true in both cases.</p> 22 <input name="victim" required/> 23 <textarea name="victim" required></textarea> 24 <hr> 25 <ol id="console"></ol> 92 <script src="../../fast/js/resources/js-test-post.js"></script> 26 93 </body> 27 94 </html> -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-002-expected.txt
r46062 r73494 1 Th ere are two form control elements below, both required and with some value: validity.valueMissing should be false in both cases.1 This test checks validity.valueMissing with some values or options with some values selected. 2 2 3 4 SUCCESS 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 5 6 PASS valueMissingFor("input") is false 7 PASS valueMissingFor("textarea") is false 8 PASS valueMissingFor("select-with-placeholder") is false 9 PASS valueMissingFor("select-without-placeholder") is false 10 PASS valueMissingFor("select-with-fake-placeholder-size2") is false 11 PASS valueMissingFor("select-without-fake-placeholder-size2") is false 12 PASS valueMissingFor("select-with-fake-placeholder-multiple") is false 13 PASS valueMissingFor("select-without-fake-placeholder-multiple") is false 14 PASS valueMissingFor("select-with-fake-placeholder-size2-multiple") is false 15 PASS valueMissingFor("select-without-fake-placeholder-size2-multiple") is false 16 PASS successfullyParsed is true 17 18 TEST COMPLETE 19 -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-002.html
r46062 r73494 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <head> 3 4 <title>required and basic valueMissing 2</title> 5 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 6 <script src="../../fast/js/resources/js-test-pre.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <input id="input" name="victim" value="something" required/> 12 <textarea id="textarea" name="victim" required>something</textarea> 13 <select id="select-with-placeholder" name="victim" required> 14 <option value="" /> 15 <option value="X" selected>X</option> 16 </select> 17 <select id="select-without-placeholder" name="victim" required> 18 <option value="X" selected>X</option> 19 <option value="" /> 20 </select> 21 <select id="select-with-fake-placeholder-size2" name="victim" size="2" required> 22 <option value="" /> 23 <option value="X" selected>X</option> 24 </select> 25 <select id="select-without-fake-placeholder-size2" name="victim" size="2" required> 26 <option value="X" selected>X</option> 27 <option value="" /> 28 </select> 29 <select id="select-with-fake-placeholder-multiple" name="victim" multiple required> 30 <option value="" /> 31 <option value="X" selected>X</option> 32 </select> 33 <select id="select-without-fake-placeholder-multiple" name="victim" multiple required> 34 <option value="X" selected>X</option> 35 <option value="" /> 36 </select> 37 <select id="select-with-fake-placeholder-size2-multiple" name="victim" multiple size="2" required> 38 <option value="" /> 39 <option value="X" selected>X</option> 40 </select> 41 <select id="select-without-fake-placeholder-size2-multiple" name="victim" multiple size="2" required> 42 <option value="X" selected>X</option> 43 <option value="" /> 44 </select> 4 45 <script language="JavaScript" type="text/javascript"> 5 function log(message) {6 document.getElementById("console").innerHTML += "<li>"+message+"</li>";46 function valueMissingFor(id) { 47 return document.getElementById(id).validity.valueMissing; 7 48 } 8 49 9 function test() { 10 if (window.layoutTestController) 11 layoutTestController.dumpAsText(); 50 description("This test checks validity.valueMissing with some values or options with some values selected."); 12 51 13 52 v = document.getElementsByName("victim"); 14 53 15 log((!v[0].validity.valueMissing && !v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE"); 16 } 54 shouldBeFalse('valueMissingFor("input")'); 55 shouldBeFalse('valueMissingFor("textarea")'); 56 shouldBeFalse('valueMissingFor("select-with-placeholder")'); 57 shouldBeFalse('valueMissingFor("select-without-placeholder")'); 58 shouldBeFalse('valueMissingFor("select-with-fake-placeholder-size2")'); 59 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-size2")'); 60 shouldBeFalse('valueMissingFor("select-with-fake-placeholder-multiple")'); 61 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-multiple")'); 62 shouldBeFalse('valueMissingFor("select-with-fake-placeholder-size2-multiple")'); 63 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-size2-multiple")'); 64 65 var successfullyParsed = true; 17 66 </script> 18 </head> 19 <body onload="test()"> 20 <p>There are two form control elements below, both required and with some value: 21 validity.valueMissing should be false in both cases.</p> 22 <input name="victim" value="something" required/> 23 <textarea name="victim" required>something</textarea> 24 <hr> 25 <ol id="console"></ol> 67 <script src="../../fast/js/resources/js-test-post.js"></script> 26 68 </body> 27 69 </html> -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-003-expected.txt
r46062 r73494 1 Th ere are two disabled form control elements below, both required and with some value: validity.valueMissing should be false in both cases.1 This test checks validity.valueMissing of disabled form controls with blank values, blank options selected, or nothing selected. 2 2 3 4 SUCCESS 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 5 6 PASS valueMissingFor("input") is false 7 PASS valueMissingFor("textarea") is false 8 PASS valueMissingFor("select-no-option") is false 9 PASS valueMissingFor("select-placeholder-selected") is false 10 PASS valueMissingFor("select-without-placeholder") is false 11 PASS valueMissingFor("select-placeholder-selected-size2") is false 12 PASS valueMissingFor("select-without-placeholder-size2") is false 13 PASS valueMissingFor("select-none-selected-multiple") is false 14 PASS valueMissingFor("select-fake-placeholder-selected-multiple") is false 15 PASS valueMissingFor("select-without-fake-placeholder-multiple") is false 16 PASS valueMissingFor("select-none-selected-size2-multiple") is false 17 PASS valueMissingFor("select-fake-placeholder-selected-size2-multiple") is false 18 PASS valueMissingFor("select-without-fake-placeholder-size2-multiple") is false 19 PASS successfullyParsed is true 20 21 TEST COMPLETE 22 -
trunk/LayoutTests/fast/forms/ValidityState-valueMissing-003.html
r46062 r73494 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <head> 3 4 <title>required and valueMissing on disabled elements</title> 5 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 6 <script src="../../fast/js/resources/js-test-pre.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <input id="input" name="victim" disabled required /> 12 <textarea id="textarea" name="victim" disabled required></textarea> 13 <select id="select-no-option" name="victim" disabled required> 14 </select> 15 <select id="select-placeholder-selected" name="victim" disabled required> 16 <option value="" selected /> 17 <option value="X">X</option> 18 </select> 19 <select id="select-without-placeholder" name="victim" disabled required> 20 <option value="X">X</option> 21 <option value="" selected /> 22 </select> 23 <select id="select-placeholder-selected-size2" name="victim" size="2" disabled required> 24 <option value="" selected /> 25 <option value="X">X</option> 26 </select> 27 <select id="select-without-placeholder-size2" name="victim" size="2" disabled required> 28 <option value="X">X</option> 29 <option value="" selected /> 30 </select> 31 <select id="select-none-selected-multiple" name="victim" multiple disabled required> 32 <option value="" /> 33 <option value="X">X</option> 34 </select> 35 <select id="select-fake-placeholder-selected-multiple" name="victim" multiple disabled required> 36 <option value="" selected /> 37 <option value="X">X</option> 38 </select> 39 <select id="select-without-fake-placeholder-multiple" name="victim" multiple disabled required> 40 <option value="X">X</option> 41 <option value="" selected /> 42 </select> 43 <select id="select-none-selected-size2-multiple" name="victim" multiple size="2" disabled required> 44 <option value="" /> 45 <option value="X">X</option> 46 </select> 47 <select id="select-fake-placeholder-selected-size2-multiple" name="victim" multiple size="2" disabled required> 48 <option value="" selected /> 49 <option value="X">X</option> 50 </select> 51 <select id="select-without-fake-placeholder-size2-multiple" name="victim" multiple size="2" disabled required> 52 <option value="X">X</option> 53 <option value="" selected /> 54 </select> 4 55 <script language="JavaScript" type="text/javascript"> 5 function log(message) {6 document.getElementById("console").innerHTML += "<li>"+message+"</li>";56 function valueMissingFor(id) { 57 return document.getElementById(id).validity.valueMissing; 7 58 } 8 59 9 function test() { 10 if (window.layoutTestController) 11 layoutTestController.dumpAsText(); 60 description("This test checks validity.valueMissing of disabled form controls with blank values, blank options selected, or nothing selected."); 12 61 13 62 v = document.getElementsByName("victim"); 14 63 15 log((!v[0].validity.valueMissing && !v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE"); 16 } 64 shouldBeFalse('valueMissingFor("input")'); 65 shouldBeFalse('valueMissingFor("textarea")'); 66 shouldBeFalse('valueMissingFor("select-no-option")'); 67 shouldBeFalse('valueMissingFor("select-placeholder-selected")'); 68 shouldBeFalse('valueMissingFor("select-without-placeholder")'); 69 shouldBeFalse('valueMissingFor("select-placeholder-selected-size2")'); 70 shouldBeFalse('valueMissingFor("select-without-placeholder-size2")'); 71 shouldBeFalse('valueMissingFor("select-none-selected-multiple")'); 72 shouldBeFalse('valueMissingFor("select-fake-placeholder-selected-multiple")'); 73 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-multiple")'); 74 shouldBeFalse('valueMissingFor("select-none-selected-size2-multiple")'); 75 shouldBeFalse('valueMissingFor("select-fake-placeholder-selected-size2-multiple")'); 76 shouldBeFalse('valueMissingFor("select-without-fake-placeholder-size2-multiple")'); 77 78 var successfullyParsed = true; 17 79 </script> 18 </head> 19 <body onload="test()"> 20 <p>There are two disabled form control elements below, both required and with some value: 21 validity.valueMissing should be false in both cases.</p> 22 <input name="victim" disabled required /> 23 <textarea name="victim" disabled required></textarea> 24 <hr> 25 <ol id="console"></ol> 80 <script src="../../fast/js/resources/js-test-post.js"></script> 26 81 </body> 27 82 </html> -
trunk/LayoutTests/fast/forms/checkValidity-002-expected.txt
r47649 r73494 1 This test checks if checkValidity() returns correctly a false (meaning error) result on invalid elements .1 This test checks if checkValidity() returns correctly a false (meaning error) result on invalid elements, and returns a true result on a blank but valid elements. Blank but non-placeholder label options are valid. 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 4 5 5 6 7 PASS v[i].checkValidity() is false 8 PASS v[i].checkValidity() is false 9 PASS v[i].checkValidity() is false 6 7 PASS checkValidityFor("input-empty") is false 8 PASS checkValidityFor("input-pattern-mismatch") is false 9 PASS checkValidityFor("textarea") is false 10 PASS checkValidityFor("select-placeholder") is false 11 PASS checkValidityFor("select-non-placeholder") is true 10 12 PASS successfullyParsed is true 11 13 -
trunk/LayoutTests/fast/forms/checkValidity-002.html
r47649 r73494 8 8 <p id="description"></p> 9 9 <form method="get"> 10 <input name="victim" type="text" required/> 11 <input name="victim" type="text" pattern="Lorem ipsum" value="Loremipsum"/> 12 <textarea name="victim" required></textarea> 10 <input id="input-empty" name="victim" type="text" required/> 11 <input id="input-pattern-mismatch" name="victim" type="text" pattern="Lorem ipsum" value="Loremipsum"/> 12 <textarea id="textarea" name="victim" required></textarea> 13 <select id="select-placeholder" name="victim" required> 14 <option value="" selected /> 15 <option value="X">X</option> 16 </select> 17 <select id="select-non-placeholder" name="victim" required> 18 <option value="X">X</option> 19 <option value="" selected /> 20 </select> 13 21 </form> 14 22 <div id="console"></div> 15 23 <script> 16 description("This test checks if checkValidity() returns correctly a false (meaning error) result on invalid elements."); 24 function checkValidityFor(id) { 25 return document.getElementById(id).checkValidity(); 26 } 17 27 18 v = document.getElementsByName("victim"); 19 for (i = 0; i < v.length; i++) 20 shouldBe("v[i].checkValidity()", "false"); 28 description("This test checks if checkValidity() returns correctly a false (meaning error) result on invalid elements, and returns a true result on a blank but valid elements. Blank but non-placeholder label options are valid."); 21 29 22 var successfullyParsed = true; 30 shouldBeFalse('checkValidityFor("input-empty")'); 31 shouldBeFalse('checkValidityFor("input-pattern-mismatch")'); 32 shouldBeFalse('checkValidityFor("textarea")'); 33 shouldBeFalse('checkValidityFor("select-placeholder")'); 34 shouldBeTrue('checkValidityFor("select-non-placeholder")'); 35 36 var successfullyParsed = true; 23 37 </script> 24 38 <script src="../js/resources/js-test-post.js"></script> -
trunk/LayoutTests/fast/forms/required-attribute-001-expected.txt
r46062 r73494 1 There are t wo form control elements below, bothrequired.1 There are three form control elements below, all required. 2 2 3 4 SUCCESS 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 5 6 PASS requiredFor("input") is true 7 PASS requiredFor("textarea") is true 8 PASS requiredFor("select") is true 9 PASS successfullyParsed is true 10 11 TEST COMPLETE 12 -
trunk/LayoutTests/fast/forms/required-attribute-001.html
r46062 r73494 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <head> 3 4 <title>required attribute presence test</title> 5 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 6 <script src="../../fast/js/resources/js-test-pre.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <input id="input" name="victim" required /> 12 <textarea id="textarea" name="victim" required></textarea> 13 <select id="select" name="victim" required> 14 <option value="" selected /> 15 <option value="X">X</option> 16 </select> 4 17 <script language="JavaScript" type="text/javascript"> 5 function log(message) {6 document.getElementById("console").innerHTML += "<li>"+message+"</li>";18 function requiredFor(id) { 19 return document.getElementById(id).required; 7 20 } 8 21 9 function test() { 10 if (window.layoutTestController) 11 layoutTestController.dumpAsText(); 22 description("There are three form control elements below, all required."); 12 23 13 24 v = document.getElementsByName("victim"); 14 25 15 log((v[0].required && v[1].required) ? "SUCCESS" : "FAILURE"); 16 } 26 shouldBeTrue('requiredFor("input")'); 27 shouldBeTrue('requiredFor("textarea")'); 28 shouldBeTrue('requiredFor("select")'); 29 30 var successfullyParsed = true; 17 31 </script> 18 </head> 19 <body onload="test()"> 20 <p>There are two form control elements below, both required.</p> 21 <input name="victim" required /> 22 <textarea name="victim" required></textarea> 23 <hr> 24 <ol id="console"></ol> 32 <script src="../../fast/js/resources/js-test-post.js"></script> 25 33 </body> 26 34 </html> -
trunk/LayoutTests/fast/forms/required-attribute-002-expected.txt
r46062 r73494 1 There are t wo form control elements below, bothoptional. They're set as required via required DOM attribute.1 There are three form control elements below, all optional. They're set as required via required DOM attribute. 2 2 3 4 SUCCESS 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 5 6 Before set: 7 PASS requiredFor("input") is false 8 PASS requiredFor("textarea") is false 9 PASS requiredFor("select") is false 10 11 After set: 12 PASS requiredFor("input") is true 13 PASS requiredFor("textarea") is true 14 PASS requiredFor("select") is true 15 16 PASS successfullyParsed is true 17 18 TEST COMPLETE 19 -
trunk/LayoutTests/fast/forms/required-attribute-002.html
r46062 r73494 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <head> 3 4 <title>required attribute JS set</title> 5 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> 6 <script src="../../fast/js/resources/js-test-pre.js"></script> 7 </head> 8 <body> 9 <p id="description"></p> 10 <div id="console"></div> 11 <input id="input" name="victim" /> 12 <textarea id="textarea" name="victim"></textarea> 13 <select id="select" name="victim"> 14 <option value="" selected /> 15 <option value="X">X</option> 16 </select> 4 17 <script language="JavaScript" type="text/javascript"> 5 function log(message) {6 document.getElementById("console").innerHTML += "<li>"+message+"</li>";18 function requiredFor(id) { 19 return document.getElementById(id).required; 7 20 } 8 21 9 function test() { 10 if (window.layoutTestController) 11 layoutTestController.dumpAsText(); 22 description("There are three form control elements below, all optional. They're set as required via required DOM attribute."); 12 23 13 24 v = document.getElementsByName("victim"); 14 25 15 if (v[0].required == false && v[1].required == false) { 16 v[0].required = true; 17 v[1].required = true; 18 log ((v[0].required && v[1].required) ? "SUCCESS" : "FAILURE"); 19 } 20 else 21 log("FAILURE"); 22 } 26 debug("Before set:"); 27 shouldBeFalse('requiredFor("input")'); 28 shouldBeFalse('requiredFor("textarea")'); 29 shouldBeFalse('requiredFor("select")'); 30 debug(""); 31 32 v[0].required = true; 33 v[1].required = true; 34 v[2].required = true; 35 36 debug("After set:"); 37 shouldBeTrue('requiredFor("input")'); 38 shouldBeTrue('requiredFor("textarea")'); 39 shouldBeTrue('requiredFor("select")'); 40 debug(""); 41 42 var successfullyParsed = true; 23 43 </script> 24 </head> 25 <body onload="test()"> 26 <p>There are two form control elements below, both optional. They're set as required via required DOM attribute.</p> 27 <input name="victim" /> 28 <textarea name="victim"></textarea> 29 <hr> 30 <ol id="console"></ol> 44 <script src="../../fast/js/resources/js-test-post.js"></script> 31 45 </body> 32 46 </html> -
trunk/LayoutTests/fast/forms/script-tests/validationMessage.js
r56242 r73494 24 24 form.appendChild(requiredTextArea); 25 25 shouldBe("requiredTextArea.validationMessage", "'value missing'"); 26 27 // A required select with an empty value 28 var requiredSelect = document.createElement("select"); 29 requiredSelect.name = "requiredSelect"; 30 requiredSelect.required = true; 31 form.appendChild(requiredSelect); 32 shouldBe("requiredSelect.validationMessage", "'value missing'"); 26 33 27 34 // A type=email input for the "type mismatch" flag -
trunk/LayoutTests/fast/forms/validationMessage-expected.txt
r56242 r73494 7 7 PASS requiredInput.validationMessage is 'value missing' 8 8 PASS requiredTextArea.validationMessage is 'value missing' 9 PASS requiredSelect.validationMessage is 'value missing' 9 10 PASS emailInput.validationMessage is 'type mismatch' 10 11 PASS but.validationMessage is '' -
trunk/WebCore/ChangeLog
r73492 r73494 1 2010-12-08 Dai Mikurube <dmikurube@google.com> 2 3 Reviewed by Kent Tamura. 4 5 Implement "required" attribute for select tags 6 https://bugs.webkit.org/show_bug.cgi?id=50380 7 8 Test: fast/forms/select-live-pseudo-selectors.html 9 platform/mac/fast/objc/dom-html-select-live-pseudo-selectors.html 10 11 * html/HTMLSelectElement.cpp: 12 (WebCore::HTMLSelectElement::deselectItems): Added calling setNeedsValidityCheck() to enable validity check after changing. No tests for this change since this function is not exposed to JavaScript or any web interface. 13 (WebCore::HTMLSelectElement::setSelectedIndex): Added calling setNeedsValidityCheck(). 14 (WebCore::HTMLSelectElement::setSelectedIndexByUser): Added calling setNeedsValidityCheck(). 15 (WebCore::HTMLSelectElement::valueMissing): Added valueMissing() to check if selecting an invalid or placeholder label option when a valid required attribute is specified. 16 (WebCore::HTMLSelectElement::listBoxSelectItem): Added calling setNeedsValidityCheck(). No tests for this change since it is not called yet. Look at the bug 36177 and the changeset 56180. 17 (WebCore::HTMLSelectElement::add): Added calling setNeedsValidityCheck(). 18 (WebCore::HTMLSelectElement::remove): Added calling setNeedsValidityCheck(). 19 (WebCore::HTMLSelectElement::restoreFormControlState): Added calling setNeedsValidityCheck(). 20 (WebCore::HTMLSelectElement::parseMappedAttribute): Added calling setNeedsValidityCheck(). 21 (WebCore::HTMLSelectElement::selectAll): Added calling setNeedsValidityCheck(). 22 (WebCore::HTMLSelectElement::reset): Added calling setNeedsValidityCheck(). 23 (WebCore::HTMLSelectElement::updateListBoxSelection): Added calling setNeedsValidityCheck(). Skipped adding tests for this change as too complicated.. 24 (WebCore::HTMLSelectElement::setLength): Added calling setNeedsValidityCheck(). 25 (WebCore::HTMLSelectElement::isRequiredFormControl): Check if required or not. 26 (WebCore::HTMLSelectElement::hasPlaceholderLabelOption): Added. 27 * html/HTMLSelectElement.h: 28 (WebCore::HTMLSelectElement::isOptionalFormControl): Check if not required. 29 * html/HTMLSelectElement.idl: Added a required attribute to select elements.. 30 * html/ValidityState.cpp: 31 (WebCore::ValidityState::valueMissing): Added valueMissing check for select elements into the global checker, ValidityState::valueMissing(). 32 1 33 2010-12-08 Renata Hodovan <reni@webkit.org> 2 34 -
trunk/WebCore/html/HTMLSelectElement.cpp
r66929 r73494 79 79 { 80 80 SelectElement::deselectItems(m_data, this, excludeElement); 81 setNeedsValidityCheck(); 81 82 } 82 83 … … 84 85 { 85 86 SelectElement::setSelectedIndex(m_data, this, optionIndex, deselect, false, false); 87 setNeedsValidityCheck(); 86 88 } 87 89 … … 92 94 if (!m_data.usesMenuList()) { 93 95 updateSelectedState(m_data, this, optionIndex, allowMultipleSelection, false); 96 setNeedsValidityCheck(); 94 97 if (fireOnChangeNow) 95 98 listBoxOnChange(); … … 105 108 106 109 SelectElement::setSelectedIndex(m_data, this, optionIndex, deselect, fireOnChangeNow, true); 110 setNeedsValidityCheck(); 111 } 112 113 bool HTMLSelectElement::hasPlaceholderLabelOption() const 114 { 115 // The select element has no placeholder label option if it has an attribute "multiple" specified or a display size of non-1. 116 // 117 // The condition "size() > 1" is actually not compliant with the HTML5 spec as of Dec 3, 2010. "size() != 1" is correct. 118 // Using "size() > 1" here because size() may be 0 in WebKit. 119 // See the discussion at https://bugs.webkit.org/show_bug.cgi?id=43887 120 // 121 // "0 size()" happens when an attribute "size" is absent or an invalid size attribute is specified. 122 // In this case, the display size should be assumed as the default. 123 // The default display size is 1 for non-multiple select elements, and 4 for multiple select elements. 124 // 125 // Finally, if size() == 0 and non-multiple, the display size can be assumed as 1. 126 if (multiple() || size() > 1) 127 return false; 128 129 int listIndex = optionToListIndex(0); 130 ASSERT(listIndex >= 0); 131 if (listIndex < 0) 132 return false; 133 HTMLOptionElement* option = static_cast<HTMLOptionElement*>(listItems()[listIndex]); 134 return !option->disabled() && !listIndex && option->value().isEmpty(); 135 } 136 137 bool HTMLSelectElement::valueMissing() const 138 { 139 if (!isRequiredFormControl()) 140 return false; 141 142 int firstSelectionIndex = selectedIndex(); 143 144 // If a non-placeholer label option is selected (firstSelectionIndex > 0), it's not value-missing. 145 return firstSelectionIndex < 0 || (!firstSelectionIndex && hasPlaceholderLabelOption()); 107 146 } 108 147 … … 113 152 else { 114 153 updateSelectedState(m_data, this, listIndex, allowMultiplySelections, shift); 154 setNeedsValidityCheck(); 115 155 if (fireOnChangeNow) 116 156 listBoxOnChange(); … … 145 185 146 186 insertBefore(element, before, ec); 187 setNeedsValidityCheck(); 147 188 } 148 189 … … 157 198 ExceptionCode ec; 158 199 item->parentNode()->removeChild(item, ec); 200 setNeedsValidityCheck(); 159 201 } 160 202 … … 196 238 { 197 239 SelectElement::restoreFormControlState(m_data, this, state); 240 setNeedsValidityCheck(); 198 241 } 199 242 … … 216 259 217 260 m_data.setSize(size); 261 setNeedsValidityCheck(); 218 262 if ((oldUsesMenuList != m_data.usesMenuList() || (!oldUsesMenuList && m_data.size() != oldSize)) && attached()) { 219 263 detach(); … … 221 265 setRecalcListItems(); 222 266 } 223 } else if (attr->name() == multipleAttr) 267 } else if (attr->name() == multipleAttr) { 224 268 SelectElement::parseMultipleAttribute(m_data, this, attr); 225 else if (attr->name() == accesskeyAttr) { 269 setNeedsValidityCheck(); 270 } else if (attr->name() == accesskeyAttr) { 226 271 // FIXME: ignore for the moment 227 272 } else if (attr->name() == alignAttr) { … … 256 301 { 257 302 SelectElement::selectAll(m_data, this); 303 setNeedsValidityCheck(); 258 304 } 259 305 … … 316 362 { 317 363 SelectElement::reset(m_data, this); 364 setNeedsValidityCheck(); 318 365 } 319 366 … … 351 398 { 352 399 SelectElement::updateListBoxSelection(m_data, this, deselectOtherOptions); 400 setNeedsValidityCheck(); 353 401 } 354 402 … … 459 507 } 460 508 } 509 setNeedsValidityCheck(); 461 510 } 462 511 … … 472 521 } 473 522 523 bool HTMLSelectElement::isRequiredFormControl() const 524 { 525 return required(); 526 } 527 474 528 } // namespace -
trunk/WebCore/html/HTMLSelectElement.h
r66929 r73494 43 43 virtual void setSelectedIndex(int index, bool deselect = true); 44 44 virtual void setSelectedIndexByUser(int index, bool deselect = true, bool fireOnChangeNow = false, bool allowMultipleSelection = false); 45 46 // For ValidityState 47 bool valueMissing() const; 45 48 46 49 unsigned length() const; … … 135 138 virtual void insertedIntoTree(bool); 136 139 137 virtual bool isOptionalFormControl() const { return true; } 140 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 141 virtual bool isRequiredFormControl() const; 142 143 bool hasPlaceholderLabelOption() const; 138 144 139 145 SelectElementData m_data; -
trunk/WebCore/html/HTMLSelectElement.idl
r61959 r73494 50 50 attribute boolean multiple; 51 51 attribute [ConvertNullToNullString] DOMString name; 52 attribute [Reflect] boolean required; 52 53 attribute long size; 53 54 -
trunk/WebCore/html/ValidityState.cpp
r73430 r73494 27 27 #include "HTMLInputElement.h" 28 28 #include "HTMLNames.h" 29 #include "HTMLSelectElement.h" 29 30 #include "HTMLTextAreaElement.h" 30 31 #include "HTMLTreeBuilder.h" … … 106 107 { 107 108 HTMLElement* element = toHTMLElement(m_control); 109 if (!element->willValidate()) 110 return false; 111 108 112 if (element->hasTagName(inputTag)) { 109 113 HTMLInputElement* input = static_cast<HTMLInputElement*>(element); … … 113 117 HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element); 114 118 return textArea->valueMissing(textArea->value()); 119 } 120 if (element->hasTagName(selectTag)) { 121 HTMLSelectElement* select = static_cast<HTMLSelectElement*>(element); 122 return select->valueMissing(); 115 123 } 116 124 return false;
Note: See TracChangeset
for help on using the changeset viewer.