Bug 343444 - Fix HTMLFormElement::GetNextRadioButton to return only radio buttons. r=jst
authorGiovanni Sferro <agi.novanta@gmail.com>
Sat, 26 Apr 2014 21:55:00 -0400
changeset 180881 c9ef39ad6e7089faae1cbffb22b8b4885ac7e626
parent 180880 ea25086073c8faa8df41a0e1aeb9cb7f8f4e32b6
child 180882 2cf294d2257fa35641677f003701285a758455ab
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjst
bugs343444
milestone31.0a1
Bug 343444 - Fix HTMLFormElement::GetNextRadioButton to return only radio buttons. r=jst
content/html/content/src/HTMLFormElement.cpp
content/html/content/test/forms/mochitest.ini
content/html/content/test/forms/test_input_radio_radiogroup.html
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -2040,33 +2040,35 @@ HTMLFormElement::GetNextRadioButton(cons
   if (index < 0) {
     return NS_ERROR_FAILURE;
   }
 
   uint32_t numRadios;
   radioGroup->GetLength(&numRadios);
   nsRefPtr<HTMLInputElement> radio;
 
+  bool isRadio = false;
   do {
     if (aPrevious) {
       if (--index < 0) {
         index = numRadios -1;
       }
     }
     else if (++index >= (int32_t)numRadios) {
       index = 0;
     }
     radio = HTMLInputElement::FromContentOrNull(radioGroup->Item(index));
     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;
 }
 
 NS_IMETHODIMP
 HTMLFormElement::WalkRadioGroup(const nsAString& aName,
                                 nsIRadioVisitor* aVisitor,
--- a/content/html/content/test/forms/mochitest.ini
+++ b/content/html/content/test/forms/mochitest.ini
@@ -1,15 +1,16 @@
 [DEFAULT]
 support-files =
   save_restore_radio_groups.sjs
   submit_invalid_file.sjs
   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]
 [test_experimental_forms_pref.html]
 [test_form_attribute-1.html]
 [test_form_attribute-2.html]
 [test_form_attribute-3.html]
 [test_form_attribute-4.html]
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/forms/test_input_radio_radiogroup.html
@@ -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>
+