Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/child/web_url_loader_impl_unittest.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another GYP fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/scheduler/child/scheduler_tqm_delegate_impl.h"
23 #include "components/scheduler/child/web_task_runner_impl.h"
24 #include "components/scheduler/child/worker_scheduler.h"
25 #include "content/child/request_extra_data.h" 22 #include "content/child/request_extra_data.h"
26 #include "content/child/request_info.h" 23 #include "content/child/request_info.h"
27 #include "content/child/resource_dispatcher.h" 24 #include "content/child/resource_dispatcher.h"
28 #include "content/public/child/fixed_received_data.h" 25 #include "content/public/child/fixed_received_data.h"
29 #include "content/public/child/request_peer.h" 26 #include "content/public/child/request_peer.h"
30 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
31 #include "content/public/common/resource_response_info.h" 28 #include "content/public/common/resource_response_info.h"
32 #include "net/base/host_port_pair.h" 29 #include "net/base/host_port_pair.h"
33 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
34 #include "net/http/http_response_headers.h" 31 #include "net/http/http_response_headers.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 bool canceled_; 97 bool canceled_;
101 bool defers_loading_; 98 bool defers_loading_;
102 GURL url_; 99 GURL url_;
103 GURL stream_url_; 100 GURL stream_url_;
104 101
105 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); 102 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher);
106 }; 103 };
107 104
108 class TestWebURLLoaderClient : public blink::WebURLLoaderClient { 105 class TestWebURLLoaderClient : public blink::WebURLLoaderClient {
109 public: 106 public:
110 TestWebURLLoaderClient(ResourceDispatcher* dispatcher, 107 TestWebURLLoaderClient(ResourceDispatcher* dispatcher)
111 scoped_refptr<scheduler::TaskQueue> task_runner) 108 : loader_(new WebURLLoaderImpl(dispatcher)),
112 : loader_(new WebURLLoaderImpl(
113 dispatcher,
114 base::WrapUnique(new scheduler::WebTaskRunnerImpl(task_runner)))),
115 delete_on_receive_redirect_(false), 109 delete_on_receive_redirect_(false),
116 delete_on_receive_response_(false), 110 delete_on_receive_response_(false),
117 delete_on_receive_data_(false), 111 delete_on_receive_data_(false),
118 delete_on_finish_(false), 112 delete_on_finish_(false),
119 delete_on_fail_(false), 113 delete_on_fail_(false),
120 did_receive_redirect_(false), 114 did_receive_redirect_(false),
121 did_receive_response_(false), 115 did_receive_response_(false),
122 check_redirect_request_priority_(false), 116 check_redirect_request_priority_(false),
123 did_finish_(false) {} 117 did_finish_(false) {}
124 118
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 std::string received_data_; 250 std::string received_data_;
257 bool did_finish_; 251 bool did_finish_;
258 blink::WebURLError error_; 252 blink::WebURLError error_;
259 blink::WebURLResponse response_; 253 blink::WebURLResponse response_;
260 254
261 DISALLOW_COPY_AND_ASSIGN(TestWebURLLoaderClient); 255 DISALLOW_COPY_AND_ASSIGN(TestWebURLLoaderClient);
262 }; 256 };
263 257
264 class WebURLLoaderImplTest : public testing::Test { 258 class WebURLLoaderImplTest : public testing::Test {
265 public: 259 public:
266 explicit WebURLLoaderImplTest() 260 WebURLLoaderImplTest() {
267 : worker_scheduler_(scheduler::WorkerScheduler::Create( 261 client_.reset(new TestWebURLLoaderClient(&dispatcher_));
268 scheduler::SchedulerTqmDelegateImpl::Create(
269 &message_loop_,
270 base::WrapUnique(new base::DefaultTickClock())))) {
271 worker_scheduler_->Init();
272 client_.reset(new TestWebURLLoaderClient(
273 &dispatcher_, worker_scheduler_->DefaultTaskRunner()));
274 } 262 }
275 263
276 ~WebURLLoaderImplTest() override {} 264 ~WebURLLoaderImplTest() override {}
277 265
278 void DoStartAsyncRequest() { 266 void DoStartAsyncRequest() {
279 blink::WebURLRequest request; 267 blink::WebURLRequest request;
280 request.initialize(); 268 request.initialize();
281 request.setURL(GURL(kTestURL)); 269 request.setURL(GURL(kTestURL));
282 client()->loader()->loadAsynchronously(request, client()); 270 client()->loader()->loadAsynchronously(request, client());
283 ASSERT_TRUE(peer()); 271 ASSERT_TRUE(peer());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 EXPECT_NE(kFtpDirListing, client()->received_data()); 341 EXPECT_NE(kFtpDirListing, client()->received_data());
354 } 342 }
355 343
356 TestWebURLLoaderClient* client() { return client_.get(); } 344 TestWebURLLoaderClient* client() { return client_.get(); }
357 TestResourceDispatcher* dispatcher() { return &dispatcher_; } 345 TestResourceDispatcher* dispatcher() { return &dispatcher_; }
358 RequestPeer* peer() { return dispatcher()->peer(); } 346 RequestPeer* peer() { return dispatcher()->peer(); }
359 base::MessageLoop* message_loop() { return &message_loop_; } 347 base::MessageLoop* message_loop() { return &message_loop_; }
360 348
361 private: 349 private:
362 base::MessageLoop message_loop_; 350 base::MessageLoop message_loop_;
363 // WorkerScheduler is needed because WebURLLoaderImpl needs a
364 // scheduler::TaskQueue.
365 std::unique_ptr<scheduler::WorkerScheduler> worker_scheduler_;
366 TestResourceDispatcher dispatcher_; 351 TestResourceDispatcher dispatcher_;
367 std::unique_ptr<TestWebURLLoaderClient> client_; 352 std::unique_ptr<TestWebURLLoaderClient> client_;
368 }; 353 };
369 354
370 TEST_F(WebURLLoaderImplTest, Success) { 355 TEST_F(WebURLLoaderImplTest, Success) {
371 DoStartAsyncRequest(); 356 DoStartAsyncRequest();
372 DoReceiveResponse(); 357 DoReceiveResponse();
373 DoReceiveData(); 358 DoReceiveData();
374 DoCompleteRequest(); 359 DoCompleteRequest();
375 EXPECT_FALSE(dispatcher()->canceled()); 360 EXPECT_FALSE(dispatcher()->canceled());
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 content::ResourceResponseInfo info; 655 content::ResourceResponseInfo info;
671 info.socket_address = net::HostPortPair(test.ip, 443); 656 info.socket_address = net::HostPortPair(test.ip, 443);
672 blink::WebURLResponse response; 657 blink::WebURLResponse response;
673 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); 658 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true);
674 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); 659 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8());
675 }; 660 };
676 } 661 }
677 662
678 } // namespace 663 } // namespace
679 } // namespace content 664 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698