michael@0: function test() { michael@0: /** Test for Bug 350525 **/ michael@0: michael@0: function test(aLambda) { michael@0: try { michael@0: return aLambda() || true; michael@0: } michael@0: catch (ex) { } michael@0: return false; michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: //////////////////////////// michael@0: // setWindowValue, et al. // michael@0: //////////////////////////// michael@0: let key = "Unique name: " + Date.now(); michael@0: let value = "Unique value: " + Math.random(); michael@0: michael@0: // test adding michael@0: ok(test(function() ss.setWindowValue(window, key, value)), "set a window value"); michael@0: michael@0: // test retrieving michael@0: is(ss.getWindowValue(window, key), value, "stored window value matches original"); michael@0: michael@0: // test deleting michael@0: ok(test(function() ss.deleteWindowValue(window, key)), "delete the window value"); michael@0: michael@0: // value should not exist post-delete michael@0: is(ss.getWindowValue(window, key), "", "window value was deleted"); michael@0: michael@0: // test deleting a non-existent value michael@0: ok(test(function() ss.deleteWindowValue(window, key)), "delete non-existent window value"); michael@0: michael@0: ///////////////////////// michael@0: // setTabValue, et al. // michael@0: ///////////////////////// michael@0: key = "Unique name: " + Math.random(); michael@0: value = "Unique value: " + Date.now(); michael@0: let tab = gBrowser.addTab(); michael@0: tab.linkedBrowser.stop(); michael@0: michael@0: // test adding michael@0: ok(test(function() ss.setTabValue(tab, key, value)), "store a tab value"); michael@0: michael@0: // test retrieving michael@0: is(ss.getTabValue(tab, key), value, "stored tab value match original"); michael@0: michael@0: // test deleting michael@0: ok(test(function() ss.deleteTabValue(tab, key)), "delete the tab value"); michael@0: michael@0: // value should not exist post-delete michael@0: is(ss.getTabValue(tab, key), "", "tab value was deleted"); michael@0: michael@0: // test deleting a non-existent value michael@0: ok(test(function() ss.deleteTabValue(tab, key)), "delete non-existent tab value"); michael@0: michael@0: // clean up michael@0: gBrowser.removeTab(tab); michael@0: michael@0: ///////////////////////////////////// michael@0: // getClosedTabCount, undoCloseTab // michael@0: ///////////////////////////////////// michael@0: michael@0: // get closed tab count michael@0: let count = ss.getClosedTabCount(window); michael@0: let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo"); michael@0: ok(0 <= count && count <= max_tabs_undo, michael@0: "getClosedTabCount returns zero or at most max_tabs_undo"); michael@0: michael@0: // create a new tab michael@0: let testURL = "about:"; michael@0: tab = gBrowser.addTab(testURL); michael@0: whenBrowserLoaded(tab.linkedBrowser, function() { michael@0: // make sure that the next closed tab will increase getClosedTabCount michael@0: gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1); michael@0: michael@0: // remove tab michael@0: gBrowser.removeTab(tab); michael@0: michael@0: // getClosedTabCount michael@0: var newcount = ss.getClosedTabCount(window); michael@0: ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented"); michael@0: michael@0: // undoCloseTab michael@0: tab = test(function() ss.undoCloseTab(window, 0)); michael@0: ok(tab, "undoCloseTab doesn't throw") michael@0: michael@0: whenTabRestored(tab, function() { michael@0: is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened"); michael@0: michael@0: // clean up michael@0: if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo")) michael@0: gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); michael@0: gBrowser.removeTab(tab); michael@0: finish(); michael@0: }); michael@0: }); michael@0: }