Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WPT and remove unnecessary
MOZ_ASSERT
of `HTMLEditor::ClearStyleAt
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 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1649639 gecko-commit: ca0c86fb52d92389c1d93dae05d011843aef3290 gecko-reviewers: m_kato
- Loading branch information
1 parent
833d390
commit 4928452
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
editing/other/removing-inline-style-specified-by-parent-block.tentative.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |