4 <title>Accessible caret move events testing
</title>
6 <link rel=
"stylesheet" type=
"text/css"
7 href=
"chrome://mochikit/content/tests/SimpleTest/test.css" />
9 <script type=
"application/javascript"
10 src=
"chrome://mochikit/content/MochiKit/packed.js"></script>
11 <script type=
"application/javascript"
12 src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
13 <script type=
"application/javascript"
14 src=
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
16 <script type=
"application/javascript"
17 src=
"chrome://mochikit/content/a11y/accessible/common.js"></script>
19 <script type=
"application/javascript">
23 function synthAction(aNodeOrID, aCaretOffset)
25 this.DOMNode = getNode(aNodeOrID);
27 this.check = function synthAction_check(aEvent)
29 is(aEvent.QueryInterface(nsIAccessibleCaretMoveEvent).caretOffset,
31 "Wrong caret offset for " + aNodeOrID);
34 this.getID = function synthAction_getID() { return aNodeOrID +
" action"; }
36 this.caretOffset = aCaretOffset;
42 function synthClick(aNodeOrID, aCaretOffset,
43 aExtraNodeOrID, aExtraCaretOffset)
45 this.__proto__ = new synthAction(aNodeOrID, aCaretOffset);
47 this.extraNode = getNode(aExtraNodeOrID);
48 this.extraCaretOffset = aExtraCaretOffset;
50 this.invoke = function synthClick_invoke()
52 // Scroll the node into view, otherwise synth click may fail.
53 this.DOMNode.scrollIntoView(true);
55 synthesizeMouse(this.DOMNode,
1,
1, {});
58 this.check = function synthFocus_check(aEvent)
60 this.__proto__.check(aEvent);
63 var acc = getAccessible(this.extraNode, [nsIAccessibleText]);
64 is(acc.caretOffset, this.extraCaretOffset,
65 "Wrong caret offset for " + aExtraNodeOrID);
69 this.getID = function synthFocus_getID() { return aNodeOrID +
" click"; }
75 function synthKey(aNodeOrID, aCaretOffset, aKey, aArgs)
77 this.__proto__ = new synthAction(aNodeOrID, aCaretOffset);
79 this.invoke = function synthKey_invoke()
81 synthesizeKey(this.mKey, this.mArgs);
85 this.mArgs = aArgs ? aArgs : {};
88 function synthTabTest(aNodeOrID, aCaretOffset, aBackTab)
90 this.__proto__ = new synthKey(aNodeOrID, aCaretOffset,
91 "VK_TAB", {shiftKey: aBackTab});
93 this.getID = function synthTabTest_getID() { return aNodeOrID +
" tab"; }
96 function synthDownKey(aNodeOrID, aCaretOffset)
98 this.__proto__ = new synthKey(aNodeOrID, aCaretOffset,
"VK_DOWN");
100 this.getID = function synthDownKey_getID()
102 return aNodeOrID +
" key down";
106 function synthRightKey(aNodeOrID, aCaretOffset)
108 this.__proto__ = new synthKey(aNodeOrID, aCaretOffset,
"VK_RIGHT");
110 this.getID = function synthRightKey_getID()
112 return aNodeOrID +
" key right";
119 function synthFocus(aNodeOrID, aCaretOffset)
121 this.__proto__ = new synthAction(aNodeOrID, aCaretOffset);
123 this.invoke = function synthFocus_invoke()
125 this.DOMNode.focus();
128 this.getID = function synthFocus_getID() { return aNodeOrID +
" focus"; }
132 * Select all invoker.
134 function synthSelectAll(aNodeOrID, aCaretOffset)
136 this.__proto__ = new synthAction(aNodeOrID, aCaretOffset);
138 this.invoke = function synthSelectAll_invoke()
140 if (this.DOMNode instanceof Components.interfaces.nsIDOMHTMLInputElement)
141 this.DOMNode.select();
143 window.getSelection().selectAllChildren(this.DOMNode);
146 this.getID = function synthSelectAll_getID()
148 return aNodeOrID +
" selectall";
157 function testCaretOffset(aAccOrElmOrID, aCaretOffset)
159 var acc = getAccessible(aAccOrElmOrID, [nsIAccessibleText]);
160 is(acc.caretOffset, aCaretOffset,
161 "Wrong caret offset for " + aAccOrElmOrID);
166 // test no focused accessibles
167 testCaretOffset(
"textbox", -
1);
168 testCaretOffset(
"textarea", -
1);
169 testCaretOffset(
"p", -
1);
171 // test caret move events and caret offsets
172 gQueue = new eventQueue(nsIAccessibleEvent.EVENT_TEXT_CARET_MOVED);
175 gQueue.push(new synthFocus(id,
5));
176 gQueue.push(new synthSelectAll(id,
5));
177 gQueue.push(new synthClick(id,
0));
178 gQueue.push(new synthRightKey(id,
1));
181 gQueue.push(new synthClick(id,
0));
182 gQueue.push(new synthRightKey(id,
1));
183 gQueue.push(new synthDownKey(id,
12));
186 gQueue.push(new synthClick(id,
0));
187 gQueue.push(new synthRightKey(id,
1));
188 gQueue.push(new synthDownKey(id,
6));
190 gQueue.push(new synthClick(
"p1_in_div",
0,
"p2_in_div", -
1));
192 gQueue.push(new synthTabTest(
"p",
0, true));
193 gQueue.push(new synthTabTest(
"textarea",
12, true));
194 gQueue.push(new synthTabTest(
"p",
0, false));
196 gQueue.invoke(); // Will call SimpleTest.finish();
199 SimpleTest.waitForExplicitFinish();
200 addLoadEvent(doTests);
207 href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=454377"
208 title=
"Accessible caret move events testing">
212 <div id=
"content" style=
"display: none"></div>
216 <input id=
"textbox" value=
"hello"/>
217 <textarea id=
"textarea">text
<br>text
</textarea>
218 <p id=
"p" contentEditable=
"true"><span>text
</span><br/>text
</p>
219 <div id=
"div" contentEditable=
"true"><p id=
"p1_in_div">text
</p><p id=
"p2_in_div">text
</p></div>