OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/loader/resource_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
14 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
15 #include "base/timer/mock_timer.h" | 14 #include "base/timer/mock_timer.h" |
16 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
17 #include "content/browser/browser_thread_impl.h" | |
18 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
19 #include "content/public/browser/resource_context.h" | 16 #include "content/public/browser/resource_context.h" |
20 #include "content/public/browser/resource_controller.h" | 17 #include "content/public/browser/resource_controller.h" |
21 #include "content/public/browser/resource_throttle.h" | 18 #include "content/public/browser/resource_throttle.h" |
22 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
23 #include "content/public/test/test_browser_context.h" | 20 #include "content/public/test/test_browser_context.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "content/test/test_render_view_host_factory.h" | 22 #include "content/test/test_render_view_host_factory.h" |
25 #include "content/test/test_web_contents.h" | 23 #include "content/test/test_web_contents.h" |
26 #include "net/base/host_port_pair.h" | 24 #include "net/base/host_port_pair.h" |
27 #include "net/base/request_priority.h" | 25 #include "net/base/request_priority.h" |
28 #include "net/http/http_server_properties_impl.h" | 26 #include "net/http/http_server_properties_impl.h" |
29 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/events/latency_info.h" | 30 #include "ui/events/latency_info.h" |
33 #include "url/scheme_host_port.h" | 31 #include "url/scheme_host_port.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 }; | 119 }; |
122 | 120 |
123 class FakeResourceContext : public ResourceContext { | 121 class FakeResourceContext : public ResourceContext { |
124 private: | 122 private: |
125 net::HostResolver* GetHostResolver() override { return NULL; } | 123 net::HostResolver* GetHostResolver() override { return NULL; } |
126 net::URLRequestContext* GetRequestContext() override { return NULL; } | 124 net::URLRequestContext* GetRequestContext() override { return NULL; } |
127 }; | 125 }; |
128 | 126 |
129 class ResourceSchedulerTest : public testing::Test { | 127 class ResourceSchedulerTest : public testing::Test { |
130 protected: | 128 protected: |
131 ResourceSchedulerTest() | 129 ResourceSchedulerTest() { |
132 : ui_thread_(BrowserThread::UI, &message_loop_), | |
133 io_thread_(BrowserThread::IO, &message_loop_) { | |
134 InitializeScheduler(); | 130 InitializeScheduler(); |
135 context_.set_http_server_properties(&http_server_properties_); | 131 context_.set_http_server_properties(&http_server_properties_); |
136 } | 132 } |
137 | 133 |
138 ~ResourceSchedulerTest() override { | 134 ~ResourceSchedulerTest() override { |
139 CleanupScheduler(); | 135 CleanupScheduler(); |
140 } | 136 } |
141 | 137 |
142 // Done separately from construction to allow for modification of command | 138 // Done separately from construction to allow for modification of command |
143 // line flags in tests. | 139 // line flags in tests. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 235 |
240 void FireCoalescingTimer() { | 236 void FireCoalescingTimer() { |
241 EXPECT_TRUE(mock_timer_->IsRunning()); | 237 EXPECT_TRUE(mock_timer_->IsRunning()); |
242 mock_timer_->Fire(); | 238 mock_timer_->Fire(); |
243 } | 239 } |
244 | 240 |
245 ResourceScheduler* scheduler() { | 241 ResourceScheduler* scheduler() { |
246 return scheduler_.get(); | 242 return scheduler_.get(); |
247 } | 243 } |
248 | 244 |
249 base::MessageLoopForIO message_loop_; | 245 TestBrowserThreadBundle thread_bundle_; |
250 BrowserThreadImpl ui_thread_; | |
251 BrowserThreadImpl io_thread_; | |
252 ResourceDispatcherHostImpl rdh_; | |
253 std::unique_ptr<ResourceScheduler> scheduler_; | 246 std::unique_ptr<ResourceScheduler> scheduler_; |
254 base::MockTimer* mock_timer_; | 247 base::MockTimer* mock_timer_; |
255 net::HttpServerPropertiesImpl http_server_properties_; | 248 net::HttpServerPropertiesImpl http_server_properties_; |
256 net::TestURLRequestContext context_; | 249 net::TestURLRequestContext context_; |
257 }; | 250 }; |
258 | 251 |
259 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { | 252 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { |
260 std::unique_ptr<TestRequest> request( | 253 std::unique_ptr<TestRequest> request( |
261 NewRequest("http://host/1", net::LOWEST)); | 254 NewRequest("http://host/1", net::LOWEST)); |
262 EXPECT_TRUE(request->started()); | 255 EXPECT_TRUE(request->started()); |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 scheduler_->OnClientDeleted(kChildId2, kRouteId2); | 823 scheduler_->OnClientDeleted(kChildId2, kRouteId2); |
831 high.reset(); | 824 high.reset(); |
832 delayable_requests.clear(); | 825 delayable_requests.clear(); |
833 base::RunLoop().RunUntilIdle(); | 826 base::RunLoop().RunUntilIdle(); |
834 EXPECT_TRUE(lowest->started()); | 827 EXPECT_TRUE(lowest->started()); |
835 } | 828 } |
836 | 829 |
837 } // unnamed namespace | 830 } // unnamed namespace |
838 | 831 |
839 } // namespace content | 832 } // namespace content |
OLD | NEW |