Bug 343444 - Fix HTMLFormElement::GetNextRadioButton to return only radio buttons. r=jst

This commit is contained in:
Giovanni Sferro 2014-04-26 21:55:00 -04:00
parent aee0f905e9
commit 8c1350195a
3 changed files with 48 additions and 2 deletions

View File

@ -2045,6 +2045,7 @@ HTMLFormElement::GetNextRadioButton(const nsAString& aName,
radioGroup->GetLength(&numRadios);
nsRefPtr<HTMLInputElement> radio;
bool isRadio = false;
do {
if (aPrevious) {
if (--index < 0) {
@ -2058,10 +2059,11 @@ HTMLFormElement::GetNextRadioButton(const nsAString& aName,
if (!radio)
continue;
if (radio->GetType() != NS_FORM_INPUT_RADIO)
isRadio = radio->GetType() == NS_FORM_INPUT_RADIO;
if (!isRadio)
continue;
} while (radio->Disabled() && radio != currentRadio);
} while ((radio->Disabled() && radio != currentRadio) || !isRadio);
NS_IF_ADDREF(*aRadioOut = radio);
return NS_OK;

View File

@ -5,6 +5,7 @@ support-files =
test_input_number_data.js
[test_button_attributes_reflection.html]
[test_input_radio_radiogroup.html]
[test_change_event.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage
[test_datalist_element.html]

View File

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=343444
-->
<head>
<title>Test for Bug 343444</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/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=343444">Mozilla Bug 343444</a>
<p id="display"></p>
<form>
<input type="radio" name="testradio" id="start"></input>
<input type="text" name="testradio"></input>
<input type="text" name="testradio"></input>
<input type="radio" name="testradio"></input>
<input type="text" name="testradio"></input>
<input type="radio" name="testradio"></input>
<input type="text" name="testradio"></input>
<input type="radio" name="testradio"></input>
<input type="radio" name="testradio"></input>
<input type="text" name="testradio"></input>
</form>
<script class="testbody" type="text/javascript">
/** Test for Bug 343444 **/
document.getElementById("start").focus();
var count=0;
while (count < 2) {
sendKey("DOWN");
ok(document.activeElement.type == "radio", "radioGroup should ignore non-radio input fields");
if (document.activeElement.id == "start") {
count++;
}
}
</script>
</pre>
</body>
</html>