OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../inspector-protocol/inspector-protocol-test.js"></script> |
| 5 <script> |
| 6 function test() |
| 7 { |
| 8 // When chunk encoded the last chunk will always be 5 bytes "0\r\n\r\n" and |
| 9 // we do not receive a dataReceived event and instead it's in loadingFinishe
d event. |
| 10 const HTTP_CLOSING_CHUNK_SIZE = 5; |
| 11 |
| 12 |
| 13 InspectorTest.eventHandler["Network.requestWillBeSent"] = onRequestWillBeSen
t; |
| 14 InspectorTest.eventHandler["Network.responseReceived"] = onResponseReceived; |
| 15 InspectorTest.eventHandler["Network.loadingFinished"] = onLoadingFinished; |
| 16 InspectorTest.eventHandler["Network.dataReceived"] = onDataReceived; |
| 17 |
| 18 var requestsMap = new Map(); |
| 19 var pendingRequests = 0; |
| 20 |
| 21 function enableNetwork() |
| 22 { |
| 23 InspectorTest.log("Test started"); |
| 24 InspectorTest.sendCommand("Network.enable", {}, didEnableNetwork); |
| 25 } |
| 26 |
| 27 function didEnableNetwork(messageObject) |
| 28 { |
| 29 if (messageObject.error) { |
| 30 InspectorTest.log("FAIL: Couldn't enable network agent" + messageObj
ect.error.message); |
| 31 InspectorTest.completeTest(); |
| 32 return; |
| 33 } |
| 34 InspectorTest.log("Network agent enabled"); |
| 35 sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" + |
| 36 "redirect=1"); |
| 37 sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" + |
| 38 "cached=1"); |
| 39 sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" + |
| 40 "size=4&" + |
| 41 "flush_header_with_x_bytes=1&" + |
| 42 "wait_after_headers_packet=25&" + |
| 43 "flush_every=1&" + |
| 44 "wait_every_x_bytes=1&" + |
| 45 "wait_duration_every_x_bytes=25"); |
| 46 sendRequest("/inspector-protocol/resources/data-xfer-resource.php?" + |
| 47 "size=4&" + |
| 48 "flush_header_with_x_bytes=1&" + |
| 49 "wait_after_headers_packet=25&" + |
| 50 "flush_every=1&" + |
| 51 "wait_every_x_bytes=1&" + |
| 52 "wait_duration_every_x_bytes=25"); |
| 53 } |
| 54 |
| 55 function onRequestWillBeSent(event) |
| 56 { |
| 57 var params = event.params; |
| 58 if (requestsMap.has(params.requestId)) { |
| 59 // is redirect. |
| 60 var request = requestsMap.get(params.requestId); |
| 61 request.reportedTotalSize += params.redirectResponse.encodedDataLeng
th; |
| 62 request.redirected = true; |
| 63 // This is to store it, but not reuse it. |
| 64 requestsMap.set(Symbol(params.requestId), request); |
| 65 } |
| 66 requestsMap.set(params.requestId, { |
| 67 url: params.request.url, |
| 68 isChunked: null, |
| 69 isH2: null, |
| 70 headersSize: 0, |
| 71 receivedDataSize: 0, |
| 72 reportedTotalSize: 0, |
| 73 redirected: false |
| 74 }); |
| 75 } |
| 76 |
| 77 function onResponseReceived(event) |
| 78 { |
| 79 var params = event.params; |
| 80 var isH2 = params.response.protocol === "h2"; |
| 81 var request = requestsMap.get(params.requestId); |
| 82 request.isChunked = isH2 || (params.response.headers["Transfer-Encoding"
] === "chunked"); |
| 83 request.isH2 = isH2; |
| 84 request.headersSize = params.response.encodedDataLength; |
| 85 } |
| 86 |
| 87 function onDataReceived(event) |
| 88 { |
| 89 var params = event.params; |
| 90 var request = requestsMap.get(params.requestId); |
| 91 request.receivedDataSize += params.encodedDataLength; |
| 92 } |
| 93 |
| 94 function onLoadingFinished(event) |
| 95 { |
| 96 var params = event.params; |
| 97 var request = requestsMap.get(params.requestId); |
| 98 request.reportedTotalSize += params.encodedDataLength; |
| 99 pendingRequests--; |
| 100 if (pendingRequests <= 0) { |
| 101 printResults(); |
| 102 InspectorTest.completeTest(); |
| 103 } |
| 104 } |
| 105 |
| 106 function sendRequest(url) |
| 107 { |
| 108 expression = "fetch('" + url + "')"; |
| 109 InspectorTest.sendCommand( "Runtime.evaluate", { "expression": expressio
n } ); |
| 110 pendingRequests++; |
| 111 } |
| 112 |
| 113 function printResults() |
| 114 { |
| 115 var requests = Array.from(requestsMap.values()); |
| 116 requests.sort( (a, b) => a.url < b.url ? 1 : -1 ); |
| 117 InspectorTest.log(""); |
| 118 for (var request of requests) { |
| 119 InspectorTest.log("url: " + request.url); |
| 120 InspectorTest.log(" isChunked: " + request.isChunked); |
| 121 InspectorTest.log(" isH2: " + request.isH2); |
| 122 InspectorTest.log(" redirected: " + request.redirected); |
| 123 InspectorTest.log(" headersSize: " + request.headersSize); |
| 124 InspectorTest.log(" receivedDataSize: " + request.receivedDataSize)
; |
| 125 InspectorTest.log(" reportedTotalSize: " + request.reportedTotalSiz
e); |
| 126 InspectorTest.log(""); |
| 127 } |
| 128 } |
| 129 |
| 130 enableNetwork(); |
| 131 } |
| 132 </script> |
| 133 </head> |
| 134 <body onload="runTest();"> |
| 135 <p>Ensures that data and header length sent from protocol is proper sizes</p> |
| 136 </body> |
OLD | NEW |