| 
									
										
										
										
											2020-08-04 15:09:24 -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-11-13 16:29:20 -08:00
										 |  |  | import * as os from 'os'; | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 11:11:32 -07:00
										 |  |  | function crash({ page, toImpl, browserName, platform, mode }: any) { | 
					
						
							| 
									
										
										
										
											2021-04-02 14:23:42 -07:00
										 |  |  |   if (browserName === 'chromium') { | 
					
						
							| 
									
										
										
										
											2020-09-15 09:46:36 -07:00
										 |  |  |     page.goto('chrome://crash').catch(e => {}); | 
					
						
							| 
									
										
										
										
											2021-04-02 14:23:42 -07:00
										 |  |  |   } else if (browserName === 'webkit') { | 
					
						
							|  |  |  |     it.skip(mode !== 'default'); | 
					
						
							|  |  |  |     it.fixme(platform === 'darwin' && parseInt(os.release(), 10) >= 20, 'Timing out after roll on BigSur'); | 
					
						
							| 
									
										
										
										
											2020-09-15 09:46:36 -07:00
										 |  |  |     toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {}); | 
					
						
							| 
									
										
										
										
											2021-04-02 14:23:42 -07:00
										 |  |  |   } else if (browserName === 'firefox') { | 
					
						
							|  |  |  |     it.skip(mode !== 'default'); | 
					
						
							| 
									
										
										
										
											2020-09-15 09:46:36 -07:00
										 |  |  |     toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {}); | 
					
						
							| 
									
										
										
										
											2021-04-02 14:23:42 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-02 14:23:42 -07:00
										 |  |  | it.describe('', () => { | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |   it('should emit crash event when page crashes', async ({ page, toImpl, browserName, platform, mode }) => { | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.setContent(`<div>This page should crash</div>`); | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |     crash({ page, toImpl, browserName, platform, mode }); | 
					
						
							| 
									
										
										
										
											2021-01-22 09:58:31 -08:00
										 |  |  |     const crashedPage = await new Promise(f => page.on('crash', f)); | 
					
						
							|  |  |  |     expect(crashedPage).toBe(page); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |   it('should throw on any action after page crashes', async ({ page, toImpl, browserName, platform, mode }) => { | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.setContent(`<div>This page should crash</div>`); | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |     crash({ page, toImpl, browserName, platform, mode }); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.waitForEvent('crash'); | 
					
						
							|  |  |  |     const err = await page.evaluate(() => {}).then(() => null, e => e); | 
					
						
							|  |  |  |     expect(err).toBeTruthy(); | 
					
						
							|  |  |  |     expect(err.message).toContain('crash'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |   it('should cancel waitForEvent when page crashes', async ({ page, toImpl, browserName, platform, mode }) => { | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.setContent(`<div>This page should crash</div>`); | 
					
						
							|  |  |  |     const promise = page.waitForEvent('response').catch(e => e); | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |     crash({ page, toImpl, browserName, platform, mode }); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     const error = await promise; | 
					
						
							|  |  |  |     expect(error.message).toContain('Page crashed'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |   it('should cancel navigation when page crashes', async ({ server, page, toImpl, browserName, platform, mode }) => { | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.setContent(`<div>This page should crash</div>`); | 
					
						
							|  |  |  |     server.setRoute('/one-style.css', () => {}); | 
					
						
							|  |  |  |     const promise = page.goto(server.PREFIX + '/one-style.html').catch(e => e); | 
					
						
							|  |  |  |     await page.waitForNavigation({ waitUntil: 'domcontentloaded' }); | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |     crash({ page, toImpl, browserName, platform, mode }); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     const error = await promise; | 
					
						
							|  |  |  |     expect(error.message).toContain('Navigation failed because page crashed'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |   it('should be able to close context when page crashes', async ({ isAndroid, isElectron, page, toImpl, browserName, platform, mode }) => { | 
					
						
							|  |  |  |     it.skip(isAndroid); | 
					
						
							|  |  |  |     it.skip(isElectron); | 
					
						
							| 
									
										
										
										
											2021-04-08 10:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.setContent(`<div>This page should crash</div>`); | 
					
						
							| 
									
										
										
										
											2021-05-16 19:58:26 -07:00
										 |  |  |     crash({ page, toImpl, browserName, platform, mode }); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  |     await page.waitForEvent('crash'); | 
					
						
							|  |  |  |     await page.context().close(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | }); |