| 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 14 #include "content/browser/loader/resource_message_filter.h" | 15 #include "content/browser/loader/resource_message_filter.h" |
| 15 #include "content/browser/loader/resource_request_info_impl.h" | 16 #include "content/browser/loader/resource_request_info_impl.h" |
| 16 #include "content/common/resource_messages.h" | 17 #include "content/common/resource_messages.h" |
| 17 #include "content/public/browser/resource_context.h" | 18 #include "content/public/browser/resource_context.h" |
| 18 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_throttle.h" | 20 #include "content/public/browser/resource_throttle.h" |
| 20 #include "content/public/common/process_type.h" | 21 #include "content/public/common/process_type.h" |
| 21 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
| 23 #include "content/public/test/mock_render_process_host.h" |
| 24 #include "content/public/test/test_browser_context.h" |
| 25 #include "content/test/test_web_contents.h" |
| 22 #include "net/base/host_port_pair.h" | 26 #include "net/base/host_port_pair.h" |
| 23 #include "net/base/request_priority.h" | 27 #include "net/base/request_priority.h" |
| 24 #include "net/http/http_server_properties_impl.h" | 28 #include "net/http/http_server_properties_impl.h" |
| 25 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 26 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 32 |
| 29 namespace content { | 33 namespace content { |
| 30 | 34 |
| 31 namespace { | 35 namespace { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 FakeResourceContext context_; | 137 FakeResourceContext context_; |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 class ResourceSchedulerTest : public testing::Test { | 140 class ResourceSchedulerTest : public testing::Test { |
| 137 protected: | 141 protected: |
| 138 ResourceSchedulerTest() | 142 ResourceSchedulerTest() |
| 139 : next_request_id_(0), | 143 : next_request_id_(0), |
| 140 ui_thread_(BrowserThread::UI, &message_loop_), | 144 ui_thread_(BrowserThread::UI, &message_loop_), |
| 141 io_thread_(BrowserThread::IO, &message_loop_), | 145 io_thread_(BrowserThread::IO, &message_loop_), |
| 142 mock_timer_(new base::MockTimer(true, true)) { | 146 mock_timer_(new base::MockTimer(true, true)) { |
| 147 // Set up web contents. |
| 148 render_process_host_factory_.reset(new MockRenderProcessHostFactory()); |
| 149 browser_context_.reset(new TestBrowserContext()); |
| 150 scoped_refptr<SiteInstance> site_instance = |
| 151 SiteInstance::Create(browser_context_.get()); |
| 152 scoped_refptr<SiteInstance> site_instance_background = |
| 153 SiteInstance::Create(browser_context_.get()); |
| 154 scoped_refptr<SiteInstance> site_instance_2 = |
| 155 SiteInstance::Create(browser_context_.get()); |
| 156 scoped_refptr<SiteInstance> site_instance_background_2 = |
| 157 SiteInstance::Create(browser_context_.get()); |
| 158 SiteInstanceImpl::set_render_process_host_factory( |
| 159 render_process_host_factory_.get()); |
| 160 |
| 161 web_contents_.reset( |
| 162 TestWebContents::Create(browser_context_.get(), site_instance.get())); |
| 163 web_contents_background_.reset( |
| 164 TestWebContents::Create(browser_context_.get(), |
| 165 site_instance_background.get())); |
| 166 web_contents_2_.reset( |
| 167 TestWebContents::Create(browser_context_.get(), site_instance_2.get())); |
| 168 web_contents_background_2_.reset( |
| 169 TestWebContents::Create(browser_context_.get(), |
| 170 site_instance_background_2.get())); |
| 171 base::RunLoop().RunUntilIdle(); |
| 172 |
| 173 visual_observer_ = scheduler_.CreateVisualObserver(web_contents_.get()); |
| 174 visual_observer_background_ = |
| 175 scheduler_.CreateVisualObserver(web_contents_background_.get()); |
| 176 visual_observer_2_ = scheduler_.CreateVisualObserver(web_contents_2_.get()); |
| 177 visual_observer_background_2_ = |
| 178 scheduler_.CreateVisualObserver(web_contents_background_2_.get()); |
| 179 |
| 180 // set up resource scheduler |
| 143 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); | 181 scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_)); |
| 144 | 182 |
| 145 // TODO(aiolos): Remove when throttling and coalescing have both landed. | 183 // TODO(aiolos): Remove when throttling and coalescing have both landed. |
| 146 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 184 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 147 false /* should_coalesce */); | 185 false /* should_coalesce */); |
| 148 | 186 |
| 149 scheduler_.OnClientCreated(kChildId, kRouteId); | 187 scheduler_.OnClientCreated(kChildId, kRouteId, visual_observer_, false); |
| 150 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 188 scheduler_.OnClientCreated(kBackgroundChildId, |
| 151 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); | 189 kBackgroundRouteId, |
| 190 visual_observer_background_, |
| 191 false); |
| 192 base::RunLoop().RunUntilIdle(); |
| 193 |
| 152 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); | 194 context_.set_http_server_properties(http_server_properties_.GetWeakPtr()); |
| 195 |
| 196 // Set up initial visibility. |
| 197 web_contents_->WasShown(); |
| 198 web_contents_background_->WasHidden(); |
| 199 web_contents_2_->WasHidden(); |
| 200 web_contents_background_2_->WasHidden(); |
| 201 base::RunLoop().RunUntilIdle(); |
| 153 } | 202 } |
| 154 | 203 |
| 155 virtual ~ResourceSchedulerTest() { | 204 virtual ~ResourceSchedulerTest() { |
| 156 scheduler_.OnClientDeleted(kChildId, kRouteId); | 205 scheduler_.OnClientDeleted(kChildId, kRouteId); |
| 157 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 206 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
| 207 base::RunLoop().RunUntilIdle(); |
| 208 |
| 209 web_contents_.reset(); |
| 210 web_contents_background_.reset(); |
| 211 web_contents_2_.reset(); |
| 212 web_contents_background_2_.reset(); |
| 213 base::RunLoop().RunUntilIdle(); |
| 214 |
| 215 browser_context_.reset(); |
| 216 render_process_host_factory_.reset(); |
| 158 } | 217 } |
| 159 | 218 |
| 160 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( | 219 scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute( |
| 161 const char* url, | 220 const char* url, |
| 162 net::RequestPriority priority, | 221 net::RequestPriority priority, |
| 163 int child_id, | 222 int child_id, |
| 164 int route_id, | 223 int route_id, |
| 165 bool is_async) { | 224 bool is_async) { |
| 166 scoped_ptr<net::URLRequest> url_request( | 225 scoped_ptr<net::URLRequest> url_request( |
| 167 context_.CreateRequest(GURL(url), priority, NULL, NULL)); | 226 context_.CreateRequest(GURL(url), priority, NULL, NULL)); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 332 |
| 274 int next_request_id_; | 333 int next_request_id_; |
| 275 base::MessageLoopForIO message_loop_; | 334 base::MessageLoopForIO message_loop_; |
| 276 BrowserThreadImpl ui_thread_; | 335 BrowserThreadImpl ui_thread_; |
| 277 BrowserThreadImpl io_thread_; | 336 BrowserThreadImpl io_thread_; |
| 278 ResourceDispatcherHostImpl rdh_; | 337 ResourceDispatcherHostImpl rdh_; |
| 279 ResourceScheduler scheduler_; | 338 ResourceScheduler scheduler_; |
| 280 base::MockTimer* mock_timer_; | 339 base::MockTimer* mock_timer_; |
| 281 net::HttpServerPropertiesImpl http_server_properties_; | 340 net::HttpServerPropertiesImpl http_server_properties_; |
| 282 net::TestURLRequestContext context_; | 341 net::TestURLRequestContext context_; |
| 342 scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory_; |
| 343 scoped_ptr<TestBrowserContext> browser_context_; |
| 344 scoped_ptr<TestWebContents> web_contents_; |
| 345 scoped_ptr<TestWebContents> web_contents_background_; |
| 346 scoped_ptr<TestWebContents> web_contents_2_; |
| 347 scoped_ptr<TestWebContents> web_contents_background_2_; |
| 348 ResourceScheduler::VisualObserver* visual_observer_; |
| 349 ResourceScheduler::VisualObserver* visual_observer_background_; |
| 350 ResourceScheduler::VisualObserver* visual_observer_2_; |
| 351 ResourceScheduler::VisualObserver* visual_observer_background_2_; |
| 283 }; | 352 }; |
| 284 | 353 |
| 285 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { | 354 TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) { |
| 286 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); | 355 scoped_ptr<TestRequest> request(NewRequest("http://host/1", net::LOWEST)); |
| 287 EXPECT_TRUE(request->started()); | 356 EXPECT_TRUE(request->started()); |
| 288 } | 357 } |
| 289 | 358 |
| 290 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { | 359 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilIdle) { |
| 291 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 360 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
| 292 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 361 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); | 701 ChangeRequestPriority(low2_spdy.get(), net::LOWEST); |
| 633 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); | 702 scoped_ptr<TestRequest> low2(NewRequest("http://host/low", net::LOWEST)); |
| 634 EXPECT_TRUE(low2->started()); | 703 EXPECT_TRUE(low2->started()); |
| 635 } | 704 } |
| 636 | 705 |
| 637 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { | 706 TEST_F(ResourceSchedulerTest, ThrottledClientCreation) { |
| 638 // TODO(aiolos): remove when throttling and coalescing have both landed | 707 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 639 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 708 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 640 false /* should_coalesce */); | 709 false /* should_coalesce */); |
| 641 EXPECT_TRUE(scheduler_.should_throttle()); | 710 EXPECT_TRUE(scheduler_.should_throttle()); |
| 642 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 711 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 712 kBackgroundRouteId2, |
| 713 visual_observer_background_2_, |
| 714 false); |
| 715 base::RunLoop().RunUntilIdle(); |
| 643 | 716 |
| 644 EXPECT_EQ(ResourceScheduler::THROTTLED, | 717 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 645 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 718 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 646 kBackgroundRouteId2)); | 719 kBackgroundRouteId2)); |
| 647 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 720 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 721 base::RunLoop().RunUntilIdle(); |
| 648 } | 722 } |
| 649 | 723 |
| 650 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { | 724 TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) { |
| 651 // TODO(aiolos): remove when throttling and coalescing have both landed | 725 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 652 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 726 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 653 false /* should_coalesce */); | 727 false /* should_coalesce */); |
| 654 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 728 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 655 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 729 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 656 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 730 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 657 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 731 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 false /* should_coalesce */); | 793 false /* should_coalesce */); |
| 720 EXPECT_EQ(ResourceScheduler::THROTTLED, | 794 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 721 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 795 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 722 kBackgroundRouteId)); | 796 kBackgroundRouteId)); |
| 723 scoped_ptr<TestRequest> high( | 797 scoped_ptr<TestRequest> high( |
| 724 NewBackgroundRequest("http://host/high", net::HIGHEST)); | 798 NewBackgroundRequest("http://host/high", net::HIGHEST)); |
| 725 scoped_ptr<TestRequest> request( | 799 scoped_ptr<TestRequest> request( |
| 726 NewBackgroundRequest("http://host/req", net::IDLE)); | 800 NewBackgroundRequest("http://host/req", net::IDLE)); |
| 727 EXPECT_FALSE(request->started()); | 801 EXPECT_FALSE(request->started()); |
| 728 | 802 |
| 729 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 803 web_contents_background_->WasShown(); |
| 804 base::RunLoop().RunUntilIdle(); |
| 730 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 805 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 731 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 806 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 732 kBackgroundRouteId)); | 807 kBackgroundRouteId)); |
| 733 EXPECT_TRUE(request->started()); | 808 EXPECT_TRUE(request->started()); |
| 734 } | 809 } |
| 735 | 810 |
| 736 TEST_F(ResourceSchedulerTest, UnthrottleNewlyAudibleClient) { | 811 TEST_F(ResourceSchedulerTest, UnthrottleNewlyAudibleClient) { |
| 737 // TODO(aiolos): remove when throttling and coalescing have both landed | 812 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 738 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 813 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 739 false /* should_coalesce */); | 814 false /* should_coalesce */); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 850 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 776 EXPECT_EQ(ResourceScheduler::THROTTLED, | 851 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 777 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 852 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 778 kBackgroundRouteId)); | 853 kBackgroundRouteId)); |
| 779 } | 854 } |
| 780 | 855 |
| 781 TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) { | 856 TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) { |
| 782 // TODO(aiolos): remove when throttling and coalescing have both landed | 857 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 783 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 858 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 784 false /* should_coalesce */); | 859 false /* should_coalesce */); |
| 785 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 860 web_contents_->WasHidden(); |
| 861 base::RunLoop().RunUntilIdle(); |
| 786 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 862 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 787 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 863 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 788 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 864 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 789 EXPECT_EQ(ResourceScheduler::THROTTLED, | 865 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 790 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 866 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 791 kBackgroundRouteId)); | 867 kBackgroundRouteId)); |
| 792 | 868 |
| 793 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 869 web_contents_->WasShown(); |
| 870 base::RunLoop().RunUntilIdle(); |
| 794 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 871 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 795 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 872 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 796 EXPECT_EQ(ResourceScheduler::THROTTLED, | 873 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 797 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 874 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 798 kBackgroundRouteId)); | 875 kBackgroundRouteId)); |
| 799 | 876 |
| 800 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 877 web_contents_->WasHidden(); |
| 878 base::RunLoop().RunUntilIdle(); |
| 801 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 879 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 802 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 880 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 803 EXPECT_EQ(ResourceScheduler::THROTTLED, | 881 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 804 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 882 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 805 kBackgroundRouteId)); | 883 kBackgroundRouteId)); |
| 806 } | 884 } |
| 807 | 885 |
| 808 TEST_F(ResourceSchedulerTest, ThrottledClientStartsNextHighestPriorityRequest) { | 886 TEST_F(ResourceSchedulerTest, ThrottledClientStartsNextHighestPriorityRequest) { |
| 809 // TODO(aiolos): remove when throttling and coalescing have both landed | 887 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 810 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 888 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 // TODO(aiolos): remove when throttling and coalescing have both landed | 1057 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 980 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1058 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 981 false /* should_coalesce */); | 1059 false /* should_coalesce */); |
| 982 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1060 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 983 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1061 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 984 kBackgroundRouteId)); | 1062 kBackgroundRouteId)); |
| 985 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1063 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 986 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1064 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 987 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1065 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 988 | 1066 |
| 989 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1067 web_contents_->WasHidden(); |
| 1068 base::RunLoop().RunUntilIdle(); |
| 990 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1069 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
| 991 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1070 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 992 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1071 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 993 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1072 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 994 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1073 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 995 kBackgroundRouteId)); | 1074 kBackgroundRouteId)); |
| 996 | 1075 |
| 997 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1076 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 998 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1077 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 999 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1078 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1016 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1095 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1017 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1096 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1018 kBackgroundRouteId)); | 1097 kBackgroundRouteId)); |
| 1019 } | 1098 } |
| 1020 | 1099 |
| 1021 TEST_F(ResourceSchedulerTest, | 1100 TEST_F(ResourceSchedulerTest, |
| 1022 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { | 1101 UnloadedClientVisibilityChangedCorrectlyUnthrottles) { |
| 1023 // TODO(aiolos): remove when throttling and coalescing have both landed | 1102 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1024 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1103 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1025 false /* should_coalesce */); | 1104 false /* should_coalesce */); |
| 1026 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1105 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1027 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1106 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1107 kBackgroundRouteId2, |
| 1108 visual_observer_background_2_, |
| 1109 false); |
| 1110 base::RunLoop().RunUntilIdle(); |
| 1111 |
| 1028 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1112 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1029 scheduler_.OnLoadingStateChanged( | 1113 scheduler_.OnLoadingStateChanged( |
| 1030 kBackgroundChildId2, kBackgroundRouteId2, true); | 1114 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1031 | 1115 |
| 1032 // 1 visible, 3 hidden | 1116 // 1 visible, 3 hidden |
| 1033 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1117 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1034 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1118 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1035 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1119 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1036 kBackgroundRouteId)); | 1120 kBackgroundRouteId)); |
| 1037 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1121 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1038 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1122 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1039 kBackgroundRouteId2)); | 1123 kBackgroundRouteId2)); |
| 1040 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1124 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1041 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1125 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1042 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1126 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1043 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1127 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1044 | 1128 |
| 1045 // 2 visible, 2 hidden | 1129 // 2 visible, 2 hidden |
| 1046 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1130 web_contents_2_->WasShown(); |
| 1131 base::RunLoop().RunUntilIdle(); |
| 1047 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1132 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1048 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1133 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1049 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1134 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1050 kBackgroundRouteId)); | 1135 kBackgroundRouteId)); |
| 1051 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1136 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1052 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1137 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1053 kBackgroundRouteId2)); | 1138 kBackgroundRouteId2)); |
| 1054 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1139 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1055 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1140 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1056 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1141 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1057 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1142 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1058 | 1143 |
| 1059 // 1 visible, 3 hidden | 1144 // 1 visible, 3 hidden |
| 1060 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1145 web_contents_2_->WasHidden(); |
| 1146 base::RunLoop().RunUntilIdle(); |
| 1061 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1147 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1062 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1148 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1063 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1149 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1064 kBackgroundRouteId)); | 1150 kBackgroundRouteId)); |
| 1065 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1151 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1066 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1152 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1067 kBackgroundRouteId2)); | 1153 kBackgroundRouteId2)); |
| 1068 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1154 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1069 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1155 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1070 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1156 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1071 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1157 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1072 | 1158 |
| 1073 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1159 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1074 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1160 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1161 base::RunLoop().RunUntilIdle(); |
| 1075 } | 1162 } |
| 1076 | 1163 |
| 1077 TEST_F(ResourceSchedulerTest, | 1164 TEST_F(ResourceSchedulerTest, |
| 1078 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { | 1165 UnloadedClientAudibilityChangedCorrectlyUnthrottles) { |
| 1079 // TODO(aiolos): remove when throttling and coalescing have both landed | 1166 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1080 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1167 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1081 false /* should_coalesce */); | 1168 false /* should_coalesce */); |
| 1082 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1169 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1083 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1170 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1171 kBackgroundRouteId2, |
| 1172 visual_observer_background_2_, |
| 1173 false); |
| 1174 base::RunLoop().RunUntilIdle(); |
| 1175 |
| 1084 scheduler_.OnLoadingStateChanged( | 1176 scheduler_.OnLoadingStateChanged( |
| 1085 kBackgroundChildId2, kBackgroundRouteId2, true); | 1177 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1086 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1178 web_contents_->WasHidden(); |
| 1179 base::RunLoop().RunUntilIdle(); |
| 1087 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1180 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1088 | 1181 |
| 1089 // 1 audible, 3 hidden | 1182 // 1 audible, 3 hidden |
| 1090 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1183 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1091 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1184 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1092 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1185 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1093 kBackgroundRouteId)); | 1186 kBackgroundRouteId)); |
| 1094 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1187 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1095 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1188 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1096 kBackgroundRouteId2)); | 1189 kBackgroundRouteId2)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1122 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1215 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1123 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1216 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1124 kBackgroundRouteId2)); | 1217 kBackgroundRouteId2)); |
| 1125 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1218 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1126 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1219 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1127 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1220 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1128 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1221 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1129 | 1222 |
| 1130 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1223 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1131 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1224 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1225 base::RunLoop().RunUntilIdle(); |
| 1132 } | 1226 } |
| 1133 | 1227 |
| 1134 TEST_F(ResourceSchedulerTest, | 1228 TEST_F(ResourceSchedulerTest, |
| 1135 LoadedClientVisibilityChangedCorrectlyUnthrottles) { | 1229 LoadedClientVisibilityChangedCorrectlyUnthrottles) { |
| 1136 // TODO(aiolos): remove when throttling and coalescing have both landed | 1230 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1137 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1231 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1138 false /* should_coalesce */); | 1232 false /* should_coalesce */); |
| 1139 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1233 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1140 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1234 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1235 kBackgroundRouteId2, |
| 1236 visual_observer_background_2_, |
| 1237 false); |
| 1238 base::RunLoop().RunUntilIdle(); |
| 1239 |
| 1141 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1240 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1142 scheduler_.OnLoadingStateChanged( | 1241 scheduler_.OnLoadingStateChanged( |
| 1143 kBackgroundChildId2, kBackgroundRouteId2, true); | 1242 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1243 |
| 1144 // 1 visible, 3 hidden | 1244 // 1 visible, 3 hidden |
| 1145 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1245 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1146 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1246 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1147 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1247 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1148 kBackgroundRouteId)); | 1248 kBackgroundRouteId)); |
| 1149 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1249 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1150 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1250 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1151 kBackgroundRouteId2)); | 1251 kBackgroundRouteId2)); |
| 1152 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1252 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1153 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1253 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1154 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1254 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1155 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1255 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1156 | 1256 |
| 1157 // 2 visible, 2 hidden | 1257 // 2 visible, 2 hidden |
| 1158 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1258 web_contents_2_->WasShown(); |
| 1259 base::RunLoop().RunUntilIdle(); |
| 1159 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1260 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1160 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1261 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1161 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1262 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1162 kBackgroundRouteId)); | 1263 kBackgroundRouteId)); |
| 1163 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1264 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1164 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1265 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1165 kBackgroundRouteId2)); | 1266 kBackgroundRouteId2)); |
| 1166 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1267 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1167 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1268 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1168 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1269 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1169 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1270 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1170 | 1271 |
| 1171 // 1 visible, 3 hidden | 1272 // 1 visible, 3 hidden |
| 1172 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1273 web_contents_2_->WasHidden(); |
| 1274 base::RunLoop().RunUntilIdle(); |
| 1173 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1275 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1174 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1276 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1175 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1277 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1176 kBackgroundRouteId)); | 1278 kBackgroundRouteId)); |
| 1177 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1279 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1178 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1280 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1179 kBackgroundRouteId2)); | 1281 kBackgroundRouteId2)); |
| 1180 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1282 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1181 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1283 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1182 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1284 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1183 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1285 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1184 | 1286 |
| 1185 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1287 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1186 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1288 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1289 base::RunLoop().RunUntilIdle(); |
| 1187 } | 1290 } |
| 1188 | 1291 |
| 1189 TEST_F(ResourceSchedulerTest, | 1292 TEST_F(ResourceSchedulerTest, |
| 1190 LoadedClientAudibilityChangedCorrectlyUnthrottles) { | 1293 LoadedClientAudibilityChangedCorrectlyUnthrottles) { |
| 1191 // TODO(aiolos): remove when throttling and coalescing have both landed | 1294 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1192 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1295 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1193 false /* should_coalesce */); | 1296 false /* should_coalesce */); |
| 1194 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1297 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1195 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1298 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1299 kBackgroundRouteId2, |
| 1300 visual_observer_background_2_, |
| 1301 false); |
| 1302 base::RunLoop().RunUntilIdle(); |
| 1303 |
| 1196 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1304 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1197 scheduler_.OnLoadingStateChanged( | 1305 scheduler_.OnLoadingStateChanged( |
| 1198 kBackgroundChildId2, kBackgroundRouteId2, true); | 1306 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1199 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1307 web_contents_->WasHidden(); |
| 1308 base::RunLoop().RunUntilIdle(); |
| 1200 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1309 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1310 |
| 1201 // 1 audible, 3 hidden | 1311 // 1 audible, 3 hidden |
| 1202 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1312 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1203 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1313 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1204 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1314 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1205 kBackgroundRouteId)); | 1315 kBackgroundRouteId)); |
| 1206 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1316 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1207 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1317 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1208 kBackgroundRouteId2)); | 1318 kBackgroundRouteId2)); |
| 1209 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1319 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1210 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1320 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1234 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1344 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1235 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1345 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1236 kBackgroundRouteId2)); | 1346 kBackgroundRouteId2)); |
| 1237 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1347 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1238 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1348 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1239 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1349 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1240 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1350 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1241 | 1351 |
| 1242 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1352 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1243 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1353 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1354 base::RunLoop().RunUntilIdle(); |
| 1244 } | 1355 } |
| 1245 | 1356 |
| 1246 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { | 1357 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) { |
| 1247 // TODO(aiolos): remove when throttling and coalescing have both landed | 1358 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1248 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1359 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1249 false /* should_coalesce */); | 1360 false /* should_coalesce */); |
| 1250 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1361 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1251 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1362 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1363 kBackgroundRouteId2, |
| 1364 visual_observer_background_2_, |
| 1365 false); |
| 1366 base::RunLoop().RunUntilIdle(); |
| 1367 |
| 1252 scheduler_.OnLoadingStateChanged( | 1368 scheduler_.OnLoadingStateChanged( |
| 1253 kBackgroundChildId2, kBackgroundRouteId2, true); | 1369 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1254 | 1370 |
| 1255 // 2 visible, 2 hidden | 1371 // 2 visible, 2 hidden |
| 1256 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1372 web_contents_2_->WasShown(); |
| 1373 base::RunLoop().RunUntilIdle(); |
| 1257 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1374 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1258 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1375 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1259 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1376 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1260 kBackgroundRouteId)); | 1377 kBackgroundRouteId)); |
| 1261 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1378 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1262 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1379 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1263 kBackgroundRouteId2)); | 1380 kBackgroundRouteId2)); |
| 1264 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1381 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1265 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1382 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1266 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1383 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1267 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1384 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1268 | 1385 |
| 1269 // 1 visible, 3 hidden | 1386 // 1 visible, 3 hidden |
| 1270 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1387 web_contents_2_->WasHidden(); |
| 1388 base::RunLoop().RunUntilIdle(); |
| 1271 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1389 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1272 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1390 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1273 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1391 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1274 kBackgroundRouteId)); | 1392 kBackgroundRouteId)); |
| 1275 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1393 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1276 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1394 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1277 kBackgroundRouteId2)); | 1395 kBackgroundRouteId2)); |
| 1278 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1396 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1279 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1397 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1280 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1398 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1281 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1399 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1282 | 1400 |
| 1283 // 0 visible, 4 hidden | 1401 // 0 visible, 4 hidden |
| 1284 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1402 web_contents_->WasHidden(); |
| 1403 base::RunLoop().RunUntilIdle(); |
| 1285 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1404 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
| 1286 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1405 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1287 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1406 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1288 kBackgroundRouteId)); | 1407 kBackgroundRouteId)); |
| 1289 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1408 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1290 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1409 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1291 kBackgroundRouteId2)); | 1410 kBackgroundRouteId2)); |
| 1292 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1411 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1293 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1412 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1294 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1413 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1295 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1414 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1296 | 1415 |
| 1297 // 1 visible, 3 hidden | 1416 // 1 visible, 3 hidden |
| 1298 scheduler_.OnVisibilityChanged(kChildId, kRouteId, true); | 1417 web_contents_->WasShown(); |
| 1418 base::RunLoop().RunUntilIdle(); |
| 1299 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1419 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1300 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1420 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1301 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1421 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1302 kBackgroundRouteId)); | 1422 kBackgroundRouteId)); |
| 1303 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1423 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1304 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1424 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1305 kBackgroundRouteId2)); | 1425 kBackgroundRouteId2)); |
| 1306 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1426 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1307 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1427 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1308 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1428 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1309 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1429 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1310 | 1430 |
| 1311 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1431 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1312 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1432 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1433 base::RunLoop().RunUntilIdle(); |
| 1313 } | 1434 } |
| 1314 | 1435 |
| 1315 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { | 1436 TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) { |
| 1316 // TODO(aiolos): remove when throttling and coalescing have both landed | 1437 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1317 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1438 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1318 false /* should_coalesce */); | 1439 false /* should_coalesce */); |
| 1319 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1440 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1320 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1441 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1442 kBackgroundRouteId2, |
| 1443 visual_observer_background_2_, |
| 1444 false); |
| 1445 base::RunLoop().RunUntilIdle(); |
| 1446 |
| 1321 scheduler_.OnLoadingStateChanged( | 1447 scheduler_.OnLoadingStateChanged( |
| 1322 kBackgroundChildId2, kBackgroundRouteId2, true); | 1448 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1323 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1449 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1324 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1450 web_contents_->WasHidden(); |
| 1451 base::RunLoop().RunUntilIdle(); |
| 1325 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | 1452 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); |
| 1326 // 2 audible, 2 hidden | 1453 // 2 audible, 2 hidden |
| 1327 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1454 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1328 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1455 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1329 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1456 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1330 kBackgroundRouteId)); | 1457 kBackgroundRouteId)); |
| 1331 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1458 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1332 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1459 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1333 kBackgroundRouteId2)); | 1460 kBackgroundRouteId2)); |
| 1334 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1461 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1500 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1374 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1501 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1375 kBackgroundRouteId2)); | 1502 kBackgroundRouteId2)); |
| 1376 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1503 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1377 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1504 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1378 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1505 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1379 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1506 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1380 | 1507 |
| 1381 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1508 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1382 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1509 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1510 base::RunLoop().RunUntilIdle(); |
| 1383 } | 1511 } |
| 1384 | 1512 |
| 1385 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { | 1513 TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) { |
| 1386 // TODO(aiolos): remove when throttling and coalescing have both landed | 1514 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1387 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1515 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1388 false /* should_coalesce */); | 1516 false /* should_coalesce */); |
| 1389 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1517 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1390 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1518 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1519 kBackgroundRouteId2, |
| 1520 visual_observer_background_2_, |
| 1521 false); |
| 1522 base::RunLoop().RunUntilIdle(); |
| 1523 |
| 1391 scheduler_.OnLoadingStateChanged( | 1524 scheduler_.OnLoadingStateChanged( |
| 1392 kBackgroundChildId2, kBackgroundRouteId2, true); | 1525 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1393 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1526 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1394 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1527 web_contents_2_->WasShown(); |
| 1528 base::RunLoop().RunUntilIdle(); |
| 1529 |
| 1395 // 2 visible, 2 hidden | 1530 // 2 visible, 2 hidden |
| 1396 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1531 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1397 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1532 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1398 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1533 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1399 kBackgroundRouteId)); | 1534 kBackgroundRouteId)); |
| 1400 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1535 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1401 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1536 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1402 kBackgroundRouteId2)); | 1537 kBackgroundRouteId2)); |
| 1403 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1538 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1404 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1539 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1405 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1540 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1406 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1541 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1407 | 1542 |
| 1408 // 1 visible, 3 hidden | 1543 // 1 visible, 3 hidden |
| 1409 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false); | 1544 web_contents_2_->WasHidden(); |
| 1545 base::RunLoop().RunUntilIdle(); |
| 1410 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1546 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1411 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1547 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1412 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1548 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1413 kBackgroundRouteId)); | 1549 kBackgroundRouteId)); |
| 1414 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1550 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1415 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1551 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1416 kBackgroundRouteId2)); | 1552 kBackgroundRouteId2)); |
| 1417 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1553 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1418 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1554 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1419 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1555 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1420 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1556 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1421 | 1557 |
| 1422 // 0 visible, 4 hidden | 1558 // 0 visible, 4 hidden |
| 1423 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1559 web_contents_->WasHidden(); |
| 1560 base::RunLoop().RunUntilIdle(); |
| 1424 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1561 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
| 1425 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1562 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1426 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1563 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1427 kBackgroundRouteId)); | 1564 kBackgroundRouteId)); |
| 1428 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1565 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1429 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1566 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1430 kBackgroundRouteId2)); | 1567 kBackgroundRouteId2)); |
| 1431 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1568 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1432 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1569 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1433 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1570 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1434 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1571 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1435 | 1572 |
| 1436 // 1 visible, 3 hidden | 1573 // 1 visible, 3 hidden |
| 1437 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1574 web_contents_2_->WasShown(); |
| 1575 base::RunLoop().RunUntilIdle(); |
| 1438 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1576 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
| 1439 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1577 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1440 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1578 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1441 kBackgroundRouteId)); | 1579 kBackgroundRouteId)); |
| 1442 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1580 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1443 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1581 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1444 kBackgroundRouteId2)); | 1582 kBackgroundRouteId2)); |
| 1445 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1583 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1446 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1584 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1447 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1585 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1448 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1586 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1449 | 1587 |
| 1450 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1588 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1451 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1589 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1590 base::RunLoop().RunUntilIdle(); |
| 1452 } | 1591 } |
| 1453 | 1592 |
| 1454 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { | 1593 TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) { |
| 1455 // TODO(aiolos): remove when throttling and coalescing have both landed | 1594 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1456 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1595 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1457 false /* should_coalesce */); | 1596 false /* should_coalesce */); |
| 1458 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1597 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1459 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1598 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1599 kBackgroundRouteId2, |
| 1600 visual_observer_background_2_, |
| 1601 false); |
| 1602 base::RunLoop().RunUntilIdle(); |
| 1603 |
| 1460 scheduler_.OnLoadingStateChanged( | 1604 scheduler_.OnLoadingStateChanged( |
| 1461 kBackgroundChildId2, kBackgroundRouteId2, true); | 1605 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1462 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1606 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1463 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1607 web_contents_->WasHidden(); |
| 1608 base::RunLoop().RunUntilIdle(); |
| 1464 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); | 1609 scheduler_.OnAudibilityChanged(kChildId, kRouteId, true); |
| 1465 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); | 1610 scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true); |
| 1611 |
| 1466 // 2 audible, 2 hidden | 1612 // 2 audible, 2 hidden |
| 1467 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1613 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1468 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1614 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1469 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1615 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1470 kBackgroundRouteId)); | 1616 kBackgroundRouteId)); |
| 1471 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1617 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1472 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1618 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1473 kBackgroundRouteId2)); | 1619 kBackgroundRouteId2)); |
| 1474 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1620 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1475 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1621 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1659 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1514 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1660 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1515 kBackgroundRouteId2)); | 1661 kBackgroundRouteId2)); |
| 1516 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1662 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1517 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1663 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1518 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1664 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1519 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1665 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1520 | 1666 |
| 1521 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1667 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1522 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1668 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1669 base::RunLoop().RunUntilIdle(); |
| 1523 } | 1670 } |
| 1524 | 1671 |
| 1525 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { | 1672 TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) { |
| 1526 // TODO(aiolos): remove when throttling and coalescing have both landed | 1673 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1527 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1674 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1528 false /* should_coalesce */); | 1675 false /* should_coalesce */); |
| 1529 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1676 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1530 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1677 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1678 kBackgroundRouteId2, |
| 1679 visual_observer_background_2_, |
| 1680 false); |
| 1681 base::RunLoop().RunUntilIdle(); |
| 1531 | 1682 |
| 1532 // 1 visible and 2 hidden loading, 1 visible loaded | 1683 // 1 visible and 2 hidden loading, 1 visible loaded |
| 1533 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1684 web_contents_2_->WasShown(); |
| 1685 base::RunLoop().RunUntilIdle(); |
| 1534 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1686 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1535 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1687 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1536 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1688 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1537 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1689 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1538 kBackgroundRouteId)); | 1690 kBackgroundRouteId)); |
| 1539 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1691 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1540 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1692 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1541 kBackgroundRouteId2)); | 1693 kBackgroundRouteId2)); |
| 1542 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1694 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1543 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1695 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1736 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1585 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1737 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1586 kBackgroundRouteId2)); | 1738 kBackgroundRouteId2)); |
| 1587 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1739 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1588 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1740 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1589 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1741 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1590 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1742 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1591 | 1743 |
| 1592 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1744 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1593 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1745 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1746 base::RunLoop().RunUntilIdle(); |
| 1594 } | 1747 } |
| 1595 | 1748 |
| 1596 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { | 1749 TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) { |
| 1597 // TODO(aiolos): remove when throttling and coalescing have both landed | 1750 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1598 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1751 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1599 false /* should_coalesce */); | 1752 false /* should_coalesce */); |
| 1600 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1753 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1601 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1754 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1602 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1755 kBackgroundRouteId2, |
| 1756 visual_observer_background_2_, |
| 1757 false); |
| 1758 base::RunLoop().RunUntilIdle(); |
| 1759 |
| 1760 web_contents_2_->WasShown(); |
| 1761 base::RunLoop().RunUntilIdle(); |
| 1603 | 1762 |
| 1604 // 2 visible loading, 1 hidden loading, 1 hidden loaded | 1763 // 2 visible loading, 1 hidden loading, 1 hidden loaded |
| 1605 scheduler_.OnLoadingStateChanged( | 1764 scheduler_.OnLoadingStateChanged( |
| 1606 kBackgroundChildId2, kBackgroundRouteId2, true); | 1765 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1607 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1766 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1608 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1767 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1609 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1768 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1610 kBackgroundRouteId)); | 1769 kBackgroundRouteId)); |
| 1611 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1770 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1612 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1771 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1639 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1798 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1640 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1799 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1641 kBackgroundRouteId2)); | 1800 kBackgroundRouteId2)); |
| 1642 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1801 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1643 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1802 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1644 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1803 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1645 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1804 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1646 | 1805 |
| 1647 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1806 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1648 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1807 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1808 base::RunLoop().RunUntilIdle(); |
| 1649 } | 1809 } |
| 1650 | 1810 |
| 1651 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { | 1811 TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) { |
| 1652 // TODO(aiolos): remove when throttling and coalescing have both landed | 1812 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1653 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1813 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1654 false /* should_coalesce */); | 1814 false /* should_coalesce */); |
| 1655 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1815 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1656 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1816 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1657 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1817 kBackgroundRouteId2, |
| 1818 visual_observer_background_2_, |
| 1819 false); |
| 1820 base::RunLoop().RunUntilIdle(); |
| 1821 |
| 1822 web_contents_2_->WasShown(); |
| 1823 base::RunLoop().RunUntilIdle(); |
| 1658 | 1824 |
| 1659 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1825 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
| 1660 scheduler_.OnLoadingStateChanged( | 1826 scheduler_.OnLoadingStateChanged( |
| 1661 kBackgroundChildId2, kBackgroundRouteId2, true); | 1827 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1662 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); | 1828 scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true); |
| 1663 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1829 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1664 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1830 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1665 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1831 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1666 kBackgroundRouteId)); | 1832 kBackgroundRouteId)); |
| 1667 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1833 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1871 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1706 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1872 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1707 kBackgroundRouteId2)); | 1873 kBackgroundRouteId2)); |
| 1708 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1874 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1709 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1875 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1710 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1876 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1711 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1877 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1712 | 1878 |
| 1713 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1879 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1714 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1880 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1881 base::RunLoop().RunUntilIdle(); |
| 1715 } | 1882 } |
| 1716 | 1883 |
| 1717 TEST_F(ResourceSchedulerTest, | 1884 TEST_F(ResourceSchedulerTest, |
| 1718 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { | 1885 ActiveAndLoadingClientDeletedCorrectlyUnthrottle) { |
| 1719 // TODO(aiolos): remove when throttling and coalescing have both landed | 1886 // TODO(aiolos): remove when throttling and coalescing have both landed |
| 1720 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1887 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1721 false /* should_coalesce */); | 1888 false /* should_coalesce */); |
| 1722 scheduler_.OnClientCreated(kChildId2, kRouteId2); | 1889 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 1723 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 1890 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 1724 scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true); | 1891 kBackgroundRouteId2, |
| 1892 visual_observer_background_2_, |
| 1893 false); |
| 1894 base::RunLoop().RunUntilIdle(); |
| 1895 |
| 1896 web_contents_2_->WasShown(); |
| 1897 base::RunLoop().RunUntilIdle(); |
| 1725 | 1898 |
| 1726 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1899 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
| 1727 scheduler_.OnLoadingStateChanged( | 1900 scheduler_.OnLoadingStateChanged( |
| 1728 kBackgroundChildId2, kBackgroundRouteId2, true); | 1901 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1729 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1902 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1730 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1903 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1731 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1904 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1732 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1905 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1733 kBackgroundRouteId)); | 1906 kBackgroundRouteId)); |
| 1734 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1907 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1735 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1908 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1736 kBackgroundRouteId2)); | 1909 kBackgroundRouteId2)); |
| 1737 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1910 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1738 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1911 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1739 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1912 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1740 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); | 1913 scheduler_.GetClientStateForTesting(kChildId2, kRouteId2)); |
| 1741 | 1914 |
| 1742 // 1 visible loaded, 1 hidden loading, 1 hidden loaded | 1915 // 1 visible loaded, 1 hidden loading, 1 hidden loaded |
| 1743 scheduler_.OnClientDeleted(kChildId2, kRouteId2); | 1916 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 1917 base::RunLoop().RunUntilIdle(); |
| 1744 EXPECT_TRUE(scheduler_.active_clients_loaded()); | 1918 EXPECT_TRUE(scheduler_.active_clients_loaded()); |
| 1745 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1919 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1746 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1920 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1747 kBackgroundRouteId)); | 1921 kBackgroundRouteId)); |
| 1748 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1922 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1749 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1923 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1750 kBackgroundRouteId2)); | 1924 kBackgroundRouteId2)); |
| 1751 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1925 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1752 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1926 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1753 | 1927 |
| 1754 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading | 1928 // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading |
| 1755 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, false); | 1929 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, false); |
| 1756 EXPECT_FALSE(scheduler_.active_clients_loaded()); | 1930 EXPECT_FALSE(scheduler_.active_clients_loaded()); |
| 1757 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1931 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1758 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1932 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1759 kBackgroundRouteId)); | 1933 kBackgroundRouteId)); |
| 1760 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1934 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1761 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 1935 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1762 kBackgroundRouteId2)); | 1936 kBackgroundRouteId2)); |
| 1763 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1937 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1764 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1938 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1765 | 1939 |
| 1766 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 1940 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 1941 base::RunLoop().RunUntilIdle(); |
| 1767 } | 1942 } |
| 1768 | 1943 |
| 1769 TEST_F(ResourceSchedulerTest, CoalescedClientCreationStartsTimer) { | 1944 TEST_F(ResourceSchedulerTest, CoalescedClientCreationStartsTimer) { |
| 1770 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1945 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1771 true /* should_coalesce */); | 1946 true /* should_coalesce */); |
| 1772 EXPECT_FALSE(mock_timer_->IsRunning()); | 1947 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1773 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1948 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1774 EXPECT_FALSE(mock_timer_->IsRunning()); | 1949 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1775 scheduler_.OnLoadingStateChanged( | 1950 scheduler_.OnLoadingStateChanged( |
| 1776 kBackgroundChildId, kBackgroundRouteId, true); | 1951 kBackgroundChildId, kBackgroundRouteId, true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1792 EXPECT_FALSE(mock_timer_->IsRunning()); | 1967 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1793 | 1968 |
| 1794 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 1969 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1795 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1970 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1796 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1971 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1797 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1972 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1798 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1973 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1799 kBackgroundRouteId)); | 1974 kBackgroundRouteId)); |
| 1800 EXPECT_FALSE(mock_timer_->IsRunning()); | 1975 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1801 | 1976 |
| 1802 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1977 web_contents_->WasHidden(); |
| 1978 base::RunLoop().RunUntilIdle(); |
| 1803 EXPECT_EQ(ResourceScheduler::COALESCED, | 1979 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1804 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1980 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1805 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1981 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1806 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1982 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1807 kBackgroundRouteId)); | 1983 kBackgroundRouteId)); |
| 1808 EXPECT_TRUE(mock_timer_->IsRunning()); | 1984 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1809 } | 1985 } |
| 1810 | 1986 |
| 1811 TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) { | 1987 TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) { |
| 1812 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 1988 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1813 true /* should_coalesce */); | 1989 true /* should_coalesce */); |
| 1814 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 1990 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1815 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 1991 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1816 EXPECT_EQ(ResourceScheduler::THROTTLED, | 1992 EXPECT_EQ(ResourceScheduler::THROTTLED, |
| 1817 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 1993 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1818 kBackgroundRouteId)); | 1994 kBackgroundRouteId)); |
| 1819 EXPECT_FALSE(mock_timer_->IsRunning()); | 1995 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1820 | 1996 |
| 1821 scheduler_.OnVisibilityChanged(kChildId, kRouteId, false); | 1997 web_contents_->WasHidden(); |
| 1998 base::RunLoop().RunUntilIdle(); |
| 1822 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 1999 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1823 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 2000 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| 1824 EXPECT_FALSE(mock_timer_->IsRunning()); | 2001 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1825 | 2002 |
| 1826 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2003 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1827 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 2004 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1828 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2005 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1829 kBackgroundRouteId)); | 2006 kBackgroundRouteId)); |
| 1830 EXPECT_EQ(ResourceScheduler::COALESCED, | 2007 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1831 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); | 2008 scheduler_.GetClientStateForTesting(kChildId, kRouteId)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1850 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 2027 scheduler_.OnAudibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); |
| 1851 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 2028 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1852 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2029 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1853 kBackgroundRouteId)); | 2030 kBackgroundRouteId)); |
| 1854 EXPECT_FALSE(mock_timer_->IsRunning()); | 2031 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1855 } | 2032 } |
| 1856 | 2033 |
| 1857 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { | 2034 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) { |
| 1858 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2035 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1859 true /* should_coalesce */); | 2036 true /* should_coalesce */); |
| 1860 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 2037 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2038 kBackgroundRouteId2, |
| 2039 visual_observer_background_2_, |
| 2040 false); |
| 2041 base::RunLoop().RunUntilIdle(); |
| 2042 |
| 1861 EXPECT_FALSE(mock_timer_->IsRunning()); | 2043 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1862 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2044 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1863 EXPECT_FALSE(mock_timer_->IsRunning()); | 2045 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1864 scheduler_.OnLoadingStateChanged( | 2046 scheduler_.OnLoadingStateChanged( |
| 1865 kBackgroundChildId, kBackgroundRouteId, true); | 2047 kBackgroundChildId, kBackgroundRouteId, true); |
| 1866 EXPECT_EQ(ResourceScheduler::COALESCED, | 2048 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1867 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2049 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1868 kBackgroundRouteId)); | 2050 kBackgroundRouteId)); |
| 1869 scheduler_.OnLoadingStateChanged( | 2051 scheduler_.OnLoadingStateChanged( |
| 1870 kBackgroundChildId2, kBackgroundRouteId2, true); | 2052 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1871 EXPECT_EQ(ResourceScheduler::COALESCED, | 2053 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1872 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 2054 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1873 kBackgroundRouteId2)); | 2055 kBackgroundRouteId2)); |
| 1874 EXPECT_TRUE(mock_timer_->IsRunning()); | 2056 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1875 | 2057 |
| 1876 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); | 2058 scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId); |
| 2059 base::RunLoop().RunUntilIdle(); |
| 1877 EXPECT_TRUE(mock_timer_->IsRunning()); | 2060 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1878 | 2061 |
| 1879 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 2062 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2063 base::RunLoop().RunUntilIdle(); |
| 1880 EXPECT_FALSE(mock_timer_->IsRunning()); | 2064 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1881 | 2065 |
| 1882 // To avoid errors on test tear down. | 2066 // To avoid errors on test tear down. |
| 1883 scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId); | 2067 scheduler_.OnClientCreated(kBackgroundChildId, |
| 2068 kBackgroundRouteId, |
| 2069 NULL, |
| 2070 false); |
| 2071 base::RunLoop().RunUntilIdle(); |
| 1884 } | 2072 } |
| 1885 | 2073 |
| 1886 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { | 2074 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) { |
| 1887 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2075 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1888 true /* should_coalesce */); | 2076 true /* should_coalesce */); |
| 1889 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 2077 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2078 kBackgroundRouteId2, |
| 2079 visual_observer_background_2_, |
| 2080 false); |
| 2081 base::RunLoop().RunUntilIdle(); |
| 2082 |
| 1890 EXPECT_FALSE(mock_timer_->IsRunning()); | 2083 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1891 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2084 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1892 EXPECT_FALSE(mock_timer_->IsRunning()); | 2085 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1893 scheduler_.OnLoadingStateChanged( | 2086 scheduler_.OnLoadingStateChanged( |
| 1894 kBackgroundChildId, kBackgroundRouteId, true); | 2087 kBackgroundChildId, kBackgroundRouteId, true); |
| 1895 EXPECT_EQ(ResourceScheduler::COALESCED, | 2088 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1896 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2089 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1897 kBackgroundRouteId)); | 2090 kBackgroundRouteId)); |
| 1898 scheduler_.OnLoadingStateChanged( | 2091 scheduler_.OnLoadingStateChanged( |
| 1899 kBackgroundChildId2, kBackgroundRouteId2, true); | 2092 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1900 EXPECT_EQ(ResourceScheduler::COALESCED, | 2093 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1901 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 2094 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1902 kBackgroundRouteId2)); | 2095 kBackgroundRouteId2)); |
| 1903 EXPECT_TRUE(mock_timer_->IsRunning()); | 2096 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1904 | 2097 |
| 1905 scheduler_.OnLoadingStateChanged( | 2098 scheduler_.OnLoadingStateChanged( |
| 1906 kBackgroundChildId, kBackgroundRouteId, false); | 2099 kBackgroundChildId, kBackgroundRouteId, false); |
| 1907 EXPECT_TRUE(mock_timer_->IsRunning()); | 2100 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1908 | 2101 |
| 1909 scheduler_.OnLoadingStateChanged( | 2102 scheduler_.OnLoadingStateChanged( |
| 1910 kBackgroundChildId2, kBackgroundRouteId2, false); | 2103 kBackgroundChildId2, kBackgroundRouteId2, false); |
| 1911 EXPECT_FALSE(mock_timer_->IsRunning()); | 2104 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1912 | 2105 |
| 1913 // This is needed to avoid errors on test tear down. | 2106 // This is needed to avoid errors on test tear down. |
| 1914 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 2107 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2108 base::RunLoop().RunUntilIdle(); |
| 1915 } | 2109 } |
| 1916 | 2110 |
| 1917 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { | 2111 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) { |
| 1918 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2112 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1919 true /* should_coalesce */); | 2113 true /* should_coalesce */); |
| 1920 scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2); | 2114 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2115 kBackgroundRouteId2, |
| 2116 visual_observer_background_2_, |
| 2117 false); |
| 2118 base::RunLoop().RunUntilIdle(); |
| 2119 |
| 1921 EXPECT_FALSE(mock_timer_->IsRunning()); | 2120 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1922 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2121 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1923 EXPECT_FALSE(mock_timer_->IsRunning()); | 2122 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1924 scheduler_.OnLoadingStateChanged( | 2123 scheduler_.OnLoadingStateChanged( |
| 1925 kBackgroundChildId, kBackgroundRouteId, true); | 2124 kBackgroundChildId, kBackgroundRouteId, true); |
| 1926 EXPECT_EQ(ResourceScheduler::COALESCED, | 2125 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1927 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2126 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1928 kBackgroundRouteId)); | 2127 kBackgroundRouteId)); |
| 1929 scheduler_.OnLoadingStateChanged( | 2128 scheduler_.OnLoadingStateChanged( |
| 1930 kBackgroundChildId2, kBackgroundRouteId2, true); | 2129 kBackgroundChildId2, kBackgroundRouteId2, true); |
| 1931 EXPECT_EQ(ResourceScheduler::COALESCED, | 2130 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1932 scheduler_.GetClientStateForTesting(kBackgroundChildId2, | 2131 scheduler_.GetClientStateForTesting(kBackgroundChildId2, |
| 1933 kBackgroundRouteId2)); | 2132 kBackgroundRouteId2)); |
| 1934 EXPECT_TRUE(mock_timer_->IsRunning()); | 2133 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1935 | 2134 |
| 1936 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 2135 web_contents_background_->WasShown(); |
| 2136 base::RunLoop().RunUntilIdle(); |
| 1937 EXPECT_TRUE(mock_timer_->IsRunning()); | 2137 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1938 | 2138 |
| 1939 scheduler_.OnVisibilityChanged( | 2139 web_contents_background_2_->WasShown(); |
| 1940 kBackgroundChildId2, kBackgroundRouteId2, true); | 2140 base::RunLoop().RunUntilIdle(); |
| 1941 EXPECT_FALSE(mock_timer_->IsRunning()); | 2141 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1942 | 2142 |
| 1943 // To avoid errors on test tear down. | 2143 // To avoid errors on test tear down. |
| 1944 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); | 2144 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2145 base::RunLoop().RunUntilIdle(); |
| 1945 } | 2146 } |
| 1946 | 2147 |
| 1947 TEST_F(ResourceSchedulerTest, | 2148 TEST_F(ResourceSchedulerTest, |
| 1948 CoalescedClientBecomesLoadingAndVisibleStopsTimer) { | 2149 CoalescedClientBecomesLoadingAndVisibleStopsTimer) { |
| 1949 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2150 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1950 true /* should_coalesce */); | 2151 true /* should_coalesce */); |
| 1951 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2152 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| 1952 EXPECT_FALSE(mock_timer_->IsRunning()); | 2153 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1953 scheduler_.OnLoadingStateChanged( | 2154 scheduler_.OnLoadingStateChanged( |
| 1954 kBackgroundChildId, kBackgroundRouteId, true); | 2155 kBackgroundChildId, kBackgroundRouteId, true); |
| 1955 EXPECT_EQ(ResourceScheduler::COALESCED, | 2156 EXPECT_EQ(ResourceScheduler::COALESCED, |
| 1956 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2157 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1957 kBackgroundRouteId)); | 2158 kBackgroundRouteId)); |
| 1958 EXPECT_TRUE(mock_timer_->IsRunning()); | 2159 EXPECT_TRUE(mock_timer_->IsRunning()); |
| 1959 | 2160 |
| 1960 scheduler_.OnLoadingStateChanged( | 2161 scheduler_.OnLoadingStateChanged( |
| 1961 kBackgroundChildId, kBackgroundRouteId, false); | 2162 kBackgroundChildId, kBackgroundRouteId, false); |
| 1962 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, | 2163 EXPECT_EQ(ResourceScheduler::UNTHROTTLED, |
| 1963 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2164 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1964 kBackgroundRouteId)); | 2165 kBackgroundRouteId)); |
| 1965 EXPECT_FALSE(mock_timer_->IsRunning()); | 2166 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1966 | 2167 |
| 1967 scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true); | 2168 web_contents_background_->WasShown(); |
| 2169 base::RunLoop().RunUntilIdle(); |
| 1968 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, | 2170 EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING, |
| 1969 scheduler_.GetClientStateForTesting(kBackgroundChildId, | 2171 scheduler_.GetClientStateForTesting(kBackgroundChildId, |
| 1970 kBackgroundRouteId)); | 2172 kBackgroundRouteId)); |
| 1971 EXPECT_FALSE(mock_timer_->IsRunning()); | 2173 EXPECT_FALSE(mock_timer_->IsRunning()); |
| 1972 } | 2174 } |
| 1973 | 2175 |
| 1974 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) { | 2176 TEST_F(ResourceSchedulerTest, CoalescedRequestsIssueOnTimer) { |
| 1975 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, | 2177 scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */, |
| 1976 true /* should_coalesce */); | 2178 true /* should_coalesce */); |
| 1977 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); | 2179 scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 EXPECT_FALSE(high2->started()); | 2293 EXPECT_FALSE(high2->started()); |
| 2092 EXPECT_FALSE(low->started()); | 2294 EXPECT_FALSE(low->started()); |
| 2093 | 2295 |
| 2094 FireCoalescingTimer(); | 2296 FireCoalescingTimer(); |
| 2095 | 2297 |
| 2096 EXPECT_TRUE(high->started()); | 2298 EXPECT_TRUE(high->started()); |
| 2097 EXPECT_TRUE(high2->started()); | 2299 EXPECT_TRUE(high2->started()); |
| 2098 EXPECT_TRUE(low->started()); | 2300 EXPECT_TRUE(low->started()); |
| 2099 } | 2301 } |
| 2100 | 2302 |
| 2303 TEST_F(ResourceSchedulerTest, CheckInitialVisibility) { |
| 2304 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 2305 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2306 kBackgroundRouteId2, |
| 2307 visual_observer_background_2_, |
| 2308 false); |
| 2309 base::RunLoop().RunUntilIdle(); |
| 2310 |
| 2311 web_contents_2_->WasShown(); |
| 2312 base::RunLoop().RunUntilIdle(); |
| 2313 |
| 2314 EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2)); |
| 2315 EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2, |
| 2316 kBackgroundRouteId2)); |
| 2317 |
| 2318 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 2319 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2320 base::RunLoop().RunUntilIdle(); |
| 2321 } |
| 2322 |
| 2323 TEST_F(ResourceSchedulerTest, GetVisualSignalFromWebContents) { |
| 2324 scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false); |
| 2325 scheduler_.OnClientCreated(kBackgroundChildId2, |
| 2326 kBackgroundRouteId2, |
| 2327 visual_observer_background_2_, |
| 2328 false); |
| 2329 base::RunLoop().RunUntilIdle(); |
| 2330 |
| 2331 web_contents_2_->WasShown(); |
| 2332 base::RunLoop().RunUntilIdle(); |
| 2333 |
| 2334 // Change visibility of web contents. |
| 2335 web_contents_2_->WasHidden(); |
| 2336 web_contents_background_2_->WasShown(); |
| 2337 base::RunLoop().RunUntilIdle(); |
| 2338 |
| 2339 // The clients get the visual signal from web contents. |
| 2340 EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2)); |
| 2341 EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2, |
| 2342 kBackgroundRouteId2)); |
| 2343 |
| 2344 scheduler_.OnClientDeleted(kChildId2, kRouteId2); |
| 2345 scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2); |
| 2346 base::RunLoop().RunUntilIdle(); |
| 2347 } |
| 2348 |
| 2101 } // unnamed namespace | 2349 } // unnamed namespace |
| 2102 | 2350 |
| 2103 } // namespace content | 2351 } // namespace content |
| OLD | NEW |