browser/components/sessionstore/test/browser_350525.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e06f8737c436
1 function test() {
2 /** Test for Bug 350525 **/
3
4 function test(aLambda) {
5 try {
6 return aLambda() || true;
7 }
8 catch (ex) { }
9 return false;
10 }
11
12 waitForExplicitFinish();
13
14 ////////////////////////////
15 // setWindowValue, et al. //
16 ////////////////////////////
17 let key = "Unique name: " + Date.now();
18 let value = "Unique value: " + Math.random();
19
20 // test adding
21 ok(test(function() ss.setWindowValue(window, key, value)), "set a window value");
22
23 // test retrieving
24 is(ss.getWindowValue(window, key), value, "stored window value matches original");
25
26 // test deleting
27 ok(test(function() ss.deleteWindowValue(window, key)), "delete the window value");
28
29 // value should not exist post-delete
30 is(ss.getWindowValue(window, key), "", "window value was deleted");
31
32 // test deleting a non-existent value
33 ok(test(function() ss.deleteWindowValue(window, key)), "delete non-existent window value");
34
35 /////////////////////////
36 // setTabValue, et al. //
37 /////////////////////////
38 key = "Unique name: " + Math.random();
39 value = "Unique value: " + Date.now();
40 let tab = gBrowser.addTab();
41 tab.linkedBrowser.stop();
42
43 // test adding
44 ok(test(function() ss.setTabValue(tab, key, value)), "store a tab value");
45
46 // test retrieving
47 is(ss.getTabValue(tab, key), value, "stored tab value match original");
48
49 // test deleting
50 ok(test(function() ss.deleteTabValue(tab, key)), "delete the tab value");
51
52 // value should not exist post-delete
53 is(ss.getTabValue(tab, key), "", "tab value was deleted");
54
55 // test deleting a non-existent value
56 ok(test(function() ss.deleteTabValue(tab, key)), "delete non-existent tab value");
57
58 // clean up
59 gBrowser.removeTab(tab);
60
61 /////////////////////////////////////
62 // getClosedTabCount, undoCloseTab //
63 /////////////////////////////////////
64
65 // get closed tab count
66 let count = ss.getClosedTabCount(window);
67 let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
68 ok(0 <= count && count <= max_tabs_undo,
69 "getClosedTabCount returns zero or at most max_tabs_undo");
70
71 // create a new tab
72 let testURL = "about:";
73 tab = gBrowser.addTab(testURL);
74 whenBrowserLoaded(tab.linkedBrowser, function() {
75 // make sure that the next closed tab will increase getClosedTabCount
76 gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
77
78 // remove tab
79 gBrowser.removeTab(tab);
80
81 // getClosedTabCount
82 var newcount = ss.getClosedTabCount(window);
83 ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented");
84
85 // undoCloseTab
86 tab = test(function() ss.undoCloseTab(window, 0));
87 ok(tab, "undoCloseTab doesn't throw")
88
89 whenTabRestored(tab, function() {
90 is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened");
91
92 // clean up
93 if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo"))
94 gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
95 gBrowser.removeTab(tab);
96 finish();
97 });
98 });
99 }

mercurial