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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/timer/mock_timer.h" | 10 #include "base/timer/mock_timer.h" |
11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
12 #include "content/browser/browser_thread_impl.h" | 12 #include "content/browser/browser_thread_impl.h" |
13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
14 #include "content/browser/loader/resource_message_filter.h" | 14 #include "content/browser/loader/resource_message_filter.h" |
15 #include "content/browser/loader/resource_request_info_impl.h" | 15 #include "content/browser/loader/resource_request_info_impl.h" |
16 #include "content/common/resource_messages.h" | 16 #include "content/common/resource_messages.h" |
17 #include "content/public/browser/resource_context.h" | 17 #include "content/public/browser/resource_context.h" |
18 #include "content/public/browser/resource_controller.h" | 18 #include "content/public/browser/resource_controller.h" |
19 #include "content/public/browser/resource_throttle.h" | 19 #include "content/public/browser/resource_throttle.h" |
20 #include "content/public/common/process_type.h" | 20 #include "content/public/common/process_type.h" |
21 #include "content/public/common/resource_type.h" | 21 #include "content/public/common/resource_type.h" |
| 22 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/test_browser_context.h" |
| 24 #include "content/test/test_web_contents.h" |
22 #include "net/base/host_port_pair.h" | 25 #include "net/base/host_port_pair.h" |
23 #include "net/base/request_priority.h" | 26 #include "net/base/request_priority.h" |
24 #include "net/http/http_server_properties_impl.h" | 27 #include "net/http/http_server_properties_impl.h" |
25 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
28 | 31 |
29 namespace content { | 32 namespace content { |
30 | 33 |
31 namespace { | 34 namespace { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 FakeResourceContext context_; | 136 FakeResourceContext context_; |
134 }; | 137 }; |
135 | 138 |
136 class ResourceSchedulerTest : public testing::Test { | 139 class ResourceSchedulerTest : public testing::Test { |
137 protected: | 140 protected: |
138 ResourceSchedulerTest() | 141 ResourceSchedulerTest() |
139 : next_request_id_(0), | 142 : next_request_id_(0), |
140 ui_thread_(BrowserThread::UI, &message_loop_), | 143 ui_thread_(BrowserThread::UI, &message_loop_), |
141 io_thread_(BrowserThread::IO, &message_loop_), | 144 io_thread_(BrowserThread::IO, &message_loop_), |
142 mock_timer_(new base::MockTimer(true, true)) { | 145 mock_timer_(new base::MockTimer(true, true)) { |
| 146 // Set up web contents. |
| 147 render_process_host_factory_.reset(new MockRenderProcessHostFactory()); |
| 148 browser_context_.reset(new TestBrowserContext()); |
| 149 scoped_refptr<SiteInstance> site_instance = |
| 150 SiteInstance::Create(browser_context_.get()); |
| 151 scoped_refptr<SiteInstance> site_instance_background = |
| 152 SiteInstance::Create(browser_context_.get()); |
| 153 scoped_refptr<SiteInstance> site_instance_2 = |
| 154 SiteInstance::Create(browser_context_.get()); |
| 155 scoped_refptr<SiteInstance> site_instance_background_2 = |
| 156 SiteInstance::Create(browser_context_.get()); |
| 157 SiteInstanceImpl::set_render_process_host_factory( |
| 158 render_process_host_factory_.get()); |
| 159 |
| 160 web_contents_.reset( |
| 161 TestWebContents::Create(browser_context_.get(), site_instance.get())); |
| 162 web_contents_background_.reset( |
| 163 TestWebContents::Create(browser_context_.get(), |
| 164 site_instance_background.get())); |
| 165 web_contents_2_.reset( |
| 166 TestWebContents::Create(browser_context_.get(), site_instance_2.get())); |
| 167 web_contents_background_2_.reset( |
| 168 TestWebContents::Create(browser_context_.get(), |
| 169 site_instance_background_2.get())); |
| 170 |
| 171 // set up resource scheduler |
143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); | 172 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); |
144 | 173 |
145 // TODO(aiolos): Remove when throttling and coalescing have both landed. | 174 // TODO(aiolos): Remove when throttling and coalescing have both landed. |
146 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 175 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
147 false /* should_coalesce */); | 176 false /* should_coalesce */); |
148 | 177 |
149 scheduler_.OnClientCreated(kChildId, kRouteId); | 178 scheduler_.OnClientCreated(kChildId, kRouteId, web_contents_.get()); |
150 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 179 scheduler_.OnClientCreated(kBackgroundChildId, |
151 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); | 180 kBackgroundRouteId, |
| 181 web_contents_background_.get()); |
| 182 |
| 183 // Set up initial visibility. |
| 184 web_contents_->WasShown(); |
| 185 web_contents_background_->WasHidden(); |
| 186 web_contents_2_->WasHidden(); |
| 187 web_contents_background_2_->WasHidden(); |
| 188 |
152 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); | 189 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); |
153 } | 190 } |
154 | 191 |
155 virtual ~ResourceSchedulerTest() { | 192 virtual ~ResourceSchedulerTest() { |
156 scheduler_.OnClientDeleted(kChildId, kRouteId); | 193 scheduler_.OnClientDeleted(kChildId, kRouteId); |
157 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 194 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
| 195 |
| 196 web_contents_.reset(); |
| 197 web_contents_background_.reset(); |
| 198 web_contents_2_.reset(); |
| 199 web_contents_background_2_.reset(); |
| 200 browser_context_.reset(); |
| 201 render_process_host_factory_.reset(); |
158 } | 202 } |
159 | 203 |
160 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( | 204 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( |
161 const char* url, | 205 const char* url, |
162 net::RequestPriority priority, | 206 net::RequestPriority priority, |
163 int child_id, | 207 int child_id, |
164 int route_id, | 208 int route_id, |
165 bool is_async) { | 209 bool is_async) { |
166 scoped_ptr<net::URLRequest> url_request( | 210 scoped_ptr<net::URLRequest> url_request( |
167 context_.CreateRequest(GURL(url), priority, NULL, NULL)); | 211 context_.CreateRequest(GURL(url), priority, NULL, NULL)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 316 |
273 int next_request_id_; | 317 int next_request_id_; |
274 base::MessageLoopForIO message_loop_; | 318 base::MessageLoopForIO message_loop_; |
275 BrowserThreadImpl ui_thread_; | 319 BrowserThreadImpl ui_thread_; |
276 BrowserThreadImpl io_thread_; | 320 BrowserThreadImpl io_thread_; |
277 ResourceDispatcherHostImpl rdh_; | 321 ResourceDispatcherHostImpl rdh_; |
278 ResourceScheduler scheduler_; | 322 ResourceScheduler scheduler_; |
279 base::MockTimer* mock_timer_; | 323 base::MockTimer* mock_timer_; |
280 net::HttpServerPropertiesImpl http_server_properties_; | 324 net::HttpServerPropertiesImpl http_server_properties_; |
281 net::TestURLRequestContext context_; | 325 net::TestURLRequestContext context_; |
| 326 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory_; |
| 327 scoped_ptr<TestBrowserContext> browser_context_; |
| 328 scoped_ptr<TestWebContents> web_contents_; |
| 329 scoped_ptr<TestWebContents> web_contents_background_; |
| 330 scoped_ptr<TestWebContents> web_contents_2_; |
| 331 scoped_ptr<TestWebContents> web_contents_background_2_; |
282 }; | 332 }; |
283 | 333 |
284 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { | 334 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { |
285 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); | 335 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); |
286 EXPECT_TRUE(request->started()); | 336 EXPECT_TRUE(request->started()); |
287 } | 337 } |
288 | 338 |
289 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { | 339 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { |
290 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 340 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
291 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 341 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); | 681 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
632 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 682 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
633 EXPECT_TRUE(low2->started()); | 683 EXPECT_TRUE(low2->started()); |
634 } | 684 } |
635 | 685 |
636 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { | 686 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { |
637 // TODO(aiolos): remove when throttling and coalescing have both landed | 687 // TODO(aiolos): remove when throttling and coalescing have both landed |
638 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 688 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
639 false /* should_coalesce */); | 689 false /* should_coalesce */); |
640 EXPECT_TRUE(scheduler_.should_throttle()); | 690 EXPECT_TRUE(scheduler_.should_throttle()); |
641 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 691 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 692 kBackgroundRouteId2, |
| 693 web_contents_background_2_.get()); |
642 | 694 |
643 EXPECT_EQ(ResourceScheduler::THROTTLED, | 695 EXPECT_EQ(ResourceScheduler::THROTTLED, |
644 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 696 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
645 kBackgroundRouteId2)); | 697 kBackgroundRouteId2)); |
646 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 698 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
647 } | 699 } |
648 | 700 |
649 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { | 701 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { |
650 // TODO(aiolos): remove when throttling and coalescing have both landed | 702 // TODO(aiolos): remove when throttling and coalescing have both landed |
651 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 703 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 false /* should_coalesce */); | 770 false /* should_coalesce */); |
719 EXPECT_EQ(ResourceScheduler::THROTTLED, | 771 EXPECT_EQ(ResourceScheduler::THROTTLED, |
720 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 772 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
721 kBackgroundRouteId)); | 773 kBackgroundRouteId)); |
722 scoped_ptr<TestRequest> high( | 774 scoped_ptr<TestRequest> high( |
723 NewBackgroundRequest("http://host/high", net::HIGHEST)); | 775 NewBackgroundRequest("http://host/high", net::HIGHEST)); |
724 scoped_ptr<TestRequest> request( | 776 scoped_ptr<TestRequest> request( |
725 NewBackgroundRequest("http://host/req", net::IDLE)); | 777 NewBackgroundRequest("http://host/req", net::IDLE)); |
726 EXPECT_FALSE(request->started()); | 778 EXPECT_FALSE(request->started()); |
727 | 779 |
728 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 780 web_contents_background_->WasShown(); |
729 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 781 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
730 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 782 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
731 kBackgroundRouteId)); | 783 kBackgroundRouteId)); |
732 EXPECT_TRUE(request->started()); | 784 EXPECT_TRUE(request->started()); |
733 } | 785 } |
734 | 786 |
735 TEST_F(ResourceSchedulerTest, UnthrottleNewlyAudibleClient) { | 787 TEST_F(ResourceSchedulerTest, UnthrottleNewlyAudibleClient) { |
736 // TODO(aiolos): remove when throttling and coalescing have both landed | 788 // TODO(aiolos): remove when throttling and coalescing have both landed |
737 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 789 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
738 false /* should_coalesce */); | 790 false /* should_coalesce */); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 826 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
775 EXPECT_EQ(ResourceScheduler::THROTTLED, | 827 EXPECT_EQ(ResourceScheduler::THROTTLED, |
776 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 828 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
777 kBackgroundRouteId)); | 829 kBackgroundRouteId)); |
778 } | 830 } |
779 | 831 |
780 TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) { | 832 TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) { |
781 // TODO(aiolos): remove when throttling and coalescing have both landed | 833 // TODO(aiolos): remove when throttling and coalescing have both landed |
782 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 834 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
783 false /* should_coalesce */); | 835 false /* should_coalesce */); |
784 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 836 web_contents_->WasHidden(); |
785 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 837 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
786 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 838 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
787 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 839 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
788 EXPECT_EQ(ResourceScheduler::THROTTLED, | 840 EXPECT_EQ(ResourceScheduler::THROTTLED, |
789 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 841 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
790 kBackgroundRouteId)); | 842 kBackgroundRouteId)); |
791 | 843 |
792 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 844 web_contents_->WasShown(); |
793 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 845 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
794 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 846 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
795 EXPECT_EQ(ResourceScheduler::THROTTLED, | 847 EXPECT_EQ(ResourceScheduler::THROTTLED, |
796 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 848 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
797 kBackgroundRouteId)); | 849 kBackgroundRouteId)); |
798 | 850 |
799 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 851 web_contents_->WasHidden(); |
800 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 852 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
801 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 853 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
802 EXPECT_EQ(ResourceScheduler::THROTTLED, | 854 EXPECT_EQ(ResourceScheduler::THROTTLED, |
803 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 855 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
804 kBackgroundRouteId)); | 856 kBackgroundRouteId)); |
805 } | 857 } |
806 | 858 |
807 TEST_F(ResourceSchedulerTest, ThrottledClientStartsNextHighestPriorityRequest) { | 859 TEST_F(ResourceSchedulerTest, ThrottledClientStartsNextHighestPriorityRequest) { |
808 // TODO(aiolos): remove when throttling and coalescing have both landed | 860 // TODO(aiolos): remove when throttling and coalescing have both landed |
809 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 861 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 // TODO(aiolos): remove when throttling and coalescing have both landed | 1030 // TODO(aiolos): remove when throttling and coalescing have both landed |
979 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1031 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
980 false /* should_coalesce */); | 1032 false /* should_coalesce */); |
981 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1033 EXPECT_EQ(ResourceScheduler::THROTTLED, |
982 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1034 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
983 kBackgroundRouteId)); | 1035 kBackgroundRouteId)); |
984 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1036 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
985 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1037 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
986 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1038 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
987 | 1039 |
988 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1040 web_contents_->WasHidden(); |
989 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1041 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
990 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1042 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
991 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1043 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
992 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1044 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
993 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1045 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
994 kBackgroundRouteId)); | 1046 kBackgroundRouteId)); |
995 | 1047 |
996 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1048 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
997 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1049 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
998 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1050 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
(...skipping 16 matching lines...) Expand all Loading... |
1015 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1067 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1016 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1068 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1017 kBackgroundRouteId)); | 1069 kBackgroundRouteId)); |
1018 } | 1070 } |
1019 | 1071 |
1020 TEST_F(ResourceSchedulerTest, | 1072 TEST_F(ResourceSchedulerTest, |
1021 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { | 1073 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { |
1022 // TODO(aiolos): remove when throttling and coalescing have both landed | 1074 // TODO(aiolos): remove when throttling and coalescing have both landed |
1023 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1075 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1024 false /* should_coalesce */); | 1076 false /* should_coalesce */); |
1025 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1077 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1026 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1078 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1079 kBackgroundRouteId2, |
| 1080 web_contents_background_2_.get()); |
1027 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1081 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1028 scheduler_.OnLoadingStateChanged( | 1082 scheduler_.OnLoadingStateChanged( |
1029 kBackgroundChildId2, kBackgroundRouteId2, true); | 1083 kBackgroundChildId2, kBackgroundRouteId2, true); |
1030 | 1084 |
1031 // 1 visible, 3 hidden | 1085 // 1 visible, 3 hidden |
1032 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1086 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1033 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1087 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1034 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1088 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1035 kBackgroundRouteId)); | 1089 kBackgroundRouteId)); |
1036 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1090 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1037 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1091 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1038 kBackgroundRouteId2)); | 1092 kBackgroundRouteId2)); |
1039 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1093 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1040 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1094 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1041 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1095 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1042 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1096 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1043 | 1097 |
1044 // 2 visible, 2 hidden | 1098 // 2 visible, 2 hidden |
1045 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1099 web_contents_2_->WasShown(); |
1046 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1100 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1047 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1101 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1048 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1102 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1049 kBackgroundRouteId)); | 1103 kBackgroundRouteId)); |
1050 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1104 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1051 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1105 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1052 kBackgroundRouteId2)); | 1106 kBackgroundRouteId2)); |
1053 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1107 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1054 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1108 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1055 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1109 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1056 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1110 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1057 | 1111 |
1058 // 1 visible, 3 hidden | 1112 // 1 visible, 3 hidden |
1059 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1113 web_contents_2_->WasHidden(); |
1060 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1114 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1061 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1115 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1062 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1116 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1063 kBackgroundRouteId)); | 1117 kBackgroundRouteId)); |
1064 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1118 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1065 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1119 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1066 kBackgroundRouteId2)); | 1120 kBackgroundRouteId2)); |
1067 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1121 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1068 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1122 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1069 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1123 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1070 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1124 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1071 | 1125 |
1072 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1126 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1073 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1127 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1074 } | 1128 } |
1075 | 1129 |
1076 TEST_F(ResourceSchedulerTest, | 1130 TEST_F(ResourceSchedulerTest, |
1077 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { | 1131 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { |
1078 // TODO(aiolos): remove when throttling and coalescing have both landed | 1132 // TODO(aiolos): remove when throttling and coalescing have both landed |
1079 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1133 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1080 false /* should_coalesce */); | 1134 false /* should_coalesce */); |
1081 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1135 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1082 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1136 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1137 kBackgroundRouteId2, |
| 1138 web_contents_background_2_.get()); |
1083 scheduler_.OnLoadingStateChanged( | 1139 scheduler_.OnLoadingStateChanged( |
1084 kBackgroundChildId2, kBackgroundRouteId2, true); | 1140 kBackgroundChildId2, kBackgroundRouteId2, true); |
1085 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1141 web_contents_->WasHidden(); |
1086 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1142 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
1087 | 1143 |
1088 // 1 audible, 3 hidden | 1144 // 1 audible, 3 hidden |
1089 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1145 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1090 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1146 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1091 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1147 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1092 kBackgroundRouteId)); | 1148 kBackgroundRouteId)); |
1093 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1149 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1094 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1150 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1095 kBackgroundRouteId2)); | 1151 kBackgroundRouteId2)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 | 1184 |
1129 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1185 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1130 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1186 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1131 } | 1187 } |
1132 | 1188 |
1133 TEST_F(ResourceSchedulerTest, | 1189 TEST_F(ResourceSchedulerTest, |
1134 LoadedClientVisibilityChangedCorrectlyUnthrottles) { | 1190 LoadedClientVisibilityChangedCorrectlyUnthrottles) { |
1135 // TODO(aiolos): remove when throttling and coalescing have both landed | 1191 // TODO(aiolos): remove when throttling and coalescing have both landed |
1136 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1192 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1137 false /* should_coalesce */); | 1193 false /* should_coalesce */); |
1138 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1194 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1139 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1195 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1196 kBackgroundRouteId2, |
| 1197 web_contents_background_2_.get()); |
1140 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1198 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1141 scheduler_.OnLoadingStateChanged( | 1199 scheduler_.OnLoadingStateChanged( |
1142 kBackgroundChildId2, kBackgroundRouteId2, true); | 1200 kBackgroundChildId2, kBackgroundRouteId2, true); |
1143 // 1 visible, 3 hidden | 1201 // 1 visible, 3 hidden |
1144 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1202 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1145 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1203 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1146 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1204 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1147 kBackgroundRouteId)); | 1205 kBackgroundRouteId)); |
1148 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1206 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1149 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1207 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1150 kBackgroundRouteId2)); | 1208 kBackgroundRouteId2)); |
1151 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1209 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1152 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1210 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1153 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1211 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1154 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1212 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1155 | 1213 |
1156 // 2 visible, 2 hidden | 1214 // 2 visible, 2 hidden |
1157 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1215 web_contents_2_->WasShown(); |
1158 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1216 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1159 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1217 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1160 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1218 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1161 kBackgroundRouteId)); | 1219 kBackgroundRouteId)); |
1162 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1220 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1163 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1221 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1164 kBackgroundRouteId2)); | 1222 kBackgroundRouteId2)); |
1165 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1223 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1166 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1224 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1167 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1225 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1168 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1226 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1169 | 1227 |
1170 // 1 visible, 3 hidden | 1228 // 1 visible, 3 hidden |
1171 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1229 web_contents_2_->WasHidden(); |
1172 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1230 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1173 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1231 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1174 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1232 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1175 kBackgroundRouteId)); | 1233 kBackgroundRouteId)); |
1176 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1234 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1177 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1235 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1178 kBackgroundRouteId2)); | 1236 kBackgroundRouteId2)); |
1179 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1237 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1180 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1238 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1181 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1239 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1182 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1240 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1183 | 1241 |
1184 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1242 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1185 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1243 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1186 } | 1244 } |
1187 | 1245 |
1188 TEST_F(ResourceSchedulerTest, | 1246 TEST_F(ResourceSchedulerTest, |
1189 LoadedClientAudibilityChangedCorrectlyUnthrottles) { | 1247 LoadedClientAudibilityChangedCorrectlyUnthrottles) { |
1190 // TODO(aiolos): remove when throttling and coalescing have both landed | 1248 // TODO(aiolos): remove when throttling and coalescing have both landed |
1191 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1249 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1192 false /* should_coalesce */); | 1250 false /* should_coalesce */); |
1193 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1251 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1194 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1252 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1253 kBackgroundRouteId2, |
| 1254 web_contents_background_2_.get()); |
1195 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1255 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1196 scheduler_.OnLoadingStateChanged( | 1256 scheduler_.OnLoadingStateChanged( |
1197 kBackgroundChildId2, kBackgroundRouteId2, true); | 1257 kBackgroundChildId2, kBackgroundRouteId2, true); |
1198 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1258 web_contents_->WasHidden(); |
1199 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1259 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
1200 // 1 audible, 3 hidden | 1260 // 1 audible, 3 hidden |
1201 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1261 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1202 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1262 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1203 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1263 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1204 kBackgroundRouteId)); | 1264 kBackgroundRouteId)); |
1205 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1265 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1206 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1266 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1207 kBackgroundRouteId2)); | 1267 kBackgroundRouteId2)); |
1208 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1268 EXPECT_EQ(ResourceScheduler::THROTTLED, |
(...skipping 30 matching lines...) Expand all Loading... |
1239 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1299 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1240 | 1300 |
1241 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1301 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1242 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1302 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1243 } | 1303 } |
1244 | 1304 |
1245 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { | 1305 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { |
1246 // TODO(aiolos): remove when throttling and coalescing have both landed | 1306 // TODO(aiolos): remove when throttling and coalescing have both landed |
1247 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1307 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1248 false /* should_coalesce */); | 1308 false /* should_coalesce */); |
1249 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1309 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1250 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1310 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1311 kBackgroundRouteId2, |
| 1312 web_contents_background_2_.get()); |
1251 scheduler_.OnLoadingStateChanged( | 1313 scheduler_.OnLoadingStateChanged( |
1252 kBackgroundChildId2, kBackgroundRouteId2, true); | 1314 kBackgroundChildId2, kBackgroundRouteId2, true); |
1253 | 1315 |
1254 // 2 visible, 2 hidden | 1316 // 2 visible, 2 hidden |
1255 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1317 web_contents_2_->WasShown(); |
1256 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1318 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1257 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1319 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1258 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1320 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1259 kBackgroundRouteId)); | 1321 kBackgroundRouteId)); |
1260 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1322 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1261 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1323 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1262 kBackgroundRouteId2)); | 1324 kBackgroundRouteId2)); |
1263 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1325 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1264 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1326 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1265 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1327 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1266 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1328 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1267 | 1329 |
1268 // 1 visible, 3 hidden | 1330 // 1 visible, 3 hidden |
1269 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1331 web_contents_2_->WasHidden(); |
1270 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1332 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1271 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1333 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1272 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1334 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1273 kBackgroundRouteId)); | 1335 kBackgroundRouteId)); |
1274 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1336 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1275 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1337 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1276 kBackgroundRouteId2)); | 1338 kBackgroundRouteId2)); |
1277 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1339 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1278 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1340 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1279 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1341 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1280 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1342 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1281 | 1343 |
1282 // 0 visible, 4 hidden | 1344 // 0 visible, 4 hidden |
1283 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1345 web_contents_->WasHidden(); |
1284 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1346 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
1285 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1347 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1286 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1348 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1287 kBackgroundRouteId)); | 1349 kBackgroundRouteId)); |
1288 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1350 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1289 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1351 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1290 kBackgroundRouteId2)); | 1352 kBackgroundRouteId2)); |
1291 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1353 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1292 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1354 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1293 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1355 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1294 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1356 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1295 | 1357 |
1296 // 1 visible, 3 hidden | 1358 // 1 visible, 3 hidden |
1297 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 1359 web_contents_->WasShown(); |
1298 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1360 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1299 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1361 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1300 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1362 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1301 kBackgroundRouteId)); | 1363 kBackgroundRouteId)); |
1302 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1364 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1303 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1365 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1304 kBackgroundRouteId2)); | 1366 kBackgroundRouteId2)); |
1305 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1367 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1306 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1368 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1307 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1369 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1308 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1370 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1309 | 1371 |
1310 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1372 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1311 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1373 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1312 } | 1374 } |
1313 | 1375 |
1314 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { | 1376 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { |
1315 // TODO(aiolos): remove when throttling and coalescing have both landed | 1377 // TODO(aiolos): remove when throttling and coalescing have both landed |
1316 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1378 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1317 false /* should_coalesce */); | 1379 false /* should_coalesce */); |
1318 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1380 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1319 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1381 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1382 kBackgroundRouteId2, |
| 1383 web_contents_background_2_.get()); |
1320 scheduler_.OnLoadingStateChanged( | 1384 scheduler_.OnLoadingStateChanged( |
1321 kBackgroundChildId2, kBackgroundRouteId2, true); | 1385 kBackgroundChildId2, kBackgroundRouteId2, true); |
1322 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1386 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
1323 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1387 web_contents_->WasHidden(); |
1324 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | 1388 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); |
1325 // 2 audible, 2 hidden | 1389 // 2 audible, 2 hidden |
1326 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1390 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1327 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1391 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1328 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1392 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1329 kBackgroundRouteId)); | 1393 kBackgroundRouteId)); |
1330 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1394 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1331 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1395 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1332 kBackgroundRouteId2)); | 1396 kBackgroundRouteId2)); |
1333 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1397 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1442 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1379 | 1443 |
1380 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1444 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1381 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1445 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1382 } | 1446 } |
1383 | 1447 |
1384 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { | 1448 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { |
1385 // TODO(aiolos): remove when throttling and coalescing have both landed | 1449 // TODO(aiolos): remove when throttling and coalescing have both landed |
1386 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1450 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1387 false /* should_coalesce */); | 1451 false /* should_coalesce */); |
1388 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1452 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1389 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1453 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1454 kBackgroundRouteId2, |
| 1455 web_contents_background_2_.get()); |
1390 scheduler_.OnLoadingStateChanged( | 1456 scheduler_.OnLoadingStateChanged( |
1391 kBackgroundChildId2, kBackgroundRouteId2, true); | 1457 kBackgroundChildId2, kBackgroundRouteId2, true); |
1392 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1458 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1393 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1459 web_contents_2_->WasShown(); |
1394 // 2 visible, 2 hidden | 1460 // 2 visible, 2 hidden |
1395 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1461 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1396 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1462 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1397 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1463 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1398 kBackgroundRouteId)); | 1464 kBackgroundRouteId)); |
1399 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1465 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1400 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1466 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1401 kBackgroundRouteId2)); | 1467 kBackgroundRouteId2)); |
1402 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1468 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1403 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1469 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1404 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1470 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1405 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1471 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1406 | 1472 |
1407 // 1 visible, 3 hidden | 1473 // 1 visible, 3 hidden |
1408 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1474 web_contents_2_->WasHidden(); |
1409 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1475 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1410 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1476 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1411 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1477 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1412 kBackgroundRouteId)); | 1478 kBackgroundRouteId)); |
1413 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1479 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1414 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1480 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1415 kBackgroundRouteId2)); | 1481 kBackgroundRouteId2)); |
1416 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1482 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1417 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1483 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1418 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1484 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1419 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1485 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1420 | 1486 |
1421 // 0 visible, 4 hidden | 1487 // 0 visible, 4 hidden |
1422 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1488 web_contents_->WasHidden(); |
1423 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1489 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
1424 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1490 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1425 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1491 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1426 kBackgroundRouteId)); | 1492 kBackgroundRouteId)); |
1427 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1493 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1428 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1494 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1429 kBackgroundRouteId2)); | 1495 kBackgroundRouteId2)); |
1430 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1496 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1431 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1497 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1432 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1498 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1433 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1499 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1434 | 1500 |
1435 // 1 visible, 3 hidden | 1501 // 1 visible, 3 hidden |
1436 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1502 web_contents_2_->WasShown(); |
1437 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1503 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
1438 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1504 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1439 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1505 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1440 kBackgroundRouteId)); | 1506 kBackgroundRouteId)); |
1441 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1507 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1442 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1508 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1443 kBackgroundRouteId2)); | 1509 kBackgroundRouteId2)); |
1444 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1510 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1445 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1511 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
1446 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1512 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1447 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1513 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1448 | 1514 |
1449 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1515 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1450 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1516 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1451 } | 1517 } |
1452 | 1518 |
1453 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { | 1519 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { |
1454 // TODO(aiolos): remove when throttling and coalescing have both landed | 1520 // TODO(aiolos): remove when throttling and coalescing have both landed |
1455 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1521 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1456 false /* should_coalesce */); | 1522 false /* should_coalesce */); |
1457 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1523 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1458 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1524 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1525 kBackgroundRouteId2, |
| 1526 web_contents_background_2_.get()); |
1459 scheduler_.OnLoadingStateChanged( | 1527 scheduler_.OnLoadingStateChanged( |
1460 kBackgroundChildId2, kBackgroundRouteId2, true); | 1528 kBackgroundChildId2, kBackgroundRouteId2, true); |
1461 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1529 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1462 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1530 web_contents_->WasHidden(); |
1463 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1531 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
1464 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | 1532 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); |
1465 // 2 audible, 2 hidden | 1533 // 2 audible, 2 hidden |
1466 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1534 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1467 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1535 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1468 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1536 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1469 kBackgroundRouteId)); | 1537 kBackgroundRouteId)); |
1470 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1538 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1471 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1539 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1472 kBackgroundRouteId2)); | 1540 kBackgroundRouteId2)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1586 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1519 | 1587 |
1520 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1588 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1521 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1589 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1522 } | 1590 } |
1523 | 1591 |
1524 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { | 1592 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { |
1525 // TODO(aiolos): remove when throttling and coalescing have both landed | 1593 // TODO(aiolos): remove when throttling and coalescing have both landed |
1526 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1594 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1527 false /* should_coalesce */); | 1595 false /* should_coalesce */); |
1528 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1596 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1529 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1597 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1598 kBackgroundRouteId2, |
| 1599 web_contents_background_2_.get()); |
1530 | 1600 |
1531 // 1 visible and 2 hidden loading, 1 visible loaded | 1601 // 1 visible and 2 hidden loading, 1 visible loaded |
1532 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1602 web_contents_2_->WasShown(); |
1533 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1603 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1534 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1604 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1535 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1605 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1536 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1606 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1537 kBackgroundRouteId)); | 1607 kBackgroundRouteId)); |
1538 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1608 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1539 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1609 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1540 kBackgroundRouteId2)); | 1610 kBackgroundRouteId2)); |
1541 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1611 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1542 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1612 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1659 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1590 | 1660 |
1591 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1661 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1592 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1662 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1593 } | 1663 } |
1594 | 1664 |
1595 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { | 1665 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { |
1596 // TODO(aiolos): remove when throttling and coalescing have both landed | 1666 // TODO(aiolos): remove when throttling and coalescing have both landed |
1597 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1667 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1598 false /* should_coalesce */); | 1668 false /* should_coalesce */); |
1599 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1669 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1600 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1670 scheduler_.OnClientCreated(kBackgroundChildId2, |
1601 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1671 kBackgroundRouteId2, |
| 1672 web_contents_background_2_.get()); |
| 1673 web_contents_2_->WasShown(); |
1602 | 1674 |
1603 // 2 visible loading, 1 hidden loading, 1 hidden loaded | 1675 // 2 visible loading, 1 hidden loading, 1 hidden loaded |
1604 scheduler_.OnLoadingStateChanged( | 1676 scheduler_.OnLoadingStateChanged( |
1605 kBackgroundChildId2, kBackgroundRouteId2, true); | 1677 kBackgroundChildId2, kBackgroundRouteId2, true); |
1606 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1678 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1607 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1679 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1608 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1680 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1609 kBackgroundRouteId)); | 1681 kBackgroundRouteId)); |
1610 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1682 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1611 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1683 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1716 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1645 | 1717 |
1646 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1718 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1647 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1719 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1648 } | 1720 } |
1649 | 1721 |
1650 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { | 1722 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { |
1651 // TODO(aiolos): remove when throttling and coalescing have both landed | 1723 // TODO(aiolos): remove when throttling and coalescing have both landed |
1652 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1724 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1653 false /* should_coalesce */); | 1725 false /* should_coalesce */); |
1654 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1726 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1655 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1727 scheduler_.OnClientCreated(kBackgroundChildId2, |
1656 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1728 kBackgroundRouteId2, |
| 1729 web_contents_background_2_.get()); |
| 1730 web_contents_2_->WasShown(); |
1657 | 1731 |
1658 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1732 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
1659 scheduler_.OnLoadingStateChanged( | 1733 scheduler_.OnLoadingStateChanged( |
1660 kBackgroundChildId2, kBackgroundRouteId2, true); | 1734 kBackgroundChildId2, kBackgroundRouteId2, true); |
1661 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1735 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
1662 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1736 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1663 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1737 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1664 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1738 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1665 kBackgroundRouteId)); | 1739 kBackgroundRouteId)); |
1666 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1740 EXPECT_EQ(ResourceScheduler::THROTTLED, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 | 1785 |
1712 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1786 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
1713 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1787 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1714 } | 1788 } |
1715 | 1789 |
1716 TEST_F(ResourceSchedulerTest, | 1790 TEST_F(ResourceSchedulerTest, |
1717 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { | 1791 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { |
1718 // TODO(aiolos): remove when throttling and coalescing have both landed | 1792 // TODO(aiolos): remove when throttling and coalescing have both landed |
1719 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1793 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1720 false /* should_coalesce */); | 1794 false /* should_coalesce */); |
1721 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1795 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
1722 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1796 scheduler_.OnClientCreated(kBackgroundChildId2, |
1723 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1797 kBackgroundRouteId2, |
| 1798 web_contents_background_2_.get()); |
| 1799 web_contents_2_->WasShown(); |
1724 | 1800 |
1725 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1801 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
1726 scheduler_.OnLoadingStateChanged( | 1802 scheduler_.OnLoadingStateChanged( |
1727 kBackgroundChildId2, kBackgroundRouteId2, true); | 1803 kBackgroundChildId2, kBackgroundRouteId2, true); |
1728 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1804 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1729 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1805 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
1730 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1806 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1731 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1807 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1732 kBackgroundRouteId)); | 1808 kBackgroundRouteId)); |
1733 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1809 EXPECT_EQ(ResourceScheduler::THROTTLED, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 EXPECT_FALSE(mock_timer_->IsRunning()); | 1867 EXPECT_FALSE(mock_timer_->IsRunning()); |
1792 | 1868 |
1793 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1869 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1794 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1870 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1795 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1871 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1796 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1872 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1797 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1873 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1798 kBackgroundRouteId)); | 1874 kBackgroundRouteId)); |
1799 EXPECT_FALSE(mock_timer_->IsRunning()); | 1875 EXPECT_FALSE(mock_timer_->IsRunning()); |
1800 | 1876 |
1801 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1877 web_contents_->WasHidden(); |
1802 EXPECT_EQ(ResourceScheduler::COALESCED, | 1878 EXPECT_EQ(ResourceScheduler::COALESCED, |
1803 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1879 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1804 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1880 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1805 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1881 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1806 kBackgroundRouteId)); | 1882 kBackgroundRouteId)); |
1807 EXPECT_TRUE(mock_timer_->IsRunning()); | 1883 EXPECT_TRUE(mock_timer_->IsRunning()); |
1808 } | 1884 } |
1809 | 1885 |
1810 TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) { | 1886 TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) { |
1811 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1887 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1812 true /* should_coalesce */); | 1888 true /* should_coalesce */); |
1813 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1889 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1814 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1890 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1815 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1891 EXPECT_EQ(ResourceScheduler::THROTTLED, |
1816 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1892 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1817 kBackgroundRouteId)); | 1893 kBackgroundRouteId)); |
1818 EXPECT_FALSE(mock_timer_->IsRunning()); | 1894 EXPECT_FALSE(mock_timer_->IsRunning()); |
1819 | 1895 |
1820 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1896 web_contents_->WasHidden(); |
1821 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1897 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1822 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1898 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
1823 EXPECT_FALSE(mock_timer_->IsRunning()); | 1899 EXPECT_FALSE(mock_timer_->IsRunning()); |
1824 | 1900 |
1825 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1901 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1826 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1902 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1827 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1903 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1828 kBackgroundRouteId)); | 1904 kBackgroundRouteId)); |
1829 EXPECT_EQ(ResourceScheduler::COALESCED, | 1905 EXPECT_EQ(ResourceScheduler::COALESCED, |
1830 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1906 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
(...skipping 18 matching lines...) Expand all Loading... |
1849 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 1925 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); |
1850 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1926 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1851 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1927 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1852 kBackgroundRouteId)); | 1928 kBackgroundRouteId)); |
1853 EXPECT_FALSE(mock_timer_->IsRunning()); | 1929 EXPECT_FALSE(mock_timer_->IsRunning()); |
1854 } | 1930 } |
1855 | 1931 |
1856 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { | 1932 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { |
1857 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1933 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1858 true /* should_coalesce */); | 1934 true /* should_coalesce */); |
1859 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1935 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1936 kBackgroundRouteId2, |
| 1937 web_contents_background_2_.get()); |
1860 EXPECT_FALSE(mock_timer_->IsRunning()); | 1938 EXPECT_FALSE(mock_timer_->IsRunning()); |
1861 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1939 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1862 EXPECT_FALSE(mock_timer_->IsRunning()); | 1940 EXPECT_FALSE(mock_timer_->IsRunning()); |
1863 scheduler_.OnLoadingStateChanged( | 1941 scheduler_.OnLoadingStateChanged( |
1864 kBackgroundChildId, kBackgroundRouteId, true); | 1942 kBackgroundChildId, kBackgroundRouteId, true); |
1865 EXPECT_EQ(ResourceScheduler::COALESCED, | 1943 EXPECT_EQ(ResourceScheduler::COALESCED, |
1866 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1944 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1867 kBackgroundRouteId)); | 1945 kBackgroundRouteId)); |
1868 scheduler_.OnLoadingStateChanged( | 1946 scheduler_.OnLoadingStateChanged( |
1869 kBackgroundChildId2, kBackgroundRouteId2, true); | 1947 kBackgroundChildId2, kBackgroundRouteId2, true); |
1870 EXPECT_EQ(ResourceScheduler::COALESCED, | 1948 EXPECT_EQ(ResourceScheduler::COALESCED, |
1871 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1949 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1872 kBackgroundRouteId2)); | 1950 kBackgroundRouteId2)); |
1873 EXPECT_TRUE(mock_timer_->IsRunning()); | 1951 EXPECT_TRUE(mock_timer_->IsRunning()); |
1874 | 1952 |
1875 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 1953 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
1876 EXPECT_TRUE(mock_timer_->IsRunning()); | 1954 EXPECT_TRUE(mock_timer_->IsRunning()); |
1877 | 1955 |
1878 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1956 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1879 EXPECT_FALSE(mock_timer_->IsRunning()); | 1957 EXPECT_FALSE(mock_timer_->IsRunning()); |
1880 | 1958 |
1881 // To avoid errors on test tear down. | 1959 // To avoid errors on test tear down. |
1882 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); | 1960 scheduler_.OnClientCreated(kBackgroundChildId, |
| 1961 kBackgroundRouteId, |
| 1962 web_contents_background_.get()); |
1883 } | 1963 } |
1884 | 1964 |
1885 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { | 1965 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { |
1886 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1966 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1887 true /* should_coalesce */); | 1967 true /* should_coalesce */); |
1888 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1968 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1969 kBackgroundRouteId2, |
| 1970 web_contents_background_2_.get()); |
1889 EXPECT_FALSE(mock_timer_->IsRunning()); | 1971 EXPECT_FALSE(mock_timer_->IsRunning()); |
1890 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1972 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1891 EXPECT_FALSE(mock_timer_->IsRunning()); | 1973 EXPECT_FALSE(mock_timer_->IsRunning()); |
1892 scheduler_.OnLoadingStateChanged( | 1974 scheduler_.OnLoadingStateChanged( |
1893 kBackgroundChildId, kBackgroundRouteId, true); | 1975 kBackgroundChildId, kBackgroundRouteId, true); |
1894 EXPECT_EQ(ResourceScheduler::COALESCED, | 1976 EXPECT_EQ(ResourceScheduler::COALESCED, |
1895 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1977 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1896 kBackgroundRouteId)); | 1978 kBackgroundRouteId)); |
1897 scheduler_.OnLoadingStateChanged( | 1979 scheduler_.OnLoadingStateChanged( |
1898 kBackgroundChildId2, kBackgroundRouteId2, true); | 1980 kBackgroundChildId2, kBackgroundRouteId2, true); |
(...skipping 10 matching lines...) Expand all Loading... |
1909 kBackgroundChildId2, kBackgroundRouteId2, false); | 1991 kBackgroundChildId2, kBackgroundRouteId2, false); |
1910 EXPECT_FALSE(mock_timer_->IsRunning()); | 1992 EXPECT_FALSE(mock_timer_->IsRunning()); |
1911 | 1993 |
1912 // This is needed to avoid errors on test tear down. | 1994 // This is needed to avoid errors on test tear down. |
1913 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1995 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1914 } | 1996 } |
1915 | 1997 |
1916 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { | 1998 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { |
1917 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1999 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1918 true /* should_coalesce */); | 2000 true /* should_coalesce */); |
1919 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 2001 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2002 kBackgroundRouteId2, |
| 2003 web_contents_background_2_.get()); |
1920 EXPECT_FALSE(mock_timer_->IsRunning()); | 2004 EXPECT_FALSE(mock_timer_->IsRunning()); |
1921 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2005 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1922 EXPECT_FALSE(mock_timer_->IsRunning()); | 2006 EXPECT_FALSE(mock_timer_->IsRunning()); |
1923 scheduler_.OnLoadingStateChanged( | 2007 scheduler_.OnLoadingStateChanged( |
1924 kBackgroundChildId, kBackgroundRouteId, true); | 2008 kBackgroundChildId, kBackgroundRouteId, true); |
1925 EXPECT_EQ(ResourceScheduler::COALESCED, | 2009 EXPECT_EQ(ResourceScheduler::COALESCED, |
1926 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2010 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1927 kBackgroundRouteId)); | 2011 kBackgroundRouteId)); |
1928 scheduler_.OnLoadingStateChanged( | 2012 scheduler_.OnLoadingStateChanged( |
1929 kBackgroundChildId2, kBackgroundRouteId2, true); | 2013 kBackgroundChildId2, kBackgroundRouteId2, true); |
1930 EXPECT_EQ(ResourceScheduler::COALESCED, | 2014 EXPECT_EQ(ResourceScheduler::COALESCED, |
1931 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 2015 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
1932 kBackgroundRouteId2)); | 2016 kBackgroundRouteId2)); |
1933 EXPECT_TRUE(mock_timer_->IsRunning()); | 2017 EXPECT_TRUE(mock_timer_->IsRunning()); |
1934 | 2018 |
1935 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 2019 web_contents_background_->WasShown(); |
1936 EXPECT_TRUE(mock_timer_->IsRunning()); | 2020 EXPECT_TRUE(mock_timer_->IsRunning()); |
1937 | 2021 |
1938 scheduler_.OnVisibilityChanged( | 2022 web_contents_background_2_->WasShown(); |
1939 kBackgroundChildId2, kBackgroundRouteId2, true); | |
1940 EXPECT_FALSE(mock_timer_->IsRunning()); | 2023 EXPECT_FALSE(mock_timer_->IsRunning()); |
1941 | 2024 |
1942 // To avoid errors on test tear down. | 2025 // To avoid errors on test tear down. |
1943 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 2026 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
1944 } | 2027 } |
1945 | 2028 |
1946 TEST_F(ResourceSchedulerTest, | 2029 TEST_F(ResourceSchedulerTest, |
1947 CoalescedClientBecomesLoadingAndVisibleStopsTimer) { | 2030 CoalescedClientBecomesLoadingAndVisibleStopsTimer) { |
1948 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2031 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1949 true /* should_coalesce */); | 2032 true /* should_coalesce */); |
1950 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2033 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
1951 EXPECT_FALSE(mock_timer_->IsRunning()); | 2034 EXPECT_FALSE(mock_timer_->IsRunning()); |
1952 scheduler_.OnLoadingStateChanged( | 2035 scheduler_.OnLoadingStateChanged( |
1953 kBackgroundChildId, kBackgroundRouteId, true); | 2036 kBackgroundChildId, kBackgroundRouteId, true); |
1954 EXPECT_EQ(ResourceScheduler::COALESCED, | 2037 EXPECT_EQ(ResourceScheduler::COALESCED, |
1955 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2038 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1956 kBackgroundRouteId)); | 2039 kBackgroundRouteId)); |
1957 EXPECT_TRUE(mock_timer_->IsRunning()); | 2040 EXPECT_TRUE(mock_timer_->IsRunning()); |
1958 | 2041 |
1959 scheduler_.OnLoadingStateChanged( | 2042 scheduler_.OnLoadingStateChanged( |
1960 kBackgroundChildId, kBackgroundRouteId, false); | 2043 kBackgroundChildId, kBackgroundRouteId, false); |
1961 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 2044 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
1962 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2045 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1963 kBackgroundRouteId)); | 2046 kBackgroundRouteId)); |
1964 EXPECT_FALSE(mock_timer_->IsRunning()); | 2047 EXPECT_FALSE(mock_timer_->IsRunning()); |
1965 | 2048 |
1966 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 2049 web_contents_background_->WasShown(); |
1967 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 2050 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
1968 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2051 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
1969 kBackgroundRouteId)); | 2052 kBackgroundRouteId)); |
1970 EXPECT_FALSE(mock_timer_->IsRunning()); | 2053 EXPECT_FALSE(mock_timer_->IsRunning()); |
1971 } | 2054 } |
1972 | 2055 |
1973 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) { | 2056 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) { |
1974 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2057 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
1975 true /* should_coalesce */); | 2058 true /* should_coalesce */); |
1976 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2059 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2090 EXPECT_FALSE(high2->started()); | 2173 EXPECT_FALSE(high2->started()); |
2091 EXPECT_FALSE(low->started()); | 2174 EXPECT_FALSE(low->started()); |
2092 | 2175 |
2093 FireCoalescingTimer(); | 2176 FireCoalescingTimer(); |
2094 | 2177 |
2095 EXPECT_TRUE(high->started()); | 2178 EXPECT_TRUE(high->started()); |
2096 EXPECT_TRUE(high2->started()); | 2179 EXPECT_TRUE(high2->started()); |
2097 EXPECT_TRUE(low->started()); | 2180 EXPECT_TRUE(low->started()); |
2098 } | 2181 } |
2099 | 2182 |
| 2183 TEST_F(ResourceSchedulerTest, CheckInitialVisibility) { |
| 2184 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
| 2185 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2186 kBackgroundRouteId2, |
| 2187 web_contents_background_2_.get()); |
| 2188 web_contents_2_->WasShown(); |
| 2189 |
| 2190 EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2)); |
| 2191 EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2, |
| 2192 kBackgroundRouteId2)); |
| 2193 |
| 2194 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 2195 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2196 } |
| 2197 |
| 2198 TEST_F(ResourceSchedulerTest, GetVisualSignalFromWebContents) { |
| 2199 scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get()); |
| 2200 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2201 kBackgroundRouteId2, |
| 2202 web_contents_background_2_.get()); |
| 2203 web_contents_2_->WasShown(); |
| 2204 |
| 2205 // Change visibility of web contents. |
| 2206 web_contents_2_->WasHidden(); |
| 2207 web_contents_background_2_->WasShown(); |
| 2208 |
| 2209 // The clients get the visual signal from web contents. |
| 2210 EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2)); |
| 2211 EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2, |
| 2212 kBackgroundRouteId2)); |
| 2213 |
| 2214 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 2215 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2216 } |
| 2217 |
2100 } // unnamed namespace | 2218 } // unnamed namespace |
2101 | 2219 |
2102 } // namespace content | 2220 } // namespace content |
OLD | NEW |