Mochitest for bug 421066 - Implement all nsIAccessibleHyperLink methods for XUL:label elements that are used as links. ( r=surkov
authormarco.zehe@googlemail.com
Mon, 14 Apr 2008 06:29:44 -0700
changeset 14304 557c1be31f8e60f62076b4a4a5eb21260a82d074
parent 14303 738ae74eaf0933930a4b5d9d0d3463359af64824
child 14305 e423b453cf77556fb0d02952b54253d0abba56e8
push id11
push userbsmedberg@mozilla.com
push dateTue, 15 Apr 2008 18:11:53 +0000
treeherdermozilla-central@40e4b99f0dea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs421066
milestone1.9pre
Mochitest for bug 421066 - Implement all nsIAccessibleHyperLink methods for XUL:label elements that are used as links. ( r=surkov
accessible/tests/mochitest/Makefile.in
accessible/tests/mochitest/test_nsIAccessibleHyperLink.xul
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -51,14 +51,15 @@ include $(topsrcdir)/config/rules.mk
 		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 \
+		test_nsIAccessibleHyperLink.xul \
 		test_nsIAccessibleHyperText.html \
 		test_bug428479.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/test_nsIAccessibleHyperLink.xul
@@ -0,0 +1,153 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="test for nsIAccessibleHyperLink interface on XUL:label elements">
+
+  <script type="application/javascript" 
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
+  <script type="application/javascript">
+  <![CDATA[
+    function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI,
+                      aStartIndex, aEndIndex, aValid, aSelectedBefore,
+                      aSelectedAfter)
+    {
+      is(aAcc.finalRole, aRole, "Wrong role for ID " + aID + "!");
+      is(aAcc.anchorCount, aAnchorCount, "Wrong number of anchors for ID " 
+         + aID + "!");
+      is(aAcc.getAnchor(0).name, aAnchorName, "Wrong name for ID " + aID + "!");
+      is(aAcc.getURI(0).spec, aURI, "URI wrong for ID " + aID + "!");
+      is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID " + aID 
+         + "!");
+      is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID " + aID + "!");
+      is(aAcc.valid, aValid, "Wrong valid state for ID " + aID + "!");      
+
+      is(aAcc.selected, aSelectedBefore, "Wrong focused state before focus for "
+         + aID + "!");
+      document.getElementById(aID).focus();
+      is(aAcc.selected, aSelectedAfter, "Wrong selected state after focus for "
+         + aID + "!");
+    }
+
+    function testStates(aID, aAcc, aState, aExtraState, aUndesiredState)
+    {
+      var state = {}, extraState = {};
+      aAcc.getFinalState(state, extraState);
+      is(state.value & aState, aState, "Wrong state bits for " + aID + "!");
+      is(extraState.value & aExtraState, aExtraState, 
+         "Wrong extra state bits for " + aID + "!");
+      if (aUndesiredState != 0)
+        is(state.value & aUndesiredState, 0, "Bits should not be set for "
+           + aID +"!");
+    }
+
+    function doTest()
+    {
+      // Mapping needed state flags for easier handling.
+      const state_focusable = 
+            Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
+      const state_focused = 
+            Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
+      const state_selectable = 
+            Components.interfaces.nsIAccessibleStates.STATE_SELECTABLE;
+      const state_linked = 
+            Components.interfaces.nsIAccessibleStates.STATE_LINKED;
+      const state_traversed = 
+            Components.interfaces.nsIAccessibleStates.STATE_TRAVERSED;
+
+      const ext_state_multi_line = 
+            Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
+      const ext_state_horizontal = 
+            Components.interfaces.nsIAccessibleStates.EXT_STATE_HORIZONTAL;
+      const ext_state_required = 
+            Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
+      const ext_state_invalid = 
+            Components.interfaces.nsIAccessibleStates.STATE_INVALID;
+
+      // Activate accessibility.
+      var accRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
+                    getService(Components.interfaces.nsIAccessibleRetrieval);
+
+      var linkLabelElement = document.getElementById("linkedLabel");
+      var linkedLabelAcc;
+      try {
+        linkedLabelAcc = accRetrieval.getAccessibleFor(linkLabelElement).
+          QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkedLabelAcc, "no interface for linked label!");
+      }
+      testThis("linkedLabel", linkedLabelAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
+               "Mozilla Foundation home", "http://www.mozilla.org/", 1, 2, true,
+               false, true);
+      testStates("linkedLabel", linkedLabelAcc,
+                 (state_focusable | state_linked),
+                 (ext_state_horizontal), 0);
+
+      var labelElementWithValue = document.getElementById("linkLabelWithValue");
+      var labelWithValueAcc;
+      try {
+        labelWithValueAcc = accRetrieval.getAccessibleFor(labelElementWithValue).
+          QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(labelWithValueAcc, "no interface for linked label with value!");
+      }
+      testThis("linkLabelWithValue", labelWithValueAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
+               "Mozilla Foundation", "http://www.mozilla.org/", 2, 3, true,
+               false, true);
+      testStates("linkLabelWithValue", labelWithValueAcc,
+                 (state_focusable | state_linked),
+                 (ext_state_horizontal), 0);
+
+      var NormalLabelElement = document.getElementById("normalLabel");
+      var normalLabelAcc;
+      try {
+        normalLabelAcc = accRetrieval.getAccessibleFor(NormalLabelElement);
+      } catch(e) {
+      }
+      ok(normalLabelAcc, "no accessible for normalLabel!");
+      if (normalLabelAcc) {
+        is(normalLabelAcc.finalRole,
+           Components.interfaces.nsIAccessibleRole.ROLE_LABEL,
+           "Wrong role!");
+        is(normalLabelAcc.name, "This label should not be a link",
+           "Wrong name for normal label!");
+    
+        var stateNormal = {}, extraStateNormal = {};
+        normalLabelAcc.getFinalState(stateNormal, extraStateNormal);
+        undesiredState = (state_focusable | state_linked);
+        is(stateNormal.value & undesiredState, 0, "Wrong state bits for normal label!");
+      }
+
+      SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addLoadEvent(doTest);
+  ]]>
+  </script>
+
+  <body xmlns="http://www.w3.org/1999/xhtml">
+    <a target="_blank"
+       href="https://bugzilla.mozilla.org/show_bug.cgi?id=421066"
+       title="Implement Mochitests for the nsIAccessibleHyperLink interface on XUL:label elements">
+      Mozilla Bug 421066
+    </a>
+    <p id="display"></p>
+    <div id="content" style="display: none">
+    </div>
+    <pre id="test">
+    </pre>
+  </body>
+
+  <label id="linkedLabel" class="text-link" href="http://www.mozilla.org/">
+    Mozilla Foundation home</label>
+  <label id="linkLabelWithValue" value="Mozilla Foundation" class="text-link"
+   href="http://www.mozilla.org/" />
+  <label id="normalLabel" value="This label should not be a link" />
+</window>