tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit f1bcc97077c234cafdcc49d2d3d9df71ae1fa357
parent 3919434e55256c0c36b25a3773eb0b36c7e09c03
Author: Hubert Boma Manilla <hmanilla@mozilla.com>
Date:   Mon, 27 Oct 2025 12:47:29 +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:
Mdevtools/client/inspector/markup/test/browser_markup_html_edit_undo-redo.js | 44++++++++++++++++++++++++++++++++++++++++----
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);