2011-02-19 10:22:49 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
let newTabOne;
|
|
|
|
let newTabTwo;
|
2011-02-28 20:07:00 -08:00
|
|
|
let newTabThree;
|
2010-11-30 00:15:51 -08:00
|
|
|
let restoredNewTabTwoLoaded = false;
|
2011-02-28 20:07:00 -08:00
|
|
|
let restoredNewTabThreeLoaded = false;
|
2010-11-30 00:15:51 -08:00
|
|
|
let frameInitialized = false;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
2011-02-19 10:22:49 -08:00
|
|
|
newWindowWithTabView(setupOne);
|
2010-11-30 00:15:51 -08:00
|
|
|
}
|
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
function setupOne(win) {
|
|
|
|
win.TabView.firstUseExperienced = true;
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
win.gBrowser.addTab("http://mochi.test:8888/browser/browser/base/content/test/tabview/search1.html");
|
|
|
|
win.gBrowser.addTab("http://mochi.test:8888/browser/browser/base/content/test/tabview/dummy_page.html");
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
afterAllTabsLoaded(function () setupTwo(win), win);
|
|
|
|
}
|
|
|
|
|
2011-02-28 20:07:00 -08:00
|
|
|
let restoreWin;
|
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
function setupTwo(win) {
|
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
2010-11-30 00:15:51 -08:00
|
|
|
|
|
|
|
let tabItems = contentWindow.TabItems.getItems();
|
2011-02-19 10:22:49 -08:00
|
|
|
is(tabItems.length, 3, "There should be 3 tab items before closing");
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2011-02-16 14:05:59 -08:00
|
|
|
let numTabsToSave = tabItems.length;
|
|
|
|
|
|
|
|
// force all canvases to update, and hook in imageData save detection
|
2010-11-30 00:15:51 -08:00
|
|
|
tabItems.forEach(function(tabItem) {
|
2011-04-22 14:44:06 -07:00
|
|
|
contentWindow.TabItems.update(tabItem.tab);
|
2011-02-19 10:22:49 -08:00
|
|
|
tabItem.addSubscriber(tabItem, "savedCachedImageData", function(item) {
|
|
|
|
item.removeSubscriber(item, "savedCachedImageData");
|
2011-02-16 14:05:59 -08:00
|
|
|
--numTabsToSave;
|
|
|
|
});
|
2010-11-30 00:15:51 -08:00
|
|
|
});
|
|
|
|
|
2010-12-10 01:46:10 -08:00
|
|
|
// after the window is closed, restore it.
|
|
|
|
let xulWindowDestory = function() {
|
|
|
|
Services.obs.removeObserver(
|
|
|
|
xulWindowDestory, "xul-window-destroyed", false);
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2010-12-10 01:46:10 -08:00
|
|
|
// "xul-window-destroyed" is just fired just before a XUL window is
|
|
|
|
// destroyed so restore window and test it after a delay
|
|
|
|
executeSoon(function() {
|
2011-02-28 20:07:00 -08:00
|
|
|
restoredWin = undoCloseWindow();
|
2011-02-19 10:22:49 -08:00
|
|
|
restoredWin.addEventListener("load", function onLoad(event) {
|
|
|
|
restoredWin.removeEventListener("load", onLoad, false);
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2011-02-28 20:07:00 -08:00
|
|
|
registerCleanupFunction(function() restoredWin.close());
|
|
|
|
|
2011-02-16 14:05:59 -08:00
|
|
|
// ensure that closed tabs have been saved
|
|
|
|
is(numTabsToSave, 0, "All tabs were saved when window was closed.");
|
2011-02-28 20:07:00 -08:00
|
|
|
is(restoredWin.gBrowser.tabs.length, 3, "The total number of tabs is 3");
|
|
|
|
|
|
|
|
// setup tab variables and listen to the tabs load progress
|
|
|
|
newTabOne = restoredWin.gBrowser.tabs[0];
|
|
|
|
newTabTwo = restoredWin.gBrowser.tabs[1];
|
|
|
|
newTabThree = restoredWin.gBrowser.tabs[2];
|
|
|
|
restoredWin.gBrowser.addTabsProgressListener(gTabsProgressListener);
|
2011-02-16 14:05:59 -08:00
|
|
|
|
2011-02-28 20:07:00 -08:00
|
|
|
// execute code when the frame is initialized
|
2010-12-17 12:22:17 -08:00
|
|
|
let onTabViewFrameInitialized = function() {
|
|
|
|
restoredWin.removeEventListener(
|
|
|
|
"tabviewframeinitialized", onTabViewFrameInitialized, false);
|
|
|
|
|
2011-04-22 14:44:06 -07:00
|
|
|
let restoredContentWindow = restoredWin.TabView.getContentWindow();
|
2010-12-17 12:22:17 -08:00
|
|
|
// prevent TabItems._update being called before checking cached images
|
|
|
|
restoredContentWindow.TabItems._pauseUpdateForTest = true;
|
2011-02-28 20:07:00 -08:00
|
|
|
|
|
|
|
let nextStep = function() {
|
|
|
|
// since we are not sure whether the frame is initialized first or two tabs
|
|
|
|
// compete loading first so we need this.
|
|
|
|
if (restoredNewTabTwoLoaded && restoredNewTabThreeLoaded)
|
|
|
|
updateAndCheck();
|
|
|
|
else
|
|
|
|
frameInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabItems = restoredContentWindow.TabItems.getItems();
|
|
|
|
let count = tabItems.length;
|
|
|
|
|
|
|
|
tabItems.forEach(function(tabItem) {
|
|
|
|
tabItem.addSubscriber(tabItem, "loadedCachedImageData", function() {
|
|
|
|
tabItem.removeSubscriber(tabItem, "loadedCachedImageData");
|
|
|
|
ok(tabItem.isShowingCachedData(),
|
|
|
|
"Tab item is showing cached data and is just connected. " +
|
|
|
|
tabItem.tab.linkedBrowser.currentURI.spec);
|
|
|
|
if (--count == 0)
|
|
|
|
nextStep();
|
|
|
|
});
|
|
|
|
});
|
2010-12-17 12:22:17 -08:00
|
|
|
}
|
2011-02-28 20:07:00 -08:00
|
|
|
|
2010-12-17 12:22:17 -08:00
|
|
|
restoredWin.addEventListener(
|
|
|
|
"tabviewframeinitialized", onTabViewFrameInitialized, false);
|
2010-11-30 00:15:51 -08:00
|
|
|
}, false);
|
2010-12-10 01:46:10 -08:00
|
|
|
});
|
|
|
|
};
|
2011-02-28 20:07:00 -08:00
|
|
|
Services.obs.addObserver(xulWindowDestory, "xul-window-destroyed", false);
|
2011-02-16 14:05:59 -08:00
|
|
|
|
2011-02-19 10:22:49 -08:00
|
|
|
win.close();
|
2010-11-30 00:15:51 -08:00
|
|
|
}
|
|
|
|
|
2011-02-28 20:07:00 -08:00
|
|
|
let gTabsProgressListener = {
|
2010-11-30 00:15:51 -08:00
|
|
|
onStateChange: function(browser, webProgress, request, stateFlags, status) {
|
2010-12-15 12:16:23 -08:00
|
|
|
// ensure about:blank doesn't trigger the code
|
|
|
|
if ((stateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
|
|
|
|
(stateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) &&
|
|
|
|
browser.currentURI.spec != "about:blank") {
|
2011-02-28 20:07:00 -08:00
|
|
|
if (newTabTwo.linkedBrowser == browser)
|
2010-11-30 00:15:51 -08:00
|
|
|
restoredNewTabTwoLoaded = true;
|
2011-02-28 20:07:00 -08:00
|
|
|
else if (newTabThree.linkedBrowser == browser)
|
|
|
|
restoredNewTabThreeLoaded = true;
|
2010-12-15 12:16:23 -08:00
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
// since we are not sure whether the frame is initialized first or two tabs
|
|
|
|
// compete loading first so we need this.
|
2011-02-28 20:07:00 -08:00
|
|
|
if (restoredNewTabTwoLoaded && restoredNewTabThreeLoaded) {
|
2010-12-15 12:16:23 -08:00
|
|
|
restoredWin.gBrowser.removeTabsProgressListener(gTabsProgressListener);
|
|
|
|
|
2011-02-28 20:07:00 -08:00
|
|
|
if (frameInitialized)
|
|
|
|
updateAndCheck();
|
2010-11-30 00:15:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateAndCheck() {
|
|
|
|
// force all canvas to update
|
2011-04-22 14:44:06 -07:00
|
|
|
let contentWindow = restoredWin.TabView.getContentWindow();
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2010-12-17 12:22:17 -08:00
|
|
|
contentWindow.TabItems._pauseUpdateForTest = false;
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
let tabItems = contentWindow.TabItems.getItems();
|
|
|
|
tabItems.forEach(function(tabItem) {
|
|
|
|
contentWindow.TabItems._update(tabItem.tab);
|
2011-02-28 20:07:00 -08:00
|
|
|
ok(!tabItem.isShowingCachedData(),
|
2010-12-10 01:46:10 -08:00
|
|
|
"Tab item is not showing cached data anymore. " +
|
|
|
|
tabItem.tab.linkedBrowser.currentURI.spec);
|
2010-11-30 00:15:51 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
// clean up and finish
|
|
|
|
restoredWin.close();
|
|
|
|
finish();
|
2011-02-28 20:07:00 -08:00
|
|
|
}
|