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