1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_350525.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +function test() { 1.5 + /** Test for Bug 350525 **/ 1.6 + 1.7 + function test(aLambda) { 1.8 + try { 1.9 + return aLambda() || true; 1.10 + } 1.11 + catch (ex) { } 1.12 + return false; 1.13 + } 1.14 + 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + //////////////////////////// 1.18 + // setWindowValue, et al. // 1.19 + //////////////////////////// 1.20 + let key = "Unique name: " + Date.now(); 1.21 + let value = "Unique value: " + Math.random(); 1.22 + 1.23 + // test adding 1.24 + ok(test(function() ss.setWindowValue(window, key, value)), "set a window value"); 1.25 + 1.26 + // test retrieving 1.27 + is(ss.getWindowValue(window, key), value, "stored window value matches original"); 1.28 + 1.29 + // test deleting 1.30 + ok(test(function() ss.deleteWindowValue(window, key)), "delete the window value"); 1.31 + 1.32 + // value should not exist post-delete 1.33 + is(ss.getWindowValue(window, key), "", "window value was deleted"); 1.34 + 1.35 + // test deleting a non-existent value 1.36 + ok(test(function() ss.deleteWindowValue(window, key)), "delete non-existent window value"); 1.37 + 1.38 + ///////////////////////// 1.39 + // setTabValue, et al. // 1.40 + ///////////////////////// 1.41 + key = "Unique name: " + Math.random(); 1.42 + value = "Unique value: " + Date.now(); 1.43 + let tab = gBrowser.addTab(); 1.44 + tab.linkedBrowser.stop(); 1.45 + 1.46 + // test adding 1.47 + ok(test(function() ss.setTabValue(tab, key, value)), "store a tab value"); 1.48 + 1.49 + // test retrieving 1.50 + is(ss.getTabValue(tab, key), value, "stored tab value match original"); 1.51 + 1.52 + // test deleting 1.53 + ok(test(function() ss.deleteTabValue(tab, key)), "delete the tab value"); 1.54 + 1.55 + // value should not exist post-delete 1.56 + is(ss.getTabValue(tab, key), "", "tab value was deleted"); 1.57 + 1.58 + // test deleting a non-existent value 1.59 + ok(test(function() ss.deleteTabValue(tab, key)), "delete non-existent tab value"); 1.60 + 1.61 + // clean up 1.62 + gBrowser.removeTab(tab); 1.63 + 1.64 + ///////////////////////////////////// 1.65 + // getClosedTabCount, undoCloseTab // 1.66 + ///////////////////////////////////// 1.67 + 1.68 + // get closed tab count 1.69 + let count = ss.getClosedTabCount(window); 1.70 + let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo"); 1.71 + ok(0 <= count && count <= max_tabs_undo, 1.72 + "getClosedTabCount returns zero or at most max_tabs_undo"); 1.73 + 1.74 + // create a new tab 1.75 + let testURL = "about:"; 1.76 + tab = gBrowser.addTab(testURL); 1.77 + whenBrowserLoaded(tab.linkedBrowser, function() { 1.78 + // make sure that the next closed tab will increase getClosedTabCount 1.79 + gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1); 1.80 + 1.81 + // remove tab 1.82 + gBrowser.removeTab(tab); 1.83 + 1.84 + // getClosedTabCount 1.85 + var newcount = ss.getClosedTabCount(window); 1.86 + ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented"); 1.87 + 1.88 + // undoCloseTab 1.89 + tab = test(function() ss.undoCloseTab(window, 0)); 1.90 + ok(tab, "undoCloseTab doesn't throw") 1.91 + 1.92 + whenTabRestored(tab, function() { 1.93 + is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened"); 1.94 + 1.95 + // clean up 1.96 + if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo")) 1.97 + gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); 1.98 + gBrowser.removeTab(tab); 1.99 + finish(); 1.100 + }); 1.101 + }); 1.102 +}