mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 03:05:34 +00:00
765e91b497
Editor creates a `<br>` element when it's root element is empty. Then, it's stored by `TextEditRules::mBogusNode` and used for checking whether the editor is empty quickly. However, this `<br>` element has `mozeditorbogusnode` attribute whose value is `true`. However, adding or removing the attribute is not cheap and web apps can refer such illegal attribute. Therefore, this patch makes `HTMLBRElement` take a specific flag whether it's a bogus node or not. However, this means that this hacky thing will be exposed outside editor module. For making what is the bogus node clearer, this patch calls the such `<br>` elements as "padding `<br>` element for empty editor". So, this patch also includes a lot of renaming methods and variables, and modifying related comments. Differential Revision: https://phabricator.services.mozilla.com/D39857 --HG-- extra : moz-landing-system : lando
91 lines
3.3 KiB
HTML
91 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi=id=1368544
|
|
-->
|
|
<html>
|
|
<head>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1368544">Mozilla Bug 1368544</a>
|
|
<div id="display"></div>
|
|
<textarea id=textarea></textarea>
|
|
<pre id="test">
|
|
</pre>
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
SimpleTest.waitForExplicitFinish();
|
|
SimpleTest.waitForFocus(() => {
|
|
let textarea = document.getElementById("textarea");
|
|
let editor = SpecialPowers.wrap(textarea).editor;
|
|
|
|
let spellChecker = SpecialPowers.Cu.createSpellChecker();
|
|
spellChecker.InitSpellChecker(editor, false);
|
|
|
|
textarea.focus();
|
|
|
|
SpecialPowers.Cu.import(
|
|
"resource://testing-common/AsyncSpellCheckTestHelper.jsm")
|
|
.onSpellCheck(textarea, () => {
|
|
spellChecker.UpdateCurrentDictionary(() => {
|
|
textarea.value = "ABC";
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child nodes");
|
|
sendString("D");
|
|
is(textarea.value, "ABCD", "D is last character");
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child nodes");
|
|
textarea.value = "";
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child node even if value is empty");
|
|
|
|
sendString("AAA");
|
|
synthesizeKey("KEY_Backspace", {repeat: 3});
|
|
is(textarea.value, "", "value is empty");
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child node even if value is empty");
|
|
|
|
textarea.value = "ABC";
|
|
SpecialPowers.wrap(textarea).setUserInput("");
|
|
is(textarea.value, "",
|
|
"textarea should become empty when setUserInput() is called with empty string");
|
|
if (navigator.appVersion.includes("Android")) {
|
|
todo(!editor.rootElement.hasChildNodes(),
|
|
"editor of textarea should have no children when user input emulation set the value to empty");
|
|
if (editor.rootElement.childNodes.length > 0) {
|
|
is(editor.rootElement.childNodes.length, 1, "There should be only one <br> node");
|
|
is(editor.rootElement.firstChild.tagName.toLowerCase(), "br", "The node should be a <br> element node");
|
|
ok(!SpecialPowers.wrap(editor.rootElement.firstChild).isPaddingForEmptyEditor,
|
|
"The <br> should not be a padding <br> element");
|
|
}
|
|
} else {
|
|
ok(!editor.rootElement.hasChildNodes(),
|
|
"editor of textarea should have no children when user input emulation set the value to empty");
|
|
}
|
|
textarea.value = "ABC";
|
|
synthesizeKey("KEY_Enter", {repeat: 2});
|
|
textarea.value = "";
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child node even if value is empty");
|
|
|
|
sendString("AAA");
|
|
is(textarea.value, "AAA", "value is AAA");
|
|
textarea.addEventListener("keyup", (e) => {
|
|
if (e.key == "Enter") {
|
|
textarea.value = "";
|
|
ok(editor.rootElement.hasChildNodes(),
|
|
"editor of textarea has child node even if value is empty");
|
|
SimpleTest.finish();
|
|
}
|
|
});
|
|
|
|
synthesizeKey("KEY_Enter");
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|