Bug 1883912: Enable Intl.ListFormat test for "unit" style. r=spidermonkey-reviewers...
[gecko.git] / editor / libeditor / tests / test_nsIEditor_undoRedoEnabled.html
blob1a0841ea1e6fe05e3f4e5a7c26ac60030f707ab8
1 <!DOCTYPE html>
2 <html>
3 <head>
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"/>
8 </head>
9 <body>
10 <p id="display"></p>
11 <div id="content"><input><textarea></textarea><div contenteditable></div></div>
12 <pre id="test">
13 <script>
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;
30 return;
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, "");
45 is(
46 editor.undoRedoEnabled,
47 true,
48 `undo/redo in editor for ${selector} should be enabled by default`
50 editor.enableUndo(false);
51 is(
52 editor.undoRedoEnabled,
53 false,
54 `undo/redo in editor for ${selector} should be disable after calling enableUndo(false)`
56 synthesizeKey("a");
57 is(
58 getValue(editableElement),
59 "a",
60 `inserting text should be handled by editor for ${selector} even if undo/redo is disabled`
62 is(
63 editor.canUndo,
64 false,
65 `undo transaction shouldn't be created by editor for ${selector} when undo/redo is disabled`
67 editor.enableUndo(true);
68 is(
69 editor.undoRedoEnabled,
70 true,
71 `undo/redo in editor for ${selector} should be enabled after calling enableUndo(true)`
73 synthesizeKey("b");
74 is(
75 getValue(editableElement),
76 "ab",
77 `inserting text should be handled by editor for ${selector} after enabling undo/redo`
79 is(
80 editor.canUndo,
81 true,
82 `undo transaction should be created by editor for ${selector} when undo/redo is enabled again`
85 SimpleTest.finish();
86 });
88 </script>
89 </pre>
90 </body>
91 </html>