6 var ss =
Cc[
"@mozilla.org/browser/sessionstore;1"].getService(
Ci.nsISessionStore);
9 ok(ss,
"SessionStore service is available");
16 let
key =
"Unique key: " + Date.now();
17 let
value =
"Unique value: " + Math.random();
21 let
tab = tabbrowser.addTab(testURL);
22 ss.setTabValue(tab, key, value);
23 tab.linkedBrowser.addEventListener(
"load",
function(aEvent) {
25 let state = ss.getTabState(tab);
26 ok(state,
"get the tab's state");
29 state = eval(
"(" + state +
")");
30 ok(state instanceof Object && state.entries instanceof
Array && state.entries.length > 0,
31 "state object seems valid");
32 ok(state.entries.length == 1 && state.entries[0].url == testURL,
33 "Got the expected state object (test URL)");
34 ok(state.extData && state.extData[key] == value,
35 "Got the expected state object (test manually set tab value)");
38 tabbrowser.removeTab(tab);
45 let value2 =
"Value " + Math.random();
46 let value3 =
"Another value: " + Date.now();
47 let state = { entries: [{
url: testURL }], extData: { key2: value2 } };
50 let
tab2 = tabbrowser.addTab();
52 ss.setTabState(tab2, state.toSource());
53 tab2.linkedBrowser.addEventListener(
"load",
function(aEvent) {
55 ok(ss.getTabValue(tab2, key2) == value2 && this.currentURI.spec ==
testURL,
56 "the tab's state was correctly restored");
59 let textbox = this.contentDocument.getElementById(
"textbox");
60 textbox.wrappedJSObject.value = value3;
63 let duplicateTab = ss.duplicateTab(
window, tab2);
64 tabbrowser.removeTab(tab2);
66 duplicateTab.linkedBrowser.addEventListener(
"load",
function(aEvent) {
68 ok(ss.getTabValue(duplicateTab, key2) == value2 && this.currentURI.spec ==
testURL,
69 "correctly duplicated the tab's state");
70 let textbox = this.contentDocument.getElementById(
"textbox");
71 is(textbox.wrappedJSObject.value, value3,
"also duplicated text data");
74 tabbrowser.removeTab(duplicateTab);
function getBrowser() gBrowser