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.

     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/. */
     5 let stateBackup = ss.getBrowserState();
     7 function test() {
     8   /** Test for bug 581593 **/
     9   waitForExplicitFinish();
    10   ignoreAllUncaughtExceptions();
    12   let oldState = { windows: [{ tabs: [{ entries: [{ url: "example.com" }] }] }]};
    13   let pageData = {
    14     url: "about:sessionrestore",
    15     formdata: { id: { "sessionData": "(" + JSON.stringify(oldState) + ")" } }
    16   };
    17   let state = { windows: [{ tabs: [{ entries: [pageData] }] }] };
    19   // The form data will be restored before SSTabRestored, so we want to listen
    20   // for that on the currently selected tab (it will be reused)
    21   gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true);
    23   ss.setBrowserState(JSON.stringify(state));
    24 }
    26 function onSSTabRestored(aEvent) {
    27   info("SSTabRestored event");
    28   gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true);
    30   // This is an ok way to check this because we will make sure that the text
    31   // field is parsable.
    32   let val = gBrowser.selectedBrowser.contentDocument.getElementById("sessionData").value;
    33   try {
    34     JSON.parse(val);
    35     ok(true, "JSON.parse succeeded");
    36   }
    37   catch (e) {
    38     ok(false, "JSON.parse failed");
    39   }
    40   cleanup();
    41 }
    43 function cleanup() {
    44   ss.setBrowserState(stateBackup);
    45   executeSoon(finish);
    46 }

mercurial