summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_pasting_in_temporarily_created_div_outside_body.html
blob: 05250be0492e6126ffd680bac4fb790afac8cb65 (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
<!doctype html>
<html>
<head>
<title>Test for paste in temporarily created div element outside the body element</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  const editor = document.querySelector("div[contenteditable]");
  const heading = document.querySelector("h1");
  getSelection().setBaseAndExtent(heading.firstChild, "So".length,
                                  heading.firstChild, "Some te".length);
  try {
    await SimpleTest.promiseClipboardChange(
      "me te", () => synthesizeKey("c", {accelKey: true}));
  } catch (ex) {
    ok(false, `Failed to copy selected text: ${ex}`);
    SimpleTest.finish();
  }
  editor.focus();
  editor.addEventListener("paste", () => {
    const anotherEditor = document.createElement("div");
    anotherEditor.setAttribute("contenteditable", "true");
    document.documentElement.appendChild(anotherEditor);
    anotherEditor.focus();
  }, {once: true});
  synthesizeKey("v", {accelKey: true});
  const tempEditor = document.documentElement.lastChild;
  is(tempEditor.nodeName.toLocaleLowerCase(), "div",
    "Paste event handler should've inserted another editor");
  is(tempEditor.textContent.trim(), "me te");
  SimpleTest.finish();
});
</script>
</head>
<body>
  <h1>Some text</h1>
  <div contenteditable></div>
</body>
</html>