42 let ss =
Cc[
"@mozilla.org/browser/sessionstore;1"].getService(
Ci.nsISessionStore);
43 let
pb =
Cc[
"@mozilla.org/privatebrowsing;1"].getService(
Ci.nsIPrivateBrowsingService);
49 let uniqueKey =
"bug 394759";
50 let uniqueValue =
"unik" + Date.now();
51 let uniqueText =
"pi != " + Math.random();
55 let max_windows_undo =
gPrefService.getIntPref(
"browser.sessionstore.max_windows_undo");
56 gPrefService.setIntPref(
"browser.sessionstore.max_windows_undo", max_windows_undo + 1);
57 let closedWindowCount = ss.getClosedWindowCount();
59 let newWin = openDialog(location,
"_blank",
"chrome,all,dialog=no", testURL);
60 newWin.addEventListener(
"load",
function(aEvent) {
61 newWin.removeEventListener(
"load",
arguments.callee,
false);
62 newWin.gBrowser.addEventListener(
"load",
function(aEvent) {
63 newWin.gBrowser.removeEventListener(
"load",
arguments.callee,
true);
65 executeSoon(
function() {
66 newWin.gBrowser.addTab();
67 executeSoon(
function() {
69 ss.setWindowValue(newWin, uniqueKey, uniqueValue);
70 let textbox = newWin.content.document.getElementById(
"textbox");
71 textbox.wrappedJSObject.value = uniqueText;
75 is(ss.getClosedWindowCount(), closedWindowCount + 1,
76 "The closed window was added to Recently Closed Windows");
77 let
data =
JSON.parse(ss.getClosedWindowData())[0];
78 ok(data.title == testURL && data.toSource().indexOf(uniqueText) > -1,
79 "The closed window data was stored correctly");
82 let newWin2 = ss.undoCloseWindow(0);
84 ok(newWin2 instanceof ChromeWindow,
85 "undoCloseWindow actually returned a window");
86 is(ss.getClosedWindowCount(), closedWindowCount,
87 "The reopened window was removed from Recently Closed Windows");
89 newWin2.addEventListener(
"load",
function(aEvent) {
90 newWin2.gBrowser.addEventListener(
"SSTabRestored",
function(aEvent) {
91 newWin2.gBrowser.removeEventListener(
"SSTabRestored",
arguments.callee,
true);
93 is(newWin2.gBrowser.tabContainer.childNodes.length, 2,
94 "The window correctly restored 2 tabs");
95 is(newWin2.gBrowser.currentURI.spec, testURL,
96 "The window correctly restored the URL");
98 let textbox = newWin2.content.document.getElementById(
"textbox");
99 is(textbox.wrappedJSObject.value, uniqueText,
100 "The window correctly restored the form");
101 is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue,
102 "The window correctly restored the data associated with it");
106 if (
gPrefService.prefHasUserValue(
"browser.sessionstore.max_windows_undo"))
107 gPrefService.clearUserPref(
"browser.sessionstore.max_windows_undo");
119 function openWindowRec(windowsToOpen, expectedResults, recCallback) {
121 if (!windowsToOpen.length) {
122 let closedWindowData =
JSON.parse(ss.getClosedWindowData());
123 let numPopups = closedWindowData.filter(
function(el,
i, arr) {
126 let numNormal = ss.getClosedWindowCount() - numPopups;
128 let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
129 : expectedResults.other;
130 is(numPopups, oResults.popup,
131 "There were " + oResults.popup +
" popup windows to repoen");
132 is(numNormal, oResults.normal,
133 "There were " + oResults.normal +
" normal windows to repoen");
136 executeSoon(recCallback);
140 let
winData = windowsToOpen.shift();
141 let
settings =
"chrome,dialog=no," +
142 (winData.isPopup ?
"all=no" :
"all");
143 let
url =
"http://window" + windowsToOpen.length +
".example.com";
144 let
window = openDialog(location,
"_blank", settings, url);
145 window.addEventListener(
"load",
function(aEvent) {
146 window.gBrowser.addEventListener(
"load",
function(aEvent) {
150 window.gBrowser.addTab();
151 window.gBrowser.removeEventListener(
"load",
arguments.callee,
true);
152 executeSoon(
function() {
154 executeSoon(
function() {
155 openWindowRec(windowsToOpen, expectedResults, recCallback);
162 let windowsToOpen = [{isPopup:
false},
167 let expectedResults = {mac: {popup: 3, normal: 0},
168 other: {popup: 3, normal: 1}};
169 let windowsToOpen2 = [{isPopup:
false},
174 let expectedResults2 = {mac: {popup: 0, normal: 3},
175 other: {popup: 0, normal: 3}};
176 openWindowRec(windowsToOpen, expectedResults,
function() {
177 openWindowRec(windowsToOpen2, expectedResults2,
callback);
183 function countClosedTabsByTitle(aClosedTabList, aTitle)
184 aClosedTabList.filter(
function(
aData)
aData.title == aTitle).length;
186 function countOpenTabsByTitle(aOpenTabList, aTitle)
187 aOpenTabList.filter(
function(
aData)
aData.entries.some(
function(aEntry) aEntry.title == aTitle) ).length
190 let oldState = ss.getBrowserState();
192 const REMEMBER = Date.now(), FORGET = Math.random();
194 windows: [ {
tabs: [{ entries: [{
url:
"http://example.com/" }] }], selected: 1 } ],
199 { entries: [{
url:
"http://example.com/", title: REMEMBER }] },
200 { entries: [{
url:
"http://mozilla.org/", title: FORGET }] }
203 title:
"mozilla.org",
209 { entries: [{
url:
"http://mozilla.org/", title: FORGET }] },
210 { entries: [{
url:
"http://example.com/", title: REMEMBER }] },
211 { entries: [{
url:
"http://example.com/", title: REMEMBER }] },
212 { entries: [{
url:
"http://mozilla.org/", title: FORGET }] },
213 { entries: [{
url:
"http://example.com/", title: REMEMBER }] }
221 { entries: [{
url:
"http://example.com/", title: REMEMBER }] }
228 {
url:
"http://mozilla.org/", title: FORGET },
229 {
url:
"http://mozilla.org/again", title:
"doesn't matter" }
238 {
url:
"http://example.com", title: REMEMBER }
249 ss.setBrowserState(
JSON.stringify(testState));
252 pb.removeDataFromDomain(
"mozilla.org");
254 let closedWindowData =
JSON.parse(ss.getClosedWindowData());
257 let
window = closedWindowData[0];
258 is(window.tabs.length, 1,
"1 tab was removed");
259 is(countOpenTabsByTitle(window.tabs, FORGET), 0,
260 "The correct tab was removed");
261 is(countOpenTabsByTitle(window.tabs, REMEMBER), 1,
262 "The correct tab was remembered");
263 is(window.selected, 1,
"Selected tab has changed");
264 is(window.title, REMEMBER,
"The window title was correctly updated");
267 window = closedWindowData[1];
268 is(window.tabs.length, 3,
"2 tabs were removed");
269 is(countOpenTabsByTitle(window.tabs, FORGET), 0,
270 "The correct tabs were removed");
271 is(countOpenTabsByTitle(window.tabs, REMEMBER), 3,
272 "The correct tabs were remembered");
273 is(window.selected, 3,
"Selected tab has changed");
274 is(window.title, REMEMBER,
"The window title was correctly updated");
277 window = closedWindowData[2];
278 is(countClosedTabsByTitle(window._closedTabs, REMEMBER), 1,
279 "The correct number of tabs were removed, and the correct ones");
280 is(countClosedTabsByTitle(window._closedTabs, FORGET), 0,
281 "All tabs to be forgotten were indeed removed");
284 ss.setBrowserState(oldState);
288 test_basic(
function() {
289 test_behavior(
function() {
290 test_purge(
function() {
_dialogDatepicker settings
return!aWindow arguments!aWindow arguments[0]
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData