| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/time/default_tick_clock.h" | 20 #include "base/time/default_tick_clock.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "content/child/request_extra_data.h" | 22 #include "content/child/request_extra_data.h" |
| 23 #include "content/child/request_info.h" | |
| 24 #include "content/child/resource_dispatcher.h" | 23 #include "content/child/resource_dispatcher.h" |
| 25 #include "content/child/sync_load_response.h" | 24 #include "content/child/sync_load_response.h" |
| 26 #include "content/public/child/fixed_received_data.h" | 25 #include "content/public/child/fixed_received_data.h" |
| 27 #include "content/public/child/request_peer.h" | 26 #include "content/public/child/request_peer.h" |
| 28 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/common/resource_response_info.h" | 28 #include "content/public/common/resource_response_info.h" |
| 30 #include "net/base/host_port_pair.h" | 29 #include "net/base/host_port_pair.h" |
| 31 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 32 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
| 33 #include "net/http/http_util.h" | 32 #include "net/http/http_util.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 60 TestResourceDispatcher() : | 59 TestResourceDispatcher() : |
| 61 ResourceDispatcher(nullptr, nullptr), | 60 ResourceDispatcher(nullptr, nullptr), |
| 62 canceled_(false), | 61 canceled_(false), |
| 63 defers_loading_(false) { | 62 defers_loading_(false) { |
| 64 } | 63 } |
| 65 | 64 |
| 66 ~TestResourceDispatcher() override {} | 65 ~TestResourceDispatcher() override {} |
| 67 | 66 |
| 68 // TestDispatcher implementation: | 67 // TestDispatcher implementation: |
| 69 | 68 |
| 70 void StartSync(const RequestInfo& request_info, | 69 void StartSync(std::unique_ptr<ResourceRequest> request, |
| 71 ResourceRequestBodyImpl* request_body, | 70 int routing_id, |
| 72 SyncLoadResponse* response, | 71 SyncLoadResponse* response, |
| 73 blink::WebURLRequest::LoadingIPCType ipc_type, | 72 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 74 mojom::URLLoaderFactory* url_loader_factory) override { | 73 mojom::URLLoaderFactory* url_loader_factory) override { |
| 75 *response = sync_load_response_; | 74 *response = sync_load_response_; |
| 76 } | 75 } |
| 77 | 76 |
| 78 int StartAsync(const RequestInfo& request_info, | 77 int StartAsync( |
| 79 ResourceRequestBodyImpl* request_body, | 78 std::unique_ptr<ResourceRequest> request, |
| 80 std::unique_ptr<RequestPeer> peer, | 79 int routing_id, |
| 81 blink::WebURLRequest::LoadingIPCType ipc_type, | 80 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner, |
| 82 mojom::URLLoaderFactory* url_loader_factory) override { | 81 const GURL& frame_origin, |
| 82 std::unique_ptr<RequestPeer> peer, |
| 83 blink::WebURLRequest::LoadingIPCType ipc_type, |
| 84 mojom::URLLoaderFactory* url_loader_factory) override { |
| 83 EXPECT_FALSE(peer_); | 85 EXPECT_FALSE(peer_); |
| 84 EXPECT_EQ(blink::WebURLRequest::LoadingIPCType::ChromeIPC, ipc_type); | 86 EXPECT_EQ(blink::WebURLRequest::LoadingIPCType::ChromeIPC, ipc_type); |
| 85 peer_ = std::move(peer); | 87 peer_ = std::move(peer); |
| 86 url_ = request_info.url; | 88 url_ = request->url; |
| 87 stream_url_ = request_info.resource_body_stream_url; | 89 stream_url_ = request->resource_body_stream_url; |
| 88 return 1; | 90 return 1; |
| 89 } | 91 } |
| 90 | 92 |
| 91 void Cancel(int request_id) override { | 93 void Cancel(int request_id) override { |
| 92 EXPECT_FALSE(canceled_); | 94 EXPECT_FALSE(canceled_); |
| 93 canceled_ = true; | 95 canceled_ = true; |
| 94 } | 96 } |
| 95 | 97 |
| 96 RequestPeer* peer() { return peer_.get(); } | 98 RequestPeer* peer() { return peer_.get(); } |
| 97 | 99 |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 stream_override->stream_url = kStreamURL; | 634 stream_override->stream_url = kStreamURL; |
| 633 stream_override->response.mime_type = kMimeType; | 635 stream_override->response.mime_type = kMimeType; |
| 634 RequestExtraData* extra_data = new RequestExtraData(); | 636 RequestExtraData* extra_data = new RequestExtraData(); |
| 635 extra_data->set_stream_override(std::move(stream_override)); | 637 extra_data->set_stream_override(std::move(stream_override)); |
| 636 request.setExtraData(extra_data); | 638 request.setExtraData(extra_data); |
| 637 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 639 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 638 switches::kEnableBrowserSideNavigation); | 640 switches::kEnableBrowserSideNavigation); |
| 639 | 641 |
| 640 client()->loader()->loadAsynchronously(request, client()); | 642 client()->loader()->loadAsynchronously(request, client()); |
| 641 | 643 |
| 642 // The stream url should have been added to the RequestInfo. | 644 // The stream url should have been added to the ResourceRequest. |
| 643 ASSERT_TRUE(peer()); | 645 ASSERT_TRUE(peer()); |
| 644 EXPECT_EQ(kNavigationURL, dispatcher()->url()); | 646 EXPECT_EQ(kNavigationURL, dispatcher()->url()); |
| 645 EXPECT_EQ(kStreamURL, dispatcher()->stream_url()); | 647 EXPECT_EQ(kStreamURL, dispatcher()->stream_url()); |
| 646 | 648 |
| 647 EXPECT_FALSE(client()->did_receive_response()); | 649 EXPECT_FALSE(client()->did_receive_response()); |
| 648 peer()->OnReceivedResponse(content::ResourceResponseInfo()); | 650 peer()->OnReceivedResponse(content::ResourceResponseInfo()); |
| 649 EXPECT_TRUE(client()->did_receive_response()); | 651 EXPECT_TRUE(client()->did_receive_response()); |
| 650 | 652 |
| 651 // The response info should have been overriden. | 653 // The response info should have been overriden. |
| 652 ASSERT_FALSE(client()->response().isNull()); | 654 ASSERT_FALSE(client()->response().isNull()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 encoded_data_length); | 713 encoded_data_length); |
| 712 | 714 |
| 713 EXPECT_EQ(kEncodedBodyLength, response.encodedBodyLength()); | 715 EXPECT_EQ(kEncodedBodyLength, response.encodedBodyLength()); |
| 714 EXPECT_EQ(kEncodedDataLength, encoded_data_length); | 716 EXPECT_EQ(kEncodedDataLength, encoded_data_length); |
| 715 int expected_decoded_body_length = strlen(kBodyData); | 717 int expected_decoded_body_length = strlen(kBodyData); |
| 716 EXPECT_EQ(expected_decoded_body_length, response.decodedBodyLength()); | 718 EXPECT_EQ(expected_decoded_body_length, response.decodedBodyLength()); |
| 717 } | 719 } |
| 718 | 720 |
| 719 } // namespace | 721 } // namespace |
| 720 } // namespace content | 722 } // namespace content |
| OLD | NEW |