summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/pivot/test_virtualcursor.html
blob: 2fb339964afb94e0f4736d16ad90be28b7e2b485 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
  <title>Tests pivot functionality in virtual cursors</title>
  <meta charset="utf-8" />
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
  </script>
  <script type="application/javascript"
          src="chrome://mochikit/content/chrome-harness.js">
  </script>

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

  <script type="application/javascript">
    var gBrowserWnd = null;
    var gQueue = null;

    function doTest()
    {
      var rootAcc = getAccessible(browserDocument(), [nsIAccessibleDocument]);
      ok(rootAcc.virtualCursor,
         "root document does not have virtualCursor");

      var doc = currentTabDocument();
      var docAcc = getAccessible(doc, [nsIAccessibleDocument]);

      // Test that embedded documents have their own virtual cursor.
      is(docAcc.childDocumentCount, 1, "Expecting one child document");
      ok(docAcc.getChildDocumentAt(0).virtualCursor,
         "child document does not have virtualCursor");

      gQueue = new eventQueue();

      gQueue.onFinish = function onFinish()
      {
        closeBrowserWindow();
      }

      queueTraversalSequence(gQueue, docAcc, HeadersTraversalRule, null,
                             ['heading-1-1', 'heading-2-1', 'heading-2-2']);

      queueTraversalSequence(
        gQueue, docAcc, ObjectTraversalRule, null,
        ['Main Title', 'Lorem ipsum ',
         'dolor', ' sit amet. Integer vitae urna leo, id ',
         'semper', ' nulla. ', 'Second Section Title',
         'Sed accumsan luctus lacus, vitae mollis arcu tristique vulputate.',
         'An ', 'embedded', ' document.', 'Hide me', 'Link 1', 'Link 2',
         'Link 3', 'Hello', 'World']);

      // Just a random smoke test to see if our setTextRange works.
      gQueue.push(
        new setVCRangeInvoker(
          docAcc,
          getAccessible(doc.getElementById('paragraph-2'), nsIAccessibleText),
          [2,6]));

      gQueue.push(new removeVCPositionInvoker(
        docAcc, doc.getElementById('hide-me')));

      gQueue.push(new removeVCRootInvoker(
        doc.getElementById('links')));

      var [x, y] = getBounds(getAccessible(doc.getElementById('heading-1-1')));
      gQueue.push(new moveVCCoordInvoker(docAcc, x + 1, y + 1, true,
                                         HeadersTraversalRule, 'heading-1-1'));

      // Already on the point, so we should not get a move event.
      gQueue.push(new moveVCCoordInvoker(docAcc, x + 1, y + 1, true,
                                         HeadersTraversalRule, false));

      // Attempting a coordinate outside any header, should not move.
      gQueue.push(new moveVCCoordInvoker(docAcc, x - 1, y - 1, true,
                                         HeadersTraversalRule, false));

      // Attempting a coordinate outside any header, should move to null
      gQueue.push(new moveVCCoordInvoker(docAcc, x - 1, y - 1, false,
                                         HeadersTraversalRule, null));

      queueTraversalSequence(
        gQueue, docAcc, ObjectTraversalRule,
        getAccessible(doc.getElementById('paragraph-1')),
        ['Lorem ipsum ', 'dolor', ' sit amet. Integer vitae urna leo, id ',
         'semper', ' nulla. ']);

      gQueue.push(new setModalRootInvoker(docAcc, docAcc.parent,
                                          NS_ERROR_INVALID_ARG));

      // Put cursor in an ignored subtree
      // set isFromUserInput to false, just to test..
      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("hidden-link")),
                                      false));
      // Next item shoud be outside of that subtree
      gQueue.push(new setVCPosInvoker(docAcc, "moveNext", ObjectTraversalRule, "An "));

      gQueue.invoke();
    }

    SimpleTest.waitForExplicitFinish();
    addLoadEvent(function () {
      /* We open a new browser because we need to test with a top-level content
         document. */
      openBrowserWindow(
        doTest,
        getRootDirectory(window.location.href) + "doc_virtualcursor.html");
    });
  </script>
</head>
<body id="body">

  <a target="_blank"
     title="Introduce virtual cursor/soft focus functionality to a11y API"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=698823">Mozilla Bug 698823</a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>
</body>
</html>