Backed out changeset ce9c917d3e22 (bug 582361) for causing wpt failures on scroll...
[gecko.git] / widget / tests / test_ime_state_others_in_parent.html
blobe6ae0ab2727ef4fc1f654d610d0b86cb9a1d7af2
1 <html>
2 <head>
3 <title>Test for IME state controlling in some special cases</title>
4 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
5 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
6 <script src="file_ime_state_test_helper.js"></script>
7 <link rel="stylesheet" type="text/css"
8 href="chrome://mochikit/content/tests/SimpleTest/test.css" />
9 </head>
10 <body>
11 <div id="display"></div>
12 <div id="content" style="display: none"></div>
13 <pre id="test"></pre>
14 <script>
15 SimpleTest.waitForExplicitFinish();
17 var gUtils = window.windowUtils;
18 var gFM = Services.focus;
20 function runEditorFlagChangeTests() {
21 var description = "runEditorFlagChangeTests: ";
23 var container = document.getElementById("display");
25 // Reset selection from previous tests.
26 window.getSelection().collapse(container, 0);
28 // the editor has focus directly.
29 container.setAttribute("contenteditable", "true");
30 container.focus();
32 is(gFM.focusedElement, container,
33 description + "The editor doesn't get focus");
34 is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
35 description + "IME isn't enabled on HTML editor");
36 const kIMEStateChangeFlags = Ci.nsIEditor.eEditorReadonlyMask;
37 const kFlagsNotAllowedWithHTMLEditor =
38 Ci.nsIEditor.eEditorPasswordMask |
39 Ci.nsIEditor.eEditorSingleLineMask;
40 var editor = window.docShell.editor;
41 var flags = editor.flags;
43 // input characters
44 synthesizeCompositionChange(
45 { "composition":
46 { "string": "\u3078\u3093\u3057\u3093",
47 "clauses":
49 { "length": 4, "attr": COMPOSITION_ATTR_RAW_CLAUSE },
52 "caret": { "start": 4, "length": 0 },
53 });
55 editor.flags &= ~kIMEStateChangeFlags;
56 ok(editor.composing,
57 description + "#1 IME composition was committed unexpectedly");
58 is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
59 description + "#1 IME isn't enabled on HTML editor");
61 editor.flags |=
62 ~(kIMEStateChangeFlags | kFlagsNotAllowedWithHTMLEditor);
63 ok(editor.composing,
64 description + "#2 IME composition was committed unexpectedly");
65 is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
66 description + "#2 IME isn't enabled on HTML editor");
68 editor.flags = flags;
69 ok(editor.composing,
70 description + "#3 IME composition was committed unexpectedly");
71 is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
72 description + "#3 IME isn't enabled on HTML editor");
74 // cancel the composition
75 synthesizeComposition({ type: "compositioncommit", data: "" });
77 container.removeAttribute("contenteditable");
80 function runEditableSubframeTests() {
81 window.open("window_imestate_iframes.html", "_blank",
82 "width=600,height=600");
85 function runTestPasswordFieldOnDialog() {
86 if (document.activeElement) {
87 document.activeElement.blur();
90 var dialog;
92 function WindowObserver() {
93 Services.obs.addObserver(this, "domwindowopened");
96 WindowObserver.prototype = {
97 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
99 observe(subject, topic, data) {
100 if (topic === "domwindowopened") {
101 ok(true, "dialog window is created");
102 dialog = subject;
103 dialog.addEventListener("load", onPasswordDialogLoad);
108 var observer = new WindowObserver();
109 var arg1 = {}, arg2 = {};
110 Services.prompt.promptPassword(window, "title", "text", arg1, "msg", arg2);
112 ok(true, "password dialog was closed");
114 Services.obs.removeObserver(observer, "domwindowopened");
116 var passwordField;
118 function onPasswordDialogLoad() {
119 ok(true, "onPasswordDialogLoad is called");
120 dialog.removeEventListener("load", onPasswordDialogLoad);
121 passwordField = dialog.document.getElementById("password1Textbox");
122 passwordField.addEventListener("focus", onPasswordFieldFocus);
125 function onPasswordFieldFocus() {
126 ok(true, "onPasswordFieldFocus is called");
127 passwordField.removeEventListener("focus", onPasswordFieldFocus);
128 var utils = dialog.windowUtils;
129 is(utils.IMEStatus, utils.IME_STATUS_PASSWORD,
130 "IME isn't disabled on a password field of password dialog");
131 synthesizeKey("VK_ESCAPE", { }, dialog);
135 SimpleTest.waitForFocus(async () => {
136 // test whether the IME state and composition are not changed unexpectedly
137 runEditorFlagChangeTests();
139 // test password field on dialog
140 // XXX temporary disable against failure
141 // runTestPasswordFieldOnDialog();
143 // This will call onFinish(), so, this test must be the last.
144 // TODO: Make this test run with remote content too.
145 runEditableSubframeTests();
148 function onFinish() {
149 SimpleTest.finish();
151 </script>
152 </body>
153 </html>