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

Side by Side Diff: content/browser/loader/resource_scheduler_unittest.cc

Issue 465363003: ResourceScheduler get visual signal from RenderViewHostImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/timer/mock_timer.h" 10 #include "base/timer/mock_timer.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/loader/resource_dispatcher_host_impl.h" 13 #include "content/browser/loader/resource_dispatcher_host_impl.h"
14 #include "content/browser/loader/resource_message_filter.h" 14 #include "content/browser/loader/resource_message_filter.h"
15 #include "content/browser/loader/resource_request_info_impl.h" 15 #include "content/browser/loader/resource_request_info_impl.h"
16 #include "content/common/resource_messages.h" 16 #include "content/common/resource_messages.h"
17 #include "content/public/browser/resource_context.h" 17 #include "content/public/browser/resource_context.h"
18 #include "content/public/browser/resource_controller.h" 18 #include "content/public/browser/resource_controller.h"
19 #include "content/public/browser/resource_throttle.h" 19 #include "content/public/browser/resource_throttle.h"
20 #include "content/public/common/process_type.h" 20 #include "content/public/common/process_type.h"
21 #include "content/public/common/resource_type.h" 21 #include "content/public/common/resource_type.h"
22 #include "content/public/test/mock_render_process_host.h"
23 #include "content/public/test/test_browser_context.h"
24 #include "content/test/test_web_contents.h"
22 #include "net/base/host_port_pair.h" 25 #include "net/base/host_port_pair.h"
23 #include "net/base/request_priority.h" 26 #include "net/base/request_priority.h"
24 #include "net/http/http_server_properties_impl.h" 27 #include "net/http/http_server_properties_impl.h"
25 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
26 #include "net/url_request/url_request_test_util.h" 29 #include "net/url_request/url_request_test_util.h"
27 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
28 31
29 namespace content { 32 namespace content {
30 33
31 namespace { 34 namespace {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 FakeResourceContext context_; 136 FakeResourceContext context_;
134 }; 137 };
135 138
136 class ResourceSchedulerTest : public testing::Test { 139 class ResourceSchedulerTest : public testing::Test {
137 protected: 140 protected:
138 ResourceSchedulerTest() 141 ResourceSchedulerTest()
139 : next_request_id_(0), 142 : next_request_id_(0),
140 ui_thread_(BrowserThread::UI, &message_loop_), 143 ui_thread_(BrowserThread::UI, &message_loop_),
141 io_thread_(BrowserThread::IO, &message_loop_), 144 io_thread_(BrowserThread::IO, &message_loop_),
142 mock_timer_(new base::MockTimer(true, true)) { 145 mock_timer_(new base::MockTimer(true, true)) {
146 // set up web contents
147 render_process_host_factory_.reset(new MockRenderProcessHostFactory());
148 browser_context_.reset(new TestBrowserContext());
149 scoped_refptr<SiteInstance> site_instance =
150 SiteInstance::Create(browser_context_.get());
151 scoped_refptr<SiteInstance> site_instance_background =
152 SiteInstance::Create(browser_context_.get());
153 scoped_refptr<SiteInstance> site_instance_2 =
154 SiteInstance::Create(browser_context_.get());
155 scoped_refptr<SiteInstance> site_instance_background_2 =
156 SiteInstance::Create(browser_context_.get());
157 SiteInstanceImpl::set_render_process_host_factory(
158 render_process_host_factory_.get());
159
160 web_contents_.reset(
161 TestWebContents::Create(browser_context_.get(), site_instance.get()));
162 web_contents_background_.reset(
163 TestWebContents::Create(browser_context_.get(),
164 site_instance_background.get()));
165 web_contents_2_.reset(
166 TestWebContents::Create(browser_context_.get(), site_instance_2.get()));
167 web_contents_background_2_.reset(
168 TestWebContents::Create(browser_context_.get(),
169 site_instance_background_2.get()));
170
171 web_contents_->WasShown();
172 web_contents_background_->WasHidden();
173 web_contents_2_->WasShown();
174 web_contents_background_2_->WasHidden();
175
176 // set up resource scheduler
143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); 177 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_));
144 178
145 // TODO(aiolos): Remove when throttling and coalescing have both landed. 179 // TODO(aiolos): Remove when throttling and coalescing have both landed.
146 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 180 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
147 false /* should_coalesce */); 181 false /* should_coalesce */);
148 182
149 scheduler_.OnClientCreated(kChildId, kRouteId); 183 scheduler_.OnClientCreated(kChildId, kRouteId, web_contents_.get());
150 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); 184 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
151 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); 185 scheduler_.OnClientCreated(kBackgroundChildId,
186 kBackgroundRouteId,
187 web_contents_background_.get());
152 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); 188 context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
153 } 189 }
154 190
155 virtual ~ResourceSchedulerTest() { 191 virtual ~ResourceSchedulerTest() {
156 scheduler_.OnClientDeleted(kChildId, kRouteId); 192 scheduler_.OnClientDeleted(kChildId, kRouteId);
157 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); 193 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
194
195 web_contents_.reset();
196 web_contents_background_.reset();
197 web_contents_2_.reset();
198 web_contents_background_2_.reset();
199 browser_context_.reset();
200 render_process_host_factory_.reset();
158 } 201 }
159 202
160 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( 203 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute(
161 const char* url, 204 const char* url,
162 net::RequestPriority priority, 205 net::RequestPriority priority,
163 int child_id, 206 int child_id,
164 int route_id, 207 int route_id,
165 bool is_async) { 208 bool is_async) {
166 scoped_ptr<net::URLRequest> url_request( 209 scoped_ptr<net::URLRequest> url_request(
167 context_.CreateRequest(GURL(url), priority, NULL, NULL)); 210 context_.CreateRequest(GURL(url), priority, NULL, NULL));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 315
273 int next_request_id_; 316 int next_request_id_;
274 base::MessageLoopForIO message_loop_; 317 base::MessageLoopForIO message_loop_;
275 BrowserThreadImpl ui_thread_; 318 BrowserThreadImpl ui_thread_;
276 BrowserThreadImpl io_thread_; 319 BrowserThreadImpl io_thread_;
277 ResourceDispatcherHostImpl rdh_; 320 ResourceDispatcherHostImpl rdh_;
278 ResourceScheduler scheduler_; 321 ResourceScheduler scheduler_;
279 base::MockTimer* mock_timer_; 322 base::MockTimer* mock_timer_;
280 net::HttpServerPropertiesImpl http_server_properties_; 323 net::HttpServerPropertiesImpl http_server_properties_;
281 net::TestURLRequestContext context_; 324 net::TestURLRequestContext context_;
325 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory_;
326 scoped_ptr<TestBrowserContext> browser_context_;
327 scoped_ptr<WebContents> web_contents_;
328 scoped_ptr<WebContents> web_contents_background_;
329 scoped_ptr<WebContents> web_contents_2_;
330 scoped_ptr<WebContents> web_contents_background_2_;
282 }; 331 };
283 332
284 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { 333 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {
285 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); 334 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST));
286 EXPECT_TRUE(request->started()); 335 EXPECT_TRUE(request->started());
287 } 336 }
288 337
289 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { 338 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) {
290 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); 339 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST));
291 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); 340 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST));
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); 680 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
632 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 681 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
633 EXPECT_TRUE(low2->started()); 682 EXPECT_TRUE(low2->started());
634 } 683 }
635 684
636 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { 685 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) {
637 // TODO(aiolos): remove when throttling and coalescing have both landed 686 // TODO(aiolos): remove when throttling and coalescing have both landed
638 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 687 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
639 false /* should_coalesce */); 688 false /* should_coalesce */);
640 EXPECT_TRUE(scheduler_.should_throttle()); 689 EXPECT_TRUE(scheduler_.should_throttle());
641 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 690 scheduler_.OnClientCreated(kBackgroundChildId2,
691 kBackgroundRouteId2,
692 web_contents_background_2_.get());
642 693
643 EXPECT_EQ(ResourceScheduler::THROTTLED, 694 EXPECT_EQ(ResourceScheduler::THROTTLED,
644 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 695 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
645 kBackgroundRouteId2)); 696 kBackgroundRouteId2));
646 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 697 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
647 } 698 }
648 699
649 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { 700 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) {
650 // TODO(aiolos): remove when throttling and coalescing have both landed 701 // TODO(aiolos): remove when throttling and coalescing have both landed
651 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 702 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, 1066 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1016 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1067 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1017 kBackgroundRouteId)); 1068 kBackgroundRouteId));
1018 } 1069 }
1019 1070
1020 TEST_F(ResourceSchedulerTest, 1071 TEST_F(ResourceSchedulerTest,
1021 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { 1072 UnloadedClientVisibilityChangedCorrectlyUnthrottles) {
1022 // TODO(aiolos): remove when throttling and coalescing have both landed 1073 // TODO(aiolos): remove when throttling and coalescing have both landed
1023 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1074 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1024 false /* should_coalesce */); 1075 false /* should_coalesce */);
1025 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1076 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1026 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1077 scheduler_.OnClientCreated(kBackgroundChildId2,
1078 kBackgroundRouteId2,
1079 web_contents_background_2_.get());
1027 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1080 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1028 scheduler_.OnLoadingStateChanged( 1081 scheduler_.OnLoadingStateChanged(
1029 kBackgroundChildId2, kBackgroundRouteId2, true); 1082 kBackgroundChildId2, kBackgroundRouteId2, true);
1030 1083
1031 // 1 visible, 3 hidden 1084 // 1 visible, 3 hidden
1032 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1085 EXPECT_FALSE(scheduler_.active_clients_loaded());
1033 EXPECT_EQ(ResourceScheduler::THROTTLED, 1086 EXPECT_EQ(ResourceScheduler::THROTTLED,
1034 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1087 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1035 kBackgroundRouteId)); 1088 kBackgroundRouteId));
1036 EXPECT_EQ(ResourceScheduler::THROTTLED, 1089 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1124
1072 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1125 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1073 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1126 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1074 } 1127 }
1075 1128
1076 TEST_F(ResourceSchedulerTest, 1129 TEST_F(ResourceSchedulerTest,
1077 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { 1130 UnloadedClientAudibilityChangedCorrectlyUnthrottles) {
1078 // TODO(aiolos): remove when throttling and coalescing have both landed 1131 // TODO(aiolos): remove when throttling and coalescing have both landed
1079 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1132 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1080 false /* should_coalesce */); 1133 false /* should_coalesce */);
1081 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1134 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1082 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1135 scheduler_.OnClientCreated(kBackgroundChildId2,
1136 kBackgroundRouteId2,
1137 web_contents_background_2_.get());
1083 scheduler_.OnLoadingStateChanged( 1138 scheduler_.OnLoadingStateChanged(
1084 kBackgroundChildId2, kBackgroundRouteId2, true); 1139 kBackgroundChildId2, kBackgroundRouteId2, true);
1085 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1140 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1086 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1141 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1087 1142
1088 // 1 audible, 3 hidden 1143 // 1 audible, 3 hidden
1089 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1144 EXPECT_FALSE(scheduler_.active_clients_loaded());
1090 EXPECT_EQ(ResourceScheduler::THROTTLED, 1145 EXPECT_EQ(ResourceScheduler::THROTTLED,
1091 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1146 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1092 kBackgroundRouteId)); 1147 kBackgroundRouteId));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1183
1129 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1184 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1130 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1185 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1131 } 1186 }
1132 1187
1133 TEST_F(ResourceSchedulerTest, 1188 TEST_F(ResourceSchedulerTest,
1134 LoadedClientVisibilityChangedCorrectlyUnthrottles) { 1189 LoadedClientVisibilityChangedCorrectlyUnthrottles) {
1135 // TODO(aiolos): remove when throttling and coalescing have both landed 1190 // TODO(aiolos): remove when throttling and coalescing have both landed
1136 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1191 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1137 false /* should_coalesce */); 1192 false /* should_coalesce */);
1138 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1193 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1139 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1194 scheduler_.OnClientCreated(kBackgroundChildId2,
1195 kBackgroundRouteId2,
1196 web_contents_background_2_.get());
1140 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1197 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1141 scheduler_.OnLoadingStateChanged( 1198 scheduler_.OnLoadingStateChanged(
1142 kBackgroundChildId2, kBackgroundRouteId2, true); 1199 kBackgroundChildId2, kBackgroundRouteId2, true);
1143 // 1 visible, 3 hidden 1200 // 1 visible, 3 hidden
1144 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1201 EXPECT_FALSE(scheduler_.active_clients_loaded());
1145 EXPECT_EQ(ResourceScheduler::THROTTLED, 1202 EXPECT_EQ(ResourceScheduler::THROTTLED,
1146 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1203 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1147 kBackgroundRouteId)); 1204 kBackgroundRouteId));
1148 EXPECT_EQ(ResourceScheduler::THROTTLED, 1205 EXPECT_EQ(ResourceScheduler::THROTTLED,
1149 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1206 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1240
1184 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1241 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1185 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1242 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1186 } 1243 }
1187 1244
1188 TEST_F(ResourceSchedulerTest, 1245 TEST_F(ResourceSchedulerTest,
1189 LoadedClientAudibilityChangedCorrectlyUnthrottles) { 1246 LoadedClientAudibilityChangedCorrectlyUnthrottles) {
1190 // TODO(aiolos): remove when throttling and coalescing have both landed 1247 // TODO(aiolos): remove when throttling and coalescing have both landed
1191 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1248 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1192 false /* should_coalesce */); 1249 false /* should_coalesce */);
1193 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1250 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1194 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1251 scheduler_.OnClientCreated(kBackgroundChildId2,
1252 kBackgroundRouteId2,
1253 web_contents_background_2_.get());
1195 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1254 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1196 scheduler_.OnLoadingStateChanged( 1255 scheduler_.OnLoadingStateChanged(
1197 kBackgroundChildId2, kBackgroundRouteId2, true); 1256 kBackgroundChildId2, kBackgroundRouteId2, true);
1198 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1257 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1199 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1258 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1200 // 1 audible, 3 hidden 1259 // 1 audible, 3 hidden
1201 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1260 EXPECT_FALSE(scheduler_.active_clients_loaded());
1202 EXPECT_EQ(ResourceScheduler::THROTTLED, 1261 EXPECT_EQ(ResourceScheduler::THROTTLED,
1203 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1262 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1204 kBackgroundRouteId)); 1263 kBackgroundRouteId));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1298 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1240 1299
1241 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1300 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1242 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1301 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1243 } 1302 }
1244 1303
1245 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { 1304 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
1246 // TODO(aiolos): remove when throttling and coalescing have both landed 1305 // TODO(aiolos): remove when throttling and coalescing have both landed
1247 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1306 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1248 false /* should_coalesce */); 1307 false /* should_coalesce */);
1249 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1308 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1250 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1309 scheduler_.OnClientCreated(kBackgroundChildId2,
1310 kBackgroundRouteId2,
1311 web_contents_background_2_.get());
1251 scheduler_.OnLoadingStateChanged( 1312 scheduler_.OnLoadingStateChanged(
1252 kBackgroundChildId2, kBackgroundRouteId2, true); 1313 kBackgroundChildId2, kBackgroundRouteId2, true);
1253 1314
1254 // 2 visible, 2 hidden 1315 // 2 visible, 2 hidden
1255 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1316 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1256 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1317 EXPECT_FALSE(scheduler_.active_clients_loaded());
1257 EXPECT_EQ(ResourceScheduler::THROTTLED, 1318 EXPECT_EQ(ResourceScheduler::THROTTLED,
1258 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1319 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1259 kBackgroundRouteId)); 1320 kBackgroundRouteId));
1260 EXPECT_EQ(ResourceScheduler::THROTTLED, 1321 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1369 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1309 1370
1310 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1371 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1311 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1372 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1312 } 1373 }
1313 1374
1314 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { 1375 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) {
1315 // TODO(aiolos): remove when throttling and coalescing have both landed 1376 // TODO(aiolos): remove when throttling and coalescing have both landed
1316 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1377 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1317 false /* should_coalesce */); 1378 false /* should_coalesce */);
1318 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1379 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1319 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1380 scheduler_.OnClientCreated(kBackgroundChildId2,
1381 kBackgroundRouteId2,
1382 web_contents_background_2_.get());
1320 scheduler_.OnLoadingStateChanged( 1383 scheduler_.OnLoadingStateChanged(
1321 kBackgroundChildId2, kBackgroundRouteId2, true); 1384 kBackgroundChildId2, kBackgroundRouteId2, true);
1322 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1385 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1323 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1386 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1324 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); 1387 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
1325 // 2 audible, 2 hidden 1388 // 2 audible, 2 hidden
1326 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1389 EXPECT_FALSE(scheduler_.active_clients_loaded());
1327 EXPECT_EQ(ResourceScheduler::THROTTLED, 1390 EXPECT_EQ(ResourceScheduler::THROTTLED,
1328 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1391 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1329 kBackgroundRouteId)); 1392 kBackgroundRouteId));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1441 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1379 1442
1380 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1443 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1381 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1444 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1382 } 1445 }
1383 1446
1384 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { 1447 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
1385 // TODO(aiolos): remove when throttling and coalescing have both landed 1448 // TODO(aiolos): remove when throttling and coalescing have both landed
1386 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1449 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1387 false /* should_coalesce */); 1450 false /* should_coalesce */);
1388 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1451 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1389 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1452 scheduler_.OnClientCreated(kBackgroundChildId2,
1453 kBackgroundRouteId2,
1454 web_contents_background_2_.get());
1390 scheduler_.OnLoadingStateChanged( 1455 scheduler_.OnLoadingStateChanged(
1391 kBackgroundChildId2, kBackgroundRouteId2, true); 1456 kBackgroundChildId2, kBackgroundRouteId2, true);
1392 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1457 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1393 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1458 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1394 // 2 visible, 2 hidden 1459 // 2 visible, 2 hidden
1395 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1460 EXPECT_FALSE(scheduler_.active_clients_loaded());
1396 EXPECT_EQ(ResourceScheduler::THROTTLED, 1461 EXPECT_EQ(ResourceScheduler::THROTTLED,
1397 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1462 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1398 kBackgroundRouteId)); 1463 kBackgroundRouteId));
1399 EXPECT_EQ(ResourceScheduler::THROTTLED, 1464 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1512 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1448 1513
1449 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1514 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1450 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1515 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1451 } 1516 }
1452 1517
1453 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { 1518 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) {
1454 // TODO(aiolos): remove when throttling and coalescing have both landed 1519 // TODO(aiolos): remove when throttling and coalescing have both landed
1455 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1520 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1456 false /* should_coalesce */); 1521 false /* should_coalesce */);
1457 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1522 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1458 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1523 scheduler_.OnClientCreated(kBackgroundChildId2,
1524 kBackgroundRouteId2,
1525 web_contents_background_2_.get());
1459 scheduler_.OnLoadingStateChanged( 1526 scheduler_.OnLoadingStateChanged(
1460 kBackgroundChildId2, kBackgroundRouteId2, true); 1527 kBackgroundChildId2, kBackgroundRouteId2, true);
1461 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1528 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1462 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1529 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1463 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1530 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1464 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); 1531 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
1465 // 2 audible, 2 hidden 1532 // 2 audible, 2 hidden
1466 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1533 EXPECT_FALSE(scheduler_.active_clients_loaded());
1467 EXPECT_EQ(ResourceScheduler::THROTTLED, 1534 EXPECT_EQ(ResourceScheduler::THROTTLED,
1468 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1535 scheduler_.GetClientStateForTesting(kBackgroundChildId,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1585 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1519 1586
1520 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1587 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1521 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1588 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1522 } 1589 }
1523 1590
1524 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { 1591 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) {
1525 // TODO(aiolos): remove when throttling and coalescing have both landed 1592 // TODO(aiolos): remove when throttling and coalescing have both landed
1526 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1593 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1527 false /* should_coalesce */); 1594 false /* should_coalesce */);
1528 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1595 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1529 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1596 scheduler_.OnClientCreated(kBackgroundChildId2,
1597 kBackgroundRouteId2,
1598 web_contents_background_2_.get());
1530 1599
1531 // 1 visible and 2 hidden loading, 1 visible loaded 1600 // 1 visible and 2 hidden loading, 1 visible loaded
1532 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1601 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1533 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1602 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1534 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1603 EXPECT_FALSE(scheduler_.active_clients_loaded());
1535 EXPECT_EQ(ResourceScheduler::THROTTLED, 1604 EXPECT_EQ(ResourceScheduler::THROTTLED,
1536 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1605 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1537 kBackgroundRouteId)); 1606 kBackgroundRouteId));
1538 EXPECT_EQ(ResourceScheduler::THROTTLED, 1607 EXPECT_EQ(ResourceScheduler::THROTTLED,
1539 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1608 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1658 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1590 1659
1591 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1660 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1592 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1661 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1593 } 1662 }
1594 1663
1595 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { 1664 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) {
1596 // TODO(aiolos): remove when throttling and coalescing have both landed 1665 // TODO(aiolos): remove when throttling and coalescing have both landed
1597 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1666 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1598 false /* should_coalesce */); 1667 false /* should_coalesce */);
1599 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1668 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1600 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1669 scheduler_.OnClientCreated(kBackgroundChildId2,
1670 kBackgroundRouteId2,
1671 web_contents_background_2_.get());
1601 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1672 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1602 1673
1603 // 2 visible loading, 1 hidden loading, 1 hidden loaded 1674 // 2 visible loading, 1 hidden loading, 1 hidden loaded
1604 scheduler_.OnLoadingStateChanged( 1675 scheduler_.OnLoadingStateChanged(
1605 kBackgroundChildId2, kBackgroundRouteId2, true); 1676 kBackgroundChildId2, kBackgroundRouteId2, true);
1606 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1677 EXPECT_FALSE(scheduler_.active_clients_loaded());
1607 EXPECT_EQ(ResourceScheduler::THROTTLED, 1678 EXPECT_EQ(ResourceScheduler::THROTTLED,
1608 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1679 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1609 kBackgroundRouteId)); 1680 kBackgroundRouteId));
1610 EXPECT_EQ(ResourceScheduler::THROTTLED, 1681 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1715 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1645 1716
1646 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1717 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1647 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1718 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1648 } 1719 }
1649 1720
1650 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { 1721 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) {
1651 // TODO(aiolos): remove when throttling and coalescing have both landed 1722 // TODO(aiolos): remove when throttling and coalescing have both landed
1652 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1723 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1653 false /* should_coalesce */); 1724 false /* should_coalesce */);
1654 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1725 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1655 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1726 scheduler_.OnClientCreated(kBackgroundChildId2,
1727 kBackgroundRouteId2,
1728 web_contents_background_2_.get());
1656 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1729 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1657 1730
1658 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading 1731 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
1659 scheduler_.OnLoadingStateChanged( 1732 scheduler_.OnLoadingStateChanged(
1660 kBackgroundChildId2, kBackgroundRouteId2, true); 1733 kBackgroundChildId2, kBackgroundRouteId2, true);
1661 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1734 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1662 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1735 EXPECT_FALSE(scheduler_.active_clients_loaded());
1663 EXPECT_EQ(ResourceScheduler::THROTTLED, 1736 EXPECT_EQ(ResourceScheduler::THROTTLED,
1664 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1737 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1665 kBackgroundRouteId)); 1738 kBackgroundRouteId));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 1784
1712 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1785 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1713 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1786 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1714 } 1787 }
1715 1788
1716 TEST_F(ResourceSchedulerTest, 1789 TEST_F(ResourceSchedulerTest,
1717 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { 1790 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) {
1718 // TODO(aiolos): remove when throttling and coalescing have both landed 1791 // TODO(aiolos): remove when throttling and coalescing have both landed
1719 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1792 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1720 false /* should_coalesce */); 1793 false /* should_coalesce */);
1721 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1794 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
1722 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1795 scheduler_.OnClientCreated(kBackgroundChildId2,
1796 kBackgroundRouteId2,
1797 web_contents_background_2_.get());
1723 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); 1798 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1724 1799
1725 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading 1800 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
1726 scheduler_.OnLoadingStateChanged( 1801 scheduler_.OnLoadingStateChanged(
1727 kBackgroundChildId2, kBackgroundRouteId2, true); 1802 kBackgroundChildId2, kBackgroundRouteId2, true);
1728 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1803 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1729 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1804 EXPECT_FALSE(scheduler_.active_clients_loaded());
1730 EXPECT_EQ(ResourceScheduler::THROTTLED, 1805 EXPECT_EQ(ResourceScheduler::THROTTLED,
1731 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1806 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1732 kBackgroundRouteId)); 1807 kBackgroundRouteId));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); 1924 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1850 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, 1925 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1851 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1926 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1852 kBackgroundRouteId)); 1927 kBackgroundRouteId));
1853 EXPECT_FALSE(mock_timer_->IsRunning()); 1928 EXPECT_FALSE(mock_timer_->IsRunning());
1854 } 1929 }
1855 1930
1856 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { 1931 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
1857 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1932 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1858 true /* should_coalesce */); 1933 true /* should_coalesce */);
1859 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1934 scheduler_.OnClientCreated(kBackgroundChildId2,
1935 kBackgroundRouteId2,
1936 web_contents_background_2_.get());
1860 EXPECT_FALSE(mock_timer_->IsRunning()); 1937 EXPECT_FALSE(mock_timer_->IsRunning());
1861 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1938 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1862 EXPECT_FALSE(mock_timer_->IsRunning()); 1939 EXPECT_FALSE(mock_timer_->IsRunning());
1863 scheduler_.OnLoadingStateChanged( 1940 scheduler_.OnLoadingStateChanged(
1864 kBackgroundChildId, kBackgroundRouteId, true); 1941 kBackgroundChildId, kBackgroundRouteId, true);
1865 EXPECT_EQ(ResourceScheduler::COALESCED, 1942 EXPECT_EQ(ResourceScheduler::COALESCED,
1866 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1943 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1867 kBackgroundRouteId)); 1944 kBackgroundRouteId));
1868 scheduler_.OnLoadingStateChanged( 1945 scheduler_.OnLoadingStateChanged(
1869 kBackgroundChildId2, kBackgroundRouteId2, true); 1946 kBackgroundChildId2, kBackgroundRouteId2, true);
1870 EXPECT_EQ(ResourceScheduler::COALESCED, 1947 EXPECT_EQ(ResourceScheduler::COALESCED,
1871 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1948 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1872 kBackgroundRouteId2)); 1949 kBackgroundRouteId2));
1873 EXPECT_TRUE(mock_timer_->IsRunning()); 1950 EXPECT_TRUE(mock_timer_->IsRunning());
1874 1951
1875 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); 1952 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
1876 EXPECT_TRUE(mock_timer_->IsRunning()); 1953 EXPECT_TRUE(mock_timer_->IsRunning());
1877 1954
1878 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1955 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1879 EXPECT_FALSE(mock_timer_->IsRunning()); 1956 EXPECT_FALSE(mock_timer_->IsRunning());
1880 1957
1881 // To avoid errors on test tear down. 1958 // To avoid errors on test tear down.
1882 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); 1959 scheduler_.OnClientCreated(kBackgroundChildId,
1960 kBackgroundRouteId,
1961 web_contents_background_.get());
1883 } 1962 }
1884 1963
1885 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { 1964 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
1886 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1965 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1887 true /* should_coalesce */); 1966 true /* should_coalesce */);
1888 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1967 scheduler_.OnClientCreated(kBackgroundChildId2,
1968 kBackgroundRouteId2,
1969 web_contents_background_2_.get());
1889 EXPECT_FALSE(mock_timer_->IsRunning()); 1970 EXPECT_FALSE(mock_timer_->IsRunning());
1890 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1971 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1891 EXPECT_FALSE(mock_timer_->IsRunning()); 1972 EXPECT_FALSE(mock_timer_->IsRunning());
1892 scheduler_.OnLoadingStateChanged( 1973 scheduler_.OnLoadingStateChanged(
1893 kBackgroundChildId, kBackgroundRouteId, true); 1974 kBackgroundChildId, kBackgroundRouteId, true);
1894 EXPECT_EQ(ResourceScheduler::COALESCED, 1975 EXPECT_EQ(ResourceScheduler::COALESCED,
1895 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1976 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1896 kBackgroundRouteId)); 1977 kBackgroundRouteId));
1897 scheduler_.OnLoadingStateChanged( 1978 scheduler_.OnLoadingStateChanged(
1898 kBackgroundChildId2, kBackgroundRouteId2, true); 1979 kBackgroundChildId2, kBackgroundRouteId2, true);
(...skipping 10 matching lines...) Expand all
1909 kBackgroundChildId2, kBackgroundRouteId2, false); 1990 kBackgroundChildId2, kBackgroundRouteId2, false);
1910 EXPECT_FALSE(mock_timer_->IsRunning()); 1991 EXPECT_FALSE(mock_timer_->IsRunning());
1911 1992
1912 // This is needed to avoid errors on test tear down. 1993 // This is needed to avoid errors on test tear down.
1913 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1994 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1914 } 1995 }
1915 1996
1916 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { 1997 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
1917 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1998 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1918 true /* should_coalesce */); 1999 true /* should_coalesce */);
1919 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 2000 scheduler_.OnClientCreated(kBackgroundChildId2,
2001 kBackgroundRouteId2,
2002 web_contents_background_2_.get());
1920 EXPECT_FALSE(mock_timer_->IsRunning()); 2003 EXPECT_FALSE(mock_timer_->IsRunning());
1921 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 2004 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1922 EXPECT_FALSE(mock_timer_->IsRunning()); 2005 EXPECT_FALSE(mock_timer_->IsRunning());
1923 scheduler_.OnLoadingStateChanged( 2006 scheduler_.OnLoadingStateChanged(
1924 kBackgroundChildId, kBackgroundRouteId, true); 2007 kBackgroundChildId, kBackgroundRouteId, true);
1925 EXPECT_EQ(ResourceScheduler::COALESCED, 2008 EXPECT_EQ(ResourceScheduler::COALESCED,
1926 scheduler_.GetClientStateForTesting(kBackgroundChildId, 2009 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1927 kBackgroundRouteId)); 2010 kBackgroundRouteId));
1928 scheduler_.OnLoadingStateChanged( 2011 scheduler_.OnLoadingStateChanged(
1929 kBackgroundChildId2, kBackgroundRouteId2, true); 2012 kBackgroundChildId2, kBackgroundRouteId2, true);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 EXPECT_FALSE(high2->started()); 2173 EXPECT_FALSE(high2->started());
2091 EXPECT_FALSE(low->started()); 2174 EXPECT_FALSE(low->started());
2092 2175
2093 FireCoalescingTimer(); 2176 FireCoalescingTimer();
2094 2177
2095 EXPECT_TRUE(high->started()); 2178 EXPECT_TRUE(high->started());
2096 EXPECT_TRUE(high2->started()); 2179 EXPECT_TRUE(high2->started());
2097 EXPECT_TRUE(low->started()); 2180 EXPECT_TRUE(low->started());
2098 } 2181 }
2099 2182
2183 TEST_F(ResourceSchedulerTest, GetVisualSignalFromWebContents) {
2184 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
2185 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
2186 scheduler_.OnClientCreated(kBackgroundChildId2,
2187 kBackgroundRouteId2,
2188 web_contents_background_2_.get());
2189 EXPECT_TRUE(scheduler_.ClientIsVisible(kChildId2, kRouteId2));
2190 EXPECT_FALSE(scheduler_.ClientIsVisible(kBackgroundChildId2,
2191 kBackgroundRouteId2));
2192
2193 // Change visibility of web contents.
2194 web_contents_2_->WasHidden();
2195 web_contents_background_2_->WasShown();
2196
2197 // The clients get the visual signal from web contents.
2198 EXPECT_FALSE(scheduler_.ClientIsVisible(kChildId2, kRouteId2));
2199 EXPECT_TRUE(scheduler_.ClientIsVisible(kBackgroundChildId2,
2200 kBackgroundRouteId2));
2201
2202 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
2203 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
2204 }
2205
2100 } // unnamed namespace 2206 } // unnamed namespace
2101 2207
2102 } // namespace content 2208 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698