accessible/tests/mochitest/pivot/test_virtualcursor_text.html
author Eitan Isaacson <eitan@monotonous.org>
Mon, 10 Dec 2018 03:30:21 +0000
changeset 449682 3386ff76878d83496bb822d09115c77472808b53
parent 426850 d55a38a6be534e3f7c62da7ae36a65d8526ea0a4
child 469642 0d9b9b96f5475adbed73922da696aeff7cbbaed3
permissions -rw-r--r--
Bug 1511955 - Don't traverse into children without hypertext interfaces. r=Jamie This prevents an infinite loop where we go into a child only to find the nearest hypertext accessible being its parent. Differential Revision: https://phabricator.services.mozilla.com/D13998

<!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="../text.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 doc = currentTabDocument();
      var docAcc = getAccessible(doc, [nsIAccessibleDocument]);

      gQueue = new eventQueue();

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

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("paragraph-1"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 4],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [4, 5],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", CHAR_BOUNDARY, [3, 4],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [5, 7],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 3],
                  getAccessible(doc.getElementById("p1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [10, 14],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 3],
                  getAccessible(doc.getElementById("p1-link-1"), nsIAccessibleText)));
      // set user input to false, and see if it works
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [5, 7],
                  getAccessible(doc.getElementById("paragraph-1"), nsIAccessibleText)),
                  false);

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("section-1"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 9],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      // set user input to false, and see if it works
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [10, 14],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText),
                  false));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [4, 6],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [7, 12],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 2],
                  getAccessible(doc.getElementById("s1-link-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [15, 19],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [20, 28],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 5],
                  getAccessible(doc.getElementById("section-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [6, 10],
                  getAccessible(doc.getElementById("section-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 5],
                  getAccessible(doc.getElementById("section-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [20, 28],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [15, 19],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 2],
                  getAccessible(doc.getElementById("s1-link-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [7, 12],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [4, 6],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [10, 14],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 9],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));

      gQueue.push(new setVCRangeInvoker(docAcc, getAccessible(doc.getElementById("s1-link-1")), [0, 0]));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", CHAR_BOUNDARY, [1, 2],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", CHAR_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [1, 2],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [1, 2],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [2, 9],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [10, 14],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [3, 4],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", CHAR_BOUNDARY, [13, 14],
                  getAccessible(doc.getElementById("s1-link-1"), nsIAccessibleText)));

      gQueue.push(new setVCRangeInvoker(docAcc, getAccessible(doc.getElementById("section-2")), [0, 0]));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", CHAR_BOUNDARY, [27, 28],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("section-2"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("paragraph-2"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 12],
                  getAccessible(doc.getElementById("paragraph-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("cell-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 8],
                  getAccessible(doc.getElementById("cell-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 3],
                  getAccessible(doc.getElementById("cell-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [4, 11],
                  getAccessible(doc.getElementById("cell-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 6],
                  getAccessible(doc.getElementById("cell-4"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [7, 13],
                  getAccessible(doc.getElementById("cell-4"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("section-3"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("section-3"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("section-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [7, 13],
                  getAccessible(doc.getElementById("cell-4"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 6],
                  getAccessible(doc.getElementById("cell-4"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [4, 11],
                  getAccessible(doc.getElementById("cell-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 3],
                  getAccessible(doc.getElementById("cell-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 8],
                  getAccessible(doc.getElementById("cell-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("cell-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 12],
                  getAccessible(doc.getElementById("paragraph-2"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("paragraph-3"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 8],
                  getAccessible(doc.getElementById("p3-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [8, 10],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 4],
                  getAccessible(doc.getElementById("p3-link-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 5],
                  getAccessible(doc.getElementById("p3-link-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [14, 20],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 5],
                  getAccessible(doc.getElementById("p3-link-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 4],
                  getAccessible(doc.getElementById("p3-link-2"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [8, 10],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 8],
                  getAccessible(doc.getElementById("p3-link-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("s1-link-2"))));
      // Start with the pivot in the middle of the paragraph
      gQueue.push(new setVCPosInvoker(docAcc, "moveNext", ObjectTraversalRule, " will traverse"));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [15, 19],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [0, 2],
                  getAccessible(doc.getElementById("s1-link-2"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("end-block"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 4],
                  getAccessible(doc.getElementById("end-block"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, null, false));
      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("start-block"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 4],
                  getAccessible(doc.getElementById("start-block"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, null, false));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, null, false));
      gQueue.push(new setVCRangeInvoker(docAcc, getAccessible(doc.getElementById("start-block")), [0, 0]));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, null, false));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                  getAccessible(doc.getElementById("paragraph-3")).firstChild));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [0, 7],
                  getAccessible(doc.getElementById("paragraph-3"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                  getAccessible(doc.getElementById("s1-link-1")).nextSibling));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [4, 6],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                  getAccessible(doc.getElementById("paragraph-4")).firstChild.nextSibling));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", WORD_BOUNDARY, [6, 10],
                  getAccessible(doc.getElementById("paragraph-4"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("section-1"))));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [20, 28],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("section-1")).lastChild));
      gQueue.push(new setVCTextInvoker(docAcc, "movePreviousByText", WORD_BOUNDARY, [20, 28],
                  getAccessible(doc.getElementById("section-1"), nsIAccessibleText)));

      gQueue.push(new setVCPosInvoker(docAcc, null, null,
                                      getAccessible(doc.getElementById("image-desc-link"))));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [0, 1],
                  getAccessible(doc.getElementById("image-desc-link"), nsIAccessibleText)));
      gQueue.push(new setVCTextInvoker(docAcc, "moveNextByText", CHAR_BOUNDARY, [1, 2],
                  getAccessible(doc.getElementById("image-desc-link"), nsIAccessibleText)));

      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_text.html");
    });
  </script>
</head>
<body id="body">

  <a target="_blank"
     title="Support Movement By Granularity"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=886076">Mozilla Bug 886076</a>
  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>
</body>
</html>