browser_popupNotification_no_anchors.js (9526B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 function test() { 6 waitForExplicitFinish(); 7 8 ok(PopupNotifications, "PopupNotifications object exists"); 9 ok(PopupNotifications.panel, "PopupNotifications panel exists"); 10 11 setup(); 12 } 13 14 var tests = [ 15 // Test that popupnotifications are anchored to the fallback anchor on 16 // about:blank, where anchor icons are hidden. 17 { 18 id: "Test#1", 19 async run() { 20 this.oldSelectedTab = gBrowser.selectedTab; 21 await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"); 22 23 this.notifyObj = new BasicNotification(this.id); 24 this.notifyObj.anchorID = "geo-notification-icon"; 25 this.notification = showNotification(this.notifyObj); 26 }, 27 async onShown(popup) { 28 checkPopup(popup, this.notifyObj); 29 is( 30 document.getElementById("geo-notification-icon").getBoundingClientRect() 31 .width, 32 0, 33 "geo anchor shouldn't be visible" 34 ); 35 assertFallbackAnchorNode(popup.anchorNode); 36 dismissNotification(popup); 37 }, 38 onHidden() { 39 this.notification.remove(); 40 gBrowser.removeTab(gBrowser.selectedTab); 41 gBrowser.selectedTab = this.oldSelectedTab; 42 }, 43 }, 44 // Test that popupnotifications are anchored to the fallback anchor after 45 // navigation to about:blank. 46 { 47 id: "Test#2", 48 async run() { 49 this.oldSelectedTab = gBrowser.selectedTab; 50 await BrowserTestUtils.openNewForegroundTab( 51 gBrowser, 52 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 53 "http://example.com/" 54 ); 55 56 this.notifyObj = new BasicNotification(this.id); 57 this.notifyObj.anchorID = "geo-notification-icon"; 58 this.notifyObj.addOptions({ 59 persistence: 1, 60 }); 61 this.notification = showNotification(this.notifyObj); 62 }, 63 async onShown(popup) { 64 await BrowserTestUtils.loadURIString({ 65 browser: gBrowser.selectedTab.linkedBrowser, 66 uriString: "about:blank", 67 }); 68 69 checkPopup(popup, this.notifyObj); 70 is( 71 document.getElementById("geo-notification-icon").getBoundingClientRect() 72 .width, 73 0, 74 "geo anchor shouldn't be visible" 75 ); 76 assertFallbackAnchorNode(popup.anchorNode); 77 dismissNotification(popup); 78 }, 79 onHidden() { 80 this.notification.remove(); 81 gBrowser.removeTab(gBrowser.selectedTab); 82 gBrowser.selectedTab = this.oldSelectedTab; 83 }, 84 }, 85 // Test that dismissed popupnotifications cannot be opened on about:blank, but 86 // can be opened after navigation. 87 { 88 id: "Test#3", 89 async run() { 90 this.oldSelectedTab = gBrowser.selectedTab; 91 await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"); 92 93 this.notifyObj = new BasicNotification(this.id); 94 this.notifyObj.anchorID = "geo-notification-icon"; 95 this.notifyObj.addOptions({ 96 dismissed: true, 97 persistence: 1, 98 }); 99 this.notification = showNotification(this.notifyObj); 100 101 is( 102 document.getElementById("geo-notification-icon").getBoundingClientRect() 103 .width, 104 0, 105 "geo anchor shouldn't be visible" 106 ); 107 108 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 109 await BrowserTestUtils.loadURIString({ 110 browser: gBrowser.selectedTab.linkedBrowser, 111 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 112 uriString: "http://example.com/", 113 }); 114 115 isnot( 116 document.getElementById("geo-notification-icon").getBoundingClientRect() 117 .width, 118 0, 119 "geo anchor should be visible" 120 ); 121 122 EventUtils.synthesizeMouse( 123 document.getElementById("geo-notification-icon"), 124 2, 125 2, 126 {} 127 ); 128 }, 129 onShown(popup) { 130 checkPopup(popup, this.notifyObj); 131 dismissNotification(popup); 132 }, 133 onHidden() { 134 this.notification.remove(); 135 gBrowser.removeTab(gBrowser.selectedTab); 136 gBrowser.selectedTab = this.oldSelectedTab; 137 }, 138 }, 139 // Test that popupnotifications are hidden while editing the URL in the 140 // location bar, anchored to the fallback anchor when the focus is moved away 141 // from the location bar, and restored when the URL is reverted. 142 { 143 id: "Test#4", 144 async run() { 145 for (let persistent of [false, true]) { 146 let shown = waitForNotificationPanel(); 147 this.notifyObj = new BasicNotification(this.id); 148 this.notifyObj.anchorID = "geo-notification-icon"; 149 this.notifyObj.addOptions({ persistent }); 150 this.notification = showNotification(this.notifyObj); 151 await shown; 152 153 checkPopup(PopupNotifications.panel, this.notifyObj); 154 155 // Typing in the location bar should hide the notification. 156 let hidden = waitForNotificationPanelHidden(); 157 gURLBar.select(); 158 EventUtils.sendString("*"); 159 await hidden; 160 161 is( 162 document 163 .getElementById("geo-notification-icon") 164 .getBoundingClientRect().width, 165 0, 166 "geo anchor shouldn't be visible" 167 ); 168 169 // Moving focus to the next control should show the notifications again, 170 // anchored to the fallback anchor. We clear the URL bar before moving the 171 // focus so that the awesomebar popup doesn't get in the way. 172 shown = waitForNotificationPanel(); 173 EventUtils.synthesizeKey("KEY_Backspace"); 174 EventUtils.synthesizeKey("KEY_Tab"); 175 await shown; 176 177 assertFallbackAnchorNode(PopupNotifications.panel.anchorNode); 178 179 // Moving focus to the location bar should hide the notification again. 180 hidden = waitForNotificationPanelHidden(); 181 EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true }); 182 await hidden; 183 184 // Reverting the URL should show the notification again. 185 shown = waitForNotificationPanel(); 186 EventUtils.synthesizeKey("KEY_Escape"); 187 await shown; 188 189 checkPopup(PopupNotifications.panel, this.notifyObj); 190 191 hidden = waitForNotificationPanelHidden(); 192 this.notification.remove(); 193 await hidden; 194 } 195 goNext(); 196 }, 197 }, 198 // Test that popupnotifications triggered while editing the URL in the 199 // location bar are only shown later when the URL is reverted. 200 { 201 id: "Test#5", 202 async run() { 203 for (let persistent of [false, true]) { 204 // Start editing the URL, ensuring that the awesomebar popup is hidden. 205 gURLBar.select(); 206 EventUtils.sendString("*"); 207 EventUtils.synthesizeKey("KEY_Backspace"); 208 // autoOpen behavior will show the panel, so it must be closed. 209 gURLBar.view.close(); 210 211 // Trying to show a notification should display nothing. 212 let notShowing = TestUtils.topicObserved( 213 "PopupNotifications-updateNotShowing" 214 ); 215 this.notifyObj = new BasicNotification(this.id); 216 this.notifyObj.anchorID = "geo-notification-icon"; 217 this.notifyObj.addOptions({ persistent }); 218 this.notification = showNotification(this.notifyObj); 219 await notShowing; 220 221 // Reverting the URL should show the notification. 222 let shown = waitForNotificationPanel(); 223 EventUtils.synthesizeKey("KEY_Escape"); 224 await shown; 225 226 checkPopup(PopupNotifications.panel, this.notifyObj); 227 228 let hidden = waitForNotificationPanelHidden(); 229 this.notification.remove(); 230 await hidden; 231 } 232 233 goNext(); 234 }, 235 }, 236 // Test that persistent panels are still open after switching to another tab 237 // and back, even while editing the URL in the new tab. 238 { 239 id: "Test#6", 240 async run() { 241 let shown = waitForNotificationPanel(); 242 this.notifyObj = new BasicNotification(this.id); 243 this.notifyObj.anchorID = "geo-notification-icon"; 244 this.notifyObj.addOptions({ 245 persistent: true, 246 }); 247 this.notification = showNotification(this.notifyObj); 248 await shown; 249 250 // Switching to a new tab should hide the notification. 251 let hidden = waitForNotificationPanelHidden(); 252 this.oldSelectedTab = gBrowser.selectedTab; 253 await BrowserTestUtils.openNewForegroundTab( 254 gBrowser, 255 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 256 "http://example.com/" 257 ); 258 await hidden; 259 260 // Start editing the URL. 261 gURLBar.select(); 262 EventUtils.sendString("*"); 263 264 // Switching to the old tab should show the notification again. 265 shown = waitForNotificationPanel(); 266 gBrowser.removeTab(gBrowser.selectedTab); 267 gBrowser.selectedTab = this.oldSelectedTab; 268 await shown; 269 270 checkPopup(PopupNotifications.panel, this.notifyObj); 271 272 hidden = waitForNotificationPanelHidden(); 273 this.notification.remove(); 274 await hidden; 275 276 goNext(); 277 }, 278 }, 279 ]; 280 281 function assertFallbackAnchorNode(anchorNode) { 282 if (anchorNode.classList.contains("searchmode-switcher-icon")) { 283 Assert.ok(true, "The anchor is searchmode-switcher-icon"); 284 } else if (anchorNode.id == "identity-icon") { 285 Assert.ok(true, "The anchor is identity-icon"); 286 } else if (anchorNode.id == "remote-control-icon") { 287 Assert.ok(true, "The anchor is remote-control-icon"); 288 } else { 289 Assert.ok(false, "The anchor is unexpected element"); 290 } 291 }