test: split test to be more fine grained (#12337)

This commit is contained in:
Nikolay Vitkov 2024-04-25 18:26:39 +02:00 committed by GitHub
parent 47013cd938
commit 7b5e286146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 230 additions and 57 deletions

View File

@ -76,13 +76,6 @@
"expectations": ["SKIP"], "expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Network Events *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{ {
"testIdPattern": "[network.spec] network Page.setBypassServiceWorker *", "testIdPattern": "[network.spec] network Page.setBypassServiceWorker *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -104,6 +97,13 @@
"expectations": ["FAIL"], "expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Request.resourceType *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Bidi does not have equivalent field"
},
{ {
"testIdPattern": "[network.spec] network Response.buffer *", "testIdPattern": "[network.spec] network Response.buffer *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -118,6 +118,13 @@
"expectations": ["FAIL"], "expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Response.remoteAddress *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Bidi does not have equivalent field"
},
{ {
"testIdPattern": "[network.spec] network Response.text *", "testIdPattern": "[network.spec] network Response.text *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -488,18 +495,6 @@
"expectations": ["FAIL"], "expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Network Events Page.Events.RequestFinished",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[network.spec] network Network Events should fire events in proper order",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[network.spec] network Page.setExtraHTTPHeaders *", "testIdPattern": "[network.spec] network Page.setExtraHTTPHeaders *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -756,6 +751,20 @@
"expectations": ["SKIP"], "expectations": ["SKIP"],
"comment": "TODO: Needs full support for continueRequest in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1850680" "comment": "TODO: Needs full support for continueRequest in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1850680"
}, },
{
"testIdPattern": "[requestinterception-experimental.spec] cooperative request interception Request.resourceType should work for document type",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "`HTTPRequest.resourceType()` has no eqivalent in BiDi spec"
},
{
"testIdPattern": "[requestinterception-experimental.spec] cooperative request interception Request.resourceType should work for stylesheets",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "`HTTPRequest.resourceType()` has no eqivalent in BiDi spec"
},
{ {
"testIdPattern": "[requestinterception-experimental.spec] cooperative request interception Request.respond *", "testIdPattern": "[requestinterception-experimental.spec] cooperative request interception Request.respond *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -812,6 +821,20 @@
"expectations": ["SKIP"], "expectations": ["SKIP"],
"comment": "TODO: Needs full support for continueRequest in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1850680" "comment": "TODO: Needs full support for continueRequest in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1850680"
}, },
{
"testIdPattern": "[requestinterception.spec] request interception Request.resourceType should work for document type",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "`HTTPRequest.resourceType()` has no eqivalent in BiDi spec"
},
{
"testIdPattern": "[requestinterception.spec] request interception Request.resourceType should work for stylesheets",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "`HTTPRequest.resourceType()` has no eqivalent in BiDi spec"
},
{ {
"testIdPattern": "[requestinterception.spec] request interception Request.respond *", "testIdPattern": "[requestinterception.spec] request interception Request.respond *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2567,6 +2590,13 @@
"expectations": ["FAIL"], "expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Network Events Page.Events.RequestFailed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Test expects slightly different error message consider changing"
},
{ {
"testIdPattern": "[network.spec] network Network Events Page.Events.RequestFinished", "testIdPattern": "[network.spec] network Network Events Page.Events.RequestFinished",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2584,8 +2614,9 @@
{ {
"testIdPattern": "[network.spec] network Network Events Page.Events.RequestServedFromCache", "testIdPattern": "[network.spec] network Network Events Page.Events.RequestServedFromCache",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"] "expectations": ["FAIL"],
"comment": "Firefox does not send events for the cached event (bypasses network?)"
}, },
{ {
"testIdPattern": "[network.spec] network Network Events Page.Events.Response", "testIdPattern": "[network.spec] network Network Events Page.Events.Response",
@ -2622,6 +2653,13 @@
"expectations": ["FAIL"], "expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Network Events should support redirects",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Response completed for the redirect get emitter after the beforeSent (or flushed with the last responseCompleted)"
},
{ {
"testIdPattern": "[network.spec] network Page.authenticate should allow disable authentication", "testIdPattern": "[network.spec] network Page.authenticate should allow disable authentication",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2817,6 +2855,13 @@
"expectations": ["SKIP"], "expectations": ["SKIP"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Response.remoteAddress should support redirects",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
},
{ {
"testIdPattern": "[network.spec] network Response.text should return uncompressed text", "testIdPattern": "[network.spec] network Response.text should return uncompressed text",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -4042,6 +4087,13 @@
"expectations": ["FAIL", "PASS"], "expectations": ["FAIL", "PASS"],
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
}, },
{
"testIdPattern": "[network.spec] network Network Events should support redirects",
"platforms": ["linux"],
"parameters": ["chrome", "headless", "webDriverBiDi"],
"expectations": ["FAIL"],
"comment": "Fix in next PR"
},
{ {
"testIdPattern": "[network.spec] network raw network headers Same-origin set-cookie subresource", "testIdPattern": "[network.spec] network raw network headers Same-origin set-cookie subresource",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],

View File

@ -492,12 +492,12 @@ describe('network', function () {
}); });
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
expect(requests).toHaveLength(1); expect(requests).toHaveLength(1);
expect(requests[0]!.url()).toBe(server.EMPTY_PAGE); const request = requests[0]!;
expect(requests[0]!.resourceType()).toBe('document'); expect(request.url()).toBe(server.EMPTY_PAGE);
expect(requests[0]!.method()).toBe('GET'); expect(request.method()).toBe('GET');
expect(requests[0]!.response()).toBeTruthy(); expect(request.response()).toBeTruthy();
expect(requests[0]!.frame() === page.mainFrame()).toBe(true); expect(request.frame() === page.mainFrame()).toBe(true);
expect(requests[0]!.frame()!.url()).toBe(server.EMPTY_PAGE); expect(request.frame()!.url()).toBe(server.EMPTY_PAGE);
}); });
it('Page.Events.RequestServedFromCache', async () => { it('Page.Events.RequestServedFromCache', async () => {
const {page, server} = await getTestState(); const {page, server} = await getTestState();
@ -509,7 +509,9 @@ describe('network', function () {
await page.goto(server.PREFIX + '/cached/one-style.html'); await page.goto(server.PREFIX + '/cached/one-style.html');
expect(cached).toEqual([]); expect(cached).toEqual([]);
await new Promise(res => {
setTimeout(res, 1000);
});
await page.reload(); await page.reload();
expect(cached).toEqual(['one-style.css']); expect(cached).toEqual(['one-style.css']);
}); });
@ -522,16 +524,11 @@ describe('network', function () {
}); });
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
expect(responses).toHaveLength(1); expect(responses).toHaveLength(1);
expect(responses[0]!.url()).toBe(server.EMPTY_PAGE); const response = responses[0]!;
expect(responses[0]!.status()).toBe(200); expect(response.url()).toBe(server.EMPTY_PAGE);
expect(responses[0]!.ok()).toBe(true); expect(response.status()).toBe(200);
expect(responses[0]!.request()).toBeTruthy(); expect(response.ok()).toBe(true);
const remoteAddress = responses[0]!.remoteAddress(); expect(response.request()).toBeTruthy();
// Either IPv6 or IPv4, depending on environment.
expect(
remoteAddress.ip!.includes('::1') || remoteAddress.ip === '127.0.0.1'
).toBe(true);
expect(remoteAddress.port).toBe(server.PORT);
}); });
it('Page.Events.RequestFailed', async () => { it('Page.Events.RequestFailed', async () => {
@ -551,17 +548,15 @@ describe('network', function () {
}); });
await page.goto(server.PREFIX + '/one-style.html'); await page.goto(server.PREFIX + '/one-style.html');
expect(failedRequests).toHaveLength(1); expect(failedRequests).toHaveLength(1);
expect(failedRequests[0]!.url()).toContain('one-style.css'); const failedRequest = failedRequests[0]!;
expect(failedRequests[0]!.response()).toBe(null); expect(failedRequest.url()).toContain('one-style.css');
expect(failedRequests[0]!.resourceType()).toBe('stylesheet'); expect(failedRequest.response()).toBe(null);
expect(failedRequest.frame()).toBeTruthy();
if (isChrome) { if (isChrome) {
expect(failedRequests[0]!.failure()!.errorText).toBe('net::ERR_FAILED'); expect(failedRequest.failure()!.errorText).toBe('net::ERR_FAILED');
} else { } else {
expect(failedRequests[0]!.failure()!.errorText).toBe( expect(failedRequest.failure()!.errorText).toBe('NS_ERROR_FAILURE');
'NS_ERROR_FAILURE'
);
} }
expect(failedRequests[0]!.frame()).toBeTruthy();
}); });
it('Page.Events.RequestFinished', async () => { it('Page.Events.RequestFinished', async () => {
const {page, server} = await getTestState(); const {page, server} = await getTestState();
@ -631,9 +626,6 @@ describe('network', function () {
const redirectChain = response.request().redirectChain(); const redirectChain = response.request().redirectChain();
expect(redirectChain).toHaveLength(1); expect(redirectChain).toHaveLength(1);
expect(redirectChain[0]!.url()).toContain('/foo.html'); expect(redirectChain[0]!.url()).toContain('/foo.html');
expect(redirectChain[0]!.response()!.remoteAddress().port).toBe(
server.PORT
);
}); });
}); });
@ -914,4 +906,71 @@ describe('network', function () {
expect(responses.get('style.css').fromServiceWorker()).toBe(false); expect(responses.get('style.css').fromServiceWorker()).toBe(false);
}); });
}); });
describe('Request.resourceType', () => {
it('should work for document type', async () => {
const {page, server} = await getTestState();
const requests: HTTPRequest[] = [];
page.on('request', request => {
return requests.push(request);
});
await page.goto(server.EMPTY_PAGE);
expect(requests).toHaveLength(1);
const request = requests[0]!;
expect(request.resourceType()).toBe('document');
});
it('should work for stylesheets', async () => {
const {page, server} = await getTestState();
const cssRequests: HTTPRequest[] = [];
page.on('request', request => {
if (request.url().endsWith('css')) {
cssRequests.push(request);
}
});
await page.goto(server.PREFIX + '/one-style.html');
expect(cssRequests).toHaveLength(1);
const request = cssRequests[0]!;
expect(request.url()).toContain('one-style.css');
expect(request.resourceType()).toBe('stylesheet');
});
});
describe('Response.remoteAddress', () => {
it('should work', async () => {
const {page, server} = await getTestState();
const responses: HTTPResponse[] = [];
page.on('response', response => {
return responses.push(response);
});
await page.goto(server.EMPTY_PAGE);
expect(responses).toHaveLength(1);
const response = responses[0]!;
const remoteAddress = response.remoteAddress();
// Either IPv6 or IPv4, depending on environment.
expect(
remoteAddress.ip!.includes('::1') || remoteAddress.ip === '127.0.0.1'
).toBe(true);
expect(remoteAddress.port).toBe(server.PORT);
});
it('should support redirects', async () => {
const {page, server} = await getTestState();
server.setRedirect('/foo.html', '/empty.html');
const FOO_URL = server.PREFIX + '/foo.html';
const response = (await page.goto(FOO_URL))!;
// Check redirect chain
const redirectChain = response.request().redirectChain();
expect(redirectChain).toHaveLength(1);
expect(redirectChain[0]!.url()).toContain('/foo.html');
expect(redirectChain[0]!.response()!.remoteAddress().port).toBe(
server.PORT
);
});
});
}); });

View File

@ -106,7 +106,6 @@ describe('cooperative request interception', function () {
expect(request.method()).toBe('GET'); expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined); expect(request.postData()).toBe(undefined);
expect(request.isNavigationRequest()).toBe(true); expect(request.isNavigationRequest()).toBe(true);
expect(request.resourceType()).toBe('document');
expect(request.frame()!.url()).toBe('about:blank'); expect(request.frame()!.url()).toBe('about:blank');
expect(request.frame() === page.mainFrame()).toBe(true); expect(request.frame() === page.mainFrame()).toBe(true);
} catch (error) { } catch (error) {
@ -408,7 +407,6 @@ describe('cooperative request interception', function () {
expect(response!.status()).toBe(200); expect(response!.status()).toBe(200);
expect(response!.url()).toContain('empty.html'); expect(response!.url()).toContain('empty.html');
expect(requests).toHaveLength(5); expect(requests).toHaveLength(5);
expect(requests[2]!.resourceType()).toBe('document');
// Check redirect chain // Check redirect chain
const redirectChain = response!.request().redirectChain(); const redirectChain = response!.request().redirectChain();
expect(redirectChain).toHaveLength(4); expect(redirectChain).toHaveLength(4);
@ -442,8 +440,6 @@ describe('cooperative request interception', function () {
expect(response!.status()).toBe(200); expect(response!.status()).toBe(200);
expect(response!.url()).toContain('one-style.html'); expect(response!.url()).toContain('one-style.html');
expect(requests).toHaveLength(5); expect(requests).toHaveLength(5);
expect(requests[0]!.resourceType()).toBe('document');
expect(requests[1]!.resourceType()).toBe('stylesheet');
// Check redirect chain // Check redirect chain
const redirectChain = requests[1]!.redirectChain(); const redirectChain = requests[1]!.redirectChain();
expect(redirectChain).toHaveLength(3); expect(redirectChain).toHaveLength(3);
@ -1006,6 +1002,41 @@ describe('cooperative request interception', function () {
} }
}); });
}); });
describe('Request.resourceType', () => {
it('should work for document type', async () => {
const {page, server} = await getTestState();
await page.setRequestInterception(true);
const requests: HTTPRequest[] = [];
page.on('request', request => {
requests.push(request);
void request.continue({}, 0);
});
await page.goto(server.EMPTY_PAGE);
expect(requests).toHaveLength(1);
const request = requests[0]!;
expect(request.resourceType()).toBe('document');
});
it('should work for stylesheets', async () => {
const {page, server} = await getTestState();
await page.setRequestInterception(true);
const cssRequests: HTTPRequest[] = [];
page.on('request', request => {
if (request.url().endsWith('css')) {
cssRequests.push(request);
}
void request.continue({}, 0);
});
await page.goto(server.PREFIX + '/one-style.html');
expect(cssRequests).toHaveLength(1);
const request = cssRequests[0]!;
expect(request.url()).toContain('one-style.css');
expect(request.resourceType()).toBe('stylesheet');
});
});
}); });
function pathToFileURL(path: string): string { function pathToFileURL(path: string): string {

View File

@ -35,7 +35,6 @@ describe('request interception', function () {
expect(request.method()).toBe('GET'); expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined); expect(request.postData()).toBe(undefined);
expect(request.isNavigationRequest()).toBe(true); expect(request.isNavigationRequest()).toBe(true);
expect(request.resourceType()).toBe('document');
expect(request.frame()!.url()).toBe('about:blank'); expect(request.frame()!.url()).toBe('about:blank');
expect(request.frame() === page.mainFrame()).toBe(true); expect(request.frame() === page.mainFrame()).toBe(true);
} catch (error) { } catch (error) {
@ -325,7 +324,6 @@ describe('request interception', function () {
expect(response.status()).toBe(200); expect(response.status()).toBe(200);
expect(response.url()).toContain('empty.html'); expect(response.url()).toContain('empty.html');
expect(requests).toHaveLength(5); expect(requests).toHaveLength(5);
expect(requests[2]!.resourceType()).toBe('document');
// Check redirect chain // Check redirect chain
const redirectChain = response.request().redirectChain(); const redirectChain = response.request().redirectChain();
expect(redirectChain).toHaveLength(4); expect(redirectChain).toHaveLength(4);
@ -359,8 +357,6 @@ describe('request interception', function () {
expect(response.status()).toBe(200); expect(response.status()).toBe(200);
expect(response.url()).toContain('one-style.html'); expect(response.url()).toContain('one-style.html');
expect(requests).toHaveLength(5); expect(requests).toHaveLength(5);
expect(requests[0]!.resourceType()).toBe('document');
expect(requests[1]!.resourceType()).toBe('stylesheet');
// Check redirect chain // Check redirect chain
const redirectChain = requests[1]!.redirectChain(); const redirectChain = requests[1]!.redirectChain();
expect(redirectChain).toHaveLength(3); expect(redirectChain).toHaveLength(3);
@ -935,6 +931,41 @@ describe('request interception', function () {
expect(error.message).toMatch(/Invalid header/); expect(error.message).toMatch(/Invalid header/);
}); });
}); });
describe('Request.resourceType', () => {
it('should work for document type', async () => {
const {page, server} = await getTestState();
await page.setRequestInterception(true);
const requests: HTTPRequest[] = [];
page.on('request', request => {
requests.push(request);
void request.continue();
});
await page.goto(server.EMPTY_PAGE);
expect(requests).toHaveLength(1);
const request = requests[0]!;
expect(request.resourceType()).toBe('document');
});
it('should work for stylesheets', async () => {
const {page, server} = await getTestState();
await page.setRequestInterception(true);
const cssRequests: HTTPRequest[] = [];
page.on('request', request => {
if (request.url().endsWith('css')) {
cssRequests.push(request);
}
void request.continue();
});
await page.goto(server.PREFIX + '/one-style.html');
expect(cssRequests).toHaveLength(1);
const request = cssRequests[0]!;
expect(request.url()).toContain('one-style.css');
expect(request.resourceType()).toBe('stylesheet');
});
});
}); });
function pathToFileURL(path: string): string { function pathToFileURL(path: string): string {