summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html')
-rw-r--r--testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html72
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html b/testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html
new file mode 100644
index 0000000000..854e6b3dae
--- /dev/null
+++ b/testing/web-platform/tests/editing/other/white-spaces-after-execCommand-insertparagraph.tentative.html
@@ -0,0 +1,72 @@
+<!doctype html>
+<html>
+<head>
+<meta charset=utf-8>
+<title>Testing normalizing white-space sequence after execCommand("insertparagraph", false, "foo")</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+"use strict";
+
+setup({explicit_done: true});
+
+function runTests() {
+ // README:
+ // These tests based on the behavior of Chrome 83. This test does NOT define
+ // nor suggest any standard behavior (actually, some expected results might
+ // look odd), but this test must help you to understand how other browsers
+ // use different logic to normalize white-space sequence.
+
+ document.body.innerHTML = "<div contenteditable></div>";
+ let editor = document.querySelector("div[contenteditable]");
+ editor.focus();
+ let selection = document.getSelection();
+
+ function escape(str) {
+ return typeof(str) === "string" ? str.replace(/\u00A0/ig, "&nbsp;") : "";
+ }
+
+ function generateWhiteSpaces(num, lastIsAlwaysNBSP) {
+ let str = "";
+ for (let i = 0; i < num - 1; i++) {
+ str += i % 2 ? " " : "\u00A0";
+ }
+ str += lastIsAlwaysNBSP || num % 2 ? "\u00A0" : " ";
+ return escape(str);
+ }
+ function getDescriptionForTextNode(textNode) {
+ return selection.focusNode === textNode ?
+ `${escape(textNode.data.slice(0, selection.focusOffset))}[]${escape(textNode.data.slice(selection.focusOffset))}` :
+ escape(textNode);
+ }
+
+ editor.innerHTML = "<div>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</div>";
+ selection.collapse(editor.firstChild.firstChild, 0);
+ test(function () {
+ document.execCommand("insertparagraph", false, "");
+ assert_equals(editor.innerHTML,
+ `<div><br></div><div>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</div>`,
+ "Modified text is wrong");
+ }, `execCommand("insertparagraph", false, "") at "<div>${getDescriptionForTextNode(editor.firstChild.firstChild)}</div>"`);
+
+ for (let i = 1; i <= 10; i++) {
+ editor.innerHTML = "<div>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</div>";
+ selection.collapse(editor.firstChild.firstChild, i);
+ test(function () {
+ let text = editor.firstChild.firstChild.data;
+ document.execCommand("insertparagraph", false, "");
+ assert_equals(editor.innerHTML,
+ `<div>${escape(text.slice(0, i))}</div><div>${escape(text.slice(i))}</div>`,
+ "Modified text is wrong");
+ }, `execCommand("insertparagraph", false, "") at "<div>${getDescriptionForTextNode(editor.firstChild.firstChild)}</div>"`);
+ }
+
+ done();
+}
+
+window.addEventListener("load", runTests, {once: true});
+</script>
+</body>
+</html>