browser_gcli_history.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2012, Mozilla Foundation and contributors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. "use strict";
  17. // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
  18. // PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT
  19. const exports = {};
  20. function test() {
  21. helpers.runTestModule(exports, "browser_gcli_history.js");
  22. }
  23. // var assert = require('../testharness/assert');
  24. var History = require("gcli/ui/history").History;
  25. exports.testSimpleHistory = function (options) {
  26. var history = new History({});
  27. history.add("foo");
  28. history.add("bar");
  29. assert.is(history.backward(), "bar");
  30. assert.is(history.backward(), "foo");
  31. // Adding to the history again moves us back to the start of the history.
  32. history.add("quux");
  33. assert.is(history.backward(), "quux");
  34. assert.is(history.backward(), "bar");
  35. assert.is(history.backward(), "foo");
  36. };
  37. exports.testBackwardsPastIndex = function (options) {
  38. var history = new History({});
  39. history.add("foo");
  40. history.add("bar");
  41. assert.is(history.backward(), "bar");
  42. assert.is(history.backward(), "foo");
  43. // Moving backwards past recorded history just keeps giving you the last
  44. // item.
  45. assert.is(history.backward(), "foo");
  46. };
  47. exports.testForwardsPastIndex = function (options) {
  48. var history = new History({});
  49. history.add("foo");
  50. history.add("bar");
  51. assert.is(history.backward(), "bar");
  52. assert.is(history.backward(), "foo");
  53. // Going forward through the history again.
  54. assert.is(history.forward(), "bar");
  55. // 'Present' time.
  56. assert.is(history.forward(), "");
  57. // Going to the 'future' just keeps giving us the empty string.
  58. assert.is(history.forward(), "");
  59. };