browser/components/sessionstore/test/browser_581593.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 let stateBackup = ss.getBrowserState();
michael@0 6
michael@0 7 function test() {
michael@0 8 /** Test for bug 581593 **/
michael@0 9 waitForExplicitFinish();
michael@0 10 ignoreAllUncaughtExceptions();
michael@0 11
michael@0 12 let oldState = { windows: [{ tabs: [{ entries: [{ url: "example.com" }] }] }]};
michael@0 13 let pageData = {
michael@0 14 url: "about:sessionrestore",
michael@0 15 formdata: { id: { "sessionData": "(" + JSON.stringify(oldState) + ")" } }
michael@0 16 };
michael@0 17 let state = { windows: [{ tabs: [{ entries: [pageData] }] }] };
michael@0 18
michael@0 19 // The form data will be restored before SSTabRestored, so we want to listen
michael@0 20 // for that on the currently selected tab (it will be reused)
michael@0 21 gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true);
michael@0 22
michael@0 23 ss.setBrowserState(JSON.stringify(state));
michael@0 24 }
michael@0 25
michael@0 26 function onSSTabRestored(aEvent) {
michael@0 27 info("SSTabRestored event");
michael@0 28 gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true);
michael@0 29
michael@0 30 // This is an ok way to check this because we will make sure that the text
michael@0 31 // field is parsable.
michael@0 32 let val = gBrowser.selectedBrowser.contentDocument.getElementById("sessionData").value;
michael@0 33 try {
michael@0 34 JSON.parse(val);
michael@0 35 ok(true, "JSON.parse succeeded");
michael@0 36 }
michael@0 37 catch (e) {
michael@0 38 ok(false, "JSON.parse failed");
michael@0 39 }
michael@0 40 cleanup();
michael@0 41 }
michael@0 42
michael@0 43 function cleanup() {
michael@0 44 ss.setBrowserState(stateBackup);
michael@0 45 executeSoon(finish);
michael@0 46 }

mercurial