summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/hyperlink/test_general.xul
blob: c7b838a15fbebb1ca624204723c82f6fc8a61ef1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?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/tests/SimpleTest/SimpleTest.js" />

  <script type="application/javascript"
          src="../common.js" />
  <script type="application/javascript"
          src="../role.js" />
  <script type="application/javascript"
          src="../states.js" />
  <script type="application/javascript"
          src="../events.js" />

  <script type="application/javascript"
          src="hyperlink.js" />

  <script type="application/javascript">
  <![CDATA[
    function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI,
                      aStartIndex, aEndIndex, aValid)
    {
      testRole(aID, aRole);
      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 + "!");      
    }

    var gQueue = null;
    function doTest()
    {
      var linkedLabelAcc = getAccessible("linkedLabel",
                                         [nsIAccessibleHyperLink]);
      testThis("linkedLabel", linkedLabelAcc, ROLE_LINK, 1,
               "Mozilla Foundation home", "http://www.mozilla.org/", 1, 2,
               true);
      testStates(linkedLabelAcc, STATE_LINKED, 0);

      var labelWithValueAcc = getAccessible("linkLabelWithValue",
                                            [nsIAccessibleHyperLink]);
      testThis("linkLabelWithValue", labelWithValueAcc, ROLE_LINK, 1,
               "Mozilla Foundation", "http://www.mozilla.org/", 2, 3, true,
               false, true);
      testStates(labelWithValueAcc, STATE_LINKED, EXT_STATE_HORIZONTAL);

      var normalLabelAcc = getAccessible("normalLabel");
      testRole(normalLabelAcc, ROLE_LABEL);
      is(normalLabelAcc.name, "This label should not be a link",
         "Wrong name for normal label!");
      testStates(normalLabelAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED));

      //////////////////////////////////////////////////////////////////////////
      // Test focus

      gQueue = new eventQueue();

      gQueue.push(new focusLink("linkedLabel", true));
      gQueue.push(new focusLink("linkLabelWithValue", true));

      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(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>