summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_focused_document_element_becoming_editable.html
blob: 98ddf54f2b775532dbad2bebde4efb9bfee0dc40 (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
154
155
156
157
<!doctype html>
<html>
<head>
<meta chareset="utf-8">
<title>Testing non-editable root becomes editable after getting focus</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<script>
SimpleTest.waitForExplicitFinish();
addEventListener("load", async () => {
  await SimpleTest.promiseFocus(window);

  await (async () => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    await new Promise(resolve => {
      iframe.addEventListener("load", async () => {
        const doc = iframe.contentDocument;
        const win = iframe.contentWindow;
        win.focus();
        doc.documentElement.focus();
        doc.designMode = "on";
        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
        is(
          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
          "IME should be enabled in the design mode document"
        );
        is(
          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
          doc.body,
          "The <body> should be observed by IMEContentObserver in design mode"
        );
        doc.designMode = "off";
        iframe.remove();
        resolve();
      }, {once: true});
      info("Waiting for load of sub-document for testing design mode");
      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    });
  })();

  await (async () => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    await new Promise(resolve => {
      iframe.addEventListener("load", async () => {
        const doc = iframe.contentDocument;
        const win = iframe.contentWindow;
        win.focus()
        doc.documentElement.focus();
        doc.documentElement.contentEditable = "true";
        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
        is(
          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
          "IME should be enabled when the <html> element whose contenteditable is set to true"
        );
        is(
          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
          doc.documentElement,
          "The <html> should be observed by IMEContentObserver when <html contenteditable=\"true\">"
        );
        iframe.remove();
        resolve();
      }, {once: true});
      info("Waiting for load of sub-document for testing <html> element becomes editable");
      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    });
  })();

  await (async () => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    await new Promise(resolve => {
      iframe.addEventListener("load", async () => {
        const doc = iframe.contentDocument;
        const win = iframe.contentWindow;
        win.focus();
        doc.body.focus();
        doc.body.contentEditable = "true";
        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
        if (doc.activeElement === doc.body && doc.hasFocus()) {
          todo_is(
            SpecialPowers.getDOMWindowUtils(win).IMEStatus,
            SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
            "IME should be enabled when the <body> element whose contenteditable is set to true and it has focus"
          );
          todo_is(
            SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
            doc.body,
            "The <body> should be observed by IMEContentObserver when <body contenteditable=\"true\"> and it has focus"
          );
        } else {
          is(
            SpecialPowers.getDOMWindowUtils(win).IMEStatus,
            SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_DISABLED,
            "IME should be disabled when the <body> element whose contenteditable is set to true but it does not have focus"
          );
          is(
            SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
            null,
            "Nobody should be observed by IMEContentObserver when <body contenteditable=\"true\"> but it does not have focus"
          );
        }
        iframe.remove();
        resolve();
      }, {once: true});
      info("Waiting for load of sub-document for testing <body> element becomes editable");
      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    });
  })();

  await (async () => {
    const iframe = document.createElement("iframe");
    document.body.appendChild(iframe);
    await new Promise(resolve => {
      iframe.addEventListener("load", async () => {
        const doc = iframe.contentDocument;
        const win = iframe.contentWindow;
        win.focus();
        const editingHost = doc.createElement("div");
        doc.documentElement.remove();
        doc.appendChild(editingHost);
        editingHost.focus();
        is(
          SpecialPowers.unwrap(SpecialPowers.focusManager.focusedElement),
          editingHost,
          "The <div contenteditable> should have focus because of only child of the Document node"
        );
        editingHost.contentEditable = "true";
        await new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r)));
        is(
          SpecialPowers.getDOMWindowUtils(win).IMEStatus,
          SpecialPowers.Ci.nsIDOMWindowUtils.IME_STATUS_ENABLED,
          "IME should be enabled in the root element"
        );
        is(
          SpecialPowers.unwrap(SpecialPowers.getDOMWindowUtils(win).nodeObservedByIMEContentObserver),
          editingHost,
          "The <div contenteditable> should be observed by IMEContentObserver"
        );
        iframe.srcdoc = "";
        resolve();
      }, {once: true});
      info("Waiting for load of sub-document for testing root <div> element becomes editable");
      iframe.srcdoc = "<!doctype html><html><meta charset=\"utf-8\"></head><body></body></html>";
    });
  })();

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