summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/undo-insertparagraph-after-moving-split-nodes.html
blob: c61bcff9e9246abdabe8f5acc97b489db5708b94 (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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Undo after splitting nodes are moved</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>
</head>
<body>
<div contenteditable></div>
<script>
"use strict";

document.execCommand("defaultParagraphSeparator", false, "div");
const utils =
  new EditorTestUtils(document.querySelector("div[contenteditable]"));

promise_test(async t => {
  utils.setupEditingHost(
    `<div>abc[]def</div><p>ghi</p>`
  );
  await utils.sendEnterKey();
  const right = utils.editingHost.querySelector("div + div");
  utils.editingHost.appendChild(right);
  // Now, the right <div> is after the <p>, it should be merged into the left
  // <div> before the <p>.
  document.execCommand("undo");
  assert_in_array(
    utils.editingHost.innerHTML,
    [
      "<div>abcdef</div><p>ghi</p>",
      "<div>abcdef<br></div><p>ghi</p>",
    ]
  );
}, "Undo insertParagraph after moving right node to different paragraph");

promise_test(async () => {
  utils.setupEditingHost(
    `<p>abc</p><div>def[]ghi</div>`
  );
  await utils.sendEnterKey();
  const left = utils.editingHost.querySelector("div");
  utils.editingHost.insertBefore(left, document.querySelector("p"));
  // Now, the left <div> is before the <p>, the right <div> after the <p> should
  // be merged into it.
  document.execCommand("undo");
  assert_in_array(
    utils.editingHost.innerHTML,
    [
      "<div>defghi</div><p>abc</p>",
      "<div>defghi<br></div><p>abc</p>",
    ]
  );
}, "Undo insertParagraph after moving left node to different paragraph");

promise_test(async () => {
  utils.setupEditingHost(
    `<div>abc[]def</div>`
  );
  await utils.sendEnterKey();
  const left = utils.editingHost.querySelector("div");
  const right = utils.editingHost.querySelector("div + div");
  left.insertBefore(right, left.firstChild);
  // Now, the right <div> is a child node of the left <div>.  Its children
  // should be merged to the parent.
  document.execCommand("undo");
  assert_in_array(
    utils.editingHost.innerHTML,
    [
      "<div>abcdef</div>",
      "<div>abcdef<br></div>",
    ]
  );
}, "Undo insertParagraph after moving right node into the left node");

promise_test(async () => {
  utils.setupEditingHost(
    `<div>abc[]def</div>`
  );
  await utils.sendEnterKey();
  const left = utils.editingHost.querySelector("div");
  const right = utils.editingHost.querySelector("div + div");
  right.appendChild(left);
  // Now, the right <div> is parent of the left <div>.  The children of the
  // right <div> should be moved to the child left <div>, but the right <div>
  // should be removed.
  document.execCommand("undo");
  assert_equals(
    utils.editingHost.innerHTML,
    "",
    "The right <div> containing the left <div> should be removed"
  );
  assert_in_array(
    left.innerHTML,
    [
      "abcdef",
      "abcdef<br>",
    ],
    "The left <div> which was disconnected should have the original content"
  );
}, "Undo insertParagraph after moving left node into the right node");
</script>
</body>
</html>