summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_nested_editor.html
blob: aeb0c115c1db271e362a89efcd4a431756dc510e (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
<!DOCTYPE html>
<html>
<head>
  <title> Test for nested contenteditable elements </title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
  <template id="focus-iframe-contenteditable-in-div">
    <div contenteditable>
      <iframe srcdoc="<div id='focusme' contenteditable></div>"></iframe>
    </div>
  </template>

  <template id="focus-contenteditable-parent-along-with-iframe">
    <div id='focusme' contenteditable></div>
    <iframe srcdoc="<div contenteditable></div>"></iframe>
  </template>

  <template id="focus-iframe-textarea-in-div">
    <div contenteditable>
      <iframe srcdoc="<textarea id='focusme'></textarea>"></iframe>
    </div>
  </template>

  <template id="focus-textarea-parent-along-with-iframe">
    <textarea id='focusme' contenteditable></textarea>
    <iframe srcdoc="<div contenteditable></div>"></iframe>
  </template>
<script>
"use strict";

async function runTest() {
  function findFocusme() {
    return new Promise(r => {
      let focusInParent = document.getElementById("focusme");
      if (focusInParent) {
        r(focusInParent);
        return;
      }
      document.querySelector("iframe").addEventListener("load", function() {
        return r(document.querySelector("iframe").contentDocument.getElementById("focusme"));
      });
    });
  }

  const focusme = await findFocusme();

  focusme.focus();
  synthesizeKey("abc");

  if (focusme.nodeName === "TEXTAREA") {
    is(focusme.value, "abc");
  } else {
    is(focusme.innerHTML, "abc");
  }
}

SimpleTest.waitForExplicitFinish();

SimpleTest.waitForFocus(async () => {
  for (const template of document.querySelectorAll("template")) {
    const content = template.content.cloneNode(true);
    document.body.appendChild(content);

    await runTest();

    document.body.innerHTML = "";
  }

  SimpleTest.finish();
});

</script>
</body>
</html>