summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/removing-inline-style-specified-by-parent-block.tentative.html
blob: c799819a38afb04a25ecad9c34252d94ec32b111 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html>
<meta charset=utf-8>
<meta name="variant" content="?b">
<meta name="variant" content="?i">
<meta name="variant" content="?u">
<title>Test removing inline style which is specified by parent block</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<div contenteditable></div>
</body>
<script>
"use strict";

const tag = location.search.substring(1);
const style = (() => {
  switch (tag) {
    case "b":
      return "font-weight: bold";
    case "i":
      return "font-style: italic";
    case "u":
      return "text-decoration: underline";
  }
})();
const cancelingStyle = (() => {
  switch (tag) {
    case "b":
      return "font-weight: normal";
    case "i":
      return "font-style: normal";
    case "u":
      return "";  // Cannot delete parent underline
  }
})();
const command = (() => {
  switch (tag) {
    case "b":
      return "bold";
    case "i":
      return "italic";
    case "u":
      return "underline";
  }
})();
const editor = document.querySelector("div[contenteditable]");

promise_test(async () => {
  await new Promise(resolve => {
    addEventListener("load", () => {
      assert_true(true, "The document is loaded");
      resolve();
    }, { once: true });
  });
}, "Waiting for load...");

promise_test(async () => {
  document.execCommand("styleWithCSS", false, "false");
  editor.innerHTML = `<p style="${style}">foo</p>`;
  editor.focus();
  getSelection().selectAllChildren(editor.querySelector("p"));
  document.execCommand(command);
  assert_in_array(
    editor.innerHTML,
    [
      "<p>foo</p>",
      "<p>foo<br></p>",
      "<p style=\"\">foo</p>",
      "<p style=\"\">foo<br></p>",
    ]);
}, "Disabling style to text, it's applied to the parent block");

promise_test(async () => {
  document.execCommand("styleWithCSS", false, "false");
  editor.innerHTML = `<p>foo</p>`;
  editor.setAttribute("style", style);
  editor.focus();
  getSelection().selectAllChildren(editor.querySelector("p"));
  document.execCommand(command);
  if (cancelingStyle !== "") {
    assert_in_array(
      editor.innerHTML,
      [
        `<p><span style="${cancelingStyle};">foo</span></p>`,
        `<p><span style="${cancelingStyle};">foo</span><br></p>`,
      ]);
  } else {
    assert_in_array(
      editor.innerHTML,
      [
        "<p>foo</p>",
        "<p>foo<br></p>",
      ]);
  }
  assert_equals(editor.getAttribute("style"), style);
  editor.removeAttribute("style");
}, "Disabling style to text, it's applied to the editing host");

promise_test(async () => {
  document.execCommand("styleWithCSS", false, "false");
  editor.innerHTML = `<p>foo</p>`;
  document.body.setAttribute("style", style);
  editor.focus();
  getSelection().selectAllChildren(editor.querySelector("p"));
  document.execCommand(command);
  if (cancelingStyle !== "") {
    assert_in_array(
      editor.innerHTML,
      [
        `<p><span style="${cancelingStyle};">foo</span></p>`,
        `<p><span style="${cancelingStyle};">foo</span><br></p>`,
      ]);
  } else {
    assert_in_array(
      editor.innerHTML,
      [
        "<p>foo</p>",
        "<p>foo<br></p>",
      ]);
  }
  assert_equals(document.body.getAttribute("style"), style);
  document.body.removeAttribute("style");
}, "Disabling style to text, it's applied to the body");
</script>