| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/url_loader_client_impl.h" | 5 #include "content/child/url_loader_client_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 void TearDown() override { | 43 void TearDown() override { |
| 44 url_loader_client_ = nullptr; | 44 url_loader_client_ = nullptr; |
| 45 url_loader_factory_proxy_ = nullptr; | 45 url_loader_factory_proxy_ = nullptr; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool Send(IPC::Message* message) override { | 48 bool Send(IPC::Message* message) override { |
| 49 ADD_FAILURE() << "IPC::Sender::Send should not be called."; | 49 ADD_FAILURE() << "IPC::Sender::Send should not be called."; |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CreateLoaderAndStart( | 53 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
| 54 mojom::URLLoaderAssociatedRequest request, | 54 int32_t routing_id, |
| 55 int32_t routing_id, | 55 int32_t request_id, |
| 56 int32_t request_id, | 56 const ResourceRequest& url_request, |
| 57 const ResourceRequest& url_request, | 57 mojom::URLLoaderClientPtr client) override { |
| 58 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) override { | 58 url_loader_client_ = std::move(client); |
| 59 url_loader_client_.Bind(std::move(client_ptr_info)); | |
| 60 } | 59 } |
| 61 | 60 |
| 62 void SyncLoad(int32_t routing_id, | 61 void SyncLoad(int32_t routing_id, |
| 63 int32_t request_id, | 62 int32_t request_id, |
| 64 const ResourceRequest& request, | 63 const ResourceRequest& request, |
| 65 const SyncLoadCallback& callback) override { | 64 const SyncLoadCallback& callback) override { |
| 66 NOTREACHED(); | 65 NOTREACHED(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 static MojoCreateDataPipeOptions DataPipeOptions() { | 68 static MojoCreateDataPipeOptions DataPipeOptions() { |
| 70 MojoCreateDataPipeOptions options; | 69 MojoCreateDataPipeOptions options; |
| 71 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 70 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 72 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 71 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 73 options.element_num_bytes = 1; | 72 options.element_num_bytes = 1; |
| 74 options.capacity_num_bytes = 4096; | 73 options.capacity_num_bytes = 4096; |
| 75 return options; | 74 return options; |
| 76 } | 75 } |
| 77 | 76 |
| 78 base::MessageLoop message_loop_; | 77 base::MessageLoop message_loop_; |
| 79 std::unique_ptr<ResourceDispatcher> dispatcher_; | 78 std::unique_ptr<ResourceDispatcher> dispatcher_; |
| 80 TestRequestPeer::Context request_peer_context_; | 79 TestRequestPeer::Context request_peer_context_; |
| 81 int request_id_ = 0; | 80 int request_id_ = 0; |
| 82 mojom::URLLoaderClientAssociatedPtr url_loader_client_; | 81 mojom::URLLoaderClientPtr url_loader_client_; |
| 83 mojom::URLLoaderFactoryPtr url_loader_factory_proxy_; | 82 mojom::URLLoaderFactoryPtr url_loader_factory_proxy_; |
| 84 mojo::Binding<mojom::URLLoaderFactory> mojo_binding_; | 83 mojo::Binding<mojom::URLLoaderFactory> mojo_binding_; |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 TEST_F(URLLoaderClientImplTest, OnReceiveResponse) { | 86 TEST_F(URLLoaderClientImplTest, OnReceiveResponse) { |
| 88 ResourceResponseHead response_head; | 87 ResourceResponseHead response_head; |
| 89 | 88 |
| 90 url_loader_client_->OnReceiveResponse(response_head, nullptr); | 89 url_loader_client_->OnReceiveResponse(response_head, nullptr); |
| 91 | 90 |
| 92 EXPECT_FALSE(request_peer_context_.received_response); | 91 EXPECT_FALSE(request_peer_context_.received_response); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 517 |
| 519 dispatcher_->SetDefersLoading(request_id_, false); | 518 dispatcher_->SetDefersLoading(request_id_, false); |
| 520 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
| 521 EXPECT_TRUE(request_peer_context_.received_response); | 520 EXPECT_TRUE(request_peer_context_.received_response); |
| 522 EXPECT_TRUE(request_peer_context_.complete); | 521 EXPECT_TRUE(request_peer_context_.complete); |
| 523 EXPECT_EQ(4, request_peer_context_.total_encoded_data_length); | 522 EXPECT_EQ(4, request_peer_context_.total_encoded_data_length); |
| 524 EXPECT_FALSE(request_peer_context_.cancelled); | 523 EXPECT_FALSE(request_peer_context_.cancelled); |
| 525 } | 524 } |
| 526 | 525 |
| 527 } // namespace content | 526 } // namespace content |
| OLD | NEW |