Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let tabState = { |
michael@0 | 5 | entries: [{url: "data:text/html;charset=utf-8,<input%20id='foo'>", formdata: { id: { "foo": "bar" } } }] |
michael@0 | 6 | }; |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); |
michael@0 | 11 | |
michael@0 | 12 | registerCleanupFunction(function () { |
michael@0 | 13 | if (gBrowser.tabs.length > 1) |
michael@0 | 14 | gBrowser.removeTab(gBrowser.tabs[1]); |
michael@0 | 15 | Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | let tab = gBrowser.addTab("about:blank"); |
michael@0 | 19 | let browser = tab.linkedBrowser; |
michael@0 | 20 | |
michael@0 | 21 | whenBrowserLoaded(browser, function () { |
michael@0 | 22 | isnot(gBrowser.selectedTab, tab, "newly created tab is not selected"); |
michael@0 | 23 | |
michael@0 | 24 | ss.setTabState(tab, JSON.stringify(tabState)); |
michael@0 | 25 | is(browser.__SS_restoreState, TAB_STATE_NEEDS_RESTORE, "tab needs restoring"); |
michael@0 | 26 | |
michael@0 | 27 | let state = JSON.parse(ss.getTabState(tab)); |
michael@0 | 28 | let formdata = state.entries[0].formdata; |
michael@0 | 29 | is(formdata && formdata.id["foo"], "bar", "tab state's formdata is valid"); |
michael@0 | 30 | |
michael@0 | 31 | whenTabRestored(tab, function () { |
michael@0 | 32 | let input = browser.contentDocument.getElementById("foo"); |
michael@0 | 33 | is(input.value, "bar", "formdata has been restored correctly"); |
michael@0 | 34 | finish(); |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | // Restore the tab by selecting it. |
michael@0 | 38 | gBrowser.selectedTab = tab; |
michael@0 | 39 | }); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function whenBrowserLoaded(aBrowser, aCallback) { |
michael@0 | 43 | aBrowser.addEventListener("load", function onLoad() { |
michael@0 | 44 | aBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 45 | executeSoon(aCallback); |
michael@0 | 46 | }, true); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function whenTabRestored(aTab, aCallback) { |
michael@0 | 50 | aTab.addEventListener("SSTabRestored", function onRestored() { |
michael@0 | 51 | aTab.removeEventListener("SSTabRestored", onRestored); |
michael@0 | 52 | executeSoon(aCallback); |
michael@0 | 53 | }); |
michael@0 | 54 | } |