diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/shared/test/unit/test_undoStack.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/shared/test/unit/test_undoStack.js')
-rw-r--r-- | devtools/client/shared/test/unit/test_undoStack.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/devtools/client/shared/test/unit/test_undoStack.js b/devtools/client/shared/test/unit/test_undoStack.js new file mode 100644 index 000000000..7499614fd --- /dev/null +++ b/devtools/client/shared/test/unit/test_undoStack.js @@ -0,0 +1,98 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const {Loader} = Components.utils.import("resource://gre/modules/commonjs/toolkit/loader.js", {}); + +const loader = new Loader.Loader({ + paths: { + "": "resource://gre/modules/commonjs/", + "devtools": "resource://devtools", + }, + globals: {}, +}); +const require = Loader.Require(loader, { id: "undo-test" }); + +const {UndoStack} = require("devtools/client/shared/undo"); + +const MAX_SIZE = 5; + +function run_test() { + let str = ""; + let stack = new UndoStack(MAX_SIZE); + + function add(ch) { + stack.do(function () { + str += ch; + }, function () { + str = str.slice(0, -1); + }); + } + + do_check_false(stack.canUndo()); + do_check_false(stack.canRedo()); + + // Check adding up to the limit of the size + add("a"); + do_check_true(stack.canUndo()); + do_check_false(stack.canRedo()); + + add("b"); + add("c"); + add("d"); + add("e"); + + do_check_eq(str, "abcde"); + + // Check a simple undo+redo + stack.undo(); + + do_check_eq(str, "abcd"); + do_check_true(stack.canRedo()); + + stack.redo(); + do_check_eq(str, "abcde"); + do_check_false(stack.canRedo()); + + // Check an undo followed by a new action + stack.undo(); + do_check_eq(str, "abcd"); + + add("q"); + do_check_eq(str, "abcdq"); + do_check_false(stack.canRedo()); + + stack.undo(); + do_check_eq(str, "abcd"); + stack.redo(); + do_check_eq(str, "abcdq"); + + // Revert back to the beginning of the queue... + while (stack.canUndo()) { + stack.undo(); + } + do_check_eq(str, ""); + + // Now put it all back.... + while (stack.canRedo()) { + stack.redo(); + } + do_check_eq(str, "abcdq"); + + // Now go over the undo limit... + add("1"); + add("2"); + add("3"); + + do_check_eq(str, "abcdq123"); + + // And now undoing the whole stack should only undo 5 actions. + while (stack.canUndo()) { + stack.undo(); + } + + do_check_eq(str, "abc"); +} |