2010-11-30 00:15:51 -08:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is tabview bug 597248 test.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Raymond Lee <raymond@appcoast.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
let newWin;
|
|
|
|
let restoredWin;
|
|
|
|
let newTabOne;
|
|
|
|
let newTabTwo;
|
|
|
|
let restoredNewTabOneLoaded = false;
|
|
|
|
let restoredNewTabTwoLoaded = false;
|
|
|
|
let frameInitialized = false;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
// open a new window
|
|
|
|
newWin = openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no");
|
|
|
|
newWin.addEventListener("load", function(event) {
|
|
|
|
newWin.removeEventListener("load", arguments.callee, false);
|
|
|
|
setupOne();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupOne() {
|
|
|
|
let loadedCount = 0;
|
|
|
|
let allLoaded = function() {
|
|
|
|
if (++loadedCount == 2) {
|
|
|
|
newWin.addEventListener("tabviewshown", setupTwo, false);
|
|
|
|
newWin.TabView.toggle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newTabOne = newWin.gBrowser.tabs[0];
|
|
|
|
newTabTwo = newWin.gBrowser.addTab();
|
2010-12-10 01:46:10 -08:00
|
|
|
load(newTabOne, "http://mochi.test:8888/browser/browser/base/content/test/tabview/search1.html", allLoaded);
|
2010-11-30 00:15:51 -08:00
|
|
|
load(newTabTwo, "http://mochi.test:8888/browser/browser/base/content/test/tabview/dummy_page.html", allLoaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupTwo() {
|
|
|
|
newWin.removeEventListener("tabviewshown", setupTwo, false);
|
|
|
|
|
|
|
|
let contentWindow = newWin.document.getElementById("tab-view").contentWindow;
|
|
|
|
|
|
|
|
let tabItems = contentWindow.TabItems.getItems();
|
|
|
|
is(tabItems.length, 2, "There should be 2 tab items before closing");
|
|
|
|
|
|
|
|
// force all canvas to update
|
|
|
|
tabItems.forEach(function(tabItem) {
|
|
|
|
contentWindow.TabItems._update(tabItem.tab);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
newWin = null;
|
|
|
|
// "xul-window-destroyed" is just fired just before a XUL window is
|
|
|
|
// destroyed so restore window and test it after a delay
|
|
|
|
executeSoon(function() {
|
2010-11-30 00:15:51 -08:00
|
|
|
restoredWin = undoCloseWindow();
|
|
|
|
restoredWin.addEventListener("load", function(event) {
|
|
|
|
restoredWin.removeEventListener("load", arguments.callee, false);
|
|
|
|
|
2010-12-15 12:16:23 -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-01-10 19:36:07 -08:00
|
|
|
/*
|
|
|
|
// bug 615954 happens too often so we disable this until we have a fix
|
2010-12-17 12:22:17 -08:00
|
|
|
let restoredContentWindow =
|
|
|
|
restoredWin.document.getElementById("tab-view").contentWindow;
|
|
|
|
// prevent TabItems._update being called before checking cached images
|
|
|
|
restoredContentWindow.TabItems._pauseUpdateForTest = true;
|
2011-01-10 19:36:07 -08:00
|
|
|
*/
|
|
|
|
restoredWin.close();
|
|
|
|
finish();
|
2010-12-17 12:22:17 -08:00
|
|
|
}
|
|
|
|
restoredWin.addEventListener(
|
|
|
|
"tabviewframeinitialized", onTabViewFrameInitialized, false);
|
|
|
|
|
2010-12-15 12:16:23 -08:00
|
|
|
is(restoredWin.gBrowser.tabs.length, 2, "The total number of tabs is 2");
|
2010-12-07 10:13:38 -08:00
|
|
|
|
2011-01-10 19:36:07 -08:00
|
|
|
/*
|
|
|
|
// bug 615954 happens too often so we disable this until we have a fix
|
|
|
|
restoredWin.addEventListener("tabviewshown", onTabViewShown, false);
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
// setup tab variables and listen to the load progress.
|
|
|
|
newTabOne = restoredWin.gBrowser.tabs[0];
|
|
|
|
newTabTwo = restoredWin.gBrowser.tabs[1];
|
|
|
|
restoredWin.gBrowser.addTabsProgressListener(gTabsProgressListener);
|
2011-01-10 19:36:07 -08:00
|
|
|
*/
|
2010-11-30 00:15:51 -08:00
|
|
|
}, false);
|
2010-12-10 01:46:10 -08:00
|
|
|
});
|
|
|
|
};
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2010-12-10 01:46:10 -08:00
|
|
|
// check the storage for stored image data
|
|
|
|
let checkDataAndCloseWindow = function() {
|
|
|
|
tabItems.forEach(function(tabItem) {
|
|
|
|
let tabData = contentWindow.Storage.getTabData(tabItem.tab);
|
|
|
|
ok(tabData && tabData.imageData,
|
|
|
|
"TabItem has stored image data before closing");
|
|
|
|
});
|
|
|
|
|
|
|
|
Services.obs.addObserver(
|
|
|
|
xulWindowDestory, "xul-window-destroyed", false);
|
2010-11-30 00:15:51 -08:00
|
|
|
newWin.close();
|
|
|
|
}
|
|
|
|
|
2010-12-10 01:46:10 -08:00
|
|
|
// stimulate a quit application requested so the image data gets stored
|
2010-11-30 00:15:51 -08:00
|
|
|
let quitRequestObserver = function(aSubject, aTopic, aData) {
|
|
|
|
ok(aTopic == "quit-application-requested" &&
|
|
|
|
aSubject instanceof Ci.nsISupportsPRBool,
|
|
|
|
"Received a quit request and going to deny it");
|
2010-12-07 10:13:38 -08:00
|
|
|
Services.obs.removeObserver(
|
|
|
|
quitRequestObserver, "quit-application-requested", false);
|
2010-12-10 01:46:10 -08:00
|
|
|
// cancel the shut down
|
2010-11-30 00:15:51 -08:00
|
|
|
aSubject.data = true;
|
|
|
|
// save all images is execuated when "quit-application-requested" topic is
|
|
|
|
// announced so executeSoon is used to avoid racing condition.
|
|
|
|
executeSoon(checkDataAndCloseWindow);
|
|
|
|
}
|
2010-12-07 10:13:38 -08:00
|
|
|
Services.obs.addObserver(
|
|
|
|
quitRequestObserver, "quit-application-requested", false);
|
2010-11-30 00:15:51 -08:00
|
|
|
ok(!Application.quit(), "Tried to quit and canceled it");
|
|
|
|
}
|
|
|
|
|
|
|
|
let gTabsProgressListener = {
|
|
|
|
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") {
|
2010-11-30 00:15:51 -08:00
|
|
|
if (newTabOne.linkedBrowser == browser)
|
|
|
|
restoredNewTabOneLoaded = true;
|
|
|
|
else if (newTabTwo.linkedBrowser == browser)
|
|
|
|
restoredNewTabTwoLoaded = 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.
|
|
|
|
if (restoredNewTabOneLoaded && restoredNewTabTwoLoaded) {
|
2010-12-15 12:16:23 -08:00
|
|
|
restoredWin.gBrowser.removeTabsProgressListener(gTabsProgressListener);
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
if (frameInitialized) {
|
|
|
|
// since a tabs progress listener is used in the code to set
|
|
|
|
// tabItem.shouldHideCachedData, executeSoon is used to avoid a racing
|
|
|
|
// condition.
|
|
|
|
executeSoon(updateAndCheck);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-12-07 10:13:38 -08:00
|
|
|
function onTabViewShown() {
|
|
|
|
restoredWin.removeEventListener("tabviewshown", onTabViewShown, false);
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2010-12-07 10:13:38 -08:00
|
|
|
let contentWindow =
|
|
|
|
restoredWin.document.getElementById("tab-view").contentWindow;
|
2010-11-30 00:15:51 -08:00
|
|
|
|
2010-12-02 01:38:54 -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 (restoredNewTabOneLoaded && restoredNewTabTwoLoaded) {
|
|
|
|
// executeSoon is used to ensure tabItem.shouldHideCachedData is set
|
2010-12-07 10:13:38 -08:00
|
|
|
// because tabs progress listener might run at the same time as this test
|
|
|
|
// code.
|
2010-12-02 01:38:54 -08:00
|
|
|
executeSoon(updateAndCheck);
|
2010-12-15 12:16:23 -08:00
|
|
|
} else {
|
2010-12-02 01:38:54 -08:00
|
|
|
frameInitialized = true;
|
2010-12-15 12:16:23 -08:00
|
|
|
}
|
2010-12-02 01:38:54 -08:00
|
|
|
}
|
|
|
|
|
2010-11-30 00:15:51 -08:00
|
|
|
let tabItems = contentWindow.TabItems.getItems();
|
2010-12-02 01:38:54 -08:00
|
|
|
let count = tabItems.length;
|
2010-11-30 00:15:51 -08:00
|
|
|
tabItems.forEach(function(tabItem) {
|
2010-12-02 01:38:54 -08:00
|
|
|
// tabitem might not be connected so use subscriber for those which are not
|
|
|
|
// connected.
|
2011-01-05 12:54:34 -08:00
|
|
|
if (tabItem._reconnected) {
|
2010-12-07 10:13:38 -08:00
|
|
|
ok(tabItem.isShowingCachedData(),
|
2010-12-10 01:46:10 -08:00
|
|
|
"Tab item is showing cached data and is already connected. " +
|
|
|
|
tabItem.tab.linkedBrowser.currentURI.spec);
|
2010-12-15 12:16:23 -08:00
|
|
|
if (--count == 0)
|
2010-12-02 01:38:54 -08:00
|
|
|
nextStep();
|
|
|
|
} else {
|
|
|
|
tabItem.addSubscriber(tabItem, "reconnected", function() {
|
|
|
|
tabItem.removeSubscriber(tabItem, "reconnected");
|
2010-12-07 10:13:38 -08:00
|
|
|
ok(tabItem.isShowingCachedData(),
|
2010-12-10 01:46:10 -08:00
|
|
|
"Tab item is showing cached data and is just connected. " +
|
|
|
|
tabItem.tab.linkedBrowser.currentURI.spec);
|
2010-12-15 12:16:23 -08:00
|
|
|
if (--count == 0)
|
2010-12-02 01:38:54 -08:00
|
|
|
nextStep();
|
|
|
|
});
|
|
|
|
}
|
2010-11-30 00:15:51 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateAndCheck() {
|
|
|
|
// force all canvas to update
|
2010-12-07 10:13:38 -08:00
|
|
|
let contentWindow =
|
|
|
|
restoredWin.document.getElementById("tab-view").contentWindow;
|
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);
|
2010-12-07 10:13:38 -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();
|
|
|
|
}
|
|
|
|
|
|
|
|
function load(tab, url, callback) {
|
|
|
|
tab.linkedBrowser.addEventListener("load", function (event) {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
callback();
|
|
|
|
}, true);
|
|
|
|
tab.linkedBrowser.loadURI(url);
|
|
|
|
}
|
|
|
|
|