Bug 1208295 - Open content preferences after receiving notifications-open-settings. r=jaws

This commit is contained in:
Matthew Noorenberghe 2015-09-25 13:18:29 -07:00
parent a81b210217
commit f5f5fe386c
8 changed files with 47 additions and 15 deletions

View File

@ -0,0 +1,7 @@
[DEFAULT]
support-files =
file_dom_notifications.html
[browser_notification_open_settings.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)

View File

@ -0,0 +1,18 @@
"use strict";
add_task(function* test_settingsOpen() {
info("Opening a dummy tab so openPreferences=>switchToTabHavingURI doesn't use the blank tab.");
yield BrowserTestUtils.withNewTab({
gBrowser,
url: "about:robots"
}, function* dummyTabTask(aBrowser) {
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#content");
info("simulate a notifications-open-settings notification");
let uri = NetUtil.newURI("https://example.com");
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
Services.obs.notifyObservers(principal, "notifications-open-settings", null);
let tab = yield tabPromise;
ok(tab, "The notification settings tab opened");
BrowserTestUtils.removeTab(tab);
});
});

View File

@ -6,7 +6,7 @@
var tab;
var notification;
var notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html";
var notificationURL = "http://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html";
var newWindowOpenedFromTab;
function test () {
@ -58,7 +58,7 @@ function onAlertShowing() {
info("Notification alert showing");
notification.removeEventListener("show", onAlertShowing);
let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul");
let alertWindow = Services.wm.getMostRecentWindow("alert:alert");
if (!alertWindow) {
todo(false, "Notifications don't use XUL windows on all platforms.");
notification.close();

View File

@ -1,5 +1,6 @@
<html>
<head>
<meta charset="utf-8">
<script>
"use strict";

View File

@ -62,7 +62,6 @@ support-files =
file_bug970276_favicon1.ico
file_bug970276_favicon2.ico
file_documentnavigation_frameset.html
file_dom_notifications.html
file_double_close_tab.html
file_favicon_change.html
file_favicon_change_not_in_document.html
@ -338,8 +337,6 @@ skip-if = os != "win" # The Fitts Law menu button is only supported on Windows (
skip-if = e10s # Bug 1100664 - test directly access content docShells (TypeError: gBrowser.docShell is null)
[browser_mixedcontent_securityflags.js]
tags = mcb
[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)
[browser_offlineQuotaNotification.js]
skip-if = buildapp == 'mulet' || e10s # Bug 1093603 - test breaks with PopupNotifications.panel.firstElementChild is null
[browser_overflowScroll.js]

View File

@ -59,16 +59,6 @@ function whenDelayedStartupFinished(aWindow, aCallback) {
}, "browser-delayed-startup-finished", false);
}
function findChromeWindowByURI(aURI) {
let windows = Services.wm.getEnumerator(null);
while (windows.hasMoreElements()) {
let win = windows.getNext();
if (win.location.href == aURI)
return win;
}
return null;
}
function updateTabContextMenu(tab) {
let menu = document.getElementById("tabContextMenu");
if (!tab)

View File

@ -15,6 +15,7 @@ MOCHITEST_CHROME_MANIFESTS += [
]
BROWSER_CHROME_MANIFESTS += [
'content/test/alerts/browser.ini',
'content/test/chat/browser.ini',
'content/test/general/browser.ini',
'content/test/newtab/browser.ini',

View File

@ -276,6 +276,9 @@ BrowserGlue.prototype = {
// nsIObserver implementation
observe: function BG_observe(subject, topic, data) {
switch (topic) {
case "notifications-open-settings":
this._openPreferences("content");
break;
case "prefservice:after-app-defaults":
this._onAppDefaults();
break;
@ -591,6 +594,7 @@ BrowserGlue.prototype = {
// initialization (called on application startup)
_init: function BG__init() {
let os = Services.obs;
os.addObserver(this, "notifications-open-settings", false);
os.addObserver(this, "prefservice:after-app-defaults", false);
os.addObserver(this, "final-ui-startup", false);
os.addObserver(this, "browser-delayed-startup-finished", false);
@ -639,6 +643,7 @@ BrowserGlue.prototype = {
// cleanup (called on application shutdown)
_dispose: function BG__dispose() {
let os = Services.obs;
os.removeObserver(this, "notifications-open-settings");
os.removeObserver(this, "prefservice:after-app-defaults");
os.removeObserver(this, "final-ui-startup");
os.removeObserver(this, "sessionstore-windows-restored");
@ -2361,6 +2366,19 @@ BrowserGlue.prototype = {
}
}),
/**
* Open preferences even if there are no open windows.
*/
_openPreferences(...args) {
if (Services.appShell.hiddenDOMWindow.openPreferences) {
Services.appShell.hiddenDOMWindow.openPreferences(...args);
return;
}
let chromeWindow = RecentWindow.getMostRecentBrowserWindow();
chromeWindow.openPreferences(...args);
},
#ifdef MOZ_SERVICES_SYNC
/**
* Called as an observer when Sync's "display URI" notification is fired.