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 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/time/default_tick_clock.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" |
18 #include "components/scheduler/child/web_task_runner_impl.h" | 20 #include "components/scheduler/child/web_task_runner_impl.h" |
| 21 #include "components/scheduler/child/worker_scheduler.h" |
19 #include "content/child/request_extra_data.h" | 22 #include "content/child/request_extra_data.h" |
20 #include "content/child/request_info.h" | 23 #include "content/child/request_info.h" |
21 #include "content/child/resource_dispatcher.h" | 24 #include "content/child/resource_dispatcher.h" |
22 #include "content/public/child/fixed_received_data.h" | 25 #include "content/public/child/fixed_received_data.h" |
23 #include "content/public/child/request_peer.h" | 26 #include "content/public/child/request_peer.h" |
24 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/resource_response_info.h" | 28 #include "content/public/common/resource_response_info.h" |
26 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
27 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
28 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 private: | 101 private: |
99 scoped_ptr<RequestPeer> peer_; | 102 scoped_ptr<RequestPeer> peer_; |
100 bool canceled_; | 103 bool canceled_; |
101 GURL url_; | 104 GURL url_; |
102 | 105 |
103 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); | 106 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); |
104 }; | 107 }; |
105 | 108 |
106 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { | 109 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { |
107 public: | 110 public: |
108 TestWebURLLoaderClient( | 111 TestWebURLLoaderClient(ResourceDispatcher* dispatcher, |
109 ResourceDispatcher* dispatcher, | 112 scoped_refptr<scheduler::TaskQueue> task_runner) |
110 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 113 : loader_(new WebURLLoaderImpl( |
111 : loader_( | 114 dispatcher, |
112 new WebURLLoaderImpl( | 115 make_scoped_ptr(new scheduler::WebTaskRunnerImpl(task_runner)))), |
113 dispatcher, | |
114 make_scoped_ptr(new scheduler::WebTaskRunnerImpl(task_runner)))), | |
115 expect_multipart_response_(false), | 116 expect_multipart_response_(false), |
116 delete_on_receive_redirect_(false), | 117 delete_on_receive_redirect_(false), |
117 delete_on_receive_response_(false), | 118 delete_on_receive_response_(false), |
118 delete_on_receive_data_(false), | 119 delete_on_receive_data_(false), |
119 delete_on_finish_(false), | 120 delete_on_finish_(false), |
120 delete_on_fail_(false), | 121 delete_on_fail_(false), |
121 did_receive_redirect_(false), | 122 did_receive_redirect_(false), |
122 did_receive_response_(false), | 123 did_receive_response_(false), |
123 did_finish_(false) {} | 124 did_finish_(false) {} |
124 | 125 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 bool did_finish_; | 254 bool did_finish_; |
254 blink::WebURLError error_; | 255 blink::WebURLError error_; |
255 blink::WebURLResponse response_; | 256 blink::WebURLResponse response_; |
256 | 257 |
257 DISALLOW_COPY_AND_ASSIGN(TestWebURLLoaderClient); | 258 DISALLOW_COPY_AND_ASSIGN(TestWebURLLoaderClient); |
258 }; | 259 }; |
259 | 260 |
260 class WebURLLoaderImplTest : public testing::Test { | 261 class WebURLLoaderImplTest : public testing::Test { |
261 public: | 262 public: |
262 explicit WebURLLoaderImplTest() | 263 explicit WebURLLoaderImplTest() |
263 : client_(&dispatcher_, message_loop_.task_runner()) {} | 264 : worker_scheduler_(scheduler::WorkerScheduler::Create( |
| 265 scheduler::SchedulerTqmDelegateImpl::Create( |
| 266 &message_loop_, |
| 267 make_scoped_ptr(new base::DefaultTickClock())))) { |
| 268 worker_scheduler_->Init(); |
| 269 client_.reset(new TestWebURLLoaderClient( |
| 270 &dispatcher_, worker_scheduler_->DefaultTaskRunner())); |
| 271 } |
| 272 |
264 ~WebURLLoaderImplTest() override {} | 273 ~WebURLLoaderImplTest() override {} |
265 | 274 |
266 void DoStartAsyncRequest() { | 275 void DoStartAsyncRequest() { |
267 blink::WebURLRequest request; | 276 blink::WebURLRequest request; |
268 request.initialize(); | 277 request.initialize(); |
269 request.setURL(GURL(kTestURL)); | 278 request.setURL(GURL(kTestURL)); |
270 client()->loader()->loadAsynchronously(request, client()); | 279 client()->loader()->loadAsynchronously(request, client()); |
271 ASSERT_TRUE(peer()); | 280 ASSERT_TRUE(peer()); |
272 } | 281 } |
273 | 282 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 369 } |
361 | 370 |
362 void DoReceiveDataMultipart() { | 371 void DoReceiveDataMultipart() { |
363 peer()->OnReceivedData(make_scoped_ptr( | 372 peer()->OnReceivedData(make_scoped_ptr( |
364 new FixedReceivedData(kMultipartResponse, strlen(kMultipartResponse), | 373 new FixedReceivedData(kMultipartResponse, strlen(kMultipartResponse), |
365 strlen(kMultipartResponse)))); | 374 strlen(kMultipartResponse)))); |
366 // Multipart delegate should modify the data the client sees. | 375 // Multipart delegate should modify the data the client sees. |
367 EXPECT_NE(kMultipartResponse, client()->received_data()); | 376 EXPECT_NE(kMultipartResponse, client()->received_data()); |
368 } | 377 } |
369 | 378 |
370 TestWebURLLoaderClient* client() { return &client_; } | 379 TestWebURLLoaderClient* client() { return client_.get(); } |
371 TestResourceDispatcher* dispatcher() { return &dispatcher_; } | 380 TestResourceDispatcher* dispatcher() { return &dispatcher_; } |
372 RequestPeer* peer() { return dispatcher()->peer(); } | 381 RequestPeer* peer() { return dispatcher()->peer(); } |
373 base::MessageLoop* message_loop() { return &message_loop_; } | 382 base::MessageLoop* message_loop() { return &message_loop_; } |
374 | 383 |
375 private: | 384 private: |
376 base::MessageLoop message_loop_; | 385 base::MessageLoop message_loop_; |
| 386 // WorkerScheduler is needed because WebURLLoaderImpl needs a |
| 387 // scheduler::TaskQueue. |
| 388 scoped_ptr<scheduler::WorkerScheduler> worker_scheduler_; |
377 TestResourceDispatcher dispatcher_; | 389 TestResourceDispatcher dispatcher_; |
378 TestWebURLLoaderClient client_; | 390 scoped_ptr<TestWebURLLoaderClient> client_; |
379 }; | 391 }; |
380 | 392 |
381 TEST_F(WebURLLoaderImplTest, Success) { | 393 TEST_F(WebURLLoaderImplTest, Success) { |
382 DoStartAsyncRequest(); | 394 DoStartAsyncRequest(); |
383 DoReceiveResponse(); | 395 DoReceiveResponse(); |
384 DoReceiveData(); | 396 DoReceiveData(); |
385 DoCompleteRequest(); | 397 DoCompleteRequest(); |
386 EXPECT_FALSE(dispatcher()->canceled()); | 398 EXPECT_FALSE(dispatcher()->canceled()); |
387 EXPECT_EQ(kTestData, client()->received_data()); | 399 EXPECT_EQ(kTestData, client()->received_data()); |
388 } | 400 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); | 724 EXPECT_EQ(kMimeType, client()->response().mimeType().latin1()); |
713 | 725 |
714 DoReceiveData(); | 726 DoReceiveData(); |
715 DoCompleteRequest(); | 727 DoCompleteRequest(); |
716 EXPECT_FALSE(dispatcher()->canceled()); | 728 EXPECT_FALSE(dispatcher()->canceled()); |
717 EXPECT_EQ(kTestData, client()->received_data()); | 729 EXPECT_EQ(kTestData, client()->received_data()); |
718 } | 730 } |
719 | 731 |
720 } // namespace | 732 } // namespace |
721 } // namespace content | 733 } // namespace content |
OLD | NEW |