OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 delete_on_finish_(false), | 117 delete_on_finish_(false), |
118 delete_on_fail_(false), | 118 delete_on_fail_(false), |
119 did_receive_redirect_(false), | 119 did_receive_redirect_(false), |
120 did_receive_response_(false), | 120 did_receive_response_(false), |
121 check_redirect_request_priority_(false), | 121 check_redirect_request_priority_(false), |
122 did_finish_(false) {} | 122 did_finish_(false) {} |
123 | 123 |
124 ~TestWebURLLoaderClient() override {} | 124 ~TestWebURLLoaderClient() override {} |
125 | 125 |
126 // blink::WebURLLoaderClient implementation: | 126 // blink::WebURLLoaderClient implementation: |
127 void willFollowRedirect( | 127 void willFollowRedirect(blink::WebURLLoader* loader, |
128 blink::WebURLLoader* loader, | 128 blink::WebURLRequest& newRequest, |
129 blink::WebURLRequest& newRequest, | 129 const blink::WebURLResponse& redirectResponse, |
130 const blink::WebURLResponse& redirectResponse) override { | 130 int64_t encodedDataLength) override { |
131 EXPECT_TRUE(loader_); | 131 EXPECT_TRUE(loader_); |
132 EXPECT_EQ(loader_.get(), loader); | 132 EXPECT_EQ(loader_.get(), loader); |
133 | 133 |
134 if (check_redirect_request_priority_) | 134 if (check_redirect_request_priority_) |
135 EXPECT_EQ(redirect_request_priority, newRequest.getPriority()); | 135 EXPECT_EQ(redirect_request_priority, newRequest.getPriority()); |
136 | 136 |
137 // No test currently simulates mutiple redirects. | 137 // No test currently simulates mutiple redirects. |
138 EXPECT_FALSE(did_receive_redirect_); | 138 EXPECT_FALSE(did_receive_redirect_); |
139 did_receive_redirect_ = true; | 139 did_receive_redirect_ = true; |
140 | 140 |
(...skipping 24 matching lines...) Expand all Loading... |
165 void didDownloadData(blink::WebURLLoader* loader, | 165 void didDownloadData(blink::WebURLLoader* loader, |
166 int dataLength, | 166 int dataLength, |
167 int encodedDataLength) override { | 167 int encodedDataLength) override { |
168 EXPECT_TRUE(loader_); | 168 EXPECT_TRUE(loader_); |
169 EXPECT_EQ(loader_.get(), loader); | 169 EXPECT_EQ(loader_.get(), loader); |
170 } | 170 } |
171 | 171 |
172 void didReceiveData(blink::WebURLLoader* loader, | 172 void didReceiveData(blink::WebURLLoader* loader, |
173 const char* data, | 173 const char* data, |
174 int dataLength, | 174 int dataLength, |
175 int encodedDataLength) override { | 175 int encodedDataLength, |
| 176 int encodedBodyLength) override { |
176 EXPECT_TRUE(loader_); | 177 EXPECT_TRUE(loader_); |
177 EXPECT_EQ(loader_.get(), loader); | 178 EXPECT_EQ(loader_.get(), loader); |
178 // The response should have started, but must not have finished, or failed. | 179 // The response should have started, but must not have finished, or failed. |
179 EXPECT_TRUE(did_receive_response_); | 180 EXPECT_TRUE(did_receive_response_); |
180 EXPECT_FALSE(did_finish_); | 181 EXPECT_FALSE(did_finish_); |
181 EXPECT_EQ(net::OK, error_.reason); | 182 EXPECT_EQ(net::OK, error_.reason); |
182 EXPECT_EQ("", error_.domain.utf8()); | 183 EXPECT_EQ("", error_.domain.utf8()); |
183 | 184 |
184 received_data_.append(data, dataLength); | 185 received_data_.append(data, dataLength); |
185 | 186 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void DoReceiveResponse() { | 308 void DoReceiveResponse() { |
308 EXPECT_FALSE(client()->did_receive_response()); | 309 EXPECT_FALSE(client()->did_receive_response()); |
309 peer()->OnReceivedResponse(content::ResourceResponseInfo()); | 310 peer()->OnReceivedResponse(content::ResourceResponseInfo()); |
310 EXPECT_TRUE(client()->did_receive_response()); | 311 EXPECT_TRUE(client()->did_receive_response()); |
311 } | 312 } |
312 | 313 |
313 // Assumes it is called only once for a request. | 314 // Assumes it is called only once for a request. |
314 void DoReceiveData() { | 315 void DoReceiveData() { |
315 EXPECT_EQ("", client()->received_data()); | 316 EXPECT_EQ("", client()->received_data()); |
316 peer()->OnReceivedData(base::WrapUnique(new FixedReceivedData( | 317 peer()->OnReceivedData(base::WrapUnique(new FixedReceivedData( |
317 kTestData, strlen(kTestData), strlen(kTestData)))); | 318 kTestData, strlen(kTestData), strlen(kTestData), strlen(kTestData)))); |
318 EXPECT_EQ(kTestData, client()->received_data()); | 319 EXPECT_EQ(kTestData, client()->received_data()); |
319 } | 320 } |
320 | 321 |
321 void DoCompleteRequest() { | 322 void DoCompleteRequest() { |
322 EXPECT_FALSE(client()->did_finish()); | 323 EXPECT_FALSE(client()->did_finish()); |
323 peer()->OnCompletedRequest(net::OK, false, false, "", base::TimeTicks(), | 324 peer()->OnCompletedRequest(net::OK, false, false, "", base::TimeTicks(), |
324 strlen(kTestData)); | 325 strlen(kTestData)); |
325 EXPECT_TRUE(client()->did_finish()); | 326 EXPECT_TRUE(client()->did_finish()); |
326 // There should be no error. | 327 // There should be no error. |
327 EXPECT_EQ(net::OK, client()->error().reason); | 328 EXPECT_EQ(net::OK, client()->error().reason); |
(...skipping 11 matching lines...) Expand all Loading... |
339 | 340 |
340 void DoReceiveResponseFtp() { | 341 void DoReceiveResponseFtp() { |
341 EXPECT_FALSE(client()->did_receive_response()); | 342 EXPECT_FALSE(client()->did_receive_response()); |
342 content::ResourceResponseInfo response_info; | 343 content::ResourceResponseInfo response_info; |
343 response_info.mime_type = kFtpDirMimeType; | 344 response_info.mime_type = kFtpDirMimeType; |
344 peer()->OnReceivedResponse(response_info); | 345 peer()->OnReceivedResponse(response_info); |
345 EXPECT_TRUE(client()->did_receive_response()); | 346 EXPECT_TRUE(client()->did_receive_response()); |
346 } | 347 } |
347 | 348 |
348 void DoReceiveDataFtp() { | 349 void DoReceiveDataFtp() { |
349 peer()->OnReceivedData(base::WrapUnique(new FixedReceivedData( | 350 auto size = strlen(kFtpDirListing); |
350 kFtpDirListing, strlen(kFtpDirListing), strlen(kFtpDirListing)))); | 351 peer()->OnReceivedData(base::WrapUnique( |
| 352 new FixedReceivedData(kFtpDirListing, size, size, size))); |
351 // The FTP delegate should modify the data the client sees. | 353 // The FTP delegate should modify the data the client sees. |
352 EXPECT_NE(kFtpDirListing, client()->received_data()); | 354 EXPECT_NE(kFtpDirListing, client()->received_data()); |
353 } | 355 } |
354 | 356 |
355 TestWebURLLoaderClient* client() { return client_.get(); } | 357 TestWebURLLoaderClient* client() { return client_.get(); } |
356 TestResourceDispatcher* dispatcher() { return &dispatcher_; } | 358 TestResourceDispatcher* dispatcher() { return &dispatcher_; } |
357 RequestPeer* peer() { return dispatcher()->peer(); } | 359 RequestPeer* peer() { return dispatcher()->peer(); } |
358 base::MessageLoop* message_loop() { return &message_loop_; } | 360 base::MessageLoop* message_loop() { return &message_loop_; } |
359 | 361 |
360 private: | 362 private: |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 info.socket_address = net::HostPortPair(test.ip, 443); | 672 info.socket_address = net::HostPortPair(test.ip, 443); |
671 blink::WebURLResponse response; | 673 blink::WebURLResponse response; |
672 response.initialize(); | 674 response.initialize(); |
673 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); | 675 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); |
674 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); | 676 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); |
675 }; | 677 }; |
676 } | 678 } |
677 | 679 |
678 } // namespace | 680 } // namespace |
679 } // namespace content | 681 } // namespace content |
OLD | NEW |