|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
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 |
|
20 |
|
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))]}; |
|
25 |
|
26 function createEntry(sessionData) { |
|
27 return { |
|
28 url: "about:sessionrestore", |
|
29 formdata: {id: {sessionData: sessionData}} |
|
30 }; |
|
31 } |
|
32 |
|
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); |
|
38 |
|
39 // test 1 |
|
40 ss.setTabState(tab, JSON.stringify(STATE)); |
|
41 yield promiseTabRestored(tab); |
|
42 checkState("test1", tab); |
|
43 |
|
44 // test 2 |
|
45 ss.setTabState(tab, JSON.stringify(STATE2)); |
|
46 yield promiseTabRestored(tab); |
|
47 checkState("test2", tab); |
|
48 |
|
49 // test 3 |
|
50 ss.setTabState(tab, JSON.stringify(STATE3)); |
|
51 yield promiseTabRestored(tab); |
|
52 checkState("test3", tab); |
|
53 |
|
54 // Cleanup. |
|
55 gBrowser.removeTab(tab); |
|
56 }); |
|
57 |
|
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)); |
|
62 |
|
63 ok(formdata.id["sessionData"], prefix + ": we have form data for about:sessionrestore"); |
|
64 |
|
65 let sessionData_raw = JSON.stringify(formdata.id["sessionData"]); |
|
66 ok(!/\\/.test(sessionData_raw), prefix + ": #sessionData contains no backslashes"); |
|
67 info(sessionData_raw); |
|
68 |
|
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 } |