| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2018 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 10:59:27 -07:00
										 |  |  | import { it, expect } from './fixtures'; | 
					
						
							| 
									
										
										
										
											2020-09-25 23:30:46 -07:00
										 |  |  | import { attachFrame } from './utils'; | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should fire for navigation requests', async ({page, server}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const requests = []; | 
					
						
							|  |  |  |   page.on('request', request => requests.push(request)); | 
					
						
							|  |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							|  |  |  |   expect(requests.length).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should fire for iframes', async ({page, server}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const requests = []; | 
					
						
							|  |  |  |   page.on('request', request => requests.push(request)); | 
					
						
							|  |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-09-18 15:52:14 -07:00
										 |  |  |   await attachFrame(page, 'frame1', server.EMPTY_PAGE); | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   expect(requests.length).toBe(2); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should fire for fetches', async ({page, server}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const requests = []; | 
					
						
							|  |  |  |   page.on('request', request => requests.push(request)); | 
					
						
							|  |  |  |   await page.goto(server.EMPTY_PAGE); | 
					
						
							|  |  |  |   await page.evaluate(() => fetch('/empty.html')); | 
					
						
							|  |  |  |   expect(requests.length).toBe(2); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  | it('should report requests and responses handled by service worker', async ({page, server}) => { | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html'); | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  |   await page.evaluate(() => window['activationPromise']); | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |   const [swResponse, request] = await Promise.all([ | 
					
						
							| 
									
										
										
										
											2020-08-28 04:20:29 -07:00
										 |  |  |     page.evaluate(() => window['fetchDummy']('foo')), | 
					
						
							| 
									
										
										
										
											2020-08-03 16:30:37 -07:00
										 |  |  |     page.waitForEvent('request'), | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  |   expect(swResponse).toBe('responseFromServiceWorker:foo'); | 
					
						
							|  |  |  |   expect(request.url()).toBe(server.PREFIX + '/serviceworkers/fetchdummy/foo'); | 
					
						
							|  |  |  |   const response = await request.response(); | 
					
						
							|  |  |  |   expect(response.url()).toBe(server.PREFIX + '/serviceworkers/fetchdummy/foo'); | 
					
						
							|  |  |  |   expect(await response.text()).toBe('responseFromServiceWorker:foo'); | 
					
						
							|  |  |  | }); |