2019-11-18 18:18:28 -08:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-12-06 16:15:27 -08:00
|
|
|
const { waitEvent } = require('../utils');
|
2019-11-18 18:18:28 -08:00
|
|
|
|
2020-02-10 13:20:13 -08:00
|
|
|
/**
|
|
|
|
* @type {ChromiumTestSuite}
|
|
|
|
*/
|
2020-01-13 10:13:28 -08:00
|
|
|
module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMIUM, WEBKIT}) {
|
2019-11-18 18:18:28 -08:00
|
|
|
const {describe, xdescribe, fdescribe} = testRunner;
|
2019-12-19 15:47:35 -08:00
|
|
|
const {it, fit, xit, dit} = testRunner;
|
2019-11-18 18:18:28 -08:00
|
|
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
|
|
|
|
2020-03-02 18:32:56 -08:00
|
|
|
describe('ChromiumBrowserContext', function() {
|
2019-12-04 16:12:43 -08:00
|
|
|
it('should create a worker from a service worker', async({browser, page, server, context}) => {
|
2020-03-02 13:58:22 -08:00
|
|
|
const [worker] = await Promise.all([
|
2020-03-05 17:22:57 -08:00
|
|
|
context.waitForEvent('serviceworker'),
|
2020-03-02 13:58:22 -08:00
|
|
|
page.goto(server.PREFIX + '/serviceworkers/empty/sw.html')
|
|
|
|
]);
|
2019-11-18 18:18:28 -08:00
|
|
|
expect(await worker.evaluate(() => self.toString())).toBe('[object ServiceWorkerGlobalScope]');
|
|
|
|
});
|
2020-02-24 08:31:58 -08:00
|
|
|
it('should not create a worker from a shared worker', async({browser, page, server, context}) => {
|
2019-11-18 18:18:28 -08:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-03-02 13:58:22 -08:00
|
|
|
let serviceWorkerCreated;
|
|
|
|
context.once('serviceworker', () => serviceWorkerCreated = true);
|
2019-11-18 18:18:28 -08:00
|
|
|
await page.evaluate(() => {
|
|
|
|
new SharedWorker('data:text/javascript,console.log("hi")');
|
|
|
|
});
|
2020-03-02 13:58:22 -08:00
|
|
|
expect(serviceWorkerCreated).not.toBeTruthy();
|
2019-11-18 18:18:28 -08:00
|
|
|
});
|
|
|
|
});
|
2019-12-06 16:15:27 -08:00
|
|
|
|
|
|
|
describe('Chromium-Specific Page Tests', function() {
|
2020-02-03 14:23:24 -08:00
|
|
|
it('Page.route should work with intervention headers', async({server, page}) => {
|
2019-12-06 16:15:27 -08:00
|
|
|
server.setRoute('/intervention', (req, res) => res.end(`
|
|
|
|
<script>
|
|
|
|
document.write('<script src="${server.CROSS_PROCESS_PREFIX}/intervention.js">' + '</scr' + 'ipt>');
|
|
|
|
</script>
|
|
|
|
`));
|
|
|
|
server.setRedirect('/intervention.js', '/redirect.js');
|
|
|
|
let serverRequest = null;
|
|
|
|
server.setRoute('/redirect.js', (req, res) => {
|
|
|
|
serverRequest = req;
|
|
|
|
res.end('console.log(1);');
|
|
|
|
});
|
|
|
|
|
2020-03-13 14:30:40 -07:00
|
|
|
await page.route('*', route => route.continue());
|
2019-12-06 16:15:27 -08:00
|
|
|
await page.goto(server.PREFIX + '/intervention');
|
|
|
|
// Check for feature URL substring rather than https://www.chromestatus.com to
|
|
|
|
// make it work with Edgium.
|
|
|
|
expect(serverRequest.headers.intervention).toContain('feature/5718547946799104');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-18 18:18:28 -08:00
|
|
|
};
|