browser_notification_open_settings.js (2559B)
1 "use strict"; 2 3 var notificationURL = 4 "https://example.org/browser/browser/base/content/test/alerts/file_dom_notifications.html"; 5 var expectedURL = "about:preferences#privacy"; 6 7 add_task(async function test_settingsOpen_observer() { 8 info( 9 "Opening a dummy tab so openPreferences=>switchToTabHavingURI doesn't use the blank tab." 10 ); 11 await BrowserTestUtils.withNewTab( 12 { 13 gBrowser, 14 url: "about:robots", 15 }, 16 async function dummyTabTask() { 17 // Ensure preferences is loaded before removing the tab. 18 let syncPaneLoadedPromise = TestUtils.topicObserved( 19 "sync-pane-loaded", 20 () => true 21 ); 22 let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL); 23 info("simulate a notifications-open-settings notification"); 24 let uri = NetUtil.newURI("https://example.com"); 25 let principal = Services.scriptSecurityManager.createContentPrincipal( 26 uri, 27 {} 28 ); 29 Services.obs.notifyObservers(principal, "notifications-open-settings"); 30 let tab = await tabPromise; 31 ok(tab, "The notification settings tab opened"); 32 await syncPaneLoadedPromise; 33 BrowserTestUtils.removeTab(tab); 34 } 35 ); 36 }); 37 38 add_task(async function test_settingsOpen_button() { 39 info("Adding notification permission"); 40 await addNotificationPermission(notificationURL); 41 42 await BrowserTestUtils.withNewTab( 43 { 44 gBrowser, 45 url: notificationURL, 46 }, 47 async function tabTask(aBrowser) { 48 info("Waiting for notification"); 49 await openNotification(aBrowser, "showNotification2"); 50 51 let alertWindow = Services.wm.getMostRecentWindow("alert:alert"); 52 if (!alertWindow) { 53 ok(true, "Notifications don't use XUL windows on all platforms."); 54 await closeNotification(aBrowser); 55 return; 56 } 57 58 // Ensure preferences is loaded before removing the tab. 59 let syncPaneLoadedPromise = TestUtils.topicObserved( 60 "sync-pane-loaded", 61 () => true 62 ); 63 let closePromise = promiseWindowClosed(alertWindow); 64 let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, expectedURL); 65 let openSettingsMenuItem = alertWindow.document.getElementById( 66 "openSettingsMenuItem" 67 ); 68 openSettingsMenuItem.click(); 69 70 info("Waiting for notification settings tab"); 71 let tab = await tabPromise; 72 ok(tab, "The notification settings tab opened"); 73 74 await syncPaneLoadedPromise; 75 await closePromise; 76 BrowserTestUtils.removeTab(tab); 77 } 78 ); 79 });