Bug 1100662 - Fix browser_notification_tab_switching.js to work in e10s mode. r=MattN

This commit is contained in:
Jared Wein 2015-11-24 11:21:10 -05:00
Родитель 77999dacbf
Коммит 6973bfb723
3 изменённых файлов: 47 добавлений и 80 удалений

Просмотреть файл

@ -8,6 +8,5 @@ support-files =
[browser_notification_open_settings.js] [browser_notification_open_settings.js]
[browser_notification_remove_permission.js] [browser_notification_remove_permission.js]
[browser_notification_permission_migration.js] [browser_notification_permission_migration.js]
[browser_notification_tab_switching.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,57 @@ var notification;
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html"; var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
var newWindowOpenedFromTab; var newWindowOpenedFromTab;
function test () { add_task(function* test_notificationPreventDefaultAndSwitchTabs() {
waitForExplicitFinish();
let pm = Services.perms; 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); pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
tab = gBrowser.addTab(notificationURL); let originalTab = gBrowser.selectedTab;
tab.linkedBrowser.addEventListener("load", onLoad, true); 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() { // First, show a notification that will be have the tab-switching prevented.
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); let win = aBrowser.contentWindow.wrappedJSObject;
tab.linkedBrowser.removeEventListener("load", onLoad, true); let notification = win.showNotification1();
let win = tab.linkedBrowser.contentWindow.wrappedJSObject; yield BrowserTestUtils.waitForEvent(notification, "show");
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() {
info("Notification alert showing"); info("Notification alert showing");
notification.removeEventListener("show", onAlertShowing);
let alertWindow = Services.wm.getMostRecentWindow("alert:alert"); let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
if (!alertWindow) { if (!alertWindow) {
ok(true, "Notifications don't use XUL windows on all platforms."); ok(true, "Notifications don't use XUL windows on all platforms.");
notification.close(); notification.close();
newWindowOpenedFromTab.close();
finish();
return; return;
} }
gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect); info("Clicking on notification");
EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow); let promiseClickEvent = BrowserTestUtils.waitForEvent(notification, "click");
info("Clicked on notification"); EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"),
alertWindow.close(); {},
} 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();
yield BrowserTestUtils.waitForEvent(notification, "close");
function onNewWindowFocused(event) { // Second, show a notification that will cause the tab to get switched.
event.target.close(); let notification2 = win.showNotification2();
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); yield BrowserTestUtils.waitForEvent(notification2, "show");
// Using timeout to test that something do *not* happen! alertWindow = Services.wm.getMostRecentWindow("alert:alert");
setTimeout(openSecondNotification, 50); 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();
yield BrowserTestUtils.waitForEvent(notification2, "close");
});
});
function openSecondNotification() { add_task(function* cleanup() {
isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); Services.perms.remove(makeURI(notificationURL), "desktop-notification");
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();
}

Просмотреть файл

@ -15,8 +15,6 @@ function showNotification1() {
var n = new Notification("Test title", options); var n = new Notification("Test title", options);
n.addEventListener("click", function(event) { n.addEventListener("click", function(event) {
event.preventDefault(); event.preventDefault();
dump("Should focus new window.");
newWindow.focus();
}); });
return n; return n;
} }