browser_615394-SSWindowState_events_setTabState.js (1860B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const testState = { 6 windows: [ 7 { 8 tabs: [ 9 { entries: [{ url: "about:blank", triggeringPrincipal_base64 }] }, 10 { entries: [{ url: "about:policies", triggeringPrincipal_base64 }] }, 11 ], 12 }, 13 ], 14 }; 15 16 function test() { 17 /** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore */ 18 waitForExplicitFinish(); 19 20 waitForBrowserState(testState, test_setTabState); 21 } 22 23 function test_setTabState() { 24 let tab = gBrowser.tabs[1]; 25 let newTabState = JSON.stringify({ 26 entries: [{ url: "http://example.org", triggeringPrincipal_base64 }], 27 extData: { foo: "bar" }, 28 }); 29 let busyEventCount = 0; 30 let readyEventCount = 0; 31 32 function onSSWindowStateBusy() { 33 busyEventCount++; 34 } 35 36 function onSSWindowStateReady() { 37 readyEventCount++; 38 is(ss.getCustomTabValue(tab, "foo"), "bar"); 39 ss.setCustomTabValue(tab, "baz", "qux"); 40 } 41 42 function onSSTabRestoring() { 43 is(busyEventCount, 1); 44 is(readyEventCount, 1); 45 is(ss.getCustomTabValue(tab, "baz"), "qux"); 46 is(tab.linkedBrowser.currentURI.spec, "http://example.org/"); 47 48 window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy); 49 window.removeEventListener("SSWindowStateReady", onSSWindowStateReady); 50 51 gBrowser.removeTab(tab); 52 finish(); 53 } 54 55 window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy); 56 window.addEventListener("SSWindowStateReady", onSSWindowStateReady); 57 tab.addEventListener("SSTabRestoring", onSSTabRestoring, { once: true }); 58 // Browser must be inserted in order to restore. 59 gBrowser._insertBrowser(tab); 60 ss.setTabState(tab, newTabState); 61 }