| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/loader/resource_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
| 6 | 6 |
| 7 #include "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/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 15 #include "content/browser/loader/resource_message_filter.h" | 15 #include "content/browser/loader/resource_message_filter.h" |
| 16 #include "content/browser/loader/resource_request_info_impl.h" | 16 #include "content/browser/loader/resource_request_info_impl.h" |
| 17 #include "content/common/resource_messages.h" | 17 #include "content/common/resource_messages.h" |
| 18 #include "content/public/browser/resource_context.h" | 18 #include "content/public/browser/resource_context.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_throttle.h" | 20 #include "content/public/browser/resource_throttle.h" |
| 21 #include "content/public/common/process_type.h" | 21 #include "content/public/common/process_type.h" |
| 22 #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" | 23 #include "content/public/test/mock_render_process_host.h" |
| 24 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
| 25 #include "content/test/test_render_view_host_factory.h" |
| 25 #include "content/test/test_web_contents.h" | 26 #include "content/test/test_web_contents.h" |
| 26 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
| 27 #include "net/base/request_priority.h" | 28 #include "net/base/request_priority.h" |
| 28 #include "net/http/http_server_properties_impl.h" | 29 #include "net/http/http_server_properties_impl.h" |
| 29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
| 30 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/events/latency_info.h" | 33 #include "ui/events/latency_info.h" |
| 33 | 34 |
| 34 namespace content { | 35 namespace content { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 : next_request_id_(0), | 143 : next_request_id_(0), |
| 143 ui_thread_(BrowserThread::UI, &message_loop_), | 144 ui_thread_(BrowserThread::UI, &message_loop_), |
| 144 io_thread_(BrowserThread::IO, &message_loop_), | 145 io_thread_(BrowserThread::IO, &message_loop_), |
| 145 mock_timer_(new base::MockTimer(true, true)) { | 146 mock_timer_(new base::MockTimer(true, true)) { |
| 146 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); | 147 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); |
| 147 | 148 |
| 148 // TODO(aiolos): Remove when throttling and coalescing have both landed. | 149 // TODO(aiolos): Remove when throttling and coalescing have both landed. |
| 149 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 150 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 150 false /* should_coalesce */); | 151 false /* should_coalesce */); |
| 151 | 152 |
| 152 scheduler_.OnClientCreated(kChildId, kRouteId, true); | 153 scheduler_.OnClientCreated(kChildId, kRouteId, true, false); |
| 153 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false); | 154 scheduler_.OnClientCreated( |
| 155 kBackgroundChildId, kBackgroundRouteId, false, false); |
| 154 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); | 156 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); |
| 155 } | 157 } |
| 156 | 158 |
| 157 virtual ~ResourceSchedulerTest() { | 159 virtual ~ResourceSchedulerTest() { |
| 158 scheduler_.OnClientDeleted(kChildId, kRouteId); | 160 scheduler_.OnClientDeleted(kChildId, kRouteId); |
| 159 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 161 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
| 160 } | 162 } |
| 161 | 163 |
| 162 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( | 164 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( |
| 163 const char* url, | 165 const char* url, |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); | 656 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
| 655 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 657 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
| 656 EXPECT_TRUE(low2->started()); | 658 EXPECT_TRUE(low2->started()); |
| 657 } | 659 } |
| 658 | 660 |
| 659 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { | 661 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { |
| 660 // TODO(aiolos): remove when throttling and coalescing have both landed | 662 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 661 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 663 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 662 false /* should_coalesce */); | 664 false /* should_coalesce */); |
| 663 EXPECT_TRUE(scheduler_.should_throttle()); | 665 EXPECT_TRUE(scheduler_.should_throttle()); |
| 664 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 666 scheduler_.OnClientCreated( |
| 667 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 665 | 668 |
| 666 EXPECT_EQ(ResourceScheduler::THROTTLED, | 669 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 667 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 670 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 668 kBackgroundRouteId2)); | 671 kBackgroundRouteId2)); |
| 669 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 672 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 670 } | 673 } |
| 671 | 674 |
| 672 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { | 675 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { |
| 673 // TODO(aiolos): remove when throttling and coalescing have both landed | 676 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 674 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 677 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1041 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1039 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1042 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1040 kBackgroundRouteId)); | 1043 kBackgroundRouteId)); |
| 1041 } | 1044 } |
| 1042 | 1045 |
| 1043 TEST_F(ResourceSchedulerTest, | 1046 TEST_F(ResourceSchedulerTest, |
| 1044 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { | 1047 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { |
| 1045 // TODO(aiolos): remove when throttling and coalescing have both landed | 1048 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1046 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1049 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1047 false /* should_coalesce */); | 1050 false /* should_coalesce */); |
| 1048 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1051 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false); |
| 1049 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1052 scheduler_.OnClientCreated( |
| 1053 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1050 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1054 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1051 scheduler_.OnLoadingStateChanged( | 1055 scheduler_.OnLoadingStateChanged( |
| 1052 kBackgroundChildId2, kBackgroundRouteId2, true); | 1056 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1053 | 1057 |
| 1054 // 1 visible, 3 hidden | 1058 // 1 visible, 3 hidden |
| 1055 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1059 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1056 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1060 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1057 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1061 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1058 kBackgroundRouteId)); | 1062 kBackgroundRouteId)); |
| 1059 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1063 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 | 1098 |
| 1095 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1099 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1096 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1100 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1097 } | 1101 } |
| 1098 | 1102 |
| 1099 TEST_F(ResourceSchedulerTest, | 1103 TEST_F(ResourceSchedulerTest, |
| 1100 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { | 1104 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { |
| 1101 // TODO(aiolos): remove when throttling and coalescing have both landed | 1105 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1102 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1106 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1103 false /* should_coalesce */); | 1107 false /* should_coalesce */); |
| 1104 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1108 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false); |
| 1105 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1109 scheduler_.OnClientCreated( |
| 1110 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1106 scheduler_.OnLoadingStateChanged( | 1111 scheduler_.OnLoadingStateChanged( |
| 1107 kBackgroundChildId2, kBackgroundRouteId2, true); | 1112 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1108 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1113 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); |
| 1109 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1114 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1110 | 1115 |
| 1111 // 1 audible, 3 hidden | 1116 // 1 audible, 3 hidden |
| 1112 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1117 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1113 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1118 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1114 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1119 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1115 kBackgroundRouteId)); | 1120 kBackgroundRouteId)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 | 1156 |
| 1152 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1157 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1153 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1158 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1154 } | 1159 } |
| 1155 | 1160 |
| 1156 TEST_F(ResourceSchedulerTest, | 1161 TEST_F(ResourceSchedulerTest, |
| 1157 LoadedClientVisibilityChangedCorrectlyUnthrottles) { | 1162 LoadedClientVisibilityChangedCorrectlyUnthrottles) { |
| 1158 // TODO(aiolos): remove when throttling and coalescing have both landed | 1163 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1159 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1164 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1160 false /* should_coalesce */); | 1165 false /* should_coalesce */); |
| 1161 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1166 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false); |
| 1162 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1167 scheduler_.OnClientCreated( |
| 1168 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1163 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1169 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1164 scheduler_.OnLoadingStateChanged( | 1170 scheduler_.OnLoadingStateChanged( |
| 1165 kBackgroundChildId2, kBackgroundRouteId2, true); | 1171 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1166 // 1 visible, 3 hidden | 1172 // 1 visible, 3 hidden |
| 1167 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1173 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1168 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1174 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1169 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1175 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1170 kBackgroundRouteId)); | 1176 kBackgroundRouteId)); |
| 1171 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1177 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1172 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1178 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 | 1212 |
| 1207 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1213 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1208 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1214 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1209 } | 1215 } |
| 1210 | 1216 |
| 1211 TEST_F(ResourceSchedulerTest, | 1217 TEST_F(ResourceSchedulerTest, |
| 1212 LoadedClientAudibilityChangedCorrectlyUnthrottles) { | 1218 LoadedClientAudibilityChangedCorrectlyUnthrottles) { |
| 1213 // TODO(aiolos): remove when throttling and coalescing have both landed | 1219 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1214 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1220 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1215 false /* should_coalesce */); | 1221 false /* should_coalesce */); |
| 1216 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1222 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false); |
| 1217 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1223 scheduler_.OnClientCreated( |
| 1224 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1218 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1225 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1219 scheduler_.OnLoadingStateChanged( | 1226 scheduler_.OnLoadingStateChanged( |
| 1220 kBackgroundChildId2, kBackgroundRouteId2, true); | 1227 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1221 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1228 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); |
| 1222 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1229 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1223 // 1 audible, 3 hidden | 1230 // 1 audible, 3 hidden |
| 1224 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1231 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1225 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1232 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1226 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1233 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1227 kBackgroundRouteId)); | 1234 kBackgroundRouteId)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1269 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1263 | 1270 |
| 1264 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1271 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1265 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1272 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1266 } | 1273 } |
| 1267 | 1274 |
| 1268 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { | 1275 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { |
| 1269 // TODO(aiolos): remove when throttling and coalescing have both landed | 1276 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1270 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1277 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1271 false /* should_coalesce */); | 1278 false /* should_coalesce */); |
| 1272 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1279 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1273 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1280 scheduler_.OnClientCreated( |
| 1281 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1274 scheduler_.OnLoadingStateChanged( | 1282 scheduler_.OnLoadingStateChanged( |
| 1275 kBackgroundChildId2, kBackgroundRouteId2, true); | 1283 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1276 | 1284 |
| 1277 // 2 visible, 2 hidden | 1285 // 2 visible, 2 hidden |
| 1278 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1286 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1279 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1287 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1280 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1288 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1281 kBackgroundRouteId)); | 1289 kBackgroundRouteId)); |
| 1282 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1290 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1283 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1291 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1338 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1331 | 1339 |
| 1332 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1340 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1333 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1341 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1334 } | 1342 } |
| 1335 | 1343 |
| 1336 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { | 1344 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { |
| 1337 // TODO(aiolos): remove when throttling and coalescing have both landed | 1345 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1338 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1346 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1339 false /* should_coalesce */); | 1347 false /* should_coalesce */); |
| 1340 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1348 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true); |
| 1341 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1349 scheduler_.OnClientCreated( |
| 1350 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1342 scheduler_.OnLoadingStateChanged( | 1351 scheduler_.OnLoadingStateChanged( |
| 1343 kBackgroundChildId2, kBackgroundRouteId2, true); | 1352 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1344 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1353 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1345 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1354 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); |
| 1346 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | |
| 1347 // 2 audible, 2 hidden | 1355 // 2 audible, 2 hidden |
| 1348 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1356 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1349 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1357 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1350 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1358 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1351 kBackgroundRouteId)); | 1359 kBackgroundRouteId)); |
| 1352 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1360 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1353 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1361 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1354 kBackgroundRouteId2)); | 1362 kBackgroundRouteId2)); |
| 1355 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1363 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1356 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1364 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1408 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1401 | 1409 |
| 1402 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1410 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1403 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1411 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1404 } | 1412 } |
| 1405 | 1413 |
| 1406 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { | 1414 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { |
| 1407 // TODO(aiolos): remove when throttling and coalescing have both landed | 1415 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1408 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1416 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1409 false /* should_coalesce */); | 1417 false /* should_coalesce */); |
| 1410 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1418 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1411 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1419 scheduler_.OnClientCreated( |
| 1420 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1412 scheduler_.OnLoadingStateChanged( | 1421 scheduler_.OnLoadingStateChanged( |
| 1413 kBackgroundChildId2, kBackgroundRouteId2, true); | 1422 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1414 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1423 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1415 // 2 visible, 2 hidden | 1424 // 2 visible, 2 hidden |
| 1416 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1425 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1417 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1426 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1418 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1427 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1419 kBackgroundRouteId)); | 1428 kBackgroundRouteId)); |
| 1420 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1429 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1421 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1430 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1477 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1469 | 1478 |
| 1470 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1479 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1471 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1480 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1472 } | 1481 } |
| 1473 | 1482 |
| 1474 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { | 1483 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { |
| 1475 // TODO(aiolos): remove when throttling and coalescing have both landed | 1484 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1476 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1485 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1477 false /* should_coalesce */); | 1486 false /* should_coalesce */); |
| 1478 scheduler_.OnClientCreated(kChildId2, kRouteId2, false); | 1487 scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true); |
| 1479 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1488 scheduler_.OnClientCreated( |
| 1489 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1480 scheduler_.OnLoadingStateChanged( | 1490 scheduler_.OnLoadingStateChanged( |
| 1481 kBackgroundChildId2, kBackgroundRouteId2, true); | 1491 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1482 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1492 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1483 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1493 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); |
| 1484 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1494 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1485 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | |
| 1486 // 2 audible, 2 hidden | 1495 // 2 audible, 2 hidden |
| 1487 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1496 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1488 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1497 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1489 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1498 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1490 kBackgroundRouteId)); | 1499 kBackgroundRouteId)); |
| 1491 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1500 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1492 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1501 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1493 kBackgroundRouteId2)); | 1502 kBackgroundRouteId2)); |
| 1494 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1503 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1495 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1504 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1548 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1540 | 1549 |
| 1541 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1550 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1542 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1551 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1543 } | 1552 } |
| 1544 | 1553 |
| 1545 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { | 1554 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { |
| 1546 // TODO(aiolos): remove when throttling and coalescing have both landed | 1555 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1547 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1556 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1548 false /* should_coalesce */); | 1557 false /* should_coalesce */); |
| 1549 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1558 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1550 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1559 scheduler_.OnClientCreated( |
| 1560 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1551 | 1561 |
| 1552 // 1 visible and 2 hidden loading, 1 visible loaded | 1562 // 1 visible and 2 hidden loading, 1 visible loaded |
| 1553 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1563 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1554 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1564 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1555 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1565 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1556 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1566 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1557 kBackgroundRouteId)); | 1567 kBackgroundRouteId)); |
| 1558 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1568 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1559 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1569 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1560 kBackgroundRouteId2)); | 1570 kBackgroundRouteId2)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1619 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1610 | 1620 |
| 1611 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1621 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1612 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1622 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1613 } | 1623 } |
| 1614 | 1624 |
| 1615 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { | 1625 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { |
| 1616 // TODO(aiolos): remove when throttling and coalescing have both landed | 1626 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1617 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1627 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1618 false /* should_coalesce */); | 1628 false /* should_coalesce */); |
| 1619 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1629 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1620 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1630 scheduler_.OnClientCreated( |
| 1631 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1621 | 1632 |
| 1622 // 2 visible loading, 1 hidden loading, 1 hidden loaded | 1633 // 2 visible loading, 1 hidden loading, 1 hidden loaded |
| 1623 scheduler_.OnLoadingStateChanged( | 1634 scheduler_.OnLoadingStateChanged( |
| 1624 kBackgroundChildId2, kBackgroundRouteId2, true); | 1635 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1625 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1636 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1626 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1637 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1627 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1638 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1628 kBackgroundRouteId)); | 1639 kBackgroundRouteId)); |
| 1629 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1640 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1630 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1641 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1674 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1664 | 1675 |
| 1665 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1676 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1666 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1677 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1667 } | 1678 } |
| 1668 | 1679 |
| 1669 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { | 1680 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { |
| 1670 // TODO(aiolos): remove when throttling and coalescing have both landed | 1681 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1671 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1682 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1672 false /* should_coalesce */); | 1683 false /* should_coalesce */); |
| 1673 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1684 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1674 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1685 scheduler_.OnClientCreated( |
| 1686 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1675 | 1687 |
| 1676 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1688 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
| 1677 scheduler_.OnLoadingStateChanged( | 1689 scheduler_.OnLoadingStateChanged( |
| 1678 kBackgroundChildId2, kBackgroundRouteId2, true); | 1690 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1679 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1691 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1680 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1692 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1681 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1693 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1682 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1694 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1683 kBackgroundRouteId)); | 1695 kBackgroundRouteId)); |
| 1684 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1696 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 | 1741 |
| 1730 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1742 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1731 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1743 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1732 } | 1744 } |
| 1733 | 1745 |
| 1734 TEST_F(ResourceSchedulerTest, | 1746 TEST_F(ResourceSchedulerTest, |
| 1735 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { | 1747 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { |
| 1736 // TODO(aiolos): remove when throttling and coalescing have both landed | 1748 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1737 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1749 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1738 false /* should_coalesce */); | 1750 false /* should_coalesce */); |
| 1739 scheduler_.OnClientCreated(kChildId2, kRouteId2, true); | 1751 scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false); |
| 1740 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1752 scheduler_.OnClientCreated( |
| 1753 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1741 | 1754 |
| 1742 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1755 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
| 1743 scheduler_.OnLoadingStateChanged( | 1756 scheduler_.OnLoadingStateChanged( |
| 1744 kBackgroundChildId2, kBackgroundRouteId2, true); | 1757 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1745 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1758 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1746 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1759 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1747 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1760 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1748 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1761 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1749 kBackgroundRouteId)); | 1762 kBackgroundRouteId)); |
| 1750 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1763 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 1879 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); |
| 1867 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1880 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1868 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1881 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1869 kBackgroundRouteId)); | 1882 kBackgroundRouteId)); |
| 1870 EXPECT_FALSE(mock_timer_->IsRunning()); | 1883 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1871 } | 1884 } |
| 1872 | 1885 |
| 1873 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { | 1886 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { |
| 1874 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1887 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1875 true /* should_coalesce */); | 1888 true /* should_coalesce */); |
| 1876 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1889 scheduler_.OnClientCreated( |
| 1890 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1877 EXPECT_FALSE(mock_timer_->IsRunning()); | 1891 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1878 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1892 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1879 EXPECT_FALSE(mock_timer_->IsRunning()); | 1893 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1880 scheduler_.OnLoadingStateChanged( | 1894 scheduler_.OnLoadingStateChanged( |
| 1881 kBackgroundChildId, kBackgroundRouteId, true); | 1895 kBackgroundChildId, kBackgroundRouteId, true); |
| 1882 EXPECT_EQ(ResourceScheduler::COALESCED, | 1896 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1883 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1897 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1884 kBackgroundRouteId)); | 1898 kBackgroundRouteId)); |
| 1885 scheduler_.OnLoadingStateChanged( | 1899 scheduler_.OnLoadingStateChanged( |
| 1886 kBackgroundChildId2, kBackgroundRouteId2, true); | 1900 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1887 EXPECT_EQ(ResourceScheduler::COALESCED, | 1901 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1888 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1902 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1889 kBackgroundRouteId2)); | 1903 kBackgroundRouteId2)); |
| 1890 EXPECT_TRUE(mock_timer_->IsRunning()); | 1904 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1891 | 1905 |
| 1892 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 1906 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
| 1893 EXPECT_TRUE(mock_timer_->IsRunning()); | 1907 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1894 | 1908 |
| 1895 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1909 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1896 EXPECT_FALSE(mock_timer_->IsRunning()); | 1910 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1897 | 1911 |
| 1898 // To avoid errors on test tear down. | 1912 // To avoid errors on test tear down. |
| 1899 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false); | 1913 scheduler_.OnClientCreated( |
| 1914 kBackgroundChildId, kBackgroundRouteId, false, false); |
| 1900 } | 1915 } |
| 1901 | 1916 |
| 1902 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { | 1917 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { |
| 1903 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1918 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1904 true /* should_coalesce */); | 1919 true /* should_coalesce */); |
| 1905 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1920 scheduler_.OnClientCreated( |
| 1921 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1906 EXPECT_FALSE(mock_timer_->IsRunning()); | 1922 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1907 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1923 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1908 EXPECT_FALSE(mock_timer_->IsRunning()); | 1924 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1909 scheduler_.OnLoadingStateChanged( | 1925 scheduler_.OnLoadingStateChanged( |
| 1910 kBackgroundChildId, kBackgroundRouteId, true); | 1926 kBackgroundChildId, kBackgroundRouteId, true); |
| 1911 EXPECT_EQ(ResourceScheduler::COALESCED, | 1927 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1912 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1928 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1913 kBackgroundRouteId)); | 1929 kBackgroundRouteId)); |
| 1914 scheduler_.OnLoadingStateChanged( | 1930 scheduler_.OnLoadingStateChanged( |
| 1915 kBackgroundChildId2, kBackgroundRouteId2, true); | 1931 kBackgroundChildId2, kBackgroundRouteId2, true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1926 kBackgroundChildId2, kBackgroundRouteId2, false); | 1942 kBackgroundChildId2, kBackgroundRouteId2, false); |
| 1927 EXPECT_FALSE(mock_timer_->IsRunning()); | 1943 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1928 | 1944 |
| 1929 // This is needed to avoid errors on test tear down. | 1945 // This is needed to avoid errors on test tear down. |
| 1930 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1946 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1931 } | 1947 } |
| 1932 | 1948 |
| 1933 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { | 1949 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { |
| 1934 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1950 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1935 true /* should_coalesce */); | 1951 true /* should_coalesce */); |
| 1936 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false); | 1952 scheduler_.OnClientCreated( |
| 1953 kBackgroundChildId2, kBackgroundRouteId2, false, false); |
| 1937 EXPECT_FALSE(mock_timer_->IsRunning()); | 1954 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1938 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1955 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1939 EXPECT_FALSE(mock_timer_->IsRunning()); | 1956 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1940 scheduler_.OnLoadingStateChanged( | 1957 scheduler_.OnLoadingStateChanged( |
| 1941 kBackgroundChildId, kBackgroundRouteId, true); | 1958 kBackgroundChildId, kBackgroundRouteId, true); |
| 1942 EXPECT_EQ(ResourceScheduler::COALESCED, | 1959 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1943 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1960 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1944 kBackgroundRouteId)); | 1961 kBackgroundRouteId)); |
| 1945 scheduler_.OnLoadingStateChanged( | 1962 scheduler_.OnLoadingStateChanged( |
| 1946 kBackgroundChildId2, kBackgroundRouteId2, true); | 1963 kBackgroundChildId2, kBackgroundRouteId2, true); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2109 | 2126 |
| 2110 FireCoalescingTimer(); | 2127 FireCoalescingTimer(); |
| 2111 | 2128 |
| 2112 EXPECT_TRUE(high->started()); | 2129 EXPECT_TRUE(high->started()); |
| 2113 EXPECT_TRUE(high2->started()); | 2130 EXPECT_TRUE(high2->started()); |
| 2114 EXPECT_TRUE(low->started()); | 2131 EXPECT_TRUE(low->started()); |
| 2115 } | 2132 } |
| 2116 | 2133 |
| 2117 TEST_F(ResourceSchedulerTest, GetVisualSignalFromRenderViewHost) { | 2134 TEST_F(ResourceSchedulerTest, GetVisualSignalFromRenderViewHost) { |
| 2118 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory; | 2135 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory; |
| 2136 scoped_ptr<TestRenderViewHostFactory> render_view_host_factory; |
| 2119 scoped_ptr<TestBrowserContext> browser_context; | 2137 scoped_ptr<TestBrowserContext> browser_context; |
| 2120 scoped_ptr<TestWebContents> web_contents_1; | 2138 scoped_ptr<TestWebContents> web_contents_1; |
| 2121 scoped_ptr<TestWebContents> web_contents_2; | 2139 scoped_ptr<TestWebContents> web_contents_2; |
| 2140 render_process_host_factory.reset(new MockRenderProcessHostFactory()); |
| 2141 render_view_host_factory.reset( |
| 2142 new TestRenderViewHostFactory(render_process_host_factory.get())); |
| 2122 | 2143 |
| 2123 render_process_host_factory.reset(new MockRenderProcessHostFactory()); | |
| 2124 browser_context.reset(new TestBrowserContext()); | 2144 browser_context.reset(new TestBrowserContext()); |
| 2125 scoped_refptr<SiteInstance> site_instance_1 = | 2145 scoped_refptr<SiteInstance> site_instance_1 = |
| 2126 SiteInstance::Create(browser_context.get()); | 2146 SiteInstance::Create(browser_context.get()); |
| 2127 scoped_refptr<SiteInstance> site_instance_2 = | 2147 scoped_refptr<SiteInstance> site_instance_2 = |
| 2128 SiteInstance::Create(browser_context.get()); | 2148 SiteInstance::Create(browser_context.get()); |
| 2129 SiteInstanceImpl::set_render_process_host_factory( | 2149 SiteInstanceImpl::set_render_process_host_factory( |
| 2130 render_process_host_factory.get()); | 2150 render_process_host_factory.get()); |
| 2131 | 2151 |
| 2132 web_contents_1.reset( | 2152 web_contents_1.reset( |
| 2133 TestWebContents::Create(browser_context.get(), site_instance_1.get())); | 2153 TestWebContents::Create(browser_context.get(), site_instance_1.get())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 web_contents_2.reset(); | 2191 web_contents_2.reset(); |
| 2172 base::RunLoop().RunUntilIdle(); | 2192 base::RunLoop().RunUntilIdle(); |
| 2173 | 2193 |
| 2174 browser_context.reset(); | 2194 browser_context.reset(); |
| 2175 render_process_host_factory.reset(); | 2195 render_process_host_factory.reset(); |
| 2176 } | 2196 } |
| 2177 | 2197 |
| 2178 } // unnamed namespace | 2198 } // unnamed namespace |
| 2179 | 2199 |
| 2180 } // namespace content | 2200 } // namespace content |
| OLD | NEW |