Bug 418368 - Create tests for NSIAccessibleHyperlink interface p=marco.zehe@googlemail.com (Marco Zehe) r=surkov.alexander@gmail.com (Alexander Surkov) a=beltzner@mozilla.com (Mike Beltzner)
authorgijskruitbosch@gmail.com
Sun, 30 Mar 2008 08:33:01 -0700
changeset 13749 da735f02c916aeb5df1993e1ae8323c4a855aa92
parent 13748 37adf38cdd21b76bddf10b4289fa93863a88f29e
child 13750 72ea7c9c473d124ffc9bf670c10af9e0e958be85
push idunknown
push userunknown
push dateunknown
reviewerssurkov, beltzner
bugs418368
milestone1.9pre
Bug 418368 - Create tests for NSIAccessibleHyperlink interface p=marco.zehe@googlemail.com (Marco Zehe) r=surkov.alexander@gmail.com (Alexander Surkov) a=beltzner@mozilla.com (Mike Beltzner)
accessible/public/nsIAccessibleHyperLink.idl
accessible/src/atk/nsMaiHyperlink.cpp
accessible/src/base/nsAccessible.cpp
accessible/src/html/nsHTMLImageAccessible.cpp
accessible/src/html/nsHTMLImageAccessible.h
accessible/src/msaa/CAccessibleHyperlink.cpp
accessible/tests/mochitest/Makefile.in
--- a/accessible/public/nsIAccessibleHyperLink.idl
+++ b/accessible/public/nsIAccessibleHyperLink.idl
@@ -38,29 +38,83 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIURI;
 interface nsIAccessible;
 
-[scriptable, uuid(a492c7d6-1dd1-11b2-9bc0-80614884799a)]
+/**
+ * A cross-platform interface that supports hyperlink-specific properties and
+ * methods.  Anchors, image maps, xul:labels with class="text-link" implement this interface.
+ */
+[scriptable, uuid(fe1dd8c0-d50a-4634-b51d-2b20bfb1e231)]
 interface nsIAccessibleHyperLink : nsISupports
 {
-  readonly attribute long anchors;
+  /**
+   * Returns the offset of the link within the parent accessible.
+   */
   readonly attribute long startIndex;
+
+  /**
+   * Returns the end index of the link within the parent accessible.
+   *
+   * @note  The link itself is represented by one embedded character within the
+   * parent text, so the endIndex should be startIndex + 1.
+   */
   readonly attribute long endIndex;
 
-  nsIURI getURI (in long i);
+  /**
+   * Determines whether the link is valid (e. g. points to a valid URL).
+   *
+   * @note  XXX Currently only used with ARIA links, and the author has to
+   * specify that the link is invalid via the aria-invalid="true" attribute.
+   * In all other cases, TRUE is returned.
+   */
+  readonly attribute boolean valid;
+
+  /**
+   * Determines whether the element currently has the focus, e. g. after
+   * returning from the destination page.
+   *
+   * @note  ARIA links can only be focused if they have the tabindex
+   * attribute set.  Also, state_focused should then be set on the accessible
+   * for this link.
+   */
+  readonly attribute boolean selected;
 
-  nsIAccessible getObject (in long i);
+  /**
+   * The numbber of anchors within this Hyperlink. Is normally 1 for anchors.
+   * This anchor is, for example, the visible output of the html:a tag.
+   * With an Image Map, reflects the actual areas within the map.
+   */
+  readonly attribute long anchorsCount;
 
-  boolean isValid ();
-  boolean isSelected ();
+  /**
+   * Returns the URI at the given index.
+   *
+   * @note  ARIA hyperlinks do not have an URI to point to, since clicks are
+   * processed via JavaScript. Therefore this property does not work on ARIA
+   * links.
+   *
+   * @param index  The 0-based index of the URI to be returned.
+   *
+   * @return the nsIURI object containing the specifications for the URI.
+   */
+  nsIURI getURI (in long index);
+
+  /**
+   * Returns a reference to the object at the given index.
+   *
+   * @param index  The 0-based index whose object is to be returned.
+   *
+   * @return the nsIAccessible object at the desired index.
+   */
+  nsIAccessible getAnchor (in long index);
 };
 
 /*
  Assumptions:
 
  The object associated with object or anchor index
  is an nsIAccessible.
  A URI can be represented by the nsIURI interface
--- a/accessible/src/atk/nsMaiHyperlink.cpp
+++ b/accessible/src/atk/nsMaiHyperlink.cpp
@@ -231,17 +231,17 @@ getUriCB(AtkHyperlink *aLink, gint aLink
 
 AtkObject *
 getObjectCB(AtkHyperlink *aLink, gint aLinkIndex)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, nsnull);
 
     nsCOMPtr<nsIAccessible> accObj;
-    accHyperlink->GetObject(aLinkIndex, getter_AddRefs(accObj));
+    accHyperlink->GetAnchor(aLinkIndex, getter_AddRefs(accObj));
     NS_ENSURE_TRUE(accObj, nsnull);
 
     AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(accObj);
     //no need to add ref it, because it is "get" not "ref"
     return atkObj;
 }
 
 gint
@@ -270,28 +270,28 @@ getStartIndexCB(AtkHyperlink *aLink)
 
 gboolean
 isValidCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, FALSE);
 
     PRBool isValid = PR_FALSE;
-    nsresult rv = accHyperlink->IsValid(&isValid);
+    nsresult rv = accHyperlink->GetValid(&isValid);
     return (NS_FAILED(rv)) ? FALSE : static_cast<gboolean>(isValid);
 }
 
 gint
 getAnchorCountCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 count = -1;
-    nsresult rv = accHyperlink->GetAnchors(&count);
+    nsresult rv = accHyperlink->GetAnchorsCount(&count);
     return (NS_FAILED(rv)) ? -1 : static_cast<gint>(count);
 }
 
 // Check if aHyperlink is a valid MaiHyperlink, and return the
 // nsIAccessibleHyperLink related.
 nsIAccessibleHyperLink *
 get_accessible_hyperlink(AtkHyperlink *aHyperlink)
 {
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -3205,71 +3205,88 @@ NS_IMETHODIMP nsAccessible::SelectAllSel
   return NS_OK;
 }
 
 // nsIAccessibleHyperLink
 // Because of new-atk design, any embedded object in text can implement
 // nsIAccessibleHyperLink, which helps determine where it is located
 // within containing text
 
-NS_IMETHODIMP nsAccessible::GetAnchors(PRInt32 *aAnchors)
+// readonly attribute long nsIAccessibleHyperLink::anchorsCount
+NS_IMETHODIMP
+nsAccessible::GetAnchorsCount(PRInt32 *aAnchorsCount)
 {
-  *aAnchors = 1;
+  NS_ENSURE_ARG_POINTER(aAnchorsCount);
+  *aAnchorsCount = 1;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::GetStartIndex(PRInt32 *aStartIndex)
+// readonly attribute long nsIAccessibleHyperLink::startIndex
+NS_IMETHODIMP
+nsAccessible::GetStartIndex(PRInt32 *aStartIndex)
 {
+  NS_ENSURE_ARG_POINTER(aStartIndex);
   *aStartIndex = 0;
   PRInt32 endIndex;
   return GetLinkOffset(aStartIndex, &endIndex);
 }
 
-NS_IMETHODIMP nsAccessible::GetEndIndex(PRInt32 *aEndIndex)
+// readonly attribute long nsIAccessibleHyperLink::endIndex
+NS_IMETHODIMP
+nsAccessible::GetEndIndex(PRInt32 *aEndIndex)
 {
+  NS_ENSURE_ARG_POINTER(aEndIndex);
   *aEndIndex = 0;
   PRInt32 startIndex;
   return GetLinkOffset(&startIndex, aEndIndex);
 }
 
-NS_IMETHODIMP nsAccessible::GetURI(PRInt32 i, nsIURI **aURI)
+NS_IMETHODIMP
+nsAccessible::GetURI(PRInt32 i, nsIURI **aURI)
 {
+  NS_ENSURE_ARG_POINTER(aURI);
   *aURI = nsnull;
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsAccessible::GetObject(PRInt32 aIndex,
+NS_IMETHODIMP
+nsAccessible::GetAnchor(PRInt32 aIndex,
                                       nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
   if (aIndex != 0)
     return NS_ERROR_INVALID_ARG;
 
   *aAccessible = this;
   NS_ADDREF_THIS();
   return NS_OK;
 }
 
-// nsIAccessibleHyperLink::IsValid()
-NS_IMETHODIMP nsAccessible::IsValid(PRBool *aIsValid)
+// readonly attribute boolean nsIAccessibleHyperLink::valid
+NS_IMETHODIMP
+nsAccessible::GetValid(PRBool *aValid)
 {
+  NS_ENSURE_ARG_POINTER(aValid);
   PRUint32 state = State(this);
-  *aIsValid = (0 == (state & nsIAccessibleStates::STATE_INVALID));
+  *aValid = (0 == (state & nsIAccessibleStates::STATE_INVALID));
   // XXX In order to implement this we would need to follow every link
   // Perhaps we can get information about invalid links from the cache
-  // In the mean time authors can use role="link" aria_invalid="true"
+  // In the mean time authors can use role="link" aria-invalid="true"
   // to force it for links they internally know to be invalid
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::IsSelected(PRBool *aIsSelected)
+// readonly attribute boolean nsIAccessibleHyperLink::selected
+NS_IMETHODIMP
+nsAccessible::GetSelected(PRBool *aSelected)
 {
-  *aIsSelected = (gLastFocusedNode == mDOMNode);
+  NS_ENSURE_ARG_POINTER(aSelected);
+  *aSelected = (gLastFocusedNode == mDOMNode);
   return NS_OK;
 }
 
 nsresult nsAccessible::GetLinkOffset(PRInt32* aStartOffset, PRInt32* aEndOffset)
 {
   *aStartOffset = *aEndOffset = 0;
   nsCOMPtr<nsIAccessible> parent(GetParent());
   if (!parent) {
--- a/accessible/src/html/nsHTMLImageAccessible.cpp
+++ b/accessible/src/html/nsHTMLImageAccessible.cpp
@@ -221,22 +221,22 @@ NS_IMETHODIMP nsHTMLImageAccessible::DoA
                      getter_AddRefs(tmp));
   }
   return nsLinkableAccessible::DoAction(index);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessibleHyperLink
 NS_IMETHODIMP
-nsHTMLImageAccessible::GetAnchors(PRInt32 *aAnchors)
+nsHTMLImageAccessible::GetAnchorsCount(PRInt32 *aAnchors)
 {
   NS_ENSURE_ARG_POINTER(aAnchors);
 
   if (!mMapElement)
-    return nsLinkableAccessible::GetAnchors(aAnchors);
+    return nsLinkableAccessible::GetAnchorsCount(aAnchors);
 
   return GetChildCount(aAnchors);
 }
 
 NS_IMETHODIMP
 nsHTMLImageAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
@@ -257,23 +257,23 @@ nsHTMLImageAccessible::GetURI(PRInt32 aI
   nsCOMPtr<nsILink> link(do_QueryInterface(domNode));
   if (link)
     link->GetHrefURI(aURI);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsHTMLImageAccessible::GetObject(PRInt32 aIndex, nsIAccessible **aAccessible)
+nsHTMLImageAccessible::GetAnchor(PRInt32 aIndex, nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
   if (!mMapElement)
-    return nsLinkableAccessible::GetObject(aIndex, aAccessible);
+    return nsLinkableAccessible::GetAnchor(aIndex, aAccessible);
 
   nsCOMPtr<nsIDOMHTMLCollection> mapAreas = GetAreaCollection();
   if (mapAreas) {
     nsCOMPtr<nsIAccessible> accessible;
     accessible = GetAreaAccessible(mapAreas, aIndex);
     if (!accessible)
       return NS_ERROR_INVALID_ARG;
 
--- a/accessible/src/html/nsHTMLImageAccessible.h
+++ b/accessible/src/html/nsHTMLImageAccessible.h
@@ -62,19 +62,19 @@ public:
 
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& _retval); 
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetRole(PRUint32 *_retval);
   NS_IMETHOD DoAction(PRUint8 index);
 
   // nsIAccessibleHyperLink
-  NS_IMETHOD GetAnchors(PRInt32 *aAnchors);
+  NS_IMETHOD GetAnchorsCount(PRInt32 *aAnchors);
   NS_IMETHOD GetURI(PRInt32 aIndex, nsIURI **aURI);
-  NS_IMETHOD GetObject(PRInt32 aIndex, nsIAccessible **aAccessible);
+  NS_IMETHOD GetAnchor(PRInt32 aIndex, nsIAccessible **aAccessible);
 
   // nsPIAccessNode
   NS_IMETHOD Shutdown();
 
   // nsIAccessibleImage
   NS_DECL_NSIACCESSIBLEIMAGE
 
 protected:
--- a/accessible/src/msaa/CAccessibleHyperlink.cpp
+++ b/accessible/src/msaa/CAccessibleHyperlink.cpp
@@ -82,17 +82,17 @@ CAccessibleHyperlink::get_anchor(long aI
 __try {
   VariantInit(aAnchor);
 
   nsCOMPtr<nsIAccessibleHyperLink> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
   nsCOMPtr<nsIAccessible> anchor;
-  nsresult rv = acc->GetObject(aIndex, getter_AddRefs(anchor));
+  nsresult rv = acc->GetAnchor(aIndex, getter_AddRefs(anchor));
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(anchor));
   if (!winAccessNode)
     return E_FAIL;
 
   void *instancePtr = NULL;
@@ -197,17 +197,17 @@ CAccessibleHyperlink::get_valid(boolean 
 __try {
   *aValid = false;
 
   nsCOMPtr<nsIAccessibleHyperLink> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
   PRBool isValid = PR_FALSE;
-  nsresult rv = acc->IsValid(&isValid);
+  nsresult rv = acc->GetValid(&isValid);
   if (NS_FAILED(rv))
     return GetHRESULT(rv);
 
   *aValid = isValid;
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -50,12 +50,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug420863.html \
 		test_groupattrs.xul \
 		test_table_indexes.html \
 		test_nsIAccessibleTable_1.html \
 		test_nsIAccessibleTable_2.html \
 		test_nsIAccessibleTable_3.html \
 		test_nsIAccessibleTable_4.html \
 		test_nsIAccessibleTable_listboxes.xul \
+		test_nsIAccessibleHyperlink.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)