summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/delete-in-last-list-item-when-parent-list-is-editing-host.html
blob: 7d1594393538b201e20b90cd79c5091fc110da07 (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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="timeout" content="long">
<meta name="variant" content="?list=ul&action=Backspace">
<meta name="variant" content="?list=ul&action=Delete">
<meta name="variant" content="?list=ol&action=Backspace">
<meta name="variant" content="?list=ol&action=Delete">
<title>Delete in last list item should not delete parent list if it's editing host</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";

const params = new URLSearchParams(location.search.substring(1));
const backspace = params.get("action") == "Backspace";
const list = params.get("list");

addEventListener("load", () => {
  document.body.innerHTML =`<${list} contenteditable></${list}>`;
  const editingHost = document.querySelector("[contenteditable]");
  const utils = new EditorTestUtils(editingHost);

  function addPromiseTest(aTest) {
    promise_test(async () => {
      editingHost.focus();
      utils.setupEditingHost(aTest.innerHTML);
      await (backspace ? utils.sendBackspaceKey() : utils.sendDeleteKey());
      utils.normalizeStyleAttributeValues();
      if (Array.isArray(aTest.expectedResult)) {
        assert_in_array(editingHost.innerHTML, aTest.expectedResult);
      } else {
        assert_equals(editingHost.innerHTML, aTest.expectedResult);
      }
      assert_equals(
        document.body.childNodes.length,
        1,
        `The editing host should be the only child of <body> (got: "${document.body.innerHTML}")`
      );
      assert_equals(
        document.body.firstChild,
        editingHost,
        `The editing host should be the only child of <body> (got: "${document.body.innerHTML}")`
      );
    }, `${backspace ? "Backspace" : "Delete"} in "<${list} contenteditable>${aTest.innerHTML}</${list}>"`);
  }

  addPromiseTest({
    innerHTML: "<li>{}</li>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  addPromiseTest({
    innerHTML: "<li><ul><li>{}</li></ul></li>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  addPromiseTest({
    innerHTML: "<li><ol><li>{}</li></ol></li>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  // If only sub-list in the editing host list element, the sub-list should be
  // replaced with a list item.
  addPromiseTest({
    innerHTML: "<ul><li>{}</li></ul>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  addPromiseTest({
    innerHTML: "<ol><li>{}</li></ol>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  addPromiseTest({
    innerHTML: "<dl><dt>{}</dt></dl>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
  addPromiseTest({
    innerHTML: "<dl><dd>{}</dd></dl>",
    expectedResult: ["<li></li>", "<li><br></li>"],
  });
}, {once:true});
</script>
</head>
<body></body>
</html>