test_virtualcursor.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Tests pivot functionality in virtual cursors</title>
  5. <meta charset="utf-8" />
  6. <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  7. <script type="application/javascript"
  8. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
  9. </script>
  10. <script type="application/javascript"
  11. src="chrome://mochikit/content/chrome-harness.js">
  12. </script>
  13. <script type="application/javascript" src="../common.js"></script>
  14. <script type="application/javascript" src="../browser.js"></script>
  15. <script type="application/javascript" src="../events.js"></script>
  16. <script type="application/javascript" src="../role.js"></script>
  17. <script type="application/javascript" src="../states.js"></script>
  18. <script type="application/javascript" src="../pivot.js"></script>
  19. <script type="application/javascript" src="../layout.js"></script>
  20. <script type="application/javascript">
  21. var gBrowserWnd = null;
  22. var gQueue = null;
  23. function doTest()
  24. {
  25. var rootAcc = getAccessible(browserDocument(), [nsIAccessibleDocument]);
  26. ok(rootAcc.virtualCursor,
  27. "root document does not have virtualCursor");
  28. var doc = currentTabDocument();
  29. var docAcc = getAccessible(doc, [nsIAccessibleDocument]);
  30. // Test that embedded documents have their own virtual cursor.
  31. is(docAcc.childDocumentCount, 1, "Expecting one child document");
  32. ok(docAcc.getChildDocumentAt(0).virtualCursor,
  33. "child document does not have virtualCursor");
  34. gQueue = new eventQueue();
  35. gQueue.onFinish = function onFinish()
  36. {
  37. closeBrowserWindow();
  38. }
  39. queueTraversalSequence(gQueue, docAcc, HeadersTraversalRule, null,
  40. ['heading-1-1', 'heading-2-1', 'heading-2-2']);
  41. queueTraversalSequence(
  42. gQueue, docAcc, ObjectTraversalRule, null,
  43. ['Main Title', 'Lorem ipsum ',
  44. 'dolor', ' sit amet. Integer vitae urna leo, id ',
  45. 'semper', ' nulla. ', 'Second Section Title',
  46. 'Sed accumsan luctus lacus, vitae mollis arcu tristique vulputate.',
  47. 'An ', 'embedded', ' document.', 'Hide me', 'Link 1', 'Link 2',
  48. 'Link 3', 'Hello', 'World']);
  49. // Just a random smoke test to see if our setTextRange works.
  50. gQueue.push(
  51. new setVCRangeInvoker(
  52. docAcc,
  53. getAccessible(doc.getElementById('paragraph-2'), nsIAccessibleText),
  54. [2,6]));
  55. gQueue.push(new removeVCPositionInvoker(
  56. docAcc, doc.getElementById('hide-me')));
  57. gQueue.push(new removeVCRootInvoker(
  58. doc.getElementById('links')));
  59. var [x, y] = getBounds(getAccessible(doc.getElementById('heading-1-1')));
  60. gQueue.push(new moveVCCoordInvoker(docAcc, x + 1, y + 1, true,
  61. HeadersTraversalRule, 'heading-1-1'));
  62. // Already on the point, so we should not get a move event.
  63. gQueue.push(new moveVCCoordInvoker(docAcc, x + 1, y + 1, true,
  64. HeadersTraversalRule, false));
  65. // Attempting a coordinate outside any header, should not move.
  66. gQueue.push(new moveVCCoordInvoker(docAcc, x - 1, y - 1, true,
  67. HeadersTraversalRule, false));
  68. // Attempting a coordinate outside any header, should move to null
  69. gQueue.push(new moveVCCoordInvoker(docAcc, x - 1, y - 1, false,
  70. HeadersTraversalRule, null));
  71. queueTraversalSequence(
  72. gQueue, docAcc, ObjectTraversalRule,
  73. getAccessible(doc.getElementById('paragraph-1')),
  74. ['Lorem ipsum ', 'dolor', ' sit amet. Integer vitae urna leo, id ',
  75. 'semper', ' nulla. ']);
  76. gQueue.push(new setModalRootInvoker(docAcc, docAcc.parent,
  77. NS_ERROR_INVALID_ARG));
  78. // Put cursor in an ignored subtree
  79. // set isFromUserInput to false, just to test..
  80. gQueue.push(new setVCPosInvoker(docAcc, null, null,
  81. getAccessible(doc.getElementById("hidden-link")),
  82. false));
  83. // Next item shoud be outside of that subtree
  84. gQueue.push(new setVCPosInvoker(docAcc, "moveNext", ObjectTraversalRule, "An "));
  85. gQueue.invoke();
  86. }
  87. SimpleTest.waitForExplicitFinish();
  88. addLoadEvent(function () {
  89. /* We open a new browser because we need to test with a top-level content
  90. document. */
  91. openBrowserWindow(
  92. doTest,
  93. getRootDirectory(window.location.href) + "doc_virtualcursor.html");
  94. });
  95. </script>
  96. </head>
  97. <body id="body">
  98. <a target="_blank"
  99. title="Introduce virtual cursor/soft focus functionality to a11y API"
  100. href="https://bugzilla.mozilla.org/show_bug.cgi?id=698823">Mozilla Bug 698823</a>
  101. <p id="display"></p>
  102. <div id="content" style="display: none"></div>
  103. <pre id="test">
  104. </pre>
  105. </body>
  106. </html>