Bug 438325 – Link with title and an image that has neither alt nor title doesn't get an accessible name
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 20 Jun 2008 21:19:23 +0800
changeset 15454 f0a83903e4bff3b7238a57cd71a3d177e2579028
parent 15448 f7aaa37e926a6b070f358c83a3917c9e7ecbb2f7
child 15455 a712c266c81b5b6151ef1460f34f09d03cb5f863
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs438325
milestone1.9.1a1pre
Bug 438325 – Link with title and an image that has neither alt nor title doesn't get an accessible name
accessible/src/html/nsHTMLLinkAccessible.cpp
accessible/tests/mochitest/test_nsIAccessibleHyperLink.html
--- a/accessible/src/html/nsHTMLLinkAccessible.cpp
+++ b/accessible/src/html/nsHTMLLinkAccessible.cpp
@@ -61,17 +61,26 @@ NS_IMETHODIMP
 nsHTMLLinkAccessible::GetName(nsAString& aName)
 { 
   aName.Truncate();
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  return AppendFlatStringFromSubtree(content, &aName);
+  nsresult rv = AppendFlatStringFromSubtree(content, &aName);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (aName.IsEmpty()) {
+    // Probably an image without alt or title inside, try to get the name on
+    // the link by usual way.
+    return GetHTMLName(aName, PR_FALSE);
+  }
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLLinkAccessible::GetRole(PRUint32 *aRole)
 {
   NS_ENSURE_ARG_POINTER(aRole);
 
   *aRole = nsIAccessibleRole::ROLE_LINK;
--- a/accessible/tests/mochitest/test_nsIAccessibleHyperLink.html
+++ b/accessible/tests/mochitest/test_nsIAccessibleHyperLink.html
@@ -235,17 +235,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         EmptyHLAcc =
              gAccRetrieval.getAccessibleFor(emptyLinkElement).
              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch (e) {
         ok(EmptyHLAcc, "no interface for empty link!");
       }
       testThis("emptyLink", EmptyHLAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
-               "", true, 98, 99);
+               null, true, 98, 99);
       testStates("emptyLink", EmptyHLAcc,
                  (state_focusable | state_linked),
                  (ext_state_horizontal), (0));
       testAction("emptyLink", EmptyHLAcc, "jump");
 
       //////////////////////////////////////////////////////////////////////////
       // normal hyperlink with embedded span
       var hyperlinkElementWithSpan = document.getElementById("LinkWithSpan");
@@ -327,18 +327,98 @@ https://bugzilla.mozilla.org/show_bug.cg
 
       //////////////////////////////////////////////////////////////////////////
       // Maps to group links (bug 431615).
       var linksMapElement = document.getElementById("linksmap");
       var linksMapAcc;
       try {
         linksMapAcc = gAccRetrieval.getAccessibleFor(linksMapElement);
       } catch(e) { }
-    
+
       ok(linksMapAcc, "no accessible for map grouping links!");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, no name from the subtree (bug 438325).
+      var id = "linkWithTitleNoNameFromSubtree";
+      var linkElement = document.getElementById(id);
+      var linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "Link with title", true, 354, 355);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, name from the subtree - onsreen name
+      // (bug 438325).
+      id = "linkWithTitleNameFromSubtree";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "the name from subtree", true, 403, 404);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, name from the nested html:img (bug 438325).
+      id = "linkWithTitleNameFromImg";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "The title for link", true, 458, 459);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with label, no name from the subtree (bug 438325).
+      id = "linkWithLabelNoNameFromSubtree";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "Link with label and nested image:", true, 462, 463);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      //
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addLoadEvent(doTest);
   </script>
 </head>
 <body>
@@ -368,27 +448,48 @@ https://bugzilla.mozilla.org/show_bug.cg
           coords="0,0,13,14"
           alt="a"
           shape="rect"></area>
   </map>
   <img width="447" id="imgmap"
        height="15"
        usemap="#atoz_map"
        src="http://www.bbc.co.uk/radio4/images/letters.gif"></img>
+
   <br>Empty link:<br>
   <a id="emptyLink" href=""><img src=""></img></a>
+
   <br>Link with embedded span<br>
   <a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a>
+
   <br>Named anchor, must not have "linked" state for it to be exposed correctly:<br>
   <a id="namedAnchor" name="named_anchor">This should never be of state_linked</a>
+
   <br>Link having no attributes, must not have "linked" state:</br>
   <a id="noLink">This should never be of state_linked</a>
+
   <br>Link with registered 'click' event: </br>
   <a id="linkWithClick" onclick="var clicked = true;">This should have state_linked</a>
 
+  <br>Link with title attribute (no name from subtree): </br>
+  <a id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/"
+     title="Link with title"><img src=""/></a>
+
+  <br>Link with title attribute (name from subtree): </br>
+  <a id="linkWithTitleNameFromSubtree" href="http://www.heise.de/"
+     title="Link with title">the name from subtree</a>
+
+  <br>Link with title attribute (name from nested image): </br>
+  <a id="linkWithTitleNameFromImg" href="http://www.heise.de/"
+     title="Link with title"><img src="" alt="The title for link"/></a>
+
+  <br><label for="linkWithLabelNoNameFromSubtree">Link with label and nested image: </label></br>
+  <a id="linkWithLabelNoNameFromSubtree"
+     href="http://www.heise.de/"><img src=""/></a>
+
   <br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass),
    also see the bug 431615:<br>
   <map id="linksmap" title="Site navigation">
     <ul>
       <li><a href="http://mozilla.org">About the project</a></li>
       <li><a href="http://mozilla.org">Sites and sounds</a></li>
     </ul>
   </map>