2011-11-02 12:32:55 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
const testState = {
|
|
|
|
windows: [{
|
|
|
|
tabs: [
|
|
|
|
{ entries: [{ url: "about:blank" }] },
|
|
|
|
]
|
|
|
|
}],
|
2013-09-05 12:39:56 -07:00
|
|
|
scratchpads: [
|
|
|
|
{ text: "text1", executionContext: 1 },
|
|
|
|
{ text: "", executionContext: 2, filename: "test.js" }
|
|
|
|
]
|
2011-11-02 12:32:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// only finish() when correct number of windows opened
|
|
|
|
var restored = [];
|
|
|
|
function addState(state) {
|
|
|
|
restored.push(state);
|
|
|
|
|
2013-09-05 12:39:56 -07:00
|
|
|
if (restored.length == testState.scratchpads.length) {
|
|
|
|
ok(statesMatch(restored, testState.scratchpads),
|
2011-11-02 12:32:55 -07:00
|
|
|
"Two scratchpad windows restored");
|
|
|
|
|
|
|
|
Services.ww.unregisterNotification(windowObserver);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
Services.ww.registerNotification(windowObserver);
|
|
|
|
|
|
|
|
ss.setBrowserState(JSON.stringify(testState));
|
|
|
|
}
|
|
|
|
|
|
|
|
function windowObserver(aSubject, aTopic, aData) {
|
2012-05-25 14:39:22 -07:00
|
|
|
if (aTopic == "domwindowopened") {
|
2011-11-02 12:32:55 -07:00
|
|
|
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
2011-12-10 09:03:57 -08:00
|
|
|
win.addEventListener("load", function onLoad() {
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
|
|
|
|
2011-11-02 12:32:55 -07:00
|
|
|
if (win.Scratchpad) {
|
2011-12-10 09:03:57 -08:00
|
|
|
win.Scratchpad.addObserver({
|
|
|
|
onReady: function() {
|
|
|
|
win.Scratchpad.removeObserver(this);
|
|
|
|
|
|
|
|
let state = win.Scratchpad.getState();
|
|
|
|
win.close();
|
|
|
|
addState(state);
|
|
|
|
},
|
|
|
|
});
|
2011-11-02 12:32:55 -07:00
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function statesMatch(restored, states) {
|
|
|
|
return states.every(function(state) {
|
|
|
|
return restored.some(function(restoredState) {
|
|
|
|
return state.filename == restoredState.filename &&
|
|
|
|
state.text == restoredState.text &&
|
|
|
|
state.executionContext == restoredState.executionContext;
|
|
|
|
})
|
|
|
|
});
|
2011-12-10 09:03:57 -08:00
|
|
|
}
|