test: group interception tests in interception.spec

This commit is contained in:
Pavel Feldman 2019-12-10 13:11:04 -08:00
parent f1f9dc166b
commit c61c5b056f
4 changed files with 58 additions and 59 deletions

View File

@ -570,6 +570,63 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
});
});
describe.skip(FFOX)('Interception.authenticate', function() {
it('should work', async({page, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await page.interception.authenticate({
username: 'user',
password: 'pass'
});
response = await page.reload();
expect(response.status()).toBe(200);
});
it('should fail if wrong credentials', async({page, server}) => {
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user2', 'pass2');
await page.interception.authenticate({
username: 'foo',
password: 'bar'
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
});
it('should allow disable authentication', async({page, server}) => {
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user3', 'pass3');
await page.interception.authenticate({
username: 'user3',
password: 'pass3'
});
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await page.interception.authenticate(null);
// Navigate to a different origin to bust Chrome's credential caching.
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.status()).toBe(401);
});
});
describe.skip(FFOX)('Interception.setOfflineMode', function() {
it('should work', async({page, server}) => {
await page.interception.setOfflineMode(true);
let error = null;
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
expect(error).toBeTruthy();
await page.interception.setOfflineMode(false);
const response = await page.reload();
expect(response.status()).toBe(200);
});
it('should emulate navigator.onLine', async({page, server}) => {
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
await page.interception.setOfflineMode(true);
expect(await page.evaluate(() => window.navigator.onLine)).toBe(false);
await page.interception.setOfflineMode(false);
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
});
});
};
/**

View File

@ -356,44 +356,5 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.');
});
});
// FIXME: WebKit doesn't support network interception.
describe.skip(FFOX || WEBKIT)('Interception.authenticate', function() {
it('should work', async({page, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await page.interception.authenticate({
username: 'user',
password: 'pass'
});
response = await page.reload();
expect(response.status()).toBe(200);
});
it('should fail if wrong credentials', async({page, server}) => {
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user2', 'pass2');
await page.interception.authenticate({
username: 'foo',
password: 'bar'
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
});
it('should allow disable authentication', async({page, server}) => {
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user3', 'pass3');
await page.interception.authenticate({
username: 'user3',
password: 'pass3'
});
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await page.interception.authenticate(null);
// Navigate to a different origin to bust Chrome's credential caching.
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.status()).toBe(401);
});
});
};

View File

@ -166,25 +166,6 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
});
});
describe.skip(FFOX || WEBKIT)('Interception.setOfflineMode', function() {
it('should work', async({page, server}) => {
await page.interception.setOfflineMode(true);
let error = null;
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
expect(error).toBeTruthy();
await page.interception.setOfflineMode(false);
const response = await page.reload();
expect(response.status()).toBe(200);
});
it('should emulate navigator.onLine', async({page, server}) => {
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
await page.interception.setOfflineMode(true);
expect(await page.evaluate(() => window.navigator.onLine)).toBe(false);
await page.interception.setOfflineMode(false);
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
});
});
describe('Page.Events.Console', function() {
it('should work', async({page, server}) => {
let message = null;

View File

@ -162,7 +162,7 @@ module.exports.addTests = ({testRunner, product, playwrightPath}) => {
if (CHROME || FFOX) {
require('./features/accessibility.spec.js').addTests(testOptions);
require('./features/permissions.spec.js').addTests(testOptions);
require('./features/requestinterception.spec.js').addTests(testOptions);
require('./features/interception.spec.js').addTests(testOptions);
}
});