|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +module.exports.describe = function ({ testRunner, expect }) { |
| 18 | + const {describe, xdescribe, fdescribe} = testRunner; |
| 19 | + const {it, fit, xit, dit} = testRunner; |
| 20 | + const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; |
| 21 | + |
| 22 | + describe('provisional page', function() { |
| 23 | + it('extraHttpHeaders should be pushed to provisional page', async({page, server}) => { |
| 24 | + await page.goto(server.EMPTY_PAGE); |
| 25 | + const pagePath = '/one-style.html'; |
| 26 | + server.setRoute(pagePath, async (req, res) => { |
| 27 | + await page.setExtraHTTPHeaders({ foo: 'bar' }); |
| 28 | + server.serveFile(req, res, pagePath); |
| 29 | + }); |
| 30 | + const [htmlReq, cssReq] = await Promise.all([ |
| 31 | + server.waitForRequest(pagePath), |
| 32 | + server.waitForRequest('/one-style.css'), |
| 33 | + page.goto(server.CROSS_PROCESS_PREFIX + pagePath) |
| 34 | + ]); |
| 35 | + expect(htmlReq.headers['foo']).toBe(undefined); |
| 36 | + expect(cssReq.headers['foo']).toBe('bar'); |
| 37 | + }); |
| 38 | + it('should continue load when interception gets disabled during provisional load', async({page, server}) => { |
| 39 | + await page.goto(server.EMPTY_PAGE); |
| 40 | + await page.setRequestInterception(true); |
| 41 | + expect(await page.evaluate(() => navigator.onLine)).toBe(true); |
| 42 | + let intercepted = null; |
| 43 | + const order = []; |
| 44 | + page.on('request', request => { |
| 45 | + intercepted = page.setRequestInterception(false).then(() => order.push('setRequestInterception')); |
| 46 | + }); |
| 47 | + const response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html').then(response => { |
| 48 | + order.push('goto'); |
| 49 | + return response; |
| 50 | + }); |
| 51 | + // Should intercept a request. |
| 52 | + expect(intercepted).not.toBe(null); |
| 53 | + await intercepted; |
| 54 | + // Should continue on disabling and load successfully. |
| 55 | + expect(response.status()).toBe(200); |
| 56 | + // Should resolve setRequestInterception before goto. |
| 57 | + expect(order[0]).toBe('setRequestInterception'); |
| 58 | + expect(order[1]).toBe('goto'); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}; |
0 commit comments