browser_350525.js (3238B)
1 "use strict"; 2 3 add_setup(async function () { 4 await SpecialPowers.pushPrefEnv({ 5 set: [["dom.ipc.processCount", 1]], 6 }); 7 }); 8 9 add_task(async function () { 10 /** Test for Bug 350525 */ 11 12 function test(aLambda) { 13 try { 14 return aLambda() || true; 15 } catch (ex) {} 16 return false; 17 } 18 19 /** 20 * setCustomWindowValue, et al. 21 */ 22 let key = "Unique name: " + Date.now(); 23 let value = "Unique value: " + Math.random(); 24 25 // test adding 26 ok( 27 test(() => ss.setCustomWindowValue(window, key, value)), 28 "set a window value" 29 ); 30 31 // test retrieving 32 is( 33 ss.getCustomWindowValue(window, key), 34 value, 35 "stored window value matches original" 36 ); 37 38 // test deleting 39 ok( 40 test(() => ss.deleteCustomWindowValue(window, key)), 41 "delete the window value" 42 ); 43 44 // value should not exist post-delete 45 is(ss.getCustomWindowValue(window, key), "", "window value was deleted"); 46 47 // test deleting a non-existent value 48 ok( 49 test(() => ss.deleteCustomWindowValue(window, key)), 50 "delete non-existent window value" 51 ); 52 53 /** 54 * setCustomTabValue, et al. 55 */ 56 key = "Unique name: " + Math.random(); 57 value = "Unique value: " + Date.now(); 58 let tab = BrowserTestUtils.addTab(gBrowser); 59 tab.linkedBrowser.stop(); 60 61 // test adding 62 ok( 63 test(() => ss.setCustomTabValue(tab, key, value)), 64 "store a tab value" 65 ); 66 67 // test retrieving 68 is(ss.getCustomTabValue(tab, key), value, "stored tab value match original"); 69 70 // test deleting 71 ok( 72 test(() => ss.deleteCustomTabValue(tab, key)), 73 "delete the tab value" 74 ); 75 76 // value should not exist post-delete 77 is(ss.getCustomTabValue(tab, key), "", "tab value was deleted"); 78 79 // test deleting a non-existent value 80 ok( 81 test(() => ss.deleteCustomTabValue(tab, key)), 82 "delete non-existent tab value" 83 ); 84 85 // clean up 86 await promiseRemoveTabAndSessionState(tab); 87 88 /** 89 * getClosedTabCountForWindow, undoCloseTab 90 */ 91 92 // get closed tab count 93 let count = ss.getClosedTabCountForWindow(window); 94 let max_tabs_undo = Services.prefs.getIntPref( 95 "browser.sessionstore.max_tabs_undo" 96 ); 97 ok( 98 0 <= count && count <= max_tabs_undo, 99 "getClosedTabCountForWindow returns zero or at most max_tabs_undo" 100 ); 101 102 // create a new tab 103 let testURL = "about:mozilla"; 104 tab = BrowserTestUtils.addTab(gBrowser, testURL); 105 await promiseBrowserLoaded(tab.linkedBrowser); 106 107 // make sure that the next closed tab will increase getClosedTabCountForWindow 108 Services.prefs.setIntPref( 109 "browser.sessionstore.max_tabs_undo", 110 max_tabs_undo + 1 111 ); 112 registerCleanupFunction(() => 113 Services.prefs.clearUserPref("browser.sessionstore.max_tabs_undo") 114 ); 115 116 // remove tab 117 await promiseRemoveTabAndSessionState(tab); 118 119 // getClosedTabCountForWindow 120 let newcount = ss.getClosedTabCountForWindow(window); 121 Assert.greater( 122 newcount, 123 count, 124 "after closing a tab, getClosedTabCountForWindow has been incremented" 125 ); 126 127 // undoCloseTab 128 tab = test(() => ss.undoCloseTab(window, 0)); 129 ok(tab, "undoCloseTab doesn't throw"); 130 131 await promiseTabRestored(tab); 132 is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened"); 133 134 // clean up 135 gBrowser.removeTab(tab); 136 });