michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const testState = { michael@0: windows: [{ michael@0: tabs: [ michael@0: { entries: [{ url: "about:blank" }] }, michael@0: ] michael@0: }], michael@0: scratchpads: [ michael@0: { text: "text1", executionContext: 1 }, michael@0: { text: "", executionContext: 2, filename: "test.js" } michael@0: ] michael@0: }; michael@0: michael@0: // only finish() when correct number of windows opened michael@0: var restored = []; michael@0: function addState(state) { michael@0: restored.push(state); michael@0: michael@0: if (restored.length == testState.scratchpads.length) { michael@0: ok(statesMatch(restored, testState.scratchpads), michael@0: "Two scratchpad windows restored"); michael@0: michael@0: Services.ww.unregisterNotification(windowObserver); michael@0: finish(); michael@0: } michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.ww.registerNotification(windowObserver); michael@0: michael@0: ss.setBrowserState(JSON.stringify(testState)); michael@0: } michael@0: michael@0: function windowObserver(aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowopened") { michael@0: let win = aSubject.QueryInterface(Ci.nsIDOMWindow); michael@0: win.addEventListener("load", function onLoad() { michael@0: win.removeEventListener("load", onLoad, false); michael@0: michael@0: if (win.Scratchpad) { michael@0: win.Scratchpad.addObserver({ michael@0: onReady: function() { michael@0: win.Scratchpad.removeObserver(this); michael@0: michael@0: let state = win.Scratchpad.getState(); michael@0: win.close(); michael@0: addState(state); michael@0: }, michael@0: }); michael@0: } michael@0: }, false); michael@0: } michael@0: } michael@0: michael@0: function statesMatch(restored, states) { michael@0: return states.every(function(state) { michael@0: return restored.some(function(restoredState) { michael@0: return state.filename == restoredState.filename && michael@0: state.text == restoredState.text && michael@0: state.executionContext == restoredState.executionContext; michael@0: }) michael@0: }); michael@0: }