|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const testState = { |
|
5 windows: [{ |
|
6 tabs: [ |
|
7 { entries: [{ url: "about:blank" }] }, |
|
8 ] |
|
9 }], |
|
10 scratchpads: [ |
|
11 { text: "text1", executionContext: 1 }, |
|
12 { text: "", executionContext: 2, filename: "test.js" } |
|
13 ] |
|
14 }; |
|
15 |
|
16 // only finish() when correct number of windows opened |
|
17 var restored = []; |
|
18 function addState(state) { |
|
19 restored.push(state); |
|
20 |
|
21 if (restored.length == testState.scratchpads.length) { |
|
22 ok(statesMatch(restored, testState.scratchpads), |
|
23 "Two scratchpad windows restored"); |
|
24 |
|
25 Services.ww.unregisterNotification(windowObserver); |
|
26 finish(); |
|
27 } |
|
28 } |
|
29 |
|
30 function test() { |
|
31 waitForExplicitFinish(); |
|
32 |
|
33 Services.ww.registerNotification(windowObserver); |
|
34 |
|
35 ss.setBrowserState(JSON.stringify(testState)); |
|
36 } |
|
37 |
|
38 function windowObserver(aSubject, aTopic, aData) { |
|
39 if (aTopic == "domwindowopened") { |
|
40 let win = aSubject.QueryInterface(Ci.nsIDOMWindow); |
|
41 win.addEventListener("load", function onLoad() { |
|
42 win.removeEventListener("load", onLoad, false); |
|
43 |
|
44 if (win.Scratchpad) { |
|
45 win.Scratchpad.addObserver({ |
|
46 onReady: function() { |
|
47 win.Scratchpad.removeObserver(this); |
|
48 |
|
49 let state = win.Scratchpad.getState(); |
|
50 win.close(); |
|
51 addState(state); |
|
52 }, |
|
53 }); |
|
54 } |
|
55 }, false); |
|
56 } |
|
57 } |
|
58 |
|
59 function statesMatch(restored, states) { |
|
60 return states.every(function(state) { |
|
61 return restored.some(function(restoredState) { |
|
62 return state.filename == restoredState.filename && |
|
63 state.text == restoredState.text && |
|
64 state.executionContext == restoredState.executionContext; |
|
65 }) |
|
66 }); |
|
67 } |