LayoutTests/ChangeLog

 12010-02-27 Kent Tamura <tkent@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Fix a bug that validity.valueMissing for a radio button with required
 6 in a form element always returns true.
 7 https://bugs.webkit.org/show_bug.cgi?id=35472
 8
 9 Add tests for radio buttons in a form element, and merge an existing
 10 radio button test to ValidityState-valueMissing-radio.html.
 11
 12 * fast/forms/ValidityState-valueMissing-007-expected.txt: Removed.
 13 * fast/forms/ValidityState-valueMissing-007.html: Removed.
 14 * fast/forms/ValidityState-valueMissing-radio-expected.txt: Added.
 15 * fast/forms/ValidityState-valueMissing-radio.html: Added.
 16 * fast/forms/script-tests/ValidityState-valueMissing-radio.js: Added.
 17
1182010-02-26 Zhenyao Mo <zmo@google.com>
219
320 Reviewed by David Levin.

LayoutTests/fast/forms/ValidityState-valueMissing-007-expected.txt

1 There are two radio buttons below with the same name, only one is required (which means the whole group is required), the other one is checked and leads the required attribute to be satisfied: no missing value.
2 
3 
4 SUCCESS

LayoutTests/fast/forms/ValidityState-valueMissing-007.html

1 <html>
2 <head>
3 <title>required and valueMissing on radio</title>
4 <script language="JavaScript" type="text/javascript">
5  function log(message) {
6  document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7  }
8 
9  function test() {
10  if (window.layoutTestController)
11  layoutTestController.dumpAsText();
12 
13  v = document.getElementsByName("victim");
14 
15  log(!v[0].validity.valueMissing ? "SUCCESS" : "FAILURE");
16  }
17 </script>
18 </head>
19 <body onload="test()">
20 <p>There are two radio buttons below with the same name, only one is required (which means the whole group is required), the other one is checked and leads the required attribute to be satisfied: no missing value.</p>
21 <input name="victim" type="radio" required/>
22 <input name="victim" type="radio" checked/>
23 <hr>
24 <ol id="console"></ol>
25 </body>
26 </html>

LayoutTests/fast/forms/ValidityState-valueMissing-radio-expected.txt

 1valueMissing tests for radio buttons
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6Without form element
 7No checked button:
 8PASS inputs[0].validity.valueMissing is true
 9PASS inputs[1].validity.valueMissing is false
 10The first button has been checked:
 11PASS inputs[0].validity.valueMissing is false
 12PASS inputs[1].validity.valueMissing is false
 13The second button has been checked:
 14PASS inputs[0].validity.valueMissing is false
 15PASS inputs[1].validity.valueMissing is false
 16With form element
 17No checked button:
 18PASS inputs[0].validity.valueMissing is true
 19PASS inputs[1].validity.valueMissing is false
 20The first button has been checked:
 21PASS inputs[0].validity.valueMissing is false
 22PASS inputs[1].validity.valueMissing is false
 23The second button has been checked:
 24PASS inputs[0].validity.valueMissing is false
 25PASS inputs[1].validity.valueMissing is false
 26PASS successfullyParsed is true
 27
 28TEST COMPLETE
 29

LayoutTests/fast/forms/ValidityState-valueMissing-radio.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3<head>
 4<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
 5<script src="../../fast/js/resources/js-test-pre.js"></script>
 6</head>
 7<body>
 8<p id="description"></p>
 9<div id="console"></div>
 10<script src="script-tests/ValidityState-valueMissing-radio.js"></script>
 11<script src="../../fast/js/resources/js-test-post.js"></script>
 12</body>
 13</html>

LayoutTests/fast/forms/script-tests/ValidityState-valueMissing-radio.js

 1description('valueMissing tests for radio buttons');
 2
 3var parent = document.createElement('div');
 4document.body.appendChild(parent);
 5
 6debug('Without form element');
 7parent.innerHTML = '<input name=victim type=radio required/>'
 8 + '<input name=victim type=radio/>';
 9var inputs = document.getElementsByName('victim');
 10debug('No checked button:');
 11shouldBeTrue('inputs[0].validity.valueMissing');
 12// The following result should be false because the element does not have
 13// "required". It conforms to HTML5, and this behavior has no practical
 14// problems.
 15shouldBeFalse('inputs[1].validity.valueMissing');
 16debug('The first button has been checked:');
 17inputs[0].checked = true;
 18shouldBeFalse('inputs[0].validity.valueMissing');
 19shouldBeFalse('inputs[1].validity.valueMissing');
 20debug('The second button has been checked:');
 21inputs[1].checked = true;
 22shouldBeFalse('inputs[0].validity.valueMissing');
 23shouldBeFalse('inputs[1].validity.valueMissing');
 24
 25debug('With form element');
 26parent.innerHTML = '<form>'
 27 + '<input name=victim type=radio required/>'
 28 + '<input name=victim type=radio/>'
 29 + '</form>';
 30inputs = document.getElementsByName('victim');
 31debug('No checked button:');
 32shouldBeTrue('inputs[0].validity.valueMissing');
 33// The following result should be false.
 34shouldBeFalse('inputs[1].validity.valueMissing');
 35debug('The first button has been checked:');
 36inputs[0].checked = true;
 37shouldBeFalse('inputs[0].validity.valueMissing');
 38shouldBeFalse('inputs[1].validity.valueMissing');
 39debug('The second button has been checked:');
 40inputs[1].checked = true;
 41shouldBeFalse('inputs[0].validity.valueMissing');
 42shouldBeFalse('inputs[1].validity.valueMissing');
 43
 44var successfullyParsed = true;

WebCore/ChangeLog

 12010-02-27 Kent Tamura <tkent@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Fix a bug that validity.valueMissing for a radio button with required
 6 in a form element always returns true.
 7 https://bugs.webkit.org/show_bug.cgi?id=35472
 8
 9 Test: fast/forms/ValidityState-valueMissing-radio.html
 10
 11 * html/HTMLInputElement.cpp:
 12 (WebCore::checkedRadioButtons): Move the location to be used by valueMissing().
 13 (WebCore::HTMLInputElement::valueMissing):
 14 Use checkedRadioButtons() instead of document()->checkedRadioButtons().
 15
1162010-02-26 Zhenyao Mo <zmo@google.com>
217
318 Reviewed by David Levin.

WebCore/html/HTMLInputElement.cpp

@@bool HTMLInputElement::autoComplete() const
163163 return true;
164164}
165165
 166static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
 167{
 168 if (HTMLFormElement* form = element->form())
 169 return form->checkedRadioButtons();
 170 return element->document()->checkedRadioButtons();
 171}
 172
166173bool HTMLInputElement::valueMissing() const
167174{
168175 if (!isRequiredFormControl() || readOnly() || disabled())

@@bool HTMLInputElement::valueMissing() const
187194 case CHECKBOX:
188195 return !checked();
189196 case RADIO:
190  return !document()->checkedRadioButtons().checkedButtonForGroup(name());
 197 return !checkedRadioButtons(this).checkedButtonForGroup(name());
191198 case COLOR:
192199 return false;
193200 case BUTTON:

@@void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
678685 applyStep(-n, ec);
679686}
680687
681 static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
682 {
683  if (HTMLFormElement* form = element->form())
684  return form->checkedRadioButtons();
685 
686  return element->document()->checkedRadioButtons();
687 }
688 
689688bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const
690689{
691690 // If text fields can be focused, then they should always be keyboard focusable