mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 671460 - clean up browser_tabview_bug599626.js; r=ehsan
This commit is contained in:
parent
8b5c3c5ed8
commit
f2deaeb3b6
@ -167,7 +167,6 @@ _BROWSER_FILES = \
|
||||
head.js \
|
||||
search1.html \
|
||||
search2.html \
|
||||
test_bug599626.html \
|
||||
test_bug600645.html \
|
||||
test_bug644097.html \
|
||||
$(NULL)
|
||||
|
@ -1,41 +1,26 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let handleDialog;
|
||||
let timer; // keep in outer scope so it's not GC'd before firing
|
||||
const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' +
|
||||
'function(e){e.returnValue="?"}</script>';
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
||||
TabView.toggle();
|
||||
showTabView(onTabViewShown);
|
||||
}
|
||||
|
||||
function onTabViewWindowLoaded() {
|
||||
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
||||
|
||||
let contentWindow = document.getElementById("tab-view").contentWindow;
|
||||
function onTabViewShown() {
|
||||
let contentWindow = TabView.getContentWindow();
|
||||
let groupItemOne = contentWindow.GroupItems.getActiveGroupItem();
|
||||
let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]);
|
||||
|
||||
// Create a group and make it active
|
||||
let box = new contentWindow.Rect(10, 10, 300, 300);
|
||||
let groupItemTwo = new contentWindow.GroupItem([], { bounds: box });
|
||||
contentWindow.UI.setActive(groupItemTwo);
|
||||
|
||||
let testTab =
|
||||
gBrowser.addTab(
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/tabview/test_bug599626.html");
|
||||
let browser = gBrowser.getBrowserForTab(testTab);
|
||||
let onLoad = function() {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
|
||||
afterAllTabsLoaded(function () {
|
||||
testStayOnPage(contentWindow, groupItemOne, groupItemTwo);
|
||||
}
|
||||
browser.addEventListener("load", onLoad, true);
|
||||
});
|
||||
}
|
||||
|
||||
function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
|
||||
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
|
||||
whenDialogOpened(function (dialog) {
|
||||
groupItemTwo.addSubscriber("groupShown", function onShown() {
|
||||
groupItemTwo.removeSubscriber("groupShown", onShown);
|
||||
|
||||
@ -44,22 +29,21 @@ function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
|
||||
is(contentWindow.TabItems.getItems().length, 2,
|
||||
"The total number of tab items is 2 when staying on the page");
|
||||
|
||||
let onTabViewShown = function() {
|
||||
window.removeEventListener("tabviewshown", onTabViewShown, false);
|
||||
|
||||
showTabView(function () {
|
||||
// start the next test
|
||||
testLeavePage(contentWindow, groupItemOne, groupItemTwo);
|
||||
};
|
||||
window.addEventListener("tabviewshown", onTabViewShown, false);
|
||||
TabView.toggle();
|
||||
});
|
||||
});
|
||||
|
||||
// stay on page
|
||||
doc.documentElement.getButton("cancel").click();
|
||||
dialog.cancelDialog();
|
||||
});
|
||||
|
||||
closeGroupItem(groupItemTwo);
|
||||
}
|
||||
|
||||
function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
|
||||
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
|
||||
whenDialogOpened(function (dialog) {
|
||||
// clean up and finish the test
|
||||
groupItemTwo.addSubscriber("close", function onClose() {
|
||||
groupItemTwo.removeSubscriber("close", onClose);
|
||||
@ -69,93 +53,35 @@ function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
|
||||
is(contentWindow.TabItems.getItems().length, 1,
|
||||
"The total number of tab items is 1 after leaving the page");
|
||||
|
||||
let endGame = function() {
|
||||
window.removeEventListener("tabviewhidden", endGame, false);
|
||||
finish();
|
||||
};
|
||||
window.addEventListener("tabviewhidden", endGame, false);
|
||||
hideTabView(finish);
|
||||
});
|
||||
|
||||
// Leave page
|
||||
doc.documentElement.getButton("accept").click();
|
||||
dialog.acceptDialog();
|
||||
});
|
||||
|
||||
closeGroupItem(groupItemTwo);
|
||||
}
|
||||
|
||||
function setupAndRun(contentWindow, groupItemOne, groupItemTwo, callback) {
|
||||
let closeButton = groupItemTwo.container.getElementsByClassName("close");
|
||||
ok(closeButton[0], "Group close button exists");
|
||||
// click the close button
|
||||
EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
|
||||
// ----------
|
||||
function whenDialogOpened(callback) {
|
||||
let listener = {
|
||||
onCloseWindow: function () {},
|
||||
onWindowTitleChange: function () {},
|
||||
|
||||
let onTabViewHidden = function() {
|
||||
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
onOpenWindow: function (xulWin) {
|
||||
let domWin = xulWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
|
||||
handleDialog = function(doc) {
|
||||
callback(doc);
|
||||
};
|
||||
startCallbackTimer();
|
||||
whenWindowLoaded(domWin, function () {
|
||||
let dialog = domWin.document.querySelector("dialog");
|
||||
if (dialog) {
|
||||
Services.wm.removeListener(listener);
|
||||
callback(dialog);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
|
||||
let tabItem = groupItemOne.getChild(0);
|
||||
tabItem.zoomIn();
|
||||
}
|
||||
|
||||
// Copied from http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/tests/mochitest/prompt_common.js
|
||||
let observer = {
|
||||
QueryInterface : function (iid) {
|
||||
const interfaces = [Ci.nsIObserver, Ci.nsISupports, Ci.nsISupportsWeakReference];
|
||||
|
||||
if (!interfaces.some( function(v) { return iid.equals(v) } ))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return this;
|
||||
},
|
||||
|
||||
observe : function (subject, topic, data) {
|
||||
let doc = getDialogDoc();
|
||||
if (doc)
|
||||
handleDialog(doc);
|
||||
else
|
||||
startCallbackTimer(); // try again in a bit
|
||||
}
|
||||
};
|
||||
|
||||
function startCallbackTimer() {
|
||||
// Delay before the callback twiddles the prompt.
|
||||
const dialogDelay = 10;
|
||||
|
||||
// Use a timer to invoke a callback to twiddle the authentication dialog
|
||||
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
function getDialogDoc() {
|
||||
// Find the <browser> which contains notifyWindow, by looking
|
||||
// through all the open windows and all the <browsers> in each.
|
||||
let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
let enumerator = wm.getXULWindowEnumerator(null);
|
||||
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let win = enumerator.getNext();
|
||||
let windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell;
|
||||
|
||||
let containedDocShells = windowDocShell.getDocShellEnumerator(
|
||||
Ci.nsIDocShellTreeItem.typeChrome,
|
||||
Ci.nsIDocShell.ENUMERATE_FORWARDS);
|
||||
while (containedDocShells.hasMoreElements()) {
|
||||
// Get the corresponding document for this docshell
|
||||
let childDocShell = containedDocShells.getNext();
|
||||
// We don't want it if it's not done loading.
|
||||
if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
|
||||
continue;
|
||||
let childDoc = childDocShell.QueryInterface(Ci.nsIDocShell).
|
||||
contentViewer.DOMDocument;
|
||||
|
||||
if (childDoc.location.href == "chrome://global/content/commonDialog.xul")
|
||||
return childDoc;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
Services.wm.addListener(listener);
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<script>
|
||||
window.onbeforeunload = function(event){
|
||||
event.returnValue = 'Confirmation? ';
|
||||
}
|
||||
</script>
|
||||
<body>
|
||||
Test page
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user