From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../client/shared/test/xpcshell/test_undoStack.js | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 devtools/client/shared/test/xpcshell/test_undoStack.js (limited to 'devtools/client/shared/test/xpcshell/test_undoStack.js') diff --git a/devtools/client/shared/test/xpcshell/test_undoStack.js b/devtools/client/shared/test/xpcshell/test_undoStack.js new file mode 100644 index 0000000000..dafb007120 --- /dev/null +++ b/devtools/client/shared/test/xpcshell/test_undoStack.js @@ -0,0 +1,88 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { UndoStack } = require("resource://devtools/client/shared/undo.js"); + +const MAX_SIZE = 5; + +function run_test() { + let str = ""; + const stack = new UndoStack(MAX_SIZE); + + function add(ch) { + stack.do( + function () { + str += ch; + }, + function () { + str = str.slice(0, -1); + } + ); + } + + Assert.ok(!stack.canUndo()); + Assert.ok(!stack.canRedo()); + + // Check adding up to the limit of the size + add("a"); + Assert.ok(stack.canUndo()); + Assert.ok(!stack.canRedo()); + + add("b"); + add("c"); + add("d"); + add("e"); + + Assert.equal(str, "abcde"); + + // Check a simple undo+redo + stack.undo(); + + Assert.equal(str, "abcd"); + Assert.ok(stack.canRedo()); + + stack.redo(); + Assert.equal(str, "abcde"); + Assert.ok(!stack.canRedo()); + + // Check an undo followed by a new action + stack.undo(); + Assert.equal(str, "abcd"); + + add("q"); + Assert.equal(str, "abcdq"); + Assert.ok(!stack.canRedo()); + + stack.undo(); + Assert.equal(str, "abcd"); + stack.redo(); + Assert.equal(str, "abcdq"); + + // Revert back to the beginning of the queue... + while (stack.canUndo()) { + stack.undo(); + } + Assert.equal(str, ""); + + // Now put it all back.... + while (stack.canRedo()) { + stack.redo(); + } + Assert.equal(str, "abcdq"); + + // Now go over the undo limit... + add("1"); + add("2"); + add("3"); + + Assert.equal(str, "abcdq123"); + + // And now undoing the whole stack should only undo 5 actions. + while (stack.canUndo()) { + stack.undo(); + } + + Assert.equal(str, "abc"); +} -- cgit v1.2.3