зеркало из https://github.com/mozilla/gecko-dev.git
Bug 671460 - clean up browser_tabview_bug599626.js; r=ehsan
This commit is contained in:
Родитель
db6effd19f
Коммит
4f8bf3479a
|
@ -167,7 +167,6 @@ _BROWSER_FILES = \
|
||||||
head.js \
|
head.js \
|
||||||
search1.html \
|
search1.html \
|
||||||
search2.html \
|
search2.html \
|
||||||
test_bug599626.html \
|
|
||||||
test_bug600645.html \
|
test_bug600645.html \
|
||||||
test_bug644097.html \
|
test_bug644097.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
|
@ -1,41 +1,26 @@
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
let handleDialog;
|
const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' +
|
||||||
let timer; // keep in outer scope so it's not GC'd before firing
|
'function(e){e.returnValue="?"}</script>';
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
|
showTabView(onTabViewShown);
|
||||||
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
|
||||||
TabView.toggle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTabViewWindowLoaded() {
|
function onTabViewShown() {
|
||||||
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
let contentWindow = TabView.getContentWindow();
|
||||||
|
|
||||||
let contentWindow = document.getElementById("tab-view").contentWindow;
|
|
||||||
let groupItemOne = contentWindow.GroupItems.getActiveGroupItem();
|
let groupItemOne = contentWindow.GroupItems.getActiveGroupItem();
|
||||||
|
let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]);
|
||||||
|
|
||||||
// Create a group and make it active
|
afterAllTabsLoaded(function () {
|
||||||
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);
|
|
||||||
|
|
||||||
testStayOnPage(contentWindow, groupItemOne, groupItemTwo);
|
testStayOnPage(contentWindow, groupItemOne, groupItemTwo);
|
||||||
}
|
});
|
||||||
browser.addEventListener("load", onLoad, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
|
function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
|
||||||
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
|
whenDialogOpened(function (dialog) {
|
||||||
groupItemTwo.addSubscriber("groupShown", function onShown() {
|
groupItemTwo.addSubscriber("groupShown", function onShown() {
|
||||||
groupItemTwo.removeSubscriber("groupShown", onShown);
|
groupItemTwo.removeSubscriber("groupShown", onShown);
|
||||||
|
|
||||||
|
@ -44,22 +29,21 @@ function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
|
||||||
is(contentWindow.TabItems.getItems().length, 2,
|
is(contentWindow.TabItems.getItems().length, 2,
|
||||||
"The total number of tab items is 2 when staying on the page");
|
"The total number of tab items is 2 when staying on the page");
|
||||||
|
|
||||||
let onTabViewShown = function() {
|
showTabView(function () {
|
||||||
window.removeEventListener("tabviewshown", onTabViewShown, false);
|
|
||||||
|
|
||||||
// start the next test
|
// start the next test
|
||||||
testLeavePage(contentWindow, groupItemOne, groupItemTwo);
|
testLeavePage(contentWindow, groupItemOne, groupItemTwo);
|
||||||
};
|
|
||||||
window.addEventListener("tabviewshown", onTabViewShown, false);
|
|
||||||
TabView.toggle();
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// stay on page
|
// stay on page
|
||||||
doc.documentElement.getButton("cancel").click();
|
dialog.cancelDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
closeGroupItem(groupItemTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
|
function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
|
||||||
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
|
whenDialogOpened(function (dialog) {
|
||||||
// clean up and finish the test
|
// clean up and finish the test
|
||||||
groupItemTwo.addSubscriber("close", function onClose() {
|
groupItemTwo.addSubscriber("close", function onClose() {
|
||||||
groupItemTwo.removeSubscriber("close", onClose);
|
groupItemTwo.removeSubscriber("close", onClose);
|
||||||
|
@ -69,93 +53,38 @@ function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
|
||||||
is(contentWindow.TabItems.getItems().length, 1,
|
is(contentWindow.TabItems.getItems().length, 1,
|
||||||
"The total number of tab items is 1 after leaving the page");
|
"The total number of tab items is 1 after leaving the page");
|
||||||
|
|
||||||
let endGame = function() {
|
hideTabView(finish);
|
||||||
window.removeEventListener("tabviewhidden", endGame, false);
|
|
||||||
finish();
|
|
||||||
};
|
|
||||||
window.addEventListener("tabviewhidden", endGame, false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Leave page
|
// Leave page
|
||||||
doc.documentElement.getButton("accept").click();
|
dialog.acceptDialog();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
closeGroupItem(groupItemTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupAndRun(contentWindow, groupItemOne, groupItemTwo, callback) {
|
// ----------
|
||||||
let closeButton = groupItemTwo.container.getElementsByClassName("close");
|
function whenDialogOpened(callback) {
|
||||||
ok(closeButton[0], "Group close button exists");
|
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
|
||||||
// click the close button
|
.getService(Ci.nsIWindowMediator);
|
||||||
EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
|
|
||||||
|
|
||||||
let onTabViewHidden = function() {
|
let listener = {
|
||||||
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
onCloseWindow: function () {},
|
||||||
|
onWindowTitleChange: function () {},
|
||||||
|
|
||||||
handleDialog = function(doc) {
|
onOpenWindow: function (xulWin) {
|
||||||
callback(doc);
|
let domWin = xulWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowInternal);
|
||||||
|
|
||||||
|
whenWindowLoaded(domWin, function () {
|
||||||
|
let dialog = domWin.document.querySelector("dialog");
|
||||||
|
if (dialog) {
|
||||||
|
wm.removeListener(listener);
|
||||||
|
callback(dialog);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
startCallbackTimer();
|
|
||||||
};
|
|
||||||
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
|
||||||
|
|
||||||
let tabItem = groupItemOne.getChild(0);
|
wm.addListener(listener);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<html>
|
|
||||||
<script>
|
|
||||||
window.onbeforeunload = function(event){
|
|
||||||
event.returnValue = 'Confirmation? ';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
Test page
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Загрузка…
Ссылка в новой задаче