| 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 ea4fc023fa0fbf6e888d355e25ed6c426c26d9a7..920574578812aaaf6c37f1459a043a3100c54383 100644
|
| --- a/content/browser/loader/resource_scheduler_unittest.cc
|
| +++ b/content/browser/loader/resource_scheduler_unittest.cc
|
| @@ -19,6 +19,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 +143,61 @@ 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()));
|
| +
|
| + web_contents_->WasShown();
|
| + web_contents_background_->WasHidden();
|
| + web_contents_2_->WasShown();
|
| + web_contents_background_2_->WasHidden();
|
| +
|
| + // 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_.OnClientCreated(kChildId, kRouteId, web_contents_.get());
|
| scheduler_.OnVisibilityChanged(kChildId, kRouteId, true);
|
| - scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
|
| + scheduler_.OnClientCreated(kBackgroundChildId,
|
| + kBackgroundRouteId,
|
| + web_contents_background_.get());
|
| context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
|
| }
|
|
|
| virtual ~ResourceSchedulerTest() {
|
| scheduler_.OnClientDeleted(kChildId, kRouteId);
|
| scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
|
| +
|
| + web_contents_.reset();
|
| + web_contents_background_.reset();
|
| + web_contents_2_.reset();
|
| + web_contents_background_2_.reset();
|
| + browser_context_.reset();
|
| + render_process_host_factory_.reset();
|
| }
|
|
|
| scoped_ptr<net::URLRequest> NewURLRequestWithChildAndRoute(
|
| @@ -279,6 +322,12 @@ 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<WebContents> web_contents_;
|
| + scoped_ptr<WebContents> web_contents_background_;
|
| + scoped_ptr<WebContents> web_contents_2_;
|
| + scoped_ptr<WebContents> web_contents_background_2_;
|
| };
|
|
|
| TEST_F(ResourceSchedulerTest, OneIsolatedLowRequest) {
|
| @@ -638,7 +687,9 @@ 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,
|
| + web_contents_background_2_.get());
|
|
|
| EXPECT_EQ(ResourceScheduler::THROTTLED,
|
| scheduler_.GetClientStateForTesting(kBackgroundChildId2,
|
| @@ -1022,8 +1073,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| @@ -1078,8 +1131,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
|
| @@ -1135,8 +1190,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| @@ -1190,8 +1247,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| @@ -1246,8 +1305,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
|
|
| @@ -1315,8 +1376,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
|
| @@ -1385,8 +1448,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| @@ -1454,8 +1519,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnLoadingStateChanged(
|
| kBackgroundChildId2, kBackgroundRouteId2, true);
|
| scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
|
| @@ -1525,8 +1592,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
|
|
| // 1 visible and 2 hidden loading, 1 visible loaded
|
| scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| @@ -1596,8 +1665,10 @@ 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_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
|
|
| // 2 visible loading, 1 hidden loading, 1 hidden loaded
|
| @@ -1651,8 +1722,10 @@ 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_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
|
|
| // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
|
| @@ -1718,8 +1791,10 @@ 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, web_contents_2_.get());
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
|
|
| // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
|
| @@ -1856,7 +1931,9 @@ TEST_F(ResourceSchedulerTest, CoalescedClientBecomesAudibleStopsTimer) {
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1879,13 +1956,17 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
|
|
| // To avoid errors on test tear down.
|
| - scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId);
|
| + scheduler_.OnClientCreated(kBackgroundChildId,
|
| + kBackgroundRouteId,
|
| + web_contents_background_.get());
|
| }
|
|
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -1916,7 +1997,9 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
|
| TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
|
| scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
|
| true /* should_coalesce */);
|
| - scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
|
| EXPECT_FALSE(mock_timer_->IsRunning());
|
| @@ -2097,6 +2180,29 @@ TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) {
|
| EXPECT_TRUE(low->started());
|
| }
|
|
|
| +TEST_F(ResourceSchedulerTest, GetVisualSignalFromWebContents) {
|
| + scheduler_.OnClientCreated(kChildId2, kRouteId2, web_contents_2_.get());
|
| + scheduler_.OnVisibilityChanged(kChildId2, kRouteId2, true);
|
| + scheduler_.OnClientCreated(kBackgroundChildId2,
|
| + kBackgroundRouteId2,
|
| + web_contents_background_2_.get());
|
| + EXPECT_TRUE(scheduler_.ClientIsVisible(kChildId2, kRouteId2));
|
| + EXPECT_FALSE(scheduler_.ClientIsVisible(kBackgroundChildId2,
|
| + kBackgroundRouteId2));
|
| +
|
| + // Change visibility of web contents.
|
| + web_contents_2_->WasHidden();
|
| + web_contents_background_2_->WasShown();
|
| +
|
| + // The clients get the visual signal from web contents.
|
| + EXPECT_FALSE(scheduler_.ClientIsVisible(kChildId2, kRouteId2));
|
| + EXPECT_TRUE(scheduler_.ClientIsVisible(kBackgroundChildId2,
|
| + kBackgroundRouteId2));
|
| +
|
| + scheduler_.OnClientDeleted(kChildId2, kRouteId2);
|
| + scheduler_.OnClientDeleted(kBackgroundChildId2, kBackgroundRouteId2);
|
| +}
|
| +
|
| } // unnamed namespace
|
|
|
| } // namespace content
|
|
|