Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/inspector-protocol/network/resource-type.js |
| diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/network/resource-type.js b/third_party/WebKit/LayoutTests/inspector-protocol/network/resource-type.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b8273dc8c1bb8545fd379120e5a9927b4b757df |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/inspector-protocol/network/resource-type.js |
| @@ -0,0 +1,80 @@ |
| +(async function(testRunner) { |
| + let {page, session, dp} = await testRunner.startBlank(`Tests that responseReceived contains the documented resource types.`); |
| + |
| + var resources = [ |
| + { url: '/resources-page.html', type: 'Document', responseAvailable: false }, |
| + { url: '/stylesheet.css', type: 'Stylesheet' }, |
| + { url: '/script.js', type: 'Script' }, |
| + { url: '/abe.png', type: 'Image' }, |
| + { url: '/test.wav', type: 'Media' }, |
| + { url: '/test.ogv', type: 'Media' }, |
| + { url: '/simple-captions.vtt', type: 'TextTrack' }, |
| + { url: '/greenbox.png', type: 'XHR' } |
| + ]; |
| + var resourcesLeft = resources.length; |
| + |
| + testRunner.log('Test started'); |
| + var messageObject = await dp.Network.enable(); |
| + if (messageObject.error) { |
| + testRunner.log(`FAIL: Couldn't enable network agent: ${messageObject.error.message}`); |
| + testRunner.completeTest(); |
| + return; |
| + } |
| + testRunner.log('Network agent enabled'); |
| + |
| + session.evaluate(` |
| + var iframe = document.createElement('iframe'); |
| + iframe.src = '${testRunner.url('../resources/resources-page.html')}'; |
| + document.body.appendChild(iframe); |
| + `); |
| + |
| + dp.Network.onResponseReceived(event => { |
|
allada
2017/06/26 22:02:54
We are introducing a race condition here. The ifra
allada
2017/06/26 22:02:54
Can we add a .once() style helper and inline much
dgozman
2017/06/26 23:22:08
Moved, although that's not a race in this case.
dgozman
2017/06/26 23:22:08
Doesn't help here unfortunately.
|
| + var url = event.params.response.url; |
| + if (url.indexOf('blob') === 0) |
| + return; |
| + |
| + var type = event.params.type; |
| + var requestId = event.params.requestId; |
| + for (var resource of resources) { |
| + if (url.substring(url.length - resource.url.length) !== resource.url) |
| + continue; |
| + if (resource.gotType) |
| + testRunner.fail('FAIL: Received resource ' + url + ' twice.'); |
| + resource.gotType = type; |
| + resource.gotUrl = url; |
| + resource.requestId = requestId; |
| + return; |
| + } |
| + testRunner.fail('FAIL: received unexpected resource ' + url); |
| + }); |
| + |
| + dp.Network.onLoadingFinished(async event => { |
| + const requestId = event.params.requestId; |
|
allada
2017/06/26 22:02:54
const
dgozman
2017/06/26 23:22:08
Done.
|
| + for (const resource of resources) { |
| + if (resource.requestId !== requestId) |
| + continue; |
| + if (!('responseAvailable' in resource)) { |
| + var protocolResponse = await dp.Network.getResponseBody({requestId}); |
| + if (protocolResponse.error) { |
| + resource.responseAvailable = false; |
| + } else { |
| + resource.responseAvailable = true; |
| + resource.responseEncoded = protocolResponse.result.base64Encoded; |
| + } |
| + } |
| + resourcesLeft -= 1; |
| + if (resourcesLeft === 0) |
| + receivedAllResources(); |
| + } |
| + }); |
| + |
| + function receivedAllResources() { |
| + for (var resource of resources) { |
| + var description = 'Resource ' + resource.url + ' got type: ' + resource.gotType + ', type: ' + resource.type + ', responseAvailable: ' + resource.responseAvailable; |
|
allada
2017/06/26 22:02:54
Lets remove "type: ' + resource.type..." it's not
dgozman
2017/06/26 23:22:08
Done.
|
| + if (resource.responseAvailable) |
| + description += ', responseEncoded: ' + resource.responseEncoded; |
| + testRunner.log(description); |
| + } |
| + testRunner.completeTest(); |
| + } |
| +}) |