summaryrefslogtreecommitdiffstats
path: root/widget/tests/test_ime_state_others_in_parent.html
blob: e6ae0ab2727ef4fc1f654d610d0b86cb9a1d7af2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
  <title>Test for IME state controlling in some special cases</title>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  <script src="file_ime_state_test_helper.js"></script>
  <link rel="stylesheet" type="text/css"
          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<div id="display"></div>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
<script>
SimpleTest.waitForExplicitFinish();

var gUtils = window.windowUtils;
var gFM = Services.focus;

function runEditorFlagChangeTests() {
  var description = "runEditorFlagChangeTests: ";

  var container = document.getElementById("display");

  // Reset selection from previous tests.
  window.getSelection().collapse(container, 0);

  // the editor has focus directly.
  container.setAttribute("contenteditable", "true");
  container.focus();

  is(gFM.focusedElement, container,
     description + "The editor doesn't get focus");
  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
     description + "IME isn't enabled on HTML editor");
  const kIMEStateChangeFlags = Ci.nsIEditor.eEditorReadonlyMask;
  const kFlagsNotAllowedWithHTMLEditor =
    Ci.nsIEditor.eEditorPasswordMask |
    Ci.nsIEditor.eEditorSingleLineMask;
  var editor = window.docShell.editor;
  var flags = editor.flags;

  // input characters
  synthesizeCompositionChange(
    { "composition":
      { "string": "\u3078\u3093\u3057\u3093",
        "clauses":
        [
          { "length": 4, "attr": COMPOSITION_ATTR_RAW_CLAUSE },
        ],
      },
      "caret": { "start": 4, "length": 0 },
    });

  editor.flags &= ~kIMEStateChangeFlags;
  ok(editor.composing,
     description + "#1 IME composition was committed unexpectedly");
  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
     description + "#1 IME isn't enabled on HTML editor");

  editor.flags |=
      ~(kIMEStateChangeFlags | kFlagsNotAllowedWithHTMLEditor);
  ok(editor.composing,
     description + "#2 IME composition was committed unexpectedly");
  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
     description + "#2 IME isn't enabled on HTML editor");

  editor.flags = flags;
  ok(editor.composing,
     description + "#3 IME composition was committed unexpectedly");
  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
     description + "#3 IME isn't enabled on HTML editor");

  // cancel the composition
  synthesizeComposition({ type: "compositioncommit", data: "" });

  container.removeAttribute("contenteditable");
}

function runEditableSubframeTests() {
  window.open("window_imestate_iframes.html", "_blank",
              "width=600,height=600");
}

function runTestPasswordFieldOnDialog() {
  if (document.activeElement) {
    document.activeElement.blur();
  }

  var dialog;

  function WindowObserver() {
    Services.obs.addObserver(this, "domwindowopened");
  }

  WindowObserver.prototype = {
    QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),

    observe(subject, topic, data) {
      if (topic === "domwindowopened") {
        ok(true, "dialog window is created");
        dialog = subject;
        dialog.addEventListener("load", onPasswordDialogLoad);
      }
    },
  };

  var observer = new WindowObserver();
  var arg1 = {}, arg2 = {};
  Services.prompt.promptPassword(window, "title", "text", arg1, "msg", arg2);

  ok(true, "password dialog was closed");

  Services.obs.removeObserver(observer, "domwindowopened");

  var passwordField;

  function onPasswordDialogLoad() {
    ok(true, "onPasswordDialogLoad is called");
    dialog.removeEventListener("load", onPasswordDialogLoad);
    passwordField = dialog.document.getElementById("password1Textbox");
    passwordField.addEventListener("focus", onPasswordFieldFocus);
  }

  function onPasswordFieldFocus() {
    ok(true, "onPasswordFieldFocus is called");
    passwordField.removeEventListener("focus", onPasswordFieldFocus);
    var utils = dialog.windowUtils;
    is(utils.IMEStatus, utils.IME_STATUS_PASSWORD,
       "IME isn't disabled on a password field of password dialog");
    synthesizeKey("VK_ESCAPE", { }, dialog);
  }
}

SimpleTest.waitForFocus(async () => {
  // test whether the IME state and composition are not changed unexpectedly
  runEditorFlagChangeTests();

  // test password field on dialog
  // XXX temporary disable against failure
  // runTestPasswordFieldOnDialog();

  // This will call onFinish(), so, this test must be the last.
  // TODO: Make this test run with remote content too.
  runEditableSubframeTests();
});

function onFinish() {
  SimpleTest.finish();
}
</script>
</body>
</html>