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