1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_581593.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let stateBackup = ss.getBrowserState(); 1.9 + 1.10 +function test() { 1.11 + /** Test for bug 581593 **/ 1.12 + waitForExplicitFinish(); 1.13 + ignoreAllUncaughtExceptions(); 1.14 + 1.15 + let oldState = { windows: [{ tabs: [{ entries: [{ url: "example.com" }] }] }]}; 1.16 + let pageData = { 1.17 + url: "about:sessionrestore", 1.18 + formdata: { id: { "sessionData": "(" + JSON.stringify(oldState) + ")" } } 1.19 + }; 1.20 + let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; 1.21 + 1.22 + // The form data will be restored before SSTabRestored, so we want to listen 1.23 + // for that on the currently selected tab (it will be reused) 1.24 + gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true); 1.25 + 1.26 + ss.setBrowserState(JSON.stringify(state)); 1.27 +} 1.28 + 1.29 +function onSSTabRestored(aEvent) { 1.30 + info("SSTabRestored event"); 1.31 + gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true); 1.32 + 1.33 + // This is an ok way to check this because we will make sure that the text 1.34 + // field is parsable. 1.35 + let val = gBrowser.selectedBrowser.contentDocument.getElementById("sessionData").value; 1.36 + try { 1.37 + JSON.parse(val); 1.38 + ok(true, "JSON.parse succeeded"); 1.39 + } 1.40 + catch (e) { 1.41 + ok(false, "JSON.parse failed"); 1.42 + } 1.43 + cleanup(); 1.44 +} 1.45 + 1.46 +function cleanup() { 1.47 + ss.setBrowserState(stateBackup); 1.48 + executeSoon(finish); 1.49 +}