browser_393716.js
Go to the documentation of this file.
1 function test() {
4  // set up the basics (SessionStore service, tabbrowser)
5  try {
6  var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
7  }
8  catch (ex) { }
9  ok(ss, "SessionStore service is available");
10  let tabbrowser = getBrowser();
12 
14  // getTabState //
16  let key = "Unique key: " + Date.now();
17  let value = "Unique value: " + Math.random();
18  let testURL = "about:config";
19 
20  // create a new tab
21  let tab = tabbrowser.addTab(testURL);
22  ss.setTabValue(tab, key, value);
23  tab.linkedBrowser.addEventListener("load", function(aEvent) {
24  // get the tab's state
25  let state = ss.getTabState(tab);
26  ok(state, "get the tab's state");
27 
28  // verify the tab state's integrity
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)");
36 
37  // clean up
38  tabbrowser.removeTab(tab);
39  }, true);
40 
42  // setTabState and duplicateTab //
44  let key2 = "key2";
45  let value2 = "Value " + Math.random();
46  let value3 = "Another value: " + Date.now();
47  let state = { entries: [{ url: testURL }], extData: { key2: value2 } };
48 
49  // create a new tab
50  let tab2 = tabbrowser.addTab();
51  // set the tab's state
52  ss.setTabState(tab2, state.toSource());
53  tab2.linkedBrowser.addEventListener("load", function(aEvent) {
54  // verify the correctness of the restored tab
55  ok(ss.getTabValue(tab2, key2) == value2 && this.currentURI.spec == testURL,
56  "the tab's state was correctly restored");
57 
58  // add text data
59  let textbox = this.contentDocument.getElementById("textbox");
60  textbox.wrappedJSObject.value = value3;
61 
62  // duplicate the tab
63  let duplicateTab = ss.duplicateTab(window, tab2);
64  tabbrowser.removeTab(tab2);
65 
66  duplicateTab.linkedBrowser.addEventListener("load", function(aEvent) {
67  // verify the correctness of the duplicated tab
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");
72 
73  // clean up
74  tabbrowser.removeTab(duplicateTab);
75  finish();
76  }, true);
77  }, true);
78 }
const Cc
function test()
function getBrowser() gBrowser
var tab
let window
var tabbrowser
waitForExplicitFinish()
var testURL
var tab2
function url(spec)
countRef value
Definition: FeedWriter.js:1423
const Ci