1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_644409-scratchpads.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 + /* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const testState = { 1.8 + windows: [{ 1.9 + tabs: [ 1.10 + { entries: [{ url: "about:blank" }] }, 1.11 + ] 1.12 + }], 1.13 + scratchpads: [ 1.14 + { text: "text1", executionContext: 1 }, 1.15 + { text: "", executionContext: 2, filename: "test.js" } 1.16 + ] 1.17 +}; 1.18 + 1.19 +// only finish() when correct number of windows opened 1.20 +var restored = []; 1.21 +function addState(state) { 1.22 + restored.push(state); 1.23 + 1.24 + if (restored.length == testState.scratchpads.length) { 1.25 + ok(statesMatch(restored, testState.scratchpads), 1.26 + "Two scratchpad windows restored"); 1.27 + 1.28 + Services.ww.unregisterNotification(windowObserver); 1.29 + finish(); 1.30 + } 1.31 +} 1.32 + 1.33 +function test() { 1.34 + waitForExplicitFinish(); 1.35 + 1.36 + Services.ww.registerNotification(windowObserver); 1.37 + 1.38 + ss.setBrowserState(JSON.stringify(testState)); 1.39 +} 1.40 + 1.41 +function windowObserver(aSubject, aTopic, aData) { 1.42 + if (aTopic == "domwindowopened") { 1.43 + let win = aSubject.QueryInterface(Ci.nsIDOMWindow); 1.44 + win.addEventListener("load", function onLoad() { 1.45 + win.removeEventListener("load", onLoad, false); 1.46 + 1.47 + if (win.Scratchpad) { 1.48 + win.Scratchpad.addObserver({ 1.49 + onReady: function() { 1.50 + win.Scratchpad.removeObserver(this); 1.51 + 1.52 + let state = win.Scratchpad.getState(); 1.53 + win.close(); 1.54 + addState(state); 1.55 + }, 1.56 + }); 1.57 + } 1.58 + }, false); 1.59 + } 1.60 +} 1.61 + 1.62 +function statesMatch(restored, states) { 1.63 + return states.every(function(state) { 1.64 + return restored.some(function(restoredState) { 1.65 + return state.filename == restoredState.filename && 1.66 + state.text == restoredState.text && 1.67 + state.executionContext == restoredState.executionContext; 1.68 + }) 1.69 + }); 1.70 +}