Bug 682790 - ignore implicit label association when it's associated explicitly, r=marcoz
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 30 Sep 2011 13:38:20 +0900
changeset 77902 7134aa74087d
parent 77901 079071eed1d1
child 77903 78dd488fa082
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmarcoz
bugs682790
milestone10.0a1
Bug 682790 - ignore implicit label association when it's associated explicitly, r=marcoz
accessible/src/base/AccIterator.cpp
accessible/tests/mochitest/name/test_general.html
accessible/tests/mochitest/relations/test_general.html
--- a/accessible/src/base/AccIterator.cpp
+++ b/accessible/src/base/AccIterator.cpp
@@ -175,24 +175,27 @@ HTMLLabelIterator::Next()
     return nsnull;
 
   // Go up tree to get a name of ancestor label if there is one (an ancestor
   // <label> implicitly points to us). Don't go up farther than form or
   // document.
   nsAccessible* walkUp = mAcc->Parent();
   while (walkUp && !walkUp->IsDoc()) {
     nsIContent* walkUpElm = walkUp->GetContent();
-    if (walkUpElm->Tag() == nsGkAtoms::label) {
-      mLabelFilter = eSkipAncestorLabel; // prevent infinite loop
-      return walkUp;
+    if (walkUpElm->IsHTML()) {
+      if (walkUpElm->Tag() == nsGkAtoms::label &&
+          !walkUpElm->HasAttr(kNameSpaceID_None, nsGkAtoms::_for)) {
+        mLabelFilter = eSkipAncestorLabel; // prevent infinite loop
+        return walkUp;
+      }
+
+      if (walkUpElm->Tag() == nsGkAtoms::form)
+        break;
     }
 
-    if (walkUpElm->Tag() == nsGkAtoms::form)
-      break;
-
     walkUp = walkUp->Parent();
   }
 
   return nsnull;
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/accessible/tests/mochitest/name/test_general.html
+++ b/accessible/tests/mochitest/name/test_general.html
@@ -165,21 +165,23 @@
 
       testName("textboxinstart", "Two days.");
       testName("textbox1", "days.");
 
       testName("comboinmiddle", "Subscribe to ATOM feed.");
       testName("combo4", "Subscribe to ATOM feed.");
 
       testName("comboinmiddle2", "Play the Haliluya sound when new mail arrives");
-      testName("combo5", "Play the Haliluya sound when new mail arrives");
+      testName("combo5", null); // label isn't used as a name for control
       testName("checkbox", "Play the Haliluya sound when new mail arrives");
+      testName("comboinmiddle3", "Play the Haliluya sound when new mail arrives");
+      testName("combo6", "Play the Haliluya sound when new mail arrives");
 
       testName("comboinend", "This day was sunny");
-      testName("combo6", "This day was");
+      testName("combo7", "This day was");
 
       testName("textboxinend", "This day was sunny");
       testName("textbox2", "This day was");
 
       // placeholder
       testName("ph_password", "a placeholder");
       testName("ph_text", "a placeholder");
       testName("ph_textarea", "a placeholder");
@@ -208,16 +210,21 @@
      title="Clean up our tree walker ">
     Mozilla Bug 530081
   </a><br>
   <a target="_blank"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=604391"
      title="Use placeholder as name if name is otherwise empty">
     Mozilla Bug 604391
   </a>
+  <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=669312"
+     title="Accessible name is duplicated when input has a label associated uisng for/id and is wrapped around the input">
+    Mozilla Bug 669312
+  </a>
   <p id="display"></p>
   <div id="content" style="display: none"></div>
   <pre id="test">
   </pre>
 
   <!-- aria-label, simple label -->
   <span id="btn_simple_aria_label" role="button" aria-label="I am a button"/>
   <br/>
@@ -432,20 +439,28 @@
       <select id="combo5">
         <option>Haliluya</option>
         <option>Hurra</option>
       </select>
       sound when new mail arrives
     </label>
     <input id="checkbox" type="checkbox" />
 
+    <label id="comboinmiddle3" for="combo6">Play the
+      <select id="combo6">
+        <option>Haliluya</option>
+        <option>Hurra</option>
+      </select>
+      sound when new mail arrives
+    </label>
+
     <!-- at the end (without and with whitespaces) -->
     <label id="comboinend">
       This day was
-      <select id="combo6" name="occupation">
+      <select id="combo7" name="occupation">
         <option>sunny</option>
         <option>rainy</option>
       </select></label>
 
     <label id="textboxinend">
       This day was
       <input id="textbox2" value="sunny">
     </label>
--- a/accessible/tests/mochitest/relations/test_general.html
+++ b/accessible/tests/mochitest/relations/test_general.html
@@ -36,16 +36,20 @@
       testRelation("control1_6", RELATION_LABELLED_BY, "label1_6");
       testRelation("control1_7", RELATION_LABELLED_BY, "label1_7");
       testRelation("control1_8", RELATION_LABELLED_BY, "label1_8");
       testRelation("control1_9", RELATION_LABELLED_BY, "label1_9");
       testRelation("control1_10", RELATION_LABELLED_BY, "label1_10");
       testRelation("control1_11", RELATION_LABELLED_BY, "label1_11");
       testRelation("control1_12", RELATION_LABELLED_BY, "label1_12");
 
+      testRelation("label1_13", RELATION_LABEL_FOR, null);
+      testRelation("control1_13", RELATION_LABELLED_BY, null);
+      testRelation("control1_14", RELATION_LABELLED_BY, "label1_14");
+
       // aria-labelledby
       testRelation("label2", RELATION_LABEL_FOR, "checkbox2");
       testRelation("checkbox2", RELATION_LABELLED_BY, "label2");
 
       // aria-labelledby, multiple relations
       testRelation("label3", RELATION_LABEL_FOR, "checkbox3");
       testRelation("label4", RELATION_LABEL_FOR, "checkbox3");
       testRelation("checkbox3", RELATION_LABELLED_BY, ["label3", "label4"]);
@@ -153,16 +157,21 @@
     Mozilla Bug 475298
   </a>
   <a target="_blank"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=558036"
      title="make HTML <output> accessible">
     Mozilla Bug 558036
   </a>
   <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=682790"
+     title="Ignore implicit label association when it's associated explicitly">
+    Mozilla Bug 682790
+  </a>
+  <a target="_blank"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=687393"
      title="HTML select options gets relation from containing label">
     Mozilla Bug 687393
   </a>
   <p id="display"></p>
   <div id="content" style="display: none"></div>
   <pre id="test">
   </pre>
@@ -199,16 +208,23 @@
   </label>
   <label id="label1_11">Label
     <input id="control1_11" type="image">
   </label>
   <label id="label1_12">Label
     <progress id="control1_12"></progress>
   </label>
 
+  <label id="label1_13" for="">Label
+    <input id="control1_13">
+  </label>
+  <label id="label1_14" for="control1_14">Label
+    <input id="control1_14">
+  </label>
+
   <span id="label2">label</span>
   <span role="checkbox" id="checkbox2" aria-labelledby="label2"></span>
 
   <span id="label3">label1</span>
   <span id="label4">label2</span>
   <span role="checkbox" id="checkbox3" aria-labelledby="label3 label4"></span>
 
   <span id="descr1">description</span>