summaryrefslogtreecommitdiffstats
path: root/widget/tests/browser/browser_test_ime_state_in_contenteditable_on_focus_move_in_remote_content.js
blob: 50b19f0cc300626f88f2e557cd4829e2c7d8eabb (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

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

Services.scriptloader.loadSubScript(
  "chrome://mochitests/content/browser/widget/tests/browser/file_ime_state_test_helper.js",
  this
);
Services.scriptloader.loadSubScript(
  "chrome://mochitests/content/browser/widget/tests/browser/file_test_ime_state_on_focus_move.js",
  this
);
add_task(async function () {
  await BrowserTestUtils.withNewTab(
    "https://example.com/browser/widget/tests/browser/file_ime_state_tests.html",
    async function (browser) {
      const tipWrapper = new TIPWrapper(window);
      ok(
        tipWrapper.isAvailable(),
        "TextInputProcessor should've been initialized"
      );

      // isnot is used in file_test_ime_state_on_focus_move.js, but it's not
      // defined as the alias of Assert.notEqual in browser-chrome tests.
      // Therefore, we need to define it here.
      // eslint-disable-next-line no-unused-vars
      const isnot = Assert.notEqual;

      async function runIMEStateOnFocusMoveTests(aDescription) {
        await (async function test_IMEState_without_focused_element() {
          const checker = new IMEStateWhenNoActiveElementTester(aDescription);
          const expectedData = await SpecialPowers.spawn(
            browser,
            [aDescription],
            description => {
              const runner =
                content.wrappedJSObject.createIMEStateWhenNoActiveElementTester(
                  description
                );
              return runner.run(content.document, content.window);
            }
          );
          checker.check(expectedData);
        })();
        for (
          let index = 0;
          index < IMEStateOnFocusMoveTester.numberOfTests;
          ++index
        ) {
          const checker = new IMEStateOnFocusMoveTester(aDescription, index);
          const expectedData = await SpecialPowers.spawn(
            browser,
            [aDescription, index],
            (description, aIndex) => {
              content.wrappedJSObject.runner =
                content.wrappedJSObject.createIMEStateOnFocusMoveTester(
                  description,
                  aIndex,
                  content.window
                );
              return content.wrappedJSObject.runner.prepareToRun(
                content.document.querySelector("div")
              );
            }
          );
          checker.prepareToCheck(expectedData, tipWrapper);
          await SpecialPowers.spawn(browser, [], () => {
            return content.wrappedJSObject.runner.run();
          });
          checker.check(expectedData);

          if (checker.canTestOpenCloseState(expectedData)) {
            for (const defaultOpenState of [false, true]) {
              const expectedOpenStateData = await SpecialPowers.spawn(
                browser,
                [],
                () => {
                  return content.wrappedJSObject.runner.prepareToRunOpenCloseTest(
                    content.document.querySelector("div")
                  );
                }
              );
              checker.prepareToCheckOpenCloseTest(
                defaultOpenState,
                expectedOpenStateData
              );
              await SpecialPowers.spawn(browser, [], () => {
                return content.wrappedJSObject.runner.runOpenCloseTest();
              });
              checker.checkOpenCloseTest(expectedOpenStateData);
            }
          }
          await SpecialPowers.spawn(browser, [], () => {
            content.wrappedJSObject.runner.destroy();
            content.wrappedJSObject.runner = undefined;
          });
          checker.destroy();
        } // for loop iterating test of IMEStateOnFocusMoveTester
      } // definition of runIMEStateOnFocusMoveTests

      // test for contentEditable="true"
      await SpecialPowers.spawn(browser, [], async () => {
        content.document
          .querySelector("div")
          .setAttribute("contenteditable", "true");
      });
      await runIMEStateOnFocusMoveTests("in div[contenteditable]");

      // test for contentEditable="false"
      await SpecialPowers.spawn(browser, [], async () => {
        content.document
          .querySelector("div")
          .setAttribute("contenteditable", "false");
      });
      await runIMEStateOnFocusMoveTests('in div[contenteditable="false"]');
    }
  );
});