diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/editing/run/undo-redo-after-mutation.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/editing/run/undo-redo-after-mutation.html')
-rw-r--r-- | testing/web-platform/tests/editing/run/undo-redo-after-mutation.html | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/testing/web-platform/tests/editing/run/undo-redo-after-mutation.html b/testing/web-platform/tests/editing/run/undo-redo-after-mutation.html new file mode 100644 index 0000000000..8d583a161f --- /dev/null +++ b/testing/web-platform/tests/editing/run/undo-redo-after-mutation.html @@ -0,0 +1,119 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div contenteditable></div> +<script> +"use strict"; +let editor = document.querySelector("div[contenteditable]"); +let selection = document.getSelection(); + +test(function () { + editor.innerHTML = "<i>will be removed</i> abc"; + selection.collapse(editor.lastChild, editor.lastChild.length); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "<i>will be removed</i> abc<br><br>", + "<br> element should be inserted by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "<i>will be removed</i> abc", + "<br> element should be removed by execCommand(\"undo\")"); + editor.firstChild.remove(); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, " abc<br><br>", + "<br> element should be inserted by execCommand(\"redo\")"); +}, "Redo for execCommand(\"insertLineBreak\") after removing prior sibling with DOM API after undoing"); + +test(function () { + editor.innerHTML = "abc"; + selection.collapse(editor.firstChild, editor.firstChild.length); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "abc<br><br>", + "<br> element should be inserted by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "abc", + "<br> element should be removed by execCommand(\"undo\")"); + let i = document.createElement("i"); + i.textContent = " appended text"; + editor.appendChild(i); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "abc<i> appended text</i><br><br>", + "<br> element should be appended by execCommand(\"redo\") after the appended text"); +}, "Redo for execCommand(\"insertLineBreak\") after appending new child with DOM API after undoing"); + +test(function () { + editor.innerHTML = "abc"; + selection.collapse(editor.firstChild, editor.firstChild.length); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "abc<br><br>", + "<br> element should be inserted by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "abc", + "<br> element should be removed by execCommand(\"undo\")"); + let i = document.createElement("i"); + i.textContent = "inserted text "; + editor.insertBefore(i, editor.firstChild); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "<i>inserted text </i>abc<br><br>", + "<br> element should be appended by execCommand(\"redo\") after the appended text"); +}, "Redo for execCommand(\"insertLineBreak\") after inserting new child with DOM API after undoing"); + +test(function () { + editor.innerHTML = "<b>will be removed</b><i>abc</i>"; + selection.collapse(editor.querySelector("b").firstChild, editor.querySelector("b").firstChild.length); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "<b>will be removed<br></b><i>abc</i>", + "<br> element should be inserted into the <b> element by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "<b>will be removed</b><i>abc</i>", + "<br> element should be removed by execCommand(\"undo\")"); + editor.querySelector("b").remove(); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "<i>abc</i>", + "<br> element shouldn't be restored by execCommand(\"redo\") after removing the <b> element"); +}, "Redo for execCommand(\"insertLineBreak\") after removing its container with DOM API after undoing"); + +test(function () { + editor.innerHTML = "<b>abc</b><i>will be removed</i>"; + selection.collapse(editor.querySelector("b").firstChild, editor.querySelector("b").firstChild.length); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "<b>abc<br></b><i>will be removed</i>", + "<br> element should be inserted into the <b> element by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "<b>abc</b><i>will be removed</i>", + "<br> element should be removed by execCommand(\"undo\")"); + editor.querySelector("i").remove(); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "<b>abc<br></b>", + "<br> element should be restored by execCommand(\"redo\") after removing the following <i> element"); +}, "Redo for execCommand(\"insertLineBreak\") after removing <i> element following the container with DOM API after undoing"); + +// Not sure whether redoing in both of the following 2 cases should work as so. +test(function () { + editor.innerHTML = "<b>will be removed</b><i>abc</i>"; + selection.collapse(editor, 1); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "<b>will be removed</b><br><i>abc</i>", + "<br> element should be inserted between the <b> and <i> elements by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "<b>will be removed</b><i>abc</i>", + "<br> element should be removed by execCommand(\"undo\")"); + editor.querySelector("b").remove(); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "<br><i>abc</i>", + "<br> element should be restored by execCommand(\"redo\") after removing the preceding <b> element"); +}, "Redo for execCommand(\"insertLineBreak\") between <b> and <i> after removing preceding <b> element with DOM API after undoing"); + +test(function () { + editor.innerHTML = "<b>abc</b><i>will be removed</i>"; + selection.collapse(editor, 1); + document.execCommand("insertLineBreak", false, ""); + assert_equals(editor.innerHTML, "<b>abc</b><br><i>will be removed</i>", + "<br> element should be inserted between the <b> and <i> elements by execCommand(\"insertLineBreak\")"); + document.execCommand("undo", false, ""); + assert_equals(editor.innerHTML, "<b>abc</b><i>will be removed</i>", + "<br> element should be removed by execCommand(\"undo\")"); + editor.querySelector("i").remove(); + document.execCommand("redo", false, ""); + assert_equals(editor.innerHTML, "<b>abc</b><br>", + "<br> element should be restored by execCommand(\"redo\") after removing the following <i> element"); +}, "Redo for execCommand(\"insertLineBreak\") between <b> and <i> after after removing following <i> element with DOM API after undoing"); +</script> |