Bug 1649639 - Add WPT and remove unnecessary `MOZ_ASSERT` of `HTMLEditor::ClearStyleAt` r=m_kato

When the method detects the style coming from a parent block, the `MOZ_ASSERT`
checks whether the current mode is "style with CSS" or not because currently,
`HTMLEditor` does not use `<span>` with CSS when the mode is not "style with
CSS".  However, fixing it requires bigger patch, and the change does not match
with the bug's summary.  So, I just remove the `MOZ_ASSERT`, add WPT and filed
bug 1649639 for the root issue.

Differential Revision: https://phabricator.services.mozilla.com/D111067
This commit is contained in:
Masayuki Nakano 2021-04-08 07:49:53 +00:00
Родитель bb36e18bfc
Коммит 0175ca9bc4
3 изменённых файлов: 142 добавлений и 1 удалений

Просмотреть файл

@ -983,7 +983,6 @@ EditResult HTMLEditor::ClearStyleAt(const EditorDOMPoint& aPoint,
// XXX Chrome resets block style and creates `<span>` elements for each // XXX Chrome resets block style and creates `<span>` elements for each
// line in this case. // line in this case.
if (!splitResult.GetNextNode()) { if (!splitResult.GetNextNode()) {
MOZ_ASSERT(IsCSSEnabled());
return EditResult(aPoint); return EditResult(aPoint);
} }

Просмотреть файл

@ -0,0 +1,17 @@
[removing-inline-style-specified-by-parent-block.tentative.html?u]
[Disabling style to text, it's applied to the editing host]
expected: FAIL
[removing-inline-style-specified-by-parent-block.tentative.html?i]
[Disabling style to text, it's applied to the editing host]
expected: FAIL
[Disabling style to text, it's applied to the body]
expected: FAIL
[removing-inline-style-specified-by-parent-block.tentative.html?b]
[Disabling style to text, it's applied to the editing host]
expected: FAIL

Просмотреть файл

@ -0,0 +1,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>