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

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

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

Powered by Google App Engine
This is Rietveld 408576698