Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / tests / test_input_events_on_deactive_window.xhtml
blobd54699f76c9ddd83ec6b7fc14c5dc52bc50192d8
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
4 type="text/css"?>
5 <window title="Testing composition, text and query content events"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
9 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
11 <body xmlns="http://www.w3.org/1999/xhtml">
12 <div id="content" style="display: none">
13 </div>
14 <p id="display">
15 <textarea id="textarea"></textarea>
16 </p>
17 <pre id="test">
18 </pre>
19 </body>
21 <script class="testbody" type="application/javascript">
22 <![CDATA[
24 SimpleTest.waitForExplicitFinish();
25 SimpleTest.waitForFocus(runTests, window);
27 var textarea = document.getElementById("textarea");
28 var otherWindow;
29 var timer;
31 function runTests()
33 textarea.focus();
34 is(Services.focus.focusedElement, textarea, "we're deactive");
35 if (Services.focus.focusedElement != textarea) {
36 SimpleTest.finish();
37 return;
40 otherWindow =
41 window.browsingContext.topChromeWindow.open(
42 "./file_input_events_on_deactive_window.html", "_blank",
43 "chrome,width=100,height=100");
44 ok(otherWindow, "failed to open other window");
45 if (!otherWindow) {
46 SimpleTest.finish();
47 return;
50 SimpleTest.waitForFocus(startTests, otherWindow);
51 otherWindow.focus();
54 function startTests()
56 clearTimeout(timer);
57 isnot(Services.focus.focusedWindow, window, "we're not deactive");
58 if (Services.focus.focusedWindow == window) {
59 otherWindow.close();
60 SimpleTest.finish();
61 return;
64 var keydownHandled, keypressHandled, keyupHandled, compositionstartHandled,
65 compositionendHandled, compositionupdateHandled, inputHandled;
67 function clear()
69 keydownHandled = false;
70 keypressHandled = false;
71 keyupHandled = false;
72 compositionstartHandled = false;
73 compositionendHandled = false;
74 compositionupdateHandled = false;
75 inputHandled = false;
78 function onEvent(aEvent)
80 if (aEvent.type == "keydown") {
81 keydownHandled = true;
82 } else if (aEvent.type == "keypress") {
83 keypressHandled = true;
84 } else if (aEvent.type == "keyup") {
85 keyupHandled = true;
86 } else if (aEvent.type == "compositionstart") {
87 compositionstartHandled = true;
88 } else if (aEvent.type == "compositionend") {
89 compositionendHandled = true;
90 } else if (aEvent.type == "compositionupdate") {
91 compositionupdateHandled = true;
92 } else if (aEvent.type == "input") {
93 inputHandled = true;
94 } else {
95 ok(false, "handled unknown event: " + aEvent.type);
99 textarea.addEventListener("keydown", onEvent);
100 textarea.addEventListener("keypress", onEvent);
101 textarea.addEventListener("keyup", onEvent);
102 textarea.addEventListener("compositionstart", onEvent);
103 textarea.addEventListener("compositionend", onEvent);
104 textarea.addEventListener("compositionupdate", onEvent);
105 textarea.addEventListener("input", onEvent);
107 startTestsInternal();
109 function startTestsInternal()
111 // key events
112 function checkKeyEvents(aKeydown, aKeypress, aKeyup, aInput, aDescription)
114 is(keydownHandled, aKeydown,
115 "keydown event is (not) handled: " + aDescription);
116 is(keypressHandled, aKeypress,
117 "keypress event is (not) handled: " + aDescription);
118 is(keyupHandled, aKeyup,
119 "keyup event is (not) handled: " + aDescription);
120 is(inputHandled, aInput,
121 "input event is (not) handled: " + aDescription);
124 function checkCompositionEvents(aStart, aEnd, aUpdate, aInput, aDescription)
126 is(compositionstartHandled, aStart,
127 "compositionstart event is (not) handled: " + aDescription);
128 is(compositionendHandled, aEnd,
129 "compositionend event is (not) handled: " + aDescription);
130 is(compositionupdateHandled, aUpdate,
131 "compositionupdate event is (not) handled: " + aDescription);
132 is(inputHandled, aInput,
133 "input event is (not) handled: " + aDescription);
136 clear();
137 synthesizeKey("a", {type: "keydown"});
138 checkKeyEvents(true, true, false, true, "a keydown and a keypress");
139 is(textarea.value, "a", "textarea value isn't 'a'");
140 clear();
141 synthesizeKey("a", {type: "keyup"});
142 checkKeyEvents(false, false, true, false, "a keyup");
143 clear();
144 synthesizeKey("KEY_Backspace");
145 checkKeyEvents(true, true, true, true, "KEY_Backspace key events");
146 is(textarea.value, "", "textarea value isn't empty");
148 // IME events
149 clear();
150 // input first character
151 synthesizeCompositionChange(
152 { "composition":
153 { "string": "\u3089",
154 "clauses":
156 { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
159 "caret": { "start": 1, "length": 0 }
161 checkCompositionEvents(true, false, true, true, "starting to compose");
162 var queryText = synthesizeQueryTextContent(0, 100);
163 ok(queryText, "query text event result is null");
164 if (!queryText) {
165 return;
167 ok(queryText.succeeded, "query text event failed");
168 if (!queryText.succeeded) {
169 return;
171 is(queryText.text, "\u3089", "composing text is incorrect");
172 var querySelectedText = synthesizeQuerySelectedText();
173 ok(querySelectedText, "query selected text event result is null");
174 if (!querySelectedText) {
175 return;
177 ok(querySelectedText.succeeded, "query selected text event failed");
178 if (!querySelectedText.succeeded) {
179 return;
181 is(querySelectedText.offset, 1,
182 "query selected text event returns wrong offset");
183 is(querySelectedText.text, "",
184 "query selected text event returns wrong selected text");
185 clear();
186 // commit composition
187 synthesizeComposition({ type: "compositioncommitasis" });
188 checkCompositionEvents(false, true, false, true, "commit composition as is");
189 queryText = synthesizeQueryTextContent(0, 100);
190 ok(queryText, "query text event result is null after commit");
191 if (!queryText) {
192 return;
194 ok(queryText.succeeded, "query text event failed after commit");
195 if (!queryText.succeeded) {
196 return;
198 is(queryText.text, "\u3089", "composing text is incorrect after commit");
199 querySelectedText = synthesizeQuerySelectedText();
200 ok(querySelectedText,
201 "query selected text event result is null after commit");
202 if (!querySelectedText) {
203 return;
205 ok(querySelectedText.succeeded,
206 "query selected text event failed after commit");
207 if (!querySelectedText.succeeded) {
208 return;
210 is(querySelectedText.offset, 1,
211 "query selected text event returns wrong offset after commit");
212 is(querySelectedText.text, "",
213 "query selected text event returns wrong selected text after commit");
214 clear();
217 textarea.removeEventListener("keydown", onEvent);
218 textarea.removeEventListener("keypress", onEvent);
219 textarea.removeEventListener("keyup", onEvent);
220 textarea.removeEventListener("compositionstart", onEvent);
221 textarea.removeEventListener("compositionupdate", onEvent);
222 textarea.removeEventListener("compositionend", onEvent);
223 textarea.removeEventListener("input", onEvent);
225 otherWindow.close();
227 SimpleTest.finish();
232 </script>
233 </window>