Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/ */
6 const Cu = Components.utils;
7 let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
9 let loader = new Loader.Loader({
10 paths: {
11 "": "resource://gre/modules/commonjs/",
12 "devtools": "resource:///modules/devtools",
13 },
14 globals: {},
15 });
16 let require = Loader.Require(loader, { id: "undo-test" })
18 let {UndoStack} = require("devtools/shared/undo");
20 const MAX_SIZE = 5;
22 function run_test()
23 {
24 let str = "";
25 let stack = new UndoStack(MAX_SIZE);
27 function add(ch) {
28 stack.do(function() {
29 str += ch;
30 }, function() {
31 str = str.slice(0, -1);
32 });
33 }
35 do_check_false(stack.canUndo());
36 do_check_false(stack.canRedo());
38 // Check adding up to the limit of the size
39 add("a");
40 do_check_true(stack.canUndo());
41 do_check_false(stack.canRedo());
43 add("b");
44 add("c");
45 add("d");
46 add("e");
48 do_check_eq(str, "abcde");
50 // Check a simple undo+redo
51 stack.undo();
53 do_check_eq(str, "abcd");
54 do_check_true(stack.canRedo());
56 stack.redo();
57 do_check_eq(str, "abcde")
58 do_check_false(stack.canRedo());
60 // Check an undo followed by a new action
61 stack.undo();
62 do_check_eq(str, "abcd");
64 add("q");
65 do_check_eq(str, "abcdq");
66 do_check_false(stack.canRedo());
68 stack.undo();
69 do_check_eq(str, "abcd");
70 stack.redo();
71 do_check_eq(str, "abcdq");
73 // Revert back to the beginning of the queue...
74 while (stack.canUndo()) {
75 stack.undo();
76 }
77 do_check_eq(str, "");
79 // Now put it all back....
80 while (stack.canRedo()) {
81 stack.redo();
82 }
83 do_check_eq(str, "abcdq");
85 // Now go over the undo limit...
86 add("1");
87 add("2");
88 add("3");
90 do_check_eq(str, "abcdq123");
92 // And now undoing the whole stack should only undo 5 actions.
93 while (stack.canUndo()) {
94 stack.undo();
95 }
97 do_check_eq(str, "abc");
98 }