summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/editing-style-of-range-around-void-element-child.tentative.html
blob: 864074c1a64800aca19b186d84659ba18e2551ed (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!doctype html>
<html>
<meta charset=utf-8>
<title>Test toggling style a range which starts from or ends by a child of a void element</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<div contenteditable></div>
<script>
"use strict";

/**
 * The expected behavior is based on Chromium, but this is edge case tests.
 * So, failures of this are not important unless crash.
 */

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 () => {
  editor.innerHTML = "<meta>bar";
  const meta = editor.querySelector("meta");
  const text = document.createTextNode("foo");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(meta.firstChild, 1, meta.nextSibling, 1);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "<meta><b>b</b>ar",
      "<meta><b>b</b>ar<br>",
    ]
  );
}, "Try to apply style from void element child");

promise_test(async () => {
  editor.innerHTML = "foo<meta>";
  const meta = editor.querySelector("meta");
  const text = document.createTextNode("bar");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(editor.firstChild, 1, meta.firstChild, 2);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "f<b>oo</b><meta>",
      "f<b>oo</b><meta><br>",
    ]
  );
}, "Try to apply style by void element child");

promise_test(async () => {
  editor.innerHTML = "<meta>";
  const meta = editor.querySelector("meta");
  const text = document.createTextNode("foo");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(meta.firstChild, 1, meta.firstChild, 2);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "<meta>",
      "<meta><br>",
    ]
  );
}, "Try to apply style in void element child");

promise_test(async () => {
  editor.innerHTML = "<meta>bar";
  const meta = editor.querySelector("meta");
  meta.setAttribute("style", "font-weight: bold");
  const text = document.createTextNode("foo");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(meta.firstChild, 1, meta.nextSibling, 1);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "<meta><b>b</b>ar",
      "<meta><b>b</b>ar<br>",
      "<meta style=\"\"><b>b</b>ar",
      "<meta style=\"\"><b>b</b>ar<br>",
    ]
  );
}, "Try to remove style from void element child");

promise_test(async () => {
  editor.innerHTML = "<meta>bar";
  const meta = editor.querySelector("meta");
  meta.setAttribute("style", "font-weight: bold");
  const text = document.createTextNode("foo");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(meta.firstChild, meta.firstChild.length, meta.nextSibling, 1);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "<meta><b>b</b>ar",
      "<meta><b>b</b>ar<br>",
      "<meta style=\"\"><b>b</b>ar",
      "<meta style=\"\"><b>b</b>ar<br>",
    ]
  );
}, "Try to remove style from end of void element child");

promise_test(async () => {
  editor.innerHTML = "foo<meta>";
  const meta = editor.querySelector("meta");
  const text = document.createTextNode("bar");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(editor.firstChild, 1, meta.firstChild, 2);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "f<b>oo</b><meta>",
      "f<b>oo</b><meta><br>",
      "f<b>oo</b><meta style=\"\">",
      "f<b>oo</b><meta style=\"\"><br>",
    ]
  );
}, "Try to remove style by void element child");

promise_test(async () => {
  editor.innerHTML = "foo<meta>";
  const meta = editor.querySelector("meta");
  const text = document.createTextNode("bar");
  meta.append(text);
  assert_equals(meta.firstChild, text);
  getSelection().setBaseAndExtent(editor.firstChild, 1, meta.firstChild, 0);
  document.execCommand("bold");
  assert_in_array(
    editor.innerHTML,
    [
      "f<b>oo</b><meta>",
      "f<b>oo</b><meta><br>",
      "f<b>oo</b><meta style=\"\">",
      "f<b>oo</b><meta style=\"\"><br>",
    ]
  );
}, "Try to remove style by start of void element child");
</script>
</body>