Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/network-data-length.html

Issue 2167853003: [DevTools] Always report encodedDataLength in Network.ResponseReceived. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/network-data-length.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/network-data-length.html b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/network-data-length.html
new file mode 100644
index 0000000000000000000000000000000000000000..0311ba4f8a716d1506b5bdc54b5332aff7806475
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/network-data-length.html
@@ -0,0 +1,134 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../inspector-protocol/inspector-protocol-test.js"></script>
+<script>
+function test()
+{
+ // When chunk encoded the last chunk will always be 5 bytes "0\r\n\r\n" and
+ // we do not receive a dataReceived event and instead it's in loadingFinished event.
+ const HTTP_CLOSING_CHUNK_SIZE = 5;
+
+
+ InspectorTest.eventHandler["Network.requestWillBeSent"] = onRequestWillBeSent;
+ InspectorTest.eventHandler["Network.responseReceived"] = onResponseReceived;
+ InspectorTest.eventHandler["Network.loadingFinished"] = onLoadingFinished;
+ InspectorTest.eventHandler["Network.dataReceived"] = onDataReceived;
+
+ var requestsMap = new Map();
+ var pendingRequests = 0;
+
+ function enableNetwork()
+ {
+ InspectorTest.log("Test started");
+ InspectorTest.sendCommand("Network.enable", {}, didEnableNetwork);
+ }
+
+ function didEnableNetwork(messageObject)
+ {
+ if (messageObject.error) {
+ InspectorTest.log("FAIL: Couldn't enable network agent" + messageObject.error.message);
+ InspectorTest.completeTest();
+ return;
+ }
+ InspectorTest.log("Network agent enabled");
+ sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" +
+ "redirect=1");
+ sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" +
+ "cached=1");
+ sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" +
+ "size=4&" +
+ "flush_header_with_x_bytes=1&" +
+ "wait_after_headers_packet=25&" +
+ "flush_every=1&" +
+ "wait_every_x_bytes=1&" +
+ "wait_duration_every_x_bytes=25");
+ sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" +
+ "size=4&" +
+ "flush_header_with_x_bytes=1&" +
+ "wait_after_headers_packet=25&" +
+ "flush_every=1&" +
+ "wait_every_x_bytes=1&" +
+ "wait_duration_every_x_bytes=25");
+ }
+
+ function onRequestWillBeSent(event)
+ {
+ var params = event.params;
+ if (requestsMap.has(params.requestId)) {
+ // is redirect.
+ var request = requestsMap.get(params.requestId);
+ request.reportedTotalSize += params.redirectResponse.encodedDataLength;
+ request.redirected = true;
+ // This is to store it, but not reuse it.
+ requestsMap.set(Symbol(params.requestId), request);
+ }
+ requestsMap.set(params.requestId, {
+ url: params.request.url,
+ isChunked: null,
+ isH2: null,
+ headersSize: 0,
+ receivedDataSize: 0,
+ reportedTotalSize: 0,
+ redirected: false
+ });
+ }
+
+ function onResponseReceived(event)
+ {
+ var params = event.params;
+ var isH2 = params.response.protocol === "h2";
+ var request = requestsMap.get(params.requestId);
+ request.isChunked = isH2 || (params.response.headers["Transfer-Encoding"] === "chunked");
+ request.isH2 = isH2;
+ request.headersSize = params.response.encodedDataLength;
+ }
+
+ function onDataReceived(event)
+ {
+ var params = event.params;
+ var request = requestsMap.get(params.requestId);
+ request.receivedDataSize += params.encodedDataLength;
+ }
+
+ function onLoadingFinished(event)
+ {
+ var params = event.params;
+ var request = requestsMap.get(params.requestId);
+ request.reportedTotalSize += params.encodedDataLength;
+ pendingRequests--;
+ if (pendingRequests <= 0) {
+ printResults();
+ InspectorTest.completeTest();
+ }
+ }
+
+ function sendRequest(url) {
dgozman 2016/09/08 23:39:49 { on next line
allada 2016/09/09 00:17:23 Done.
+ expression = "fetch('" + url + "')";
+ InspectorTest.sendCommand( "Runtime.evaluate", { "expression": expression } );
+ pendingRequests++;
+ }
+
+ function printResults() {
dgozman 2016/09/08 23:39:49 { on next line
allada 2016/09/09 00:17:23 Done.
+ var requests = Array.from(requestsMap.values());
+ requests.sort( (a, b) => a.url < b.url ? 1 : -1 );
+ InspectorTest.log("");
+ for (var request of requests) {
+ InspectorTest.log("url: " + request.url);
+ InspectorTest.log(" isChunked: " + request.isChunked);
+ InspectorTest.log(" isH2: " + request.isH2);
+ InspectorTest.log(" redirected: " + request.redirected);
+ InspectorTest.log(" headersSize: " + request.headersSize);
+ InspectorTest.log(" receivedDataSize: " + request.receivedDataSize);
+ InspectorTest.log(" reportedTotalSize: " + request.reportedTotalSize);
+ InspectorTest.log("");
+ }
+ }
+
+ enableNetwork();
+}
+</script>
+</head>
+<body onload="runTest();">
+<p>Ensures that data and header length sent from protocol is proper sizes</p>
+</body>

Powered by Google App Engine
This is Rietveld 408576698