4 <title>Test for nsIEditor.undoRedoEnabled
</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 setValue(editableElement
, "");
46 editor
.undoRedoEnabled
,
48 `undo/redo in editor for ${selector} should be enabled by default`
50 editor
.enableUndo(false);
52 editor
.undoRedoEnabled
,
54 `undo/redo in editor for ${selector} should be disable after calling enableUndo(false)`
58 getValue(editableElement
),
60 `inserting text should be handled by editor for ${selector} even if undo/redo is disabled`
65 `undo transaction shouldn't be created by editor for ${selector} when undo/redo is disabled`
67 editor
.enableUndo(true);
69 editor
.undoRedoEnabled
,
71 `undo/redo in editor for ${selector} should be enabled after calling enableUndo(true)`
75 getValue(editableElement
),
77 `inserting text should be handled by editor for ${selector} after enabling undo/redo`
82 `undo transaction should be created by editor for ${selector} when undo/redo is enabled again`