mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
Bug 1100662 - Fix browser_notification_tab_switching.js to work in e10s mode. r=Gijs
This commit is contained in:
parent
11d0936177
commit
9736582b2a
@ -8,6 +8,5 @@ support-files =
|
||||
[browser_notification_open_settings.js]
|
||||
[browser_notification_remove_permission.js]
|
||||
[browser_notification_permission_migration.js]
|
||||
|
||||
[browser_notification_tab_switching.js]
|
||||
skip-if = buildapp == 'mulet' || e10s # Bug 1100662 - content access causing uncaught exception - Error: cannot ipc non-cpow object at chrome://mochitests/content/browser/browser/base/content/test/general/browser_notification_tab_switching.js:32 (or in RemoteAddonsChild.jsm)
|
||||
skip-if = buildapp == 'mulet'
|
||||
|
@ -9,87 +9,55 @@ var notification;
|
||||
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
|
||||
var newWindowOpenedFromTab;
|
||||
|
||||
function test () {
|
||||
waitForExplicitFinish();
|
||||
|
||||
add_task(function* test_notificationPreventDefaultAndSwitchTabs() {
|
||||
let pm = Services.perms;
|
||||
registerCleanupFunction(function() {
|
||||
pm.remove(makeURI(notificationURL), "desktop-notification");
|
||||
gBrowser.removeTab(tab);
|
||||
window.restore();
|
||||
});
|
||||
|
||||
pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
|
||||
|
||||
tab = gBrowser.addTab(notificationURL);
|
||||
tab.linkedBrowser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
let originalTab = gBrowser.selectedTab;
|
||||
yield BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: notificationURL
|
||||
}, function* dummyTabTask(aBrowser) {
|
||||
// Put new tab in background so it is obvious when it is re-focused.
|
||||
yield BrowserTestUtils.switchTab(gBrowser, originalTab);
|
||||
isnot(gBrowser.selectedBrowser, aBrowser, "Notification page loaded as a background tab");
|
||||
|
||||
function onLoad() {
|
||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
||||
tab.linkedBrowser.removeEventListener("load", onLoad, true);
|
||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
win.newWindow = win.open("about:blank", "", "height=100,width=100");
|
||||
newWindowOpenedFromTab = win.newWindow;
|
||||
win.newWindow.addEventListener("load", function() {
|
||||
info("new window loaded");
|
||||
win.newWindow.addEventListener("blur", function b() {
|
||||
info("new window got blur");
|
||||
win.newWindow.removeEventListener("blur", b);
|
||||
notification = win.showNotification1();
|
||||
win.newWindow.addEventListener("focus", onNewWindowFocused);
|
||||
notification.addEventListener("show", onAlertShowing);
|
||||
});
|
||||
|
||||
function waitUntilNewWindowHasFocus() {
|
||||
if (!win.newWindow.document.hasFocus()) {
|
||||
setTimeout(waitUntilNewWindowHasFocus, 50);
|
||||
} else {
|
||||
// Focus another window so that new window gets blur event.
|
||||
gBrowser.selectedBrowser.contentWindow.focus();
|
||||
}
|
||||
}
|
||||
win.newWindow.focus();
|
||||
waitUntilNewWindowHasFocus();
|
||||
});
|
||||
}
|
||||
|
||||
function onAlertShowing() {
|
||||
// First, show a notification that will be have the tab-switching prevented.
|
||||
let win = aBrowser.contentWindow.wrappedJSObject;
|
||||
let notification = win.showNotification1();
|
||||
yield BrowserTestUtils.waitForEvent(notification, "show");
|
||||
info("Notification alert showing");
|
||||
notification.removeEventListener("show", onAlertShowing);
|
||||
|
||||
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
if (!alertWindow) {
|
||||
ok(true, "Notifications don't use XUL windows on all platforms.");
|
||||
notification.close();
|
||||
newWindowOpenedFromTab.close();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect);
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow);
|
||||
info("Clicked on notification");
|
||||
alertWindow.close();
|
||||
}
|
||||
info("Clicking on notification");
|
||||
let promiseClickEvent = BrowserTestUtils.waitForEvent(notification, "click");
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
|
||||
{},
|
||||
alertWindow);
|
||||
let clickEvent = yield promiseClickEvent;
|
||||
ok(clickEvent.defaultPrevented, "The event handler for the first notification cancels the event");
|
||||
isnot(gBrowser.selectedBrowser, aBrowser, "Notification page still a background tab");
|
||||
notification.close();
|
||||
|
||||
function onNewWindowFocused(event) {
|
||||
event.target.close();
|
||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
||||
// Using timeout to test that something do *not* happen!
|
||||
setTimeout(openSecondNotification, 50);
|
||||
}
|
||||
// Second, show a notification that will cause the tab to get switched.
|
||||
let notification2 = win.showNotification2();
|
||||
yield BrowserTestUtils.waitForEvent(notification2, "show");
|
||||
alertWindow = Services.wm.getMostRecentWindow("alert:alert");
|
||||
let promiseTabSelect = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabSelect");
|
||||
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
|
||||
{},
|
||||
alertWindow);
|
||||
yield promiseTabSelect;
|
||||
is(gBrowser.selectedBrowser.currentURI.spec, notificationURL,
|
||||
"Clicking on the second notification should select its originating tab");
|
||||
notification2.close();
|
||||
});
|
||||
});
|
||||
|
||||
function openSecondNotification() {
|
||||
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab");
|
||||
let win = tab.linkedBrowser.contentWindow.wrappedJSObject;
|
||||
notification = win.showNotification2();
|
||||
notification.addEventListener("show", onAlertShowing);
|
||||
}
|
||||
|
||||
function onTabSelect() {
|
||||
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
|
||||
is(gBrowser.selectedBrowser.contentWindow.location.href, notificationURL,
|
||||
"Notification tab should be selected.");
|
||||
|
||||
finish();
|
||||
}
|
||||
add_task(function* cleanup() {
|
||||
Services.perms.remove(makeURI(notificationURL), "desktop-notification");
|
||||
});
|
||||
|
@ -15,8 +15,6 @@ function showNotification1() {
|
||||
var n = new Notification("Test title", options);
|
||||
n.addEventListener("click", function(event) {
|
||||
event.preventDefault();
|
||||
dump("Should focus new window.");
|
||||
newWindow.focus();
|
||||
});
|
||||
return n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user