41 function test(aLambda) {
43 return aLambda() ||
true;
49 "//input[@name='input']": Date.now().toString(),
50 "//input[@name='spaced 1']": Math.random().toString(),
51 "//input[3]":
"three",
52 "//input[@type='checkbox']":
true,
53 "//input[@name='uncheck']":
false,
54 "//input[@type='radio'][1]":
false,
55 "//input[@type='radio'][2]":
true,
56 "//input[@type='radio'][3]":
false,
58 "//select[@multiple]": [1, 3],
60 "//textarea[2]":
"Some text... " + Math.random(),
61 "//textarea[3]":
"Some more text\n" +
new Date(),
62 "//input[@type='file']":
"/dev/null"
65 function getElementByXPath(
aTab, aQuery) {
66 let
doc =
aTab.linkedBrowser.contentDocument;
67 let xptype =
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
68 return doc.evaluate(aQuery, doc,
null, xptype,
null).singleNodeValue;
72 let
node = getElementByXPath(
aTab, aQuery);
73 if (typeof
aValue ==
"string")
75 else if (typeof
aValue ==
"boolean")
77 else if (typeof
aValue ==
"number")
78 node.selectedIndex =
aValue;
80 Array.forEach(node.options,
function(aOpt,
aIx)
81 (aOpt.selected =
aValue.indexOf(
aIx) > -1));
84 function compareFormValue(
aTab, aQuery,
aValue) {
85 let
node = getElementByXPath(
aTab, aQuery);
88 if (node instanceof
Ci.nsIDOMHTMLInputElement)
89 return aValue == (node.type ==
"checkbox" || node.type ==
"radio" ?
90 node.checked : node.value);
91 if (node instanceof
Ci.nsIDOMHTMLTextAreaElement)
92 return aValue == node.value;
94 return aValue == node.selectedIndex;
95 return Array.every(node.options,
function(aOpt,
aIx)
96 (
aValue.indexOf(
aIx) > -1) == aOpt.selected);
103 let
pb =
Cc[
"@mozilla.org/privatebrowsing;1"].
105 gPrefService.setBoolPref(
"browser.privatebrowsing.keep_current_session",
true);
108 let ss =
test(
function()
Cc[
"@mozilla.org/browser/sessionstore;1"].
115 const testURL =
"chrome://mochikit/content/browser/" +
116 "browser/components/sessionstore/test/browser/browser_248970_b_sample.html";
117 const testURL2 =
"http://localhost:8888/browser/" +
118 "browser/components/sessionstore/test/browser/browser_248970_b_sample.html";
122 let max_tabs_undo =
gPrefService.getIntPref(
"browser.sessionstore.max_tabs_undo");
123 ok(0 <= count && count <= max_tabs_undo,
124 "getClosedTabCount should return zero or at most max_tabs_undo");
128 let
value =
"Value " + Math.random();
129 let state = { entries: [{
url:
testURL }], extData: { key: value } };
132 tab_A = gBrowser.addTab(
testURL);
133 ss.setTabState(tab_A, state.toSource());
134 tab_A.linkedBrowser.addEventListener(
"load",
function(aEvent) {
138 gPrefService.setIntPref(
"browser.sessionstore.max_tabs_undo", max_tabs_undo + 1)
141 for (let
i in fieldList)
142 setFormValue(tab_A,
i, fieldList[
i]);
145 gBrowser.removeTab(tab_A);
148 ok(ss.getClosedTabCount(
window) >
count,
"getClosedTabCount has increased after closing a tab");
151 let tab_A_restored =
test(
function() ss.undoCloseTab(
window, 0));
152 ok(tab_A_restored,
"a tab is in undo list");
153 tab_A_restored.linkedBrowser.addEventListener(
"load",
function(aEvent) {
156 is(
testURL, this.currentURI.spec,
"it's the same tab that we expect");
157 gBrowser.removeTab(tab_A_restored);
160 pb.privateBrowsingEnabled =
true;
161 ok(pb.privateBrowsingEnabled,
"private browsing enabled");
165 let value1 =
"Value " + Math.random();
166 let state1 = { entries: [{
url: testURL2 }], extData: { key1: value1 } };
169 tab_B = gBrowser.addTab(testURL2);
170 ss.setTabState(tab_B, state1.toSource());
171 tab_B.linkedBrowser.addEventListener(
"load",
function(aEvent) {
175 for (let item in fieldList)
176 setFormValue(tab_B, item, fieldList[item]);
179 let tab_C = gBrowser.duplicateTab(tab_B);
180 tab_C.linkedBrowser.addEventListener(
"load",
function(aEvent) {
184 is(ss.getTabValue(tab_C, key1), value1,
185 "tab successfully duplicated - correct state");
187 for (let item in fieldList)
188 ok(compareFormValue(tab_C, item, fieldList[item]),
189 "The value for \"" + item +
"\" was correctly duplicated");
192 gBrowser.removeTab(tab_C);
193 gBrowser.removeTab(tab_B);
196 pb.privateBrowsingEnabled =
false;
197 ok(!pb.privateBrowsingEnabled,
"private browsing disabled");
200 if (
gPrefService.prefHasUserValue(
"browser.privatebrowsing.keep_current_session"))
201 gPrefService.clearUserPref(
"browser.privatebrowsing.keep_current_session");
function doc() browser.contentDocument
getService(Ci.sbIFaceplateManager)
restoreHistoryPrecursor aIx
return!aWindow arguments!aWindow arguments[0]
_replaceLoadingTitle aTab
this removeEventListener("load", this.__SS_restore, true)
_getSelectedPageStyle s i