4 <title>Test for nsIEditor.clearUndoRedo()
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <div id=
"content"><input><textarea></textarea><div contenteditable
></div></div>
15 SimpleTest
.waitForExplicitFinish();
16 SimpleTest
.waitForFocus(() => {
17 function isTextEditor(aElement
) {
18 return aElement
.tagName
.toLowerCase() == "input" ||
19 aElement
.tagName
.toLowerCase() == "textarea";
21 function getEditor(aElement
) {
22 if (isTextEditor(aElement
)) {
23 return SpecialPowers
.wrap(aElement
).editor
;
25 return SpecialPowers
.wrap(window
).docShell
.editingSession
?.getEditorForWindow(window
);
27 function setValue(aElement
, aValue
) {
28 if (isTextEditor(aElement
)) {
29 aElement
.value
= aValue
;
32 aElement
.innerHTML
= aValue
;
34 function getValue(aElement
) {
35 if (isTextEditor(aElement
)) {
36 return aElement
.value
;
38 return aElement
.innerHTML
.replace(/<br>/g, "");
40 for (const selector
of ["input", "textarea", "div[contenteditable]"]) {
41 const editableElement
= document
.querySelector(selector
);
42 editableElement
.focus();
43 const editor
= getEditor(editableElement
);
44 (function test_clearing_undo_history() {
45 setValue(editableElement
, "");
49 `Editor for ${selector} shouldn't have undo transaction at start`
53 getValue(editableElement
),
55 `Editor for ${selector} should've handled typing "a"`
60 `Editor for ${selector} should have undo transaction for the inserted text`
62 editor
.clearUndoRedo();
66 `Editor for ${selector} shouldn't have undo transaction after calling nsIEditor.clearUndoRedo()`
68 document
.execCommand("undo");
70 getValue(editableElement
),
72 `Editor for ${selector} should do noting for document.execCommand("undo")`
76 (function test_clearing_redo_history() {
77 setValue(editableElement
, "");
81 `Editor for ${selector} shouldn't have redo transaction at start`
85 getValue(editableElement
),
87 `Editor for ${selector} should've handled typing "b"`
92 `Editor for ${selector} shouldn't have redo transaction after inserting text`
94 document
.execCommand("undo");
96 getValue(editableElement
),
98 `Editor for ${selector} should've handled the typing "b" after undoing`
103 `Editor for ${selector} should have redo transaction of inserting text`
105 editor
.clearUndoRedo();
109 `Editor for ${selector} shouldn't have redo transaction after calling nsIEditor.clearUndoRedo()`
111 document
.execCommand("redo");
113 getValue(editableElement
),
115 `Editor for ${selector} should do noting for document.execCommand("redo")`