2008-08-26 08:30:56 -07:00
|
|
|
function test() {
|
|
|
|
/** Test for Bug 393716 **/
|
2011-06-25 14:38:31 -07:00
|
|
|
|
2008-08-26 08:30:56 -07:00
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
// getTabState //
|
|
|
|
/////////////////
|
2011-04-13 06:35:06 -07:00
|
|
|
let key = "Unique key: " + Date.now();
|
2008-08-26 08:30:56 -07:00
|
|
|
let value = "Unique value: " + Math.random();
|
|
|
|
let testURL = "about:config";
|
|
|
|
|
|
|
|
// create a new tab
|
2011-06-25 14:38:31 -07:00
|
|
|
let tab = gBrowser.addTab(testURL);
|
2008-08-26 08:30:56 -07:00
|
|
|
ss.setTabValue(tab, key, value);
|
|
|
|
tab.linkedBrowser.addEventListener("load", function(aEvent) {
|
2009-10-13 06:31:53 -07:00
|
|
|
this.removeEventListener("load", arguments.callee, true);
|
2008-08-26 08:30:56 -07:00
|
|
|
// get the tab's state
|
|
|
|
let state = ss.getTabState(tab);
|
|
|
|
ok(state, "get the tab's state");
|
|
|
|
|
|
|
|
// verify the tab state's integrity
|
2010-06-09 13:55:45 -07:00
|
|
|
state = JSON.parse(state);
|
2008-08-26 08:30:56 -07:00
|
|
|
ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0,
|
|
|
|
"state object seems valid");
|
|
|
|
ok(state.entries.length == 1 && state.entries[0].url == testURL,
|
|
|
|
"Got the expected state object (test URL)");
|
|
|
|
ok(state.extData && state.extData[key] == value,
|
|
|
|
"Got the expected state object (test manually set tab value)");
|
|
|
|
|
|
|
|
// clean up
|
2011-06-25 14:38:31 -07:00
|
|
|
gBrowser.removeTab(tab);
|
2008-08-26 08:30:56 -07:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// setTabState and duplicateTab //
|
|
|
|
//////////////////////////////////
|
|
|
|
let key2 = "key2";
|
|
|
|
let value2 = "Value " + Math.random();
|
2011-04-13 06:35:06 -07:00
|
|
|
let value3 = "Another value: " + Date.now();
|
2008-08-26 08:30:56 -07:00
|
|
|
let state = { entries: [{ url: testURL }], extData: { key2: value2 } };
|
|
|
|
|
|
|
|
// create a new tab
|
2011-06-25 14:38:31 -07:00
|
|
|
let tab2 = gBrowser.addTab();
|
2008-08-26 08:30:56 -07:00
|
|
|
// set the tab's state
|
2010-06-09 13:55:45 -07:00
|
|
|
ss.setTabState(tab2, JSON.stringify(state));
|
2008-08-26 08:30:56 -07:00
|
|
|
tab2.linkedBrowser.addEventListener("load", function(aEvent) {
|
2009-10-13 06:31:53 -07:00
|
|
|
this.removeEventListener("load", arguments.callee, true);
|
2008-08-26 08:30:56 -07:00
|
|
|
// verify the correctness of the restored tab
|
|
|
|
ok(ss.getTabValue(tab2, key2) == value2 && this.currentURI.spec == testURL,
|
|
|
|
"the tab's state was correctly restored");
|
|
|
|
|
|
|
|
// add text data
|
|
|
|
let textbox = this.contentDocument.getElementById("textbox");
|
2010-10-10 15:48:39 -07:00
|
|
|
textbox.value = value3;
|
2008-08-26 08:30:56 -07:00
|
|
|
|
|
|
|
// duplicate the tab
|
|
|
|
let duplicateTab = ss.duplicateTab(window, tab2);
|
2011-06-25 14:38:31 -07:00
|
|
|
gBrowser.removeTab(tab2);
|
2008-08-26 08:30:56 -07:00
|
|
|
|
|
|
|
duplicateTab.linkedBrowser.addEventListener("load", function(aEvent) {
|
2009-10-13 06:31:53 -07:00
|
|
|
this.removeEventListener("load", arguments.callee, true);
|
2008-08-26 08:30:56 -07:00
|
|
|
// verify the correctness of the duplicated tab
|
|
|
|
ok(ss.getTabValue(duplicateTab, key2) == value2 && this.currentURI.spec == testURL,
|
|
|
|
"correctly duplicated the tab's state");
|
|
|
|
let textbox = this.contentDocument.getElementById("textbox");
|
2010-10-10 15:48:39 -07:00
|
|
|
is(textbox.value, value3, "also duplicated text data");
|
2008-08-26 08:30:56 -07:00
|
|
|
|
|
|
|
// clean up
|
2011-06-25 14:38:31 -07:00
|
|
|
gBrowser.removeTab(duplicateTab);
|
2008-08-26 08:30:56 -07:00
|
|
|
finish();
|
|
|
|
}, true);
|
|
|
|
}, true);
|
|
|
|
}
|