| Index: content/browser/loader/resource_scheduler_unittest.cc
|
| diff --git a/content/browser/loader/resource_scheduler_unittest.cc b/content/browser/loader/resource_scheduler_unittest.cc
|
| index 3de46c5ceca922241f01daddac2d21e2b9713f59..f85e6a1cb2067e6bc3802e2ecdaada57cdb66a6a 100644
|
| --- a/content/browser/loader/resource_scheduler_unittest.cc
|
| +++ b/content/browser/loader/resource_scheduler_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/run_loop.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/timer/mock_timer.h"
|
| #include "base/timer/timer.h"
|
| @@ -19,6 +20,9 @@
|
| #include "content/public/browser/resource_throttle.h"
|
| #include "content/public/common/process_type.h"
|
| #include "content/public/common/resource_type.h"
|
| +#include "content/public/test/mock_render_process_host.h"
|
| +#include "content/public/test/test_browser_context.h"
|
| +#include "content/test/test_web_contents.h"
|
| #include "net/base/host_port_pair.h"
|
| #include "net/base/request_priority.h"
|
| #include "net/http/http_server_properties_impl.h"
|
| @@ -140,21 +144,76 @@ class ResourceSchedulerTest : public testing::Test {
|
| ui_thread_(BrowserThread::UI, &message_loop_),
|
| io_thread_(BrowserThread::IO, &message_loop_),
|
| mock_timer_(new base::MockTimer(true, true)) {
|
| + // Set up web contents.
|
| + render_process_host_factory_.reset(new MockRenderProcessHostFactory());
|
| + browser_context_.reset(new TestBrowserContext());
|
| + scoped_refptr<SiteInstance> site_instance =
|
| + SiteInstance::Create(browser_context_.get());
|
| + scoped_refptr<SiteInstance> site_instance_background =
|
| + SiteInstance::Create(browser_context_.get());
|
| + scoped_refptr<SiteInstance> site_instance_2 =
|
| + SiteInstance::Create(browser_context_.get());
|
| + scoped_refptr<SiteInstance> site_instance_background_2 =
|
| + SiteInstance::Create(browser_context_.get());
|
| + SiteInstanceImpl::set_render_process_host_factory(
|
| + render_process_host_factory_.get());
|
| +
|
| + web_contents_.reset(
|
| + TestWebContents::Create(browser_context_.get(), site_instance.get()));
|
| + web_contents_background_.reset(
|
| + TestWebContents::Create(browser_context_.get(),
|
| + site_instance_background.get()));
|
| + web_contents_2_.reset(
|
| + TestWebContents::Create(browser_context_.get(), site_instance_2.get()));
|
| + web_contents_background_2_.reset(
|
| + TestWebContents::Create(browser_context_.get(),
|
| + site_instance_background_2.get()));
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + visual_observer_ = scheduler_.CreateVisualObserver(web_contents_.get());
|
| + visual_observer_background_ =
|
| + scheduler_.CreateVisualObserver(web_contents_background_.get());
|
| + visual_observer_2_ = scheduler_.CreateVisualObserver(web_contents_2_.get());
|
| + visual_observer_background_2_ =
|
| + scheduler_.CreateVisualObserver(web_contents_background_2_.get());
|
| +
|
| + // set up resource scheduler
|
| scheduler_.set_timer_for_testing(scoped_ptr<base::Timer>(mock_timer_));
|
|
|
| // TODO(aiolos): Remove when throttling and coalescing have both landed.
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
|
|
| - scheduler_.OnClientCreated(kChildId, kRouteId);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
|
| - scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
|
| + scheduler_.OnClientCreated(kChildId, kRouteId, visual_observer_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId,
|
| + kBackgroundRouteId,
|
| + visual_observer_background_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
|
| +
|
| + // Set up initial visibility.
|
| + web_contents_->WasShown();
|
| + web_contents_background_->WasHidden();
|
| + web_contents_2_->WasHidden();
|
| + web_contents_background_2_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| virtual ~ResourceSchedulerTest() {
|
| scheduler_.OnClientDeleted(kChildId, kRouteId);
|
| scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_.reset();
|
| + web_contents_background_.reset();
|
| + web_contents_2_.reset();
|
| + web_contents_background_2_.reset();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + browser_context_.reset();
|
| + render_process_host_factory_.reset();
|
| }
|
|
|
| scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute(
|
| @@ -280,6 +339,16 @@ class ResourceSchedulerTest : public testing::Test {
|
| base::MockTimer* mock_timer_;
|
| net::HttpServerPropertiesImpl http_server_properties_;
|
| net::TestURLRequestContext context_;
|
| + scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory_;
|
| + scoped_ptr<TestBrowserContext> browser_context_;
|
| + scoped_ptr<TestWebContents> web_contents_;
|
| + scoped_ptr<TestWebContents> web_contents_background_;
|
| + scoped_ptr<TestWebContents> web_contents_2_;
|
| + scoped_ptr<TestWebContents> web_contents_background_2_;
|
| + ResourceScheduler::VisualObserver* visual_observer_;
|
| + ResourceScheduler::VisualObserver* visual_observer_background_;
|
| + ResourceScheduler::VisualObserver* visual_observer_2_;
|
| + ResourceScheduler::VisualObserver* visual_observer_background_2_;
|
| };
|
|
|
| TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {
|
| @@ -639,12 +708,17 @@ TEST_F(ResourceSchedulerTest, ThrottledClientCreation) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| EXPECT_TRUE(scheduler_.should_throttle());
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId2,
|
| kBackgroundRouteId2));
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, ActiveClientThrottleUpdateOnLoadingChange) {
|
| @@ -726,7 +800,8 @@ TEST_F(ResourceSchedulerTest, UnthrottleNewlyVisibleClient) {
|
| NewBackgroundRequest("http://host/req", net::IDLE));
|
| EXPECT_FALSE(request->started());
|
|
|
| - scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
|
| + web_contents_background_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| kBackgroundRouteId));
|
| @@ -782,7 +857,8 @@ TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
| EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| @@ -790,14 +866,16 @@ TEST_F(ResourceSchedulerTest, AudibleClientStillUnthrottledOnVisabilityChange) {
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| kBackgroundRouteId));
|
|
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
|
| + web_contents_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| kBackgroundRouteId));
|
|
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -986,7 +1064,8 @@ TEST_F(ResourceSchedulerTest, AllBackgroundClientsUnthrottle) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
|
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| @@ -1023,8 +1102,13 @@ TEST_F(ResourceSchedulerTest,
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| @@ -1043,7 +1127,8 @@ TEST_F(ResourceSchedulerTest,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 2 visible, 2 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1057,7 +1142,8 @@ TEST_F(ResourceSchedulerTest,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false);
|
| + web_contents_2_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1072,6 +1158,7 @@ TEST_F(ResourceSchedulerTest,
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest,
|
| @@ -1079,11 +1166,17 @@ TEST_F(ResourceSchedulerTest,
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
|
|
| // 1 audible, 3 hidden
|
| @@ -1129,6 +1222,7 @@ TEST_F(ResourceSchedulerTest,
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest,
|
| @@ -1136,11 +1230,17 @@ TEST_F(ResourceSchedulerTest,
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| +
|
| // 1 visible, 3 hidden
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -1155,7 +1255,8 @@ TEST_F(ResourceSchedulerTest,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 2 visible, 2 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1169,7 +1270,8 @@ TEST_F(ResourceSchedulerTest,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false);
|
| + web_contents_2_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1184,6 +1286,7 @@ TEST_F(ResourceSchedulerTest,
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest,
|
| @@ -1191,13 +1294,20 @@ TEST_F(ResourceSchedulerTest,
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
| +
|
| // 1 audible, 3 hidden
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -1241,19 +1351,26 @@ TEST_F(ResourceSchedulerTest,
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
|
|
| // 2 visible, 2 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1267,7 +1384,8 @@ TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false);
|
| + web_contents_2_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1281,7 +1399,8 @@ TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 0 visible, 4 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1295,7 +1414,8 @@ TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
|
| + web_contents_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1310,18 +1430,25 @@ TEST_F(ResourceSchedulerTest, UnloadedClientBecomesHiddenCorrectlyUnthrottles) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
|
| // 2 audible, 2 hidden
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| @@ -1380,18 +1507,26 @@ TEST_F(ResourceSchedulerTest, UnloadedClientBecomesSilentCorrectlyUnthrottles) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| // 2 visible, 2 hidden
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -1406,7 +1541,8 @@ TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, false);
|
| + web_contents_2_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1420,7 +1556,8 @@ TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 0 visible, 4 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1434,7 +1571,8 @@ TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| // 1 visible, 3 hidden
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1449,20 +1587,28 @@ TEST_F(ResourceSchedulerTest, LoadedClientBecomesHiddenCorrectlyThrottles) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
| scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
|
| +
|
| // 2 audible, 2 hidden
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -1520,17 +1666,23 @@ TEST_F(ResourceSchedulerTest, LoadedClientBecomesSilentCorrectlyThrottles) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // 1 visible and 2 hidden loading, 1 visible loaded
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| @@ -1591,15 +1743,22 @@ TEST_F(ResourceSchedulerTest, HiddenLoadedChangesCorrectlyStayThrottled) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // 2 visible loading, 1 hidden loading, 1 hidden loaded
|
| scheduler_.OnLoadingStateChanged(
|
| @@ -1646,15 +1805,22 @@ TEST_F(ResourceSchedulerTest, PartialVisibleClientLoadedDoesNotUnthrottle) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) {
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
|
| scheduler_.OnLoadingStateChanged(
|
| @@ -1712,6 +1878,7 @@ TEST_F(ResourceSchedulerTest, FullVisibleLoadedCorrectlyUnthrottle) {
|
|
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest,
|
| @@ -1719,9 +1886,15 @@ TEST_F(ResourceSchedulerTest,
|
| // TODO(aiolos): remove when throttling and coalescing have both landed
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| false /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kChildId2, kRouteId2);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| - scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
|
| scheduler_.OnLoadingStateChanged(
|
| @@ -1741,6 +1914,7 @@ TEST_F(ResourceSchedulerTest,
|
|
|
| // 1 visible loaded, 1 hidden loading, 1 hidden loaded
|
| scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(scheduler_.active_clients_loaded());
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| @@ -1764,6 +1938,7 @@ TEST_F(ResourceSchedulerTest,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
|
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, CoalescedClientCreationStartsTimer) {
|
| @@ -1799,7 +1974,8 @@ TEST_F(ResourceSchedulerTest, ActiveLoadingClientLoadedAndHiddenStartsTimer) {
|
| kBackgroundRouteId));
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::COALESCED,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| @@ -1818,7 +1994,8 @@ TEST_F(ResourceSchedulerTest, ActiveLoadingClientHiddenAndLoadedStartsTimer) {
|
| kBackgroundRouteId));
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| - scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| + web_contents_->WasHidden();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::UNTHROTTLED,
|
| scheduler_.GetClientStateForTesting(kChildId, kRouteId));
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1857,7 +2034,12 @@ TEST_F(ResourceSchedulerTest, CoalescedClientBecomesAudibleStopsTimer) {
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1874,19 +2056,30 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
|
| EXPECT_TRUE(mock_timer_->IsRunning());
|
|
|
| scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(mock_timer_->IsRunning());
|
|
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| // To avoid errors on test tear down.
|
| - scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
|
| + scheduler_.OnClientCreated(kBackgroundChildId,
|
| + kBackgroundRouteId,
|
| + NULL,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1912,12 +2105,18 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
|
|
|
| // This is needed to avoid errors on test tear down.
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1933,15 +2132,17 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
|
| kBackgroundRouteId2));
|
| EXPECT_TRUE(mock_timer_->IsRunning());
|
|
|
| - scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
|
| + web_contents_background_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(mock_timer_->IsRunning());
|
|
|
| - scheduler_.OnVisibilityChanged(
|
| - kBackgroundChildId2, kBackgroundRouteId2, true);
|
| + web_contents_background_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| // To avoid errors on test tear down.
|
| scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest,
|
| @@ -1964,7 +2165,8 @@ TEST_F(ResourceSchedulerTest,
|
| kBackgroundRouteId));
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| - scheduler_.OnVisibilityChanged(kBackgroundChildId, kBackgroundRouteId, true);
|
| + web_contents_background_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(ResourceScheduler::ACTIVE_AND_LOADING,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId,
|
| kBackgroundRouteId));
|
| @@ -2098,6 +2300,52 @@ TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) {
|
| EXPECT_TRUE(low->started());
|
| }
|
|
|
| +TEST_F(ResourceSchedulerTest, CheckInitialVisibility) {
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2));
|
| + EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2,
|
| + kBackgroundRouteId2));
|
| +
|
| + scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| + scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| +}
|
| +
|
| +TEST_F(ResourceSchedulerTest, GetVisualSignalFromWebContents) {
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, visual_observer_2_, false);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + visual_observer_background_2_,
|
| + false);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + web_contents_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // Change visibility of web contents.
|
| + web_contents_2_->WasHidden();
|
| + web_contents_background_2_->WasShown();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // The clients get the visual signal from web contents.
|
| + EXPECT_FALSE(scheduler_.IsClientVisibleForTesting(kChildId2, kRouteId2));
|
| + EXPECT_TRUE(scheduler_.IsClientVisibleForTesting(kBackgroundChildId2,
|
| + kBackgroundRouteId2));
|
| +
|
| + scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| + scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| + base::RunLoop().RunUntilIdle();
|
| +}
|
| +
|
| } // unnamed namespace
|
|
|
| } // namespace content
|
|
|