browser_350525.js
Go to the documentation of this file.
1 function test() {
4  function test(aLambda) {
5  try {
6  return aLambda() || true;
7  }
8  catch (ex) { }
9  return false;
10  }
11 
12  // test setup
13  let tabbrowser = getBrowser();
15 
16  // component
17  let ssComponent = test(function() Cc["@mozilla.org/browser/sessionstore;1"]);
18  ok(ssComponent, "reference the sessionstore component");
19 
20  // service
21  let ss = test(function() ssComponent.getService(Ci.nsISessionStore));
22  ok(ss, "reference the sessionstore service");
23 
25  // setWindowValue, et al. //
27  let key = "Unique name: " + Date.now();
28  let value = "Unique value: " + Math.random();
29 
30  // test adding
31  ok(test(function() ss.setWindowValue(window, key, value)), "set a window value");
32 
33  // test retrieving
34  is(ss.getWindowValue(window, key), value, "stored window value matches original");
35 
36  // test deleting
37  ok(test(function() ss.deleteWindowValue(window, key)), "delete the window value");
38 
39  // value should not exist post-delete
40  is(ss.getWindowValue(window, key), "", "window value was deleted");
41 
43  // setTabValue, et al. //
45  key = "Unique name: " + Math.random();
46  value = "Unique value: " + Date.now();
47  let tab = tabbrowser.addTab();
48 
49  // test adding
50  ok(test(function() ss.setTabValue(tab, key, value)), "store a tab value");
51 
52  // test retrieving
53  is(ss.getTabValue(tab, key), value, "stored tab value match original");
54 
55  // test deleting
56  ok(test(function() ss.deleteTabValue(tab, key)), "delete the tab value");
57  // value should not exist post-delete
58  is(ss.getTabValue(tab, key), "", "tab value was deleted");
59 
60  // clean up
61  tabbrowser.removeTab(tab);
62 
64  // getClosedTabCount, undoCloseTab //
66 
67  // get closed tab count
68  let count = ss.getClosedTabCount(window);
69  let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
70  ok(0 <= count && count <= max_tabs_undo,
71  "getClosedTabCount returns zero or at most max_tabs_undo");
72 
73  // create a new tab
74  let testURL = "about:";
75  tab = tabbrowser.addTab(testURL);
76  tab.linkedBrowser.addEventListener("load", function(aEvent) {
77  // make sure that the next closed tab will increase getClosedTabCount
78  gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
79 
80  // remove tab
81  tabbrowser.removeTab(tab);
82 
83  // getClosedTabCount
84  var newcount = ss.getClosedTabCount(window);
85  ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented");
86 
87  // undoCloseTab
88  tab = test(function() ss.undoCloseTab(window, 0));
89  ok(tab, "undoCloseTab doesn't throw")
90 
91  tab.linkedBrowser.addEventListener("load", function(aEvent) {
92  is(this.currentURI.spec, testURL, "correct tab was reopened");
93 
94  // clean up
95  if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
96  gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
97  tabbrowser.removeTab(tab);
98  finish();
99  }, true);
100  }, true);
101 }
const Cc
function test()
function getBrowser() gBrowser
var tab
let window
var count
Definition: test_bug7406.js:32
var tabbrowser
waitForExplicitFinish()
var testURL
var gPrefService
Definition: overlay.js:34
countRef value
Definition: FeedWriter.js:1423
const Ci