@@ -19,6 +19,16 @@ function promiseNotification(id) {
19
19
} ) ;
20
20
}
21
21
22
+ function triggerMainPopupCommand ( popup ) {
23
+ info ( "triggering main command" ) ;
24
+ let notifications = popup . childNodes ;
25
+ ok ( notifications . length > 0 , "at least one notification displayed" ) ;
26
+ let notification = notifications [ 0 ] ;
27
+ info ( "triggering command: " + notification . getAttribute ( "buttonlabel" ) ) ;
28
+
29
+ return EventUtils . synthesizeMouseAtCenter ( notification . button , { } ) ;
30
+ }
31
+
22
32
let expectAbortError = expectError ( "Abort" ) ;
23
33
24
34
function verifyAnonymizedCertificate ( result ) {
@@ -115,6 +125,103 @@ add_task(async function test_register_direct_cancel() {
115
125
await BrowserTestUtils . removeTab ( tab ) ;
116
126
} ) ;
117
127
128
+ // Add two tabs, open WebAuthn in the first, switch, assert the prompt is
129
+ // not visible, switch back, assert the prompt is there and cancel it.
130
+ add_task ( async function test_tab_switching ( ) {
131
+ // Open a new tab.
132
+ let tab_one = await BrowserTestUtils . openNewForegroundTab ( gBrowser , TEST_URL ) ;
133
+
134
+ // Request a new credential and wait for the prompt.
135
+ let active = true ;
136
+ let request = promiseWebAuthnMakeCredential ( tab_one , "indirect" , { } )
137
+ . then ( arrivingHereIsBad )
138
+ . catch ( expectAbortError )
139
+ . then ( ( ) => ( active = false ) ) ;
140
+ await promiseNotification ( "webauthn-prompt-register" ) ;
141
+ is ( PopupNotifications . panel . state , "open" , "Doorhanger is visible" ) ;
142
+
143
+ // Open and switch to a second tab.
144
+ let tab_two = await BrowserTestUtils . openNewForegroundTab (
145
+ gBrowser ,
146
+ "https://example.org/"
147
+ ) ;
148
+
149
+ await TestUtils . waitForCondition (
150
+ ( ) => PopupNotifications . panel . state == "closed"
151
+ ) ;
152
+ is ( PopupNotifications . panel . state , "closed" , "Doorhanger is hidden" ) ;
153
+
154
+ // Go back to the first tab
155
+ await BrowserTestUtils . removeTab ( tab_two ) ;
156
+
157
+ await promiseNotification ( "webauthn-prompt-register" ) ;
158
+
159
+ await TestUtils . waitForCondition (
160
+ ( ) => PopupNotifications . panel . state == "open"
161
+ ) ;
162
+ is ( PopupNotifications . panel . state , "open" , "Doorhanger is visible" ) ;
163
+
164
+ // Cancel the request.
165
+ ok ( active , "request should still be active" ) ;
166
+ await triggerMainPopupCommand ( PopupNotifications . panel ) ;
167
+ await request ;
168
+ ok ( ! active , "request should be stopped" ) ;
169
+
170
+ // Close tab.
171
+ await BrowserTestUtils . removeTab ( tab_one ) ;
172
+ } ) ;
173
+
174
+ // Add two tabs, open WebAuthn in the first, switch, assert the prompt is
175
+ // not visible, switch back, assert the prompt is there and cancel it.
176
+ add_task ( async function test_window_switching ( ) {
177
+ // Open a new tab.
178
+ let tab = await BrowserTestUtils . openNewForegroundTab ( gBrowser , TEST_URL ) ;
179
+
180
+ // Request a new credential and wait for the prompt.
181
+ let active = true ;
182
+ let request = promiseWebAuthnMakeCredential ( tab , "indirect" , { } )
183
+ . then ( arrivingHereIsBad )
184
+ . catch ( expectAbortError )
185
+ . then ( ( ) => ( active = false ) ) ;
186
+ await promiseNotification ( "webauthn-prompt-register" ) ;
187
+
188
+ await TestUtils . waitForCondition (
189
+ ( ) => PopupNotifications . panel . state == "open"
190
+ ) ;
191
+ is ( PopupNotifications . panel . state , "open" , "Doorhanger is visible" ) ;
192
+
193
+ // Open and switch to a second window
194
+ let new_window = await BrowserTestUtils . openNewBrowserWindow ( ) ;
195
+ await SimpleTest . promiseFocus ( new_window ) ;
196
+
197
+ await TestUtils . waitForCondition (
198
+ ( ) => new_window . PopupNotifications . panel . state == "closed"
199
+ ) ;
200
+ is (
201
+ new_window . PopupNotifications . panel . state ,
202
+ "closed" ,
203
+ "Doorhanger is hidden"
204
+ ) ;
205
+
206
+ // Go back to the first tab
207
+ await BrowserTestUtils . closeWindow ( new_window ) ;
208
+ await SimpleTest . promiseFocus ( window ) ;
209
+
210
+ await TestUtils . waitForCondition (
211
+ ( ) => PopupNotifications . panel . state == "open"
212
+ ) ;
213
+ is ( PopupNotifications . panel . state , "open" , "Doorhanger is still visible" ) ;
214
+
215
+ // Cancel the request.
216
+ ok ( active , "request should still be active" ) ;
217
+ await triggerMainPopupCommand ( PopupNotifications . panel ) ;
218
+ await request ;
219
+ ok ( ! active , "request should be stopped" ) ;
220
+
221
+ // Close tab.
222
+ await BrowserTestUtils . removeTab ( tab ) ;
223
+ } ) ;
224
+
118
225
add_task ( async function test_setup_softtoken ( ) {
119
226
await SpecialPowers . pushPrefEnv ( {
120
227
set : [
0 commit comments