browser/components/sessionstore/test/browser_350525.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial