Chromium Code Reviews| Index: LayoutTests/inspector-protocol/network/resource-type.html |
| diff --git a/LayoutTests/inspector-protocol/network/resource-type.html b/LayoutTests/inspector-protocol/network/resource-type.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..92e78083cdc11944aa65501b137864bce10ef49b |
| --- /dev/null |
| +++ b/LayoutTests/inspector-protocol/network/resource-type.html |
| @@ -0,0 +1,87 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<head> |
| +<script src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script> |
| +<script> |
| +function appendIframe() |
| +{ |
| + var iframe = document.createElement("iframe"); |
| + iframe.src = "resources/resources-page.html"; |
| + document.body.appendChild(iframe); |
| +} |
| + |
| +function test() |
| +{ |
| + InspectorTest.eventHandler["Network.responseReceived"] = onResponseReceived; |
| + |
| + function enableNetwork() |
| + { |
| + InspectorTest.log("Test started"); |
| + InspectorTest.sendCommand("Network.enable", {}, didEnableNetwork); |
| + } |
| + |
| + function didEnableNetwork(messageObject) |
| + { |
| + if ("error" in messageObject) { |
|
eustas
2014/01/13 16:00:33
We usually don't use "in" keyword.
"if (messageOb
pwnall-personal
2014/01/13 20:33:29
Done.
Thank you!
|
| + InspectorTest.log("FAIL: Couldn't enable network agent" + messageObject.error.message); |
| + InspectorTest.completeTest(); |
| + return; |
| + } |
| + InspectorTest.log("Network agent enabled"); |
| + InspectorTest.sendCommand("Runtime.evaluate", { "expression": "appendIframe()"}); |
| + } |
| + |
| + var resources = [ |
| + { url: '/resources-page.html', type: "Document" }, |
| + { 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" }, |
| + ]; |
| + var resourcesLeft = resources.length; |
| + |
| + function onResponseReceived(event) |
| + { |
| + var url = event.params.response.url; |
| + var type = event.params.type; |
| + for (var i = 0; i < resources.length; ++i) { |
| + var resource = resources[i]; |
| + if (url.substring(url.length - resource.url.length) === resource.url) { |
| + if ("gotType" in resource) { |
|
eustas
2014/01/13 16:00:33
ditto
pwnall-personal
2014/01/13 20:33:29
Done.
|
| + InspectorTest.log("FAIL: Received resource " + url + " twice."); |
| + InspectorTest.completeTest(); |
| + } |
| + resource.gotType = type; |
| + resource.gotUrl = url; |
| + resourcesLeft -= 1; |
| + InspectorTest.log("Received expected resource. " + resourcesLeft + " left."); |
|
eustas
2014/01/13 16:00:33
This additional output doesn't make much sense.
pwnall-personal
2014/01/13 20:33:29
Done.
Removed. Thank you!
|
| + if (resourcesLeft === 0) |
| + receivedAllResources(); |
| + return; |
| + } |
| + } |
| + InspectorTest.log("FAIL: received unexpected resource " + url); |
| + InspectorTest.completeTest(); |
| + } |
| + |
| + function receivedAllResources() |
|
eustas
2014/01/13 16:00:33
If you turn protocol test common test (http/tests/
pwnall-personal
2014/01/13 20:33:29
I was afraid to write test at that level because m
|
| + { |
| + for (var i = 0; i < resources.length; ++i) { |
| + var resource = resources[i]; |
| + InspectorTest.log("Resource " + resource.url + " got type " + resource.gotType); |
| + InspectorTest.assertEquals(resource.type, resource.gotType); |
| + } |
| + InspectorTest.completeTest(); |
| + } |
| + |
| + enableNetwork(); |
| +} |
| +</script> |
| +</head> |
| +<body onload="runTest();"> |
| +<p>Tests that responseReceived contains the |
| + <a href="https://developers.google.com/chrome-developer-tools/docs/protocol/tot/page#type-ResourceType">documented resource types</a>. |
| +</p> |
| +</body> |