browser/components/sessionstore/test/browser_467409-backslashplosion.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 "use strict";
     6 // Test Summary:
     7 // 1.  Open about:sessionrestore where formdata is a JS object, not a string
     8 // 1a. Check that #sessionData on the page is readable after JSON.parse (skipped, checking formdata is sufficient)
     9 // 1b. Check that there are no backslashes in the formdata
    10 // 1c. Check that formdata doesn't require JSON.parse
    11 //
    12 // 2.  Use the current state (currently about:sessionrestore with data) and then open that in a new instance of about:sessionrestore
    13 // 2a. Check that there are no backslashes in the formdata
    14 // 2b. Check that formdata doesn't require JSON.parse
    15 //
    16 // 3.  [backwards compat] Use a stringified state as formdata when opening about:sessionrestore
    17 // 3a. Make sure there are nodes in the tree on about:sessionrestore (skipped, checking formdata is sufficient)
    18 // 3b. Check that there are no backslashes in the formdata
    19 // 3c. Check that formdata doesn't require JSON.parse
    21 const CRASH_STATE = {windows: [{tabs: [{entries: [{url: "about:mozilla" }]}]}]};
    22 const STATE = {entries: [createEntry(CRASH_STATE)]};
    23 const STATE2 = {entries: [createEntry({windows: [{tabs: [STATE]}]})]};
    24 const STATE3 = {entries: [createEntry(JSON.stringify(CRASH_STATE))]};
    26 function createEntry(sessionData) {
    27   return {
    28     url: "about:sessionrestore",
    29     formdata: {id: {sessionData: sessionData}}
    30   };
    31 }
    33 add_task(function test_nested_about_sessionrestore() {
    34   // Prepare a blank tab.
    35   let tab = gBrowser.addTab("about:blank");
    36   let browser = tab.linkedBrowser;
    37   yield promiseBrowserLoaded(browser);
    39   // test 1
    40   ss.setTabState(tab, JSON.stringify(STATE));
    41   yield promiseTabRestored(tab);
    42   checkState("test1", tab);
    44   // test 2
    45   ss.setTabState(tab, JSON.stringify(STATE2));
    46   yield promiseTabRestored(tab);
    47   checkState("test2", tab);
    49   // test 3
    50   ss.setTabState(tab, JSON.stringify(STATE3));
    51   yield promiseTabRestored(tab);
    52   checkState("test3", tab);
    54   // Cleanup.
    55   gBrowser.removeTab(tab);
    56 });
    58 function checkState(prefix, tab) {
    59   // Flush and query tab state.
    60   SyncHandlers.get(tab.linkedBrowser).flush();
    61   let {formdata} = JSON.parse(ss.getTabState(tab));
    63   ok(formdata.id["sessionData"], prefix + ": we have form data for about:sessionrestore");
    65   let sessionData_raw = JSON.stringify(formdata.id["sessionData"]);
    66   ok(!/\\/.test(sessionData_raw), prefix + ": #sessionData contains no backslashes");
    67   info(sessionData_raw);
    69   let gotError = false;
    70   try {
    71     JSON.parse(formdata.id["sessionData"]);
    72   } catch (e) {
    73     info(prefix + ": got error: " + e);
    74     gotError = true;
    75   }
    76   ok(gotError, prefix + ": attempting to JSON.parse form data threw error");
    77 }

mercurial