michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let stateBackup = ss.getBrowserState(); michael@0: michael@0: function test() { michael@0: /** Test for bug 581593 **/ michael@0: waitForExplicitFinish(); michael@0: ignoreAllUncaughtExceptions(); michael@0: michael@0: let oldState = { windows: [{ tabs: [{ entries: [{ url: "example.com" }] }] }]}; michael@0: let pageData = { michael@0: url: "about:sessionrestore", michael@0: formdata: { id: { "sessionData": "(" + JSON.stringify(oldState) + ")" } } michael@0: }; michael@0: let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; michael@0: michael@0: // The form data will be restored before SSTabRestored, so we want to listen michael@0: // for that on the currently selected tab (it will be reused) michael@0: gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true); michael@0: michael@0: ss.setBrowserState(JSON.stringify(state)); michael@0: } michael@0: michael@0: function onSSTabRestored(aEvent) { michael@0: info("SSTabRestored event"); michael@0: gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true); michael@0: michael@0: // This is an ok way to check this because we will make sure that the text michael@0: // field is parsable. michael@0: let val = gBrowser.selectedBrowser.contentDocument.getElementById("sessionData").value; michael@0: try { michael@0: JSON.parse(val); michael@0: ok(true, "JSON.parse succeeded"); michael@0: } michael@0: catch (e) { michael@0: ok(false, "JSON.parse failed"); michael@0: } michael@0: cleanup(); michael@0: } michael@0: michael@0: function cleanup() { michael@0: ss.setBrowserState(stateBackup); michael@0: executeSoon(finish); michael@0: }