|
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/. */ |
|
4 |
|
5 let stateBackup = ss.getBrowserState(); |
|
6 |
|
7 function test() { |
|
8 /** Test for bug 581593 **/ |
|
9 waitForExplicitFinish(); |
|
10 ignoreAllUncaughtExceptions(); |
|
11 |
|
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] }] }] }; |
|
18 |
|
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); |
|
22 |
|
23 ss.setBrowserState(JSON.stringify(state)); |
|
24 } |
|
25 |
|
26 function onSSTabRestored(aEvent) { |
|
27 info("SSTabRestored event"); |
|
28 gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true); |
|
29 |
|
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 } |
|
42 |
|
43 function cleanup() { |
|
44 ss.setBrowserState(stateBackup); |
|
45 executeSoon(finish); |
|
46 } |