commit df4f346c044e1734b479344240a0c1d10d2d4526
parent 6495e90f7704d844ebaf55d62651ef2eb0cdc3bb
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date: Mon, 27 Oct 2025 08:34:30 +0000
Bug 1991431 - [devtools] Update browser_markup_html_edit_undo-redo.js to properly test the Html Editor undo redo behaviour r=devtools-reviewers,nchevobbe
browser_markup_html_edit_undo-redo.js was directly calling source editor apis `setText` and `undo` in certain places.
Therefore certain behaviours of the HtmlEditor do not have test coverage.
This refactors the test to use the key shortcuts, and more directly reflects user patterns of usage.
Differential Revision: https://phabricator.services.mozilla.com/D268900
Diffstat:
1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/devtools/client/inspector/markup/test/browser_markup_html_edit_undo-redo.js b/devtools/client/inspector/markup/test/browser_markup_html_edit_undo-redo.js
@@ -3,7 +3,7 @@
"use strict";
-// Test that the undo/redo stack is correctly cleared when opening the HTML editor on a
+// Test that the undo and redo correctly updates the content when opening the HTML editor on a
// new node. Bug 1327674.
const DIV1_HTML = '<div id="d1">content1</div>';
@@ -59,27 +59,63 @@ add_task(async function () {
"The editor content for d2 is correct."
);
- inspector.markup.htmlEditor.editor.setText(DIV2_HTML_UPDATED);
+ // Wait a bit so that the next change is tracked as a
+ // seperate history change
+ await waitForTime(1000);
+
+ inspector.markup.htmlEditor.editor.focus();
+ // Select and replace the content
+ await EventUtils.synthesizeKey("a", { accelKey: true });
+ EventUtils.sendString(DIV2_HTML_UPDATED);
+
+ // Wait a bit so that the next change is tracked as a
+ // seperate history change
+ await waitForTime(1000);
+
is(
inspector.markup.htmlEditor.editor.getText(),
DIV2_HTML_UPDATED,
"The editor content for d2 is updated."
);
- inspector.markup.htmlEditor.editor.undo();
+ await EventUtils.synthesizeKey("z", { accelKey: true });
+ is(
+ inspector.markup.htmlEditor.editor.getText(),
+ '<div id="d2"',
+ "The editor content for d2 is reverted partially."
+ );
+
+ await EventUtils.synthesizeKey("z", { accelKey: true });
is(
inspector.markup.htmlEditor.editor.getText(),
DIV2_HTML,
"The editor content for d2 is reverted."
);
- inspector.markup.htmlEditor.editor.undo();
+ // Undo should be at the last change in history
+ await EventUtils.synthesizeKey("z", { accelKey: true });
is(
inspector.markup.htmlEditor.editor.getText(),
DIV2_HTML,
"The editor content for d2 has not been set to content1."
);
+ // Redo
+ await EventUtils.synthesizeKey("z", { shiftKey: true, accelKey: true });
+ is(
+ inspector.markup.htmlEditor.editor.getText(),
+ '<div id="d2"',
+ "The editor content for d2 is back to updated partially."
+ );
+
+ // Redo should be back to to the updated content
+ await EventUtils.synthesizeKey("z", { shiftKey: true, accelKey: true });
+ is(
+ inspector.markup.htmlEditor.editor.getText(),
+ DIV2_HTML_UPDATED,
+ "The editor content for d2 is back to updated"
+ );
+
info("Hide the HTML editor for #d2");
onEditorHidden = once(inspector.markup.htmlEditor, "popuphidden");
EventUtils.sendKey("ESCAPE", inspector.markup.htmlEditor.doc.defaultView);