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) { | |
dgozman
2016/09/08 23:39:49
{ on next line
allada
2016/09/09 00:17:23
Done.
| |
107 expression = "fetch('" + url + "')"; | |
108 InspectorTest.sendCommand( "Runtime.evaluate", { "expression": expressio n } ); | |
109 pendingRequests++; | |
110 } | |
111 | |
112 function printResults() { | |
dgozman
2016/09/08 23:39:49
{ on next line
allada
2016/09/09 00:17:23
Done.
| |
113 var requests = Array.from(requestsMap.values()); | |
114 requests.sort( (a, b) => a.url < b.url ? 1 : -1 ); | |
115 InspectorTest.log(""); | |
116 for (var request of requests) { | |
117 InspectorTest.log("url: " + request.url); | |
118 InspectorTest.log(" isChunked: " + request.isChunked); | |
119 InspectorTest.log(" isH2: " + request.isH2); | |
120 InspectorTest.log(" redirected: " + request.redirected); | |
121 InspectorTest.log(" headersSize: " + request.headersSize); | |
122 InspectorTest.log(" receivedDataSize: " + request.receivedDataSize) ; | |
123 InspectorTest.log(" reportedTotalSize: " + request.reportedTotalSiz e); | |
124 InspectorTest.log(""); | |
125 } | |
126 } | |
127 | |
128 enableNetwork(); | |
129 } | |
130 </script> | |
131 </head> | |
132 <body onload="runTest();"> | |
133 <p>Ensures that data and header length sent from protocol is proper sizes</p> | |
134 </body> | |
OLD | NEW |