2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
3 <?xml-stylesheet href=
"chrome://mochikit/content/tests/SimpleTest/test.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">
15 <textarea id=
"textarea"></textarea>
21 <script class=
"testbody" type=
"application/javascript">
24 SimpleTest.waitForExplicitFinish();
25 SimpleTest.waitForFocus(runTests, window);
27 var textarea = document.getElementById(
"textarea");
34 is(Services.focus.focusedElement, textarea,
"we're deactive");
35 if (Services.focus.focusedElement != textarea) {
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");
50 SimpleTest.waitForFocus(startTests, otherWindow);
57 isnot(Services.focus.focusedWindow, window,
"we're not deactive");
58 if (Services.focus.focusedWindow == window) {
64 var keydownHandled, keypressHandled, keyupHandled, compositionstartHandled,
65 compositionendHandled, compositionupdateHandled, inputHandled;
69 keydownHandled = false;
70 keypressHandled = false;
72 compositionstartHandled = false;
73 compositionendHandled = false;
74 compositionupdateHandled = 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") {
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") {
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()
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);
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'");
141 synthesizeKey(
"a", {type:
"keyup"});
142 checkKeyEvents(false, false, true, false,
"a keyup");
144 synthesizeKey(
"KEY_Backspace");
145 checkKeyEvents(true, true, true, true,
"KEY_Backspace key events");
146 is(textarea.value,
"",
"textarea value isn't empty");
150 // input first character
151 synthesizeCompositionChange(
153 {
"string":
"\u3089",
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");
167 ok(queryText.succeeded,
"query text event failed");
168 if (!queryText.succeeded) {
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) {
177 ok(querySelectedText.succeeded,
"query selected text event failed");
178 if (!querySelectedText.succeeded) {
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");
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");
194 ok(queryText.succeeded,
"query text event failed after commit");
195 if (!queryText.succeeded) {
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) {
205 ok(querySelectedText.succeeded,
206 "query selected text event failed after commit");
207 if (!querySelectedText.succeeded) {
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");
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);