Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / accessible / tests / mochitest / test_events_caretmove.html
blobb5021838039fdcfe0406d22037cafacf3d8206f1
1 <html>
3 <head>
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">
20 /**
21 * Invoker base class.
23 function synthAction(aNodeOrID, aCaretOffset)
25 this.DOMNode = getNode(aNodeOrID);
27 this.check = function synthAction_check(aEvent)
29 is(aEvent.QueryInterface(nsIAccessibleCaretMoveEvent).caretOffset,
30 this.caretOffset,
31 "Wrong caret offset for " + aNodeOrID);
34 this.getID = function synthAction_getID() { return aNodeOrID + " action"; }
36 this.caretOffset = aCaretOffset;
39 /**
40 * Click invoker.
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);
62 if (this.extraNode) {
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"; }
72 /**
73 * Key press invokers.
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);
84 this.mKey = aKey;
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";
117 * Focus invoker.
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();
142 else
143 window.getSelection().selectAllChildren(this.DOMNode);
146 this.getID = function synthSelectAll_getID()
148 return aNodeOrID + " selectall";
153 * Do tests.
155 var gQueue = null;
157 function testCaretOffset(aAccOrElmOrID, aCaretOffset)
159 var acc = getAccessible(aAccOrElmOrID, [nsIAccessibleText]);
160 is(acc.caretOffset, aCaretOffset,
161 "Wrong caret offset for " + aAccOrElmOrID);
164 function doTests()
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);
174 var id = "textbox";
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));
180 id = "textarea";
181 gQueue.push(new synthClick(id, 0));
182 gQueue.push(new synthRightKey(id, 1));
183 gQueue.push(new synthDownKey(id, 12));
185 id = "p";
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);
201 </script>
202 </head>
204 <body>
206 <a target="_blank"
207 href="https://bugzilla.mozilla.org/show_bug.cgi?id=454377"
208 title="Accessible caret move events testing">
209 Mozilla Bug 454377
210 </a>
211 <p id="display"></p>
212 <div id="content" style="display: none"></div>
213 <pre id="test">
214 </pre>
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>
221 </body>
222 </html>