summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/textselection
diff options
context:
space:
mode:
Diffstat (limited to 'accessible/tests/mochitest/textselection')
-rw-r--r--accessible/tests/mochitest/textselection/a11y.ini6
-rw-r--r--accessible/tests/mochitest/textselection/test_general.html221
-rw-r--r--accessible/tests/mochitest/textselection/test_userinput.html95
3 files changed, 322 insertions, 0 deletions
diff --git a/accessible/tests/mochitest/textselection/a11y.ini b/accessible/tests/mochitest/textselection/a11y.ini
new file mode 100644
index 000000000..6581af56d
--- /dev/null
+++ b/accessible/tests/mochitest/textselection/a11y.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+support-files =
+ !/accessible/tests/mochitest/*.js
+
+[test_general.html]
+[test_userinput.html]
diff --git a/accessible/tests/mochitest/textselection/test_general.html b/accessible/tests/mochitest/textselection/test_general.html
new file mode 100644
index 000000000..87d95eaf0
--- /dev/null
+++ b/accessible/tests/mochitest/textselection/test_general.html
@@ -0,0 +1,221 @@
+<html>
+
+<head>
+ <title>Text selection testing</title>
+
+ <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="../common.js"></script>
+ <script type="application/javascript"
+ src="../events.js"></script>
+
+ <script type="application/javascript">
+ /**
+ * Invokers
+ */
+ function addSelection(aID, aStartOffset, aEndOffset)
+ {
+ this.hyperTextNode = getNode(aID);
+ this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
+
+ this.eventSeq = [
+ new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
+ ];
+
+ this.invoke = function addSelection_invoke()
+ {
+ this.hyperText.addSelection(aStartOffset, aEndOffset);
+ }
+
+ this.finalCheck = function addSelection_finalCheck()
+ {
+ is(this.hyperText.selectionCount, 1,
+ "addSelection: Wrong selection count for " + aID);
+ var startOffset = {}, endOffset = {};
+ this.hyperText.getSelectionBounds(0, startOffset, endOffset);
+
+ is(startOffset.value, aStartOffset,
+ "addSelection: Wrong start offset for " + aID);
+ is(endOffset.value, aEndOffset,
+ "addSelection: Wrong end offset for " + aID);
+ }
+
+ this.getID = function addSelection_getID()
+ {
+ return "nsIAccessibleText::addSelection test for " + aID;
+ }
+ }
+
+ function changeSelection(aID, aStartOffset, aEndOffset)
+ {
+ this.hyperTextNode = getNode(aID);
+ this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
+
+ this.eventSeq = [
+ new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
+ ];
+
+ this.invoke = function changeSelection_invoke()
+ {
+ this.hyperText.setSelectionBounds(0, aStartOffset, aEndOffset);
+ }
+
+ this.finalCheck = function changeSelection_finalCheck()
+ {
+ is(this.hyperText.selectionCount, 1,
+ "setSelectionBounds: Wrong selection count for " + aID);
+ var startOffset = {}, endOffset = {};
+ this.hyperText.getSelectionBounds(0, startOffset, endOffset);
+
+ is(startOffset.value, aStartOffset,
+ "setSelectionBounds: Wrong start offset for " + aID);
+ is(endOffset.value, aEndOffset,
+ "setSelectionBounds: Wrong end offset for " + aID);
+ }
+
+ this.getID = function changeSelection_getID()
+ {
+ return "nsIAccessibleText::setSelectionBounds test for " + aID;
+ }
+ }
+
+ function removeSelection(aID)
+ {
+ this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
+
+ this.eventSeq = [
+ new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, document)
+ ];
+
+ this.invoke = function removeSelection_invoke()
+ {
+ this.hyperText.removeSelection(0);
+ }
+
+ this.finalCheck = function removeSelection_finalCheck()
+ {
+ is(this.hyperText.selectionCount, 0,
+ "removeSelection: Wrong selection count for " + aID);
+ }
+
+ this.getID = function removeSelection_getID()
+ {
+ return "nsIAccessibleText::removeSelection test for " + aID;
+ }
+ }
+
+ function changeDOMSelection(aID, aNodeID1, aNodeOffset1,
+ aNodeID2, aNodeOffset2,
+ aTests)
+ {
+ this.hyperText = getAccessible(aID, [ nsIAccessibleText ]);
+
+ this.eventSeq = [
+ new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID)
+ ];
+
+ this.invoke = function changeDOMSelection_invoke()
+ {
+ var sel = window.getSelection();
+ var range = document.createRange();
+ range.setStart(getNode(aNodeID1), aNodeOffset1);
+ range.setEnd(getNode(aNodeID2), aNodeOffset2);
+ sel.addRange(range);
+ }
+
+ this.finalCheck = function changeDOMSelection_finalCheck()
+ {
+ for (var i = 0; i < aTests.length; i++) {
+ var text = getAccessible(aTests[i][0], nsIAccessibleText);
+ is(text.selectionCount, 1,
+ "setSelectionBounds: Wrong selection count for " + aID);
+ var startOffset = {}, endOffset = {};
+ text.getSelectionBounds(0, startOffset, endOffset);
+
+ is(startOffset.value, aTests[i][1],
+ "setSelectionBounds: Wrong start offset for " + aID);
+ is(endOffset.value, aTests[i][2],
+ "setSelectionBounds: Wrong end offset for " + aID);
+ }
+ }
+
+ this.getID = function changeDOMSelection_getID()
+ {
+ return "DOM selection change for " + aID;
+ }
+ }
+
+ function onfocusEventSeq(aID)
+ {
+ var caretMovedChecker =
+ new invokerChecker(EVENT_TEXT_CARET_MOVED, aID);
+ var selChangedChecker =
+ new invokerChecker(EVENT_TEXT_SELECTION_CHANGED, aID);
+ selChangedChecker.unexpected = true;
+
+ return [ caretMovedChecker, selChangedChecker ];
+ }
+
+ /**
+ * Do tests
+ */
+
+ //gA11yEventDumpToConsole = true; // debug stuff
+
+ var gQueue = null;
+ function doTests()
+ {
+ gQueue = new eventQueue();
+
+ gQueue.push(new addSelection("paragraph", 1, 3));
+ gQueue.push(new changeSelection("paragraph", 2, 4));
+ gQueue.push(new removeSelection("paragraph"));
+
+ gQueue.push(new synthFocus("textbox", onfocusEventSeq("textbox")));
+ gQueue.push(new changeSelection("textbox", 1, 3));
+
+ gQueue.push(new synthFocus("textarea", onfocusEventSeq("textarea")));
+ gQueue.push(new changeSelection("textarea", 1, 3));
+
+ gQueue.push(new changeDOMSelection("c1", "c1_span1", 0, "c1_span2", 0,
+ [["c1", 2, 2]]));
+ gQueue.push(new changeDOMSelection("c2", "c2", 0, "c2_div2", 1,
+ [["c2", 0, 3], ["c2_div2", 0, 2]]));
+ gQueue.invoke(); // Will call SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ addA11yLoadEvent(doTests);
+ </script>
+</head>
+
+<body>
+
+ <a target="_blank"
+ href="https://bugzilla.mozilla.org/show_bug.cgi?id=688126"
+ title="nsIAccessibleText::setSelectionBounds doesn't fire text selection changed events in some cases">
+ Bug 688126
+ </a>
+ <a target="_blank"
+ href="https://bugzilla.mozilla.org/show_bug.cgi?id=688124"
+ title="no text selection changed event when selection is removed">
+ Bug 688124
+ </a>
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test">
+ </pre>
+
+ <p id="paragraph">hello</p>
+ <input id="textbox" value="hello"/>
+ <textarea id="textarea">hello</textarea>
+ <div id="c1">hi<span id="c1_span1"></span><span id="c1_span2"></span>hi</div>
+ <div id="c2">hi<div id="c2_div2">hi</div></div>
+
+</body>
+</html>
diff --git a/accessible/tests/mochitest/textselection/test_userinput.html b/accessible/tests/mochitest/textselection/test_userinput.html
new file mode 100644
index 000000000..1f7127866
--- /dev/null
+++ b/accessible/tests/mochitest/textselection/test_userinput.html
@@ -0,0 +1,95 @@
+<html>
+
+<head>
+ <title>Text selection by user input</title>
+
+ <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/tests/SimpleTest/EventUtils.js"></script>
+
+ <script type="application/javascript"
+ src="../common.js"></script>
+ <script type="application/javascript"
+ src="../role.js"></script>
+ <script type="application/javascript"
+ src="../states.js"></script>
+ <script type="application/javascript"
+ src="../events.js"></script>
+
+ <script type="application/javascript">
+ /**
+ * Invokers
+ */
+ function synthTabAndCheckPrevTabbed(aID, aPrevID)
+ {
+ this.__proto__ = new synthTab(aID, new focusChecker(aID));
+
+ this.finalCheck = function changeSelection_finalCheck()
+ {
+ var prevTabbed = getAccessible(aPrevID, [ nsIAccessibleText ]);
+ is(prevTabbed.selectionCount, 0,
+ "Wrong selection count for " + aPrevID);
+
+ var exceptionCaught = false;
+ try {
+ var startOffsetObj = {}, endOffsetObj = {};
+ prevTabbed.getSelectionBounds(0, startOffsetObj, endOffsetObj);
+ } catch (e) {
+ exceptionCaught = true;
+ }
+
+ ok(exceptionCaught, "No selection was expected for " + aPrevID);
+ }
+
+ this.getID = function changeSelection_getID()
+ {
+ return "Hidden selection check for " + aPrevID;
+ }
+ }
+
+ /**
+ * Do tests
+ */
+
+ //gA11yEventDumpToConsole = true; // debug stuff
+
+ var gQueue = null;
+ function doTests()
+ {
+ gQueue = new eventQueue();
+
+ // Tab to 't2' and then tab out it: it must has no selection.
+ gQueue.push(new synthFocus("t1"));
+ gQueue.push(new synthTab("t2", new focusChecker("t2")));
+ gQueue.push(new synthTabAndCheckPrevTabbed("t3", "t2"));
+
+ gQueue.invoke(); // Will call SimpleTest.finish();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ addA11yLoadEvent(doTests);
+ </script>
+</head>
+
+<body>
+
+ <a target="_blank"
+ href="https://bugzilla.mozilla.org/show_bug.cgi?id=440590"
+ title="Text selection information is not updated when HTML and XUL entries lose focus">
+ Bug 440590
+ </a>
+ <p id="display"></p>
+ <div id="content" style="display: none"></div>
+ <pre id="test">
+ </pre>
+
+ <input type="text" id="t1" maxlength="3" size="3" value="1">
+ <input type="text" id="t2" maxlength="3" size="3" value="1">
+ <input type="text" id="t3" maxlength="3" size="3" value="1">
+
+</body>
+</html>