File: paste-when-nested-with-contenteditable-true.https.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (108 lines) | stat: -rw-r--r-- 4,554 bytes parent folder | download | duplicates (10)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Delete editor in a shadow</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="../include/editor-test-utils.js"></script>
<script>
"use strict";

addEventListener("load", () => {
  promise_test(async () => {
    const div = document.createElement("div");
    div.contentEditable = "true";
    div.innerHTML = "<b>abc</b>";
    document.body.appendChild(div);
    await test_driver.click(div);
    getSelection().selectAllChildren(div);
    await (new EditorTestUtils(div)).sendCopyShortcutKey();
    assert_true(true);
  }, `Initializing the clipboard with <b>abc</b>...`);

  promise_test(async () => {
    const editingHost = document.createElement("div");
    document.body.appendChild(editingHost);
    editingHost.focus();
    const utils = new EditorTestUtils(editingHost);
    let lastBeforeInputEvent;
    editingHost.addEventListener("beforeinput", event => lastBeforeInputEvent = event);
    for (const data of [
      {
        desc: `pasting in contenteditable="plaintext-only" in contenteditable="true"`,
        init: `<div contenteditable="plaintext-only">[ABC]</div>`,
        expected: `<div contenteditable="plaintext-only"><b>abc</b></div>`
      },
      {
        desc: `pasting in contenteditable="plaintext-only" in contenteditable="true" and contenteditable="false"`,
        init: `<div contenteditable="false"><div contenteditable="plaintext-only">[ABC]</div></div>`,
        expected: `<div contenteditable="false"><div contenteditable="plaintext-only">abc</div></div>`,
      },
    ]) {
      promise_test(async t => {
        editingHost.setAttribute("contenteditable", "true");
        utils.setupEditingHost(data.init);
        lastBeforeInputEvent = undefined;
        await utils.sendPasteShortcutKey();
        test(() => {
          assert_equals(
            lastBeforeInputEvent?.inputType,
            "insertFromPaste",
            "beforeinput.inputType should be insertFromPaste"
          );
          assert_equals(lastBeforeInputEvent?.data, null, "beforeinput.data should be null");
          assert_true(
            String(lastBeforeInputEvent?.dataTransfer?.getData("text/html")).includes("<b>abc</b>"),
            "beforeinput.dataTransfer should have the styled text as text/html"
          );
        }, `${t.name}: beforeinput`);
        test(() => {
          assert_equals(editingHost.outerHTML, `<div contenteditable="true">${data.expected}</div>`);
        }, `${t.name}: innerHTML`);
      }, data.desc);
    }
    for (const data of [
      {
        desc: `pasting in contenteditable="true" in contenteditable="plaintext-only"`,
        init: `<div contenteditable="true">[ABC]</div>`,
        expected: `<div contenteditable="true">abc</div>`
      },
      {
        desc: `pasting in contenteditable="true" in contenteditable="plaintext-only" and contenteditable="false"`,
        init: `<div contenteditable="false"><div contenteditable="true">[ABC]</div></div>`,
        expected: `<div contenteditable="false"><div contenteditable="true"><b>abc</b></div></div>`,
      },
    ]) {
      promise_test(async t => {
        editingHost.setAttribute("contenteditable", "plaintext-only");
        utils.setupEditingHost(data.init);
        lastBeforeInputEvent = undefined;
        await utils.sendPasteShortcutKey();
        test(() => {
          assert_equals(
            lastBeforeInputEvent?.inputType,
            "insertFromPaste",
            "beforeinput.inputType should be insertFromPaste"
          );
          assert_equals(lastBeforeInputEvent?.data, null, "beforeinput.data should be null");
          assert_true(
            String(lastBeforeInputEvent?.dataTransfer?.getData("text/html")).includes("<b>abc</b>"),
            "beforeinput.dataTransfer should have the styled text as text/html"
          );
        }, `${t.name}: beforeinput`);
        test(() => {
          assert_equals(editingHost.outerHTML, `<div contenteditable="plaintext-only">${data.expected}</div>`);
        }, `${t.name}: innerHTML`);
      }, data.desc);
    }
  }, "The result should depend on the outermost editing host in the innermost non-editable element whether pasting with or without format");
}, {once: true});
</script>
</head>
<body></body>
</html>