summaryrefslogtreecommitdiffstats
path: root/widget/tests/test_ime_state_on_focus_move_in_parent.html
blob: fd74d61c7ed54c613e5d876ed31e156dacadb27b (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
<!doctype html>
<html style="ime-mode: disabled;">
<head>
  <meta charset="utf-8">
  <title>Test for IME state management on focus move in parent process</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>
  <script src="file_test_ime_state_on_focus_move.js"></script>
  <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body style="ime-mode: disabled;">
<div style="ime-mode: disabled;"></div>
<script>
"use strict";

/* import-globals-from file_ime_state_test_helper.js */
/* import-globals-from file_test_ime_state_on_focus_move.js */

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  const tipWrapper = new TIPWrapper(window);
  ok(tipWrapper.isAvailable(), "TextInputProcessor should've been initialized");

  const container = document.querySelector("div");
  async function runIMEStateOnFocusMoveTests(aDescription) {
    {
      const runnerAndChecker = new IMEStateWhenNoActiveElementTester(aDescription);
      const expectedData = await runnerAndChecker.run(document);
      runnerAndChecker.check(expectedData);
    }
    for (let index = 0; index < IMEStateOnFocusMoveTester.numberOfTests; ++index) {
      const runnerAndChecker = new IMEStateOnFocusMoveTester(aDescription, index);
      const expectedData = await runnerAndChecker.prepareToRun(container);
      runnerAndChecker.prepareToCheck(expectedData, tipWrapper);
      await runnerAndChecker.run();
      runnerAndChecker.check(expectedData);
      if (runnerAndChecker.canTestOpenCloseState(expectedData)) {
        for (const defaultOpenState of [false, true]) {
          const expectedOpenStateData =
            await runnerAndChecker.prepareToRunOpenCloseTest(container);
          runnerAndChecker.prepareToCheckOpenCloseTest(
            defaultOpenState,
            expectedOpenStateData
          );
          await runnerAndChecker.runOpenCloseTest();
          runnerAndChecker.checkOpenCloseTest(expectedOpenStateData);
        }
      }
      runnerAndChecker.destroy();
    }
  }

  // test for normal contents.
  await runIMEStateOnFocusMoveTests("in non-editable container");

  // test for contentEditable="true"
  container.setAttribute("contenteditable", "true");
  await runIMEStateOnFocusMoveTests("in div[contenteditable]");

  // test for contentEditable="false"
  container.setAttribute("contenteditable", "false");
  await runIMEStateOnFocusMoveTests('in div[contenteditable="false"]');

  // test for removing contentEditable
  container.setAttribute("contenteditable", "true");
  container.focus();
  await new Promise(resolve =>
    requestAnimationFrame(
      () => requestAnimationFrame(resolve)
    )
  );
  container.removeAttribute("contenteditable");
  await runIMEStateOnFocusMoveTests("after removing contenteditable from the container");

  // test designMode
  document.designMode = "on";
  await runIMEStateOnFocusMoveTests('in designMode="on"');
  document.designMode = "off";
  await runIMEStateOnFocusMoveTests('in designMode="off"');

  tipWrapper.destroy();

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