| 
									
										
										
										
											2020-10-19 21:06:06 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2017 Google Inc. All rights reserved. | 
					
						
							|  |  |  |  * Modifications copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-06 07:08:22 -07:00
										 |  |  | import { test as it, expect } from './pageTest'; | 
					
						
							| 
									
										
										
										
											2020-10-19 21:06:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 20:09:22 +02:00
										 |  |  | it.skip(({ isWebView2 }) => isWebView2, 'Page.close() is not supported in WebView2'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 18:58:08 +02:00
										 |  |  | it('should close page with active dialog', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2024-05-31 14:44:26 -07:00
										 |  |  |   await page.evaluate('"trigger builtinSetTimeout"'); | 
					
						
							|  |  |  |   await page.setContent(`<button onclick="builtinSetTimeout(() => alert(1))">alert</button>`); | 
					
						
							| 
									
										
										
										
											2023-11-01 16:36:39 -07:00
										 |  |  |   void page.click('button').catch(() => {}); | 
					
						
							| 
									
										
										
										
											2020-10-19 21:06:06 -07:00
										 |  |  |   await page.waitForEvent('dialog'); | 
					
						
							|  |  |  |   await page.close(); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-10-20 08:55:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 14:09:56 -07:00
										 |  |  | it('should not accept dialog after close', async ({ page, mode }) => { | 
					
						
							| 
									
										
										
										
											2023-07-31 11:24:04 -07:00
										 |  |  |   it.fixme(mode.startsWith('service2'), 'Times out'); | 
					
						
							| 
									
										
										
										
											2023-09-27 14:09:56 -07:00
										 |  |  |   const promise = page.waitForEvent('dialog'); | 
					
						
							| 
									
										
										
										
											2020-11-02 13:06:54 -08:00
										 |  |  |   page.evaluate(() => alert()).catch(() => {}); | 
					
						
							| 
									
										
										
										
											2023-09-27 14:09:56 -07:00
										 |  |  |   const dialog = await promise; | 
					
						
							| 
									
										
										
										
											2020-11-02 13:06:54 -08:00
										 |  |  |   await page.close(); | 
					
						
							|  |  |  |   const e = await dialog.dismiss().catch(e => e); | 
					
						
							|  |  |  |   expect(e.message).toContain('Target page, context or browser has been closed'); | 
					
						
							|  |  |  | }); |