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" />
11 <div id=
"display"></div>
12 <div id=
"content" style=
"display: none"></div>
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");
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
;
44 synthesizeCompositionChange(
46 { "string": "\u3078\u3093\u3057\u3093",
49 { "length": 4, "attr": COMPOSITION_ATTR_RAW_CLAUSE
},
52 "caret": { "start": 4, "length": 0 },
55 editor
.flags
&= ~kIMEStateChangeFlags
;
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");
62 ~(kIMEStateChangeFlags
| kFlagsNotAllowedWithHTMLEditor
);
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");
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();
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");
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");
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() {