| 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 <string.h> | 7 #include <string.h> |
| 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "content/child/request_extra_data.h" | 16 #include "content/child/request_extra_data.h" |
| 16 #include "content/child/request_info.h" | 17 #include "content/child/request_info.h" |
| 17 #include "content/child/resource_dispatcher.h" | 18 #include "content/child/resource_dispatcher.h" |
| 18 #include "content/public/child/request_peer.h" | 19 #include "content/public/child/request_peer.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/common/resource_response_info.h" | 21 #include "content/public/common/resource_response_info.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 23 #include "net/http/http_util.h" | 24 #include "net/http/http_util.h" |
| 24 #include "net/url_request/redirect_info.h" | 25 #include "net/url_request/redirect_info.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
| 27 #include "third_party/WebKit/public/platform/WebURLError.h" | 28 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 28 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 29 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 30 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 30 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 31 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 37 using FixedReceivedData = RequestPeer::FixedReceivedData; |
| 38 |
| 36 const char kTestURL[] = "http://foo"; | 39 const char kTestURL[] = "http://foo"; |
| 37 const char kTestData[] = "blah!"; | 40 const char kTestData[] = "blah!"; |
| 38 | 41 |
| 39 const char kFtpDirMimeType[] = "text/vnd.chromium.ftp-dir"; | 42 const char kFtpDirMimeType[] = "text/vnd.chromium.ftp-dir"; |
| 40 // Simple FTP directory listing. Tests are not concerned with correct parsing, | 43 // Simple FTP directory listing. Tests are not concerned with correct parsing, |
| 41 // but rather correct cleanup when deleted while parsing. Important details of | 44 // but rather correct cleanup when deleted while parsing. Important details of |
| 42 // this list are that it contains more than one entry that are not "." or "..". | 45 // this list are that it contains more than one entry that are not "." or "..". |
| 43 const char kFtpDirListing[] = | 46 const char kFtpDirListing[] = |
| 44 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 goat\n" | 47 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 goat\n" |
| 45 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 hat"; | 48 "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11 hat"; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 281 |
| 279 void DoReceiveResponse() { | 282 void DoReceiveResponse() { |
| 280 EXPECT_FALSE(client()->did_receive_response()); | 283 EXPECT_FALSE(client()->did_receive_response()); |
| 281 peer()->OnReceivedResponse(content::ResourceResponseInfo()); | 284 peer()->OnReceivedResponse(content::ResourceResponseInfo()); |
| 282 EXPECT_TRUE(client()->did_receive_response()); | 285 EXPECT_TRUE(client()->did_receive_response()); |
| 283 } | 286 } |
| 284 | 287 |
| 285 // Assumes it is called only once for a request. | 288 // Assumes it is called only once for a request. |
| 286 void DoReceiveData() { | 289 void DoReceiveData() { |
| 287 EXPECT_EQ("", client()->received_data()); | 290 EXPECT_EQ("", client()->received_data()); |
| 288 peer()->OnReceivedData(kTestData, strlen(kTestData), strlen(kTestData)); | 291 peer()->OnReceivedData(make_scoped_ptr(new FixedReceivedData( |
| 292 kTestData, strlen(kTestData), strlen(kTestData)))); |
| 289 EXPECT_EQ(kTestData, client()->received_data()); | 293 EXPECT_EQ(kTestData, client()->received_data()); |
| 290 } | 294 } |
| 291 | 295 |
| 292 void DoCompleteRequest() { | 296 void DoCompleteRequest() { |
| 293 EXPECT_FALSE(client()->did_finish()); | 297 EXPECT_FALSE(client()->did_finish()); |
| 294 peer()->OnCompletedRequest(net::OK, false, false, "", base::TimeTicks(), | 298 peer()->OnCompletedRequest(net::OK, false, false, "", base::TimeTicks(), |
| 295 strlen(kTestData)); | 299 strlen(kTestData)); |
| 296 EXPECT_TRUE(client()->did_finish()); | 300 EXPECT_TRUE(client()->did_finish()); |
| 297 // There should be no error. | 301 // There should be no error. |
| 298 EXPECT_EQ(net::OK, client()->error().reason); | 302 EXPECT_EQ(net::OK, client()->error().reason); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 310 | 314 |
| 311 void DoReceiveResponseFtp() { | 315 void DoReceiveResponseFtp() { |
| 312 EXPECT_FALSE(client()->did_receive_response()); | 316 EXPECT_FALSE(client()->did_receive_response()); |
| 313 content::ResourceResponseInfo response_info; | 317 content::ResourceResponseInfo response_info; |
| 314 response_info.mime_type = kFtpDirMimeType; | 318 response_info.mime_type = kFtpDirMimeType; |
| 315 peer()->OnReceivedResponse(response_info); | 319 peer()->OnReceivedResponse(response_info); |
| 316 EXPECT_TRUE(client()->did_receive_response()); | 320 EXPECT_TRUE(client()->did_receive_response()); |
| 317 } | 321 } |
| 318 | 322 |
| 319 void DoReceiveDataFtp() { | 323 void DoReceiveDataFtp() { |
| 320 peer()->OnReceivedData(kFtpDirListing, strlen(kFtpDirListing), | 324 peer()->OnReceivedData(make_scoped_ptr(new FixedReceivedData( |
| 321 strlen(kFtpDirListing)); | 325 kFtpDirListing, strlen(kFtpDirListing), strlen(kFtpDirListing)))); |
| 322 // The FTP delegate should modify the data the client sees. | 326 // The FTP delegate should modify the data the client sees. |
| 323 EXPECT_NE(kFtpDirListing, client()->received_data()); | 327 EXPECT_NE(kFtpDirListing, client()->received_data()); |
| 324 } | 328 } |
| 325 | 329 |
| 326 void DoReceiveResponseMultipart() { | 330 void DoReceiveResponseMultipart() { |
| 327 EXPECT_FALSE(client()->did_receive_response()); | 331 EXPECT_FALSE(client()->did_receive_response()); |
| 328 content::ResourceResponseInfo response_info; | 332 content::ResourceResponseInfo response_info; |
| 329 response_info.headers = new net::HttpResponseHeaders( | 333 response_info.headers = new net::HttpResponseHeaders( |
| 330 net::HttpUtil::AssembleRawHeaders(kMultipartResponseHeaders, | 334 net::HttpUtil::AssembleRawHeaders(kMultipartResponseHeaders, |
| 331 strlen(kMultipartResponseHeaders))); | 335 strlen(kMultipartResponseHeaders))); |
| 332 response_info.mime_type = kMultipartResponseMimeType; | 336 response_info.mime_type = kMultipartResponseMimeType; |
| 333 peer()->OnReceivedResponse(response_info); | 337 peer()->OnReceivedResponse(response_info); |
| 334 EXPECT_TRUE(client()->did_receive_response()); | 338 EXPECT_TRUE(client()->did_receive_response()); |
| 335 } | 339 } |
| 336 | 340 |
| 337 void DoReceiveDataMultipart() { | 341 void DoReceiveDataMultipart() { |
| 338 peer()->OnReceivedData(kMultipartResponse, strlen(kMultipartResponse), | 342 peer()->OnReceivedData(make_scoped_ptr( |
| 339 strlen(kMultipartResponse)); | 343 new FixedReceivedData(kMultipartResponse, strlen(kMultipartResponse), |
| 344 strlen(kMultipartResponse)))); |
| 340 // Multipart delegate should modify the data the client sees. | 345 // Multipart delegate should modify the data the client sees. |
| 341 EXPECT_NE(kMultipartResponse, client()->received_data()); | 346 EXPECT_NE(kMultipartResponse, client()->received_data()); |
| 342 } | 347 } |
| 343 | 348 |
| 344 TestWebURLLoaderClient* client() { return &client_; } | 349 TestWebURLLoaderClient* client() { return &client_; } |
| 345 TestResourceDispatcher* dispatcher() { return &dispatcher_; } | 350 TestResourceDispatcher* dispatcher() { return &dispatcher_; } |
| 346 RequestPeer* peer() { return dispatcher()->peer(); } | 351 RequestPeer* peer() { return dispatcher()->peer(); } |
| 347 base::MessageLoop* message_loop() { return &message_loop_; } | 352 base::MessageLoop* message_loop() { return &message_loop_; } |
| 348 | 353 |
| 349 private: | 354 private: |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); | 684 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); |
| 680 | 685 |
| 681 DoReceiveData(); | 686 DoReceiveData(); |
| 682 DoCompleteRequest(); | 687 DoCompleteRequest(); |
| 683 EXPECT_FALSE(dispatcher()->canceled()); | 688 EXPECT_FALSE(dispatcher()->canceled()); |
| 684 EXPECT_EQ(kTestData, client()->received_data()); | 689 EXPECT_EQ(kTestData, client()->received_data()); |
| 685 } | 690 } |
| 686 | 691 |
| 687 } // namespace | 692 } // namespace |
| 688 } // namespace content | 693 } // namespace content |
| OLD | NEW |