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

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: Do not throttle when should not 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/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/timer/mock_timer.h" 11 #include "base/timer/mock_timer.h"
11 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
12 #include "content/browser/browser_thread_impl.h" 13 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/loader/resource_dispatcher_host_impl.h" 14 #include "content/browser/loader/resource_dispatcher_host_impl.h"
14 #include "content/browser/loader/resource_message_filter.h" 15 #include "content/browser/loader/resource_message_filter.h"
15 #include "content/browser/loader/resource_request_info_impl.h" 16 #include "content/browser/loader/resource_request_info_impl.h"
16 #include "content/common/resource_messages.h" 17 #include "content/common/resource_messages.h"
17 #include "content/public/browser/resource_context.h" 18 #include "content/public/browser/resource_context.h"
18 #include "content/public/browser/resource_controller.h" 19 #include "content/public/browser/resource_controller.h"
19 #include "content/public/browser/resource_throttle.h" 20 #include "content/public/browser/resource_throttle.h"
20 #include "content/public/common/process_type.h" 21 #include "content/public/common/process_type.h"
21 #include "content/public/common/resource_type.h" 22 #include "content/public/common/resource_type.h"
23 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_context.h"
25 #include "content/test/test_web_contents.h"
22 #include "net/base/host_port_pair.h" 26 #include "net/base/host_port_pair.h"
23 #include "net/base/request_priority.h" 27 #include "net/base/request_priority.h"
24 #include "net/http/http_server_properties_impl.h" 28 #include "net/http/http_server_properties_impl.h"
25 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
26 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
27 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/events/latency_info.h"
28 33
29 namespace content { 34 namespace content {
30 35
31 namespace { 36 namespace {
32 37
33 class TestRequestFactory; 38 class TestRequestFactory;
34 39
35 const int kChildId = 30; 40 const int kChildId = 30;
36 const int kRouteId = 75; 41 const int kRouteId = 75;
37 const int kChildId2 = 43; 42 const int kChildId2 = 43;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 : next_request_id_(0), 144 : next_request_id_(0),
140 ui_thread_(BrowserThread::UI, &message_loop_), 145 ui_thread_(BrowserThread::UI, &message_loop_),
141 io_thread_(BrowserThread::IO, &message_loop_), 146 io_thread_(BrowserThread::IO, &message_loop_),
142 mock_timer_(new base::MockTimer(true, true)) { 147 mock_timer_(new base::MockTimer(true, true)) {
143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); 148 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_));
144 149
145 // TODO(aiolos): Remove when throttling and coalescing have both landed. 150 // TODO(aiolos): Remove when throttling and coalescing have both landed.
146 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 151 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
147 false /* should_coalesce */); 152 false /* should_coalesce */);
148 153
149 scheduler_.OnClientCreated(kChildId, kRouteId); 154 scheduler_.OnClientCreated(kChildId, kRouteId, true);
150 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); 155 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
151 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
152 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); 156 context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
153 } 157 }
154 158
155 virtual ~ResourceSchedulerTest() { 159 virtual ~ResourceSchedulerTest() {
156 scheduler_.OnClientDeleted(kChildId, kRouteId); 160 scheduler_.OnClientDeleted(kChildId, kRouteId);
157 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); 161 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
158 } 162 }
159 163
160 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( 164 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute(
161 const char* url, 165 const char* url,
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); 636 ChangeRequestPriority(low2_spdy.get(), net::LOWEST);
633 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); 637 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST));
634 EXPECT_TRUE(low2->started()); 638 EXPECT_TRUE(low2->started());
635 } 639 }
636 640
637 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { 641 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) {
638 // TODO(aiolos): remove when throttling and coalescing have both landed 642 // TODO(aiolos): remove when throttling and coalescing have both landed
639 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 643 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
640 false /* should_coalesce */); 644 false /* should_coalesce */);
641 EXPECT_TRUE(scheduler_.should_throttle()); 645 EXPECT_TRUE(scheduler_.should_throttle());
642 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 646 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
643 647
644 EXPECT_EQ(ResourceScheduler::THROTTLED, 648 EXPECT_EQ(ResourceScheduler::THROTTLED,
645 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 649 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
646 kBackgroundRouteId2)); 650 kBackgroundRouteId2));
647 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 651 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
648 } 652 }
649 653
650 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { 654 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) {
651 // TODO(aiolos): remove when throttling and coalescing have both landed 655 // TODO(aiolos): remove when throttling and coalescing have both landed
652 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 656 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, 1020 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1017 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1021 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1018 kBackgroundRouteId)); 1022 kBackgroundRouteId));
1019 } 1023 }
1020 1024
1021 TEST_F(ResourceSchedulerTest, 1025 TEST_F(ResourceSchedulerTest,
1022 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { 1026 UnloadedClientVisibilityChangedCorrectlyUnthrottles) {
1023 // TODO(aiolos): remove when throttling and coalescing have both landed 1027 // TODO(aiolos): remove when throttling and coalescing have both landed
1024 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1028 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1025 false /* should_coalesce */); 1029 false /* should_coalesce */);
1026 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1030 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1027 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1031 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1028 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1032 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1029 scheduler_.OnLoadingStateChanged( 1033 scheduler_.OnLoadingStateChanged(
1030 kBackgroundChildId2, kBackgroundRouteId2, true); 1034 kBackgroundChildId2, kBackgroundRouteId2, true);
1031 1035
1032 // 1 visible, 3 hidden 1036 // 1 visible, 3 hidden
1033 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1037 EXPECT_FALSE(scheduler_.active_clients_loaded());
1034 EXPECT_EQ(ResourceScheduler::THROTTLED, 1038 EXPECT_EQ(ResourceScheduler::THROTTLED,
1035 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1039 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1036 kBackgroundRouteId)); 1040 kBackgroundRouteId));
1037 EXPECT_EQ(ResourceScheduler::THROTTLED, 1041 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1076
1073 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1077 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1074 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1078 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1075 } 1079 }
1076 1080
1077 TEST_F(ResourceSchedulerTest, 1081 TEST_F(ResourceSchedulerTest,
1078 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { 1082 UnloadedClientAudibilityChangedCorrectlyUnthrottles) {
1079 // TODO(aiolos): remove when throttling and coalescing have both landed 1083 // TODO(aiolos): remove when throttling and coalescing have both landed
1080 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1084 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1081 false /* should_coalesce */); 1085 false /* should_coalesce */);
1082 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1086 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1083 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1087 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1084 scheduler_.OnLoadingStateChanged( 1088 scheduler_.OnLoadingStateChanged(
1085 kBackgroundChildId2, kBackgroundRouteId2, true); 1089 kBackgroundChildId2, kBackgroundRouteId2, true);
1086 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1090 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1087 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1091 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1088 1092
1089 // 1 audible, 3 hidden 1093 // 1 audible, 3 hidden
1090 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1094 EXPECT_FALSE(scheduler_.active_clients_loaded());
1091 EXPECT_EQ(ResourceScheduler::THROTTLED, 1095 EXPECT_EQ(ResourceScheduler::THROTTLED,
1092 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1096 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1093 kBackgroundRouteId)); 1097 kBackgroundRouteId));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1133
1130 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1134 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1131 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1135 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1132 } 1136 }
1133 1137
1134 TEST_F(ResourceSchedulerTest, 1138 TEST_F(ResourceSchedulerTest,
1135 LoadedClientVisibilityChangedCorrectlyUnthrottles) { 1139 LoadedClientVisibilityChangedCorrectlyUnthrottles) {
1136 // TODO(aiolos): remove when throttling and coalescing have both landed 1140 // TODO(aiolos): remove when throttling and coalescing have both landed
1137 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1141 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1138 false /* should_coalesce */); 1142 false /* should_coalesce */);
1139 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1143 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1140 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1144 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1141 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1145 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1142 scheduler_.OnLoadingStateChanged( 1146 scheduler_.OnLoadingStateChanged(
1143 kBackgroundChildId2, kBackgroundRouteId2, true); 1147 kBackgroundChildId2, kBackgroundRouteId2, true);
1144 // 1 visible, 3 hidden 1148 // 1 visible, 3 hidden
1145 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1149 EXPECT_FALSE(scheduler_.active_clients_loaded());
1146 EXPECT_EQ(ResourceScheduler::THROTTLED, 1150 EXPECT_EQ(ResourceScheduler::THROTTLED,
1147 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1151 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1148 kBackgroundRouteId)); 1152 kBackgroundRouteId));
1149 EXPECT_EQ(ResourceScheduler::THROTTLED, 1153 EXPECT_EQ(ResourceScheduler::THROTTLED,
1150 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1154 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 1188
1185 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1189 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1186 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1190 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1187 } 1191 }
1188 1192
1189 TEST_F(ResourceSchedulerTest, 1193 TEST_F(ResourceSchedulerTest,
1190 LoadedClientAudibilityChangedCorrectlyUnthrottles) { 1194 LoadedClientAudibilityChangedCorrectlyUnthrottles) {
1191 // TODO(aiolos): remove when throttling and coalescing have both landed 1195 // TODO(aiolos): remove when throttling and coalescing have both landed
1192 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1196 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1193 false /* should_coalesce */); 1197 false /* should_coalesce */);
1194 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1198 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1195 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1199 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1196 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1200 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1197 scheduler_.OnLoadingStateChanged( 1201 scheduler_.OnLoadingStateChanged(
1198 kBackgroundChildId2, kBackgroundRouteId2, true); 1202 kBackgroundChildId2, kBackgroundRouteId2, true);
1199 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1203 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1200 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1204 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1201 // 1 audible, 3 hidden 1205 // 1 audible, 3 hidden
1202 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1206 EXPECT_FALSE(scheduler_.active_clients_loaded());
1203 EXPECT_EQ(ResourceScheduler::THROTTLED, 1207 EXPECT_EQ(ResourceScheduler::THROTTLED,
1204 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1208 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1205 kBackgroundRouteId)); 1209 kBackgroundRouteId));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1244 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1241 1245
1242 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1246 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1243 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1247 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1244 } 1248 }
1245 1249
1246 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { 1250 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
1247 // TODO(aiolos): remove when throttling and coalescing have both landed 1251 // TODO(aiolos): remove when throttling and coalescing have both landed
1248 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1252 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1249 false /* should_coalesce */); 1253 false /* should_coalesce */);
1250 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1254 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1251 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1255 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1252 scheduler_.OnLoadingStateChanged( 1256 scheduler_.OnLoadingStateChanged(
1253 kBackgroundChildId2, kBackgroundRouteId2, true); 1257 kBackgroundChildId2, kBackgroundRouteId2, true);
1254 1258
1255 // 2 visible, 2 hidden 1259 // 2 visible, 2 hidden
1256 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1257 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1260 EXPECT_FALSE(scheduler_.active_clients_loaded());
1258 EXPECT_EQ(ResourceScheduler::THROTTLED, 1261 EXPECT_EQ(ResourceScheduler::THROTTLED,
1259 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1262 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1260 kBackgroundRouteId)); 1263 kBackgroundRouteId));
1261 EXPECT_EQ(ResourceScheduler::THROTTLED, 1264 EXPECT_EQ(ResourceScheduler::THROTTLED,
1262 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1265 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1263 kBackgroundRouteId2)); 1266 kBackgroundRouteId2));
1264 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, 1267 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1265 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); 1268 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2));
1266 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, 1269 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1312 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1310 1313
1311 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1314 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1312 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1315 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1313 } 1316 }
1314 1317
1315 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { 1318 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) {
1316 // TODO(aiolos): remove when throttling and coalescing have both landed 1319 // TODO(aiolos): remove when throttling and coalescing have both landed
1317 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1320 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1318 false /* should_coalesce */); 1321 false /* should_coalesce */);
1319 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1322 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1320 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1323 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1321 scheduler_.OnLoadingStateChanged( 1324 scheduler_.OnLoadingStateChanged(
1322 kBackgroundChildId2, kBackgroundRouteId2, true); 1325 kBackgroundChildId2, kBackgroundRouteId2, true);
1323 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1326 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1324 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1327 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1325 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); 1328 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
1326 // 2 audible, 2 hidden 1329 // 2 audible, 2 hidden
1327 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1330 EXPECT_FALSE(scheduler_.active_clients_loaded());
1328 EXPECT_EQ(ResourceScheduler::THROTTLED, 1331 EXPECT_EQ(ResourceScheduler::THROTTLED,
1329 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1332 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1330 kBackgroundRouteId)); 1333 kBackgroundRouteId));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1382 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1380 1383
1381 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1384 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1382 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1385 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1383 } 1386 }
1384 1387
1385 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { 1388 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
1386 // TODO(aiolos): remove when throttling and coalescing have both landed 1389 // TODO(aiolos): remove when throttling and coalescing have both landed
1387 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1390 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1388 false /* should_coalesce */); 1391 false /* should_coalesce */);
1389 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1392 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1390 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1393 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1391 scheduler_.OnLoadingStateChanged( 1394 scheduler_.OnLoadingStateChanged(
1392 kBackgroundChildId2, kBackgroundRouteId2, true); 1395 kBackgroundChildId2, kBackgroundRouteId2, true);
1393 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1396 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1394 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1395 // 2 visible, 2 hidden 1397 // 2 visible, 2 hidden
1396 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1398 EXPECT_FALSE(scheduler_.active_clients_loaded());
1397 EXPECT_EQ(ResourceScheduler::THROTTLED, 1399 EXPECT_EQ(ResourceScheduler::THROTTLED,
1398 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1400 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1399 kBackgroundRouteId)); 1401 kBackgroundRouteId));
1400 EXPECT_EQ(ResourceScheduler::THROTTLED, 1402 EXPECT_EQ(ResourceScheduler::THROTTLED,
1401 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1403 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1402 kBackgroundRouteId2)); 1404 kBackgroundRouteId2));
1403 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, 1405 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1404 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); 1406 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1450 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1449 1451
1450 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1452 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1451 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1453 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1452 } 1454 }
1453 1455
1454 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { 1456 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) {
1455 // TODO(aiolos): remove when throttling and coalescing have both landed 1457 // TODO(aiolos): remove when throttling and coalescing have both landed
1456 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1458 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1457 false /* should_coalesce */); 1459 false /* should_coalesce */);
1458 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1460 scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
1459 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1461 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1460 scheduler_.OnLoadingStateChanged( 1462 scheduler_.OnLoadingStateChanged(
1461 kBackgroundChildId2, kBackgroundRouteId2, true); 1463 kBackgroundChildId2, kBackgroundRouteId2, true);
1462 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1464 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1463 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); 1465 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
1464 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); 1466 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
1465 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); 1467 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
1466 // 2 audible, 2 hidden 1468 // 2 audible, 2 hidden
1467 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1469 EXPECT_FALSE(scheduler_.active_clients_loaded());
1468 EXPECT_EQ(ResourceScheduler::THROTTLED, 1470 EXPECT_EQ(ResourceScheduler::THROTTLED,
1469 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1471 scheduler_.GetClientStateForTesting(kBackgroundChildId,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1521 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1520 1522
1521 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1523 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1522 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1524 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1523 } 1525 }
1524 1526
1525 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { 1527 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) {
1526 // TODO(aiolos): remove when throttling and coalescing have both landed 1528 // TODO(aiolos): remove when throttling and coalescing have both landed
1527 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1529 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1528 false /* should_coalesce */); 1530 false /* should_coalesce */);
1529 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1531 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1530 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1532 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1531 1533
1532 // 1 visible and 2 hidden loading, 1 visible loaded 1534 // 1 visible and 2 hidden loading, 1 visible loaded
1533 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1534 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1535 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1535 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1536 EXPECT_FALSE(scheduler_.active_clients_loaded());
1536 EXPECT_EQ(ResourceScheduler::THROTTLED, 1537 EXPECT_EQ(ResourceScheduler::THROTTLED,
1537 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1538 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1538 kBackgroundRouteId)); 1539 kBackgroundRouteId));
1539 EXPECT_EQ(ResourceScheduler::THROTTLED, 1540 EXPECT_EQ(ResourceScheduler::THROTTLED,
1540 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1541 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1541 kBackgroundRouteId2)); 1542 kBackgroundRouteId2));
1542 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, 1543 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
1543 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); 1544 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1591 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1591 1592
1592 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1593 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1593 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1594 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1594 } 1595 }
1595 1596
1596 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { 1597 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) {
1597 // TODO(aiolos): remove when throttling and coalescing have both landed 1598 // TODO(aiolos): remove when throttling and coalescing have both landed
1598 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1599 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1599 false /* should_coalesce */); 1600 false /* should_coalesce */);
1600 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1601 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1601 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1602 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1602 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1603 1603
1604 // 2 visible loading, 1 hidden loading, 1 hidden loaded 1604 // 2 visible loading, 1 hidden loading, 1 hidden loaded
1605 scheduler_.OnLoadingStateChanged( 1605 scheduler_.OnLoadingStateChanged(
1606 kBackgroundChildId2, kBackgroundRouteId2, true); 1606 kBackgroundChildId2, kBackgroundRouteId2, true);
1607 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1607 EXPECT_FALSE(scheduler_.active_clients_loaded());
1608 EXPECT_EQ(ResourceScheduler::THROTTLED, 1608 EXPECT_EQ(ResourceScheduler::THROTTLED,
1609 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1609 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1610 kBackgroundRouteId)); 1610 kBackgroundRouteId));
1611 EXPECT_EQ(ResourceScheduler::THROTTLED, 1611 EXPECT_EQ(ResourceScheduler::THROTTLED,
1612 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1612 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); 1645 scheduler_.GetClientStateForTesting(kChildId, kRouteId));
1646 1646
1647 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1647 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1648 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1648 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1649 } 1649 }
1650 1650
1651 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { 1651 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) {
1652 // TODO(aiolos): remove when throttling and coalescing have both landed 1652 // TODO(aiolos): remove when throttling and coalescing have both landed
1653 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1653 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1654 false /* should_coalesce */); 1654 false /* should_coalesce */);
1655 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1655 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1656 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1656 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1657 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1658 1657
1659 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading 1658 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
1660 scheduler_.OnLoadingStateChanged( 1659 scheduler_.OnLoadingStateChanged(
1661 kBackgroundChildId2, kBackgroundRouteId2, true); 1660 kBackgroundChildId2, kBackgroundRouteId2, true);
1662 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); 1661 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
1663 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1662 EXPECT_FALSE(scheduler_.active_clients_loaded());
1664 EXPECT_EQ(ResourceScheduler::THROTTLED, 1663 EXPECT_EQ(ResourceScheduler::THROTTLED,
1665 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1664 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1666 kBackgroundRouteId)); 1665 kBackgroundRouteId));
1667 EXPECT_EQ(ResourceScheduler::THROTTLED, 1666 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 1711
1713 scheduler_.OnClientDeleted(kChildId2, kRouteId2); 1712 scheduler_.OnClientDeleted(kChildId2, kRouteId2);
1714 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1713 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1715 } 1714 }
1716 1715
1717 TEST_F(ResourceSchedulerTest, 1716 TEST_F(ResourceSchedulerTest,
1718 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { 1717 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) {
1719 // TODO(aiolos): remove when throttling and coalescing have both landed 1718 // TODO(aiolos): remove when throttling and coalescing have both landed
1720 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1719 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1721 false /* should_coalesce */); 1720 false /* should_coalesce */);
1722 scheduler_.OnClientCreated(kChildId2, kRouteId2); 1721 scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
1723 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1722 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1724 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
1725 1723
1726 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading 1724 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
1727 scheduler_.OnLoadingStateChanged( 1725 scheduler_.OnLoadingStateChanged(
1728 kBackgroundChildId2, kBackgroundRouteId2, true); 1726 kBackgroundChildId2, kBackgroundRouteId2, true);
1729 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1727 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1730 EXPECT_FALSE(scheduler_.active_clients_loaded()); 1728 EXPECT_FALSE(scheduler_.active_clients_loaded());
1731 EXPECT_EQ(ResourceScheduler::THROTTLED, 1729 EXPECT_EQ(ResourceScheduler::THROTTLED,
1732 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1730 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1733 kBackgroundRouteId)); 1731 kBackgroundRouteId));
1734 EXPECT_EQ(ResourceScheduler::THROTTLED, 1732 EXPECT_EQ(ResourceScheduler::THROTTLED,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); 1848 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
1851 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, 1849 EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
1852 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1850 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1853 kBackgroundRouteId)); 1851 kBackgroundRouteId));
1854 EXPECT_FALSE(mock_timer_->IsRunning()); 1852 EXPECT_FALSE(mock_timer_->IsRunning());
1855 } 1853 }
1856 1854
1857 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { 1855 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
1858 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1856 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1859 true /* should_coalesce */); 1857 true /* should_coalesce */);
1860 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1858 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1861 EXPECT_FALSE(mock_timer_->IsRunning()); 1859 EXPECT_FALSE(mock_timer_->IsRunning());
1862 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1860 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1863 EXPECT_FALSE(mock_timer_->IsRunning()); 1861 EXPECT_FALSE(mock_timer_->IsRunning());
1864 scheduler_.OnLoadingStateChanged( 1862 scheduler_.OnLoadingStateChanged(
1865 kBackgroundChildId, kBackgroundRouteId, true); 1863 kBackgroundChildId, kBackgroundRouteId, true);
1866 EXPECT_EQ(ResourceScheduler::COALESCED, 1864 EXPECT_EQ(ResourceScheduler::COALESCED,
1867 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1865 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1868 kBackgroundRouteId)); 1866 kBackgroundRouteId));
1869 scheduler_.OnLoadingStateChanged( 1867 scheduler_.OnLoadingStateChanged(
1870 kBackgroundChildId2, kBackgroundRouteId2, true); 1868 kBackgroundChildId2, kBackgroundRouteId2, true);
1871 EXPECT_EQ(ResourceScheduler::COALESCED, 1869 EXPECT_EQ(ResourceScheduler::COALESCED,
1872 scheduler_.GetClientStateForTesting(kBackgroundChildId2, 1870 scheduler_.GetClientStateForTesting(kBackgroundChildId2,
1873 kBackgroundRouteId2)); 1871 kBackgroundRouteId2));
1874 EXPECT_TRUE(mock_timer_->IsRunning()); 1872 EXPECT_TRUE(mock_timer_->IsRunning());
1875 1873
1876 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); 1874 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
1877 EXPECT_TRUE(mock_timer_->IsRunning()); 1875 EXPECT_TRUE(mock_timer_->IsRunning());
1878 1876
1879 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1877 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1880 EXPECT_FALSE(mock_timer_->IsRunning()); 1878 EXPECT_FALSE(mock_timer_->IsRunning());
1881 1879
1882 // To avoid errors on test tear down. 1880 // To avoid errors on test tear down.
1883 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); 1881 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
1884 } 1882 }
1885 1883
1886 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { 1884 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
1887 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1885 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1888 true /* should_coalesce */); 1886 true /* should_coalesce */);
1889 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1887 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1890 EXPECT_FALSE(mock_timer_->IsRunning()); 1888 EXPECT_FALSE(mock_timer_->IsRunning());
1891 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1889 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1892 EXPECT_FALSE(mock_timer_->IsRunning()); 1890 EXPECT_FALSE(mock_timer_->IsRunning());
1893 scheduler_.OnLoadingStateChanged( 1891 scheduler_.OnLoadingStateChanged(
1894 kBackgroundChildId, kBackgroundRouteId, true); 1892 kBackgroundChildId, kBackgroundRouteId, true);
1895 EXPECT_EQ(ResourceScheduler::COALESCED, 1893 EXPECT_EQ(ResourceScheduler::COALESCED,
1896 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1894 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1897 kBackgroundRouteId)); 1895 kBackgroundRouteId));
1898 scheduler_.OnLoadingStateChanged( 1896 scheduler_.OnLoadingStateChanged(
1899 kBackgroundChildId2, kBackgroundRouteId2, true); 1897 kBackgroundChildId2, kBackgroundRouteId2, true);
(...skipping 10 matching lines...) Expand all
1910 kBackgroundChildId2, kBackgroundRouteId2, false); 1908 kBackgroundChildId2, kBackgroundRouteId2, false);
1911 EXPECT_FALSE(mock_timer_->IsRunning()); 1909 EXPECT_FALSE(mock_timer_->IsRunning());
1912 1910
1913 // This is needed to avoid errors on test tear down. 1911 // This is needed to avoid errors on test tear down.
1914 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); 1912 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
1915 } 1913 }
1916 1914
1917 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { 1915 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
1918 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, 1916 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
1919 true /* should_coalesce */); 1917 true /* should_coalesce */);
1920 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); 1918 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
1921 EXPECT_FALSE(mock_timer_->IsRunning()); 1919 EXPECT_FALSE(mock_timer_->IsRunning());
1922 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); 1920 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
1923 EXPECT_FALSE(mock_timer_->IsRunning()); 1921 EXPECT_FALSE(mock_timer_->IsRunning());
1924 scheduler_.OnLoadingStateChanged( 1922 scheduler_.OnLoadingStateChanged(
1925 kBackgroundChildId, kBackgroundRouteId, true); 1923 kBackgroundChildId, kBackgroundRouteId, true);
1926 EXPECT_EQ(ResourceScheduler::COALESCED, 1924 EXPECT_EQ(ResourceScheduler::COALESCED,
1927 scheduler_.GetClientStateForTesting(kBackgroundChildId, 1925 scheduler_.GetClientStateForTesting(kBackgroundChildId,
1928 kBackgroundRouteId)); 1926 kBackgroundRouteId));
1929 scheduler_.OnLoadingStateChanged( 1927 scheduler_.OnLoadingStateChanged(
1930 kBackgroundChildId2, kBackgroundRouteId2, true); 1928 kBackgroundChildId2, kBackgroundRouteId2, true);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 EXPECT_FALSE(high2->started()); 2089 EXPECT_FALSE(high2->started());
2092 EXPECT_FALSE(low->started()); 2090 EXPECT_FALSE(low->started());
2093 2091
2094 FireCoalescingTimer(); 2092 FireCoalescingTimer();
2095 2093
2096 EXPECT_TRUE(high->started()); 2094 EXPECT_TRUE(high->started());
2097 EXPECT_TRUE(high2->started()); 2095 EXPECT_TRUE(high2->started());
2098 EXPECT_TRUE(low->started()); 2096 EXPECT_TRUE(low->started());
2099 } 2097 }
2100 2098
2099 TEST_F(ResourceSchedulerTest, GetVisualSignalFromRenderViewHost) {
2100 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory;
2101 scoped_ptr<TestBrowserContext> browser_context;
2102 scoped_ptr<TestWebContents> web_contents_1;
2103 scoped_ptr<TestWebContents> web_contents_2;
2104
2105 render_process_host_factory.reset(new MockRenderProcessHostFactory());
2106 browser_context.reset(new TestBrowserContext());
2107 scoped_refptr<SiteInstance> site_instance_1 =
2108 SiteInstance::Create(browser_context.get());
2109 scoped_refptr<SiteInstance> site_instance_2 =
2110 SiteInstance::Create(browser_context.get());
2111 SiteInstanceImpl::set_render_process_host_factory(
2112 render_process_host_factory.get());
2113
2114 web_contents_1.reset(
2115 TestWebContents::Create(browser_context.get(), site_instance_1.get()));
2116 web_contents_2.reset(
2117 TestWebContents::Create(browser_context.get(), site_instance_2.get()));
2118 base::RunLoop().RunUntilIdle();
2119
2120 RenderViewHostImpl* rvh1 = web_contents_1->GetRenderViewHost();
2121 RenderViewHostImpl* rvh2 = web_contents_2->GetRenderViewHost();
2122 ResourceScheduler* scheduler = ResourceDispatcherHostImpl::Get()->scheduler();
2123
2124 // Check initial visibility is set correctly.
2125 EXPECT_EQ(scheduler->IsClientVisibleForTesting(rvh1->GetProcess()->GetID(),
2126 rvh1->GetRoutingID()),
2127 !rvh1->is_hidden());
2128 EXPECT_EQ(scheduler->IsClientVisibleForTesting(rvh2->GetProcess()->GetID(),
2129 rvh1->GetRoutingID()),
2130 !rvh2->is_hidden());
2131
2132 // 1 visible, 1 hidden
2133 rvh1->WasShown(ui::LatencyInfo());
2134 rvh2->WasHidden();
2135 base::RunLoop().RunUntilIdle();
2136
2137 EXPECT_TRUE(scheduler->IsClientVisibleForTesting(rvh1->GetProcess()->GetID(),
2138 rvh1->GetRoutingID()));
2139 EXPECT_FALSE(scheduler->IsClientVisibleForTesting(rvh2->GetProcess()->GetID(),
2140 rvh2->GetRoutingID()));
2141
2142 // Flip the visibility and check again.
2143 rvh1->WasHidden();
2144 rvh2->WasShown(ui::LatencyInfo());
2145 base::RunLoop().RunUntilIdle();
2146
2147 EXPECT_FALSE(scheduler->IsClientVisibleForTesting(rvh1->GetProcess()->GetID(),
2148 rvh1->GetRoutingID()));
2149 EXPECT_TRUE(scheduler->IsClientVisibleForTesting(rvh2->GetProcess()->GetID(),
2150 rvh2->GetRoutingID()));
2151 // Clean up.
2152 web_contents_1.reset();
2153 web_contents_2.reset();
2154 base::RunLoop().RunUntilIdle();
2155
2156 browser_context.reset();
2157 render_process_host_factory.reset();
2158 }
2159
2101 } // unnamed namespace 2160 } // unnamed namespace
2102 2161
2103 } // namespace content 2162 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_scheduler.cc ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698