Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / loader / resource_scheduler_unittest.cc
index a7baed1..2d1b0fe 100644 (file)
@@ -22,6 +22,7 @@
 #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_render_view_host_factory.h"
 #include "content/test/test_web_contents.h"
 #include "net/base/host_port_pair.h"
 #include "net/base/request_priority.h"
@@ -55,7 +56,7 @@ class TestRequest : public ResourceController {
         url_request_(url_request.Pass()) {
     throttle_->set_controller_for_testing(this);
   }
-  virtual ~TestRequest() {}
+  ~TestRequest() override {}
 
   bool started() const { return started_; }
 
@@ -65,7 +66,7 @@ class TestRequest : public ResourceController {
     started_ = !deferred;
   }
 
-  virtual void Cancel() OVERRIDE {
+  void Cancel() override {
     // Alert the scheduler that the request can be deleted.
     throttle_.reset(0);
   }
@@ -74,9 +75,9 @@ class TestRequest : public ResourceController {
 
  protected:
   // ResourceController interface:
-  virtual void CancelAndIgnore() OVERRIDE {}
-  virtual void CancelWithError(int error_code) OVERRIDE {}
-  virtual void Resume() OVERRIDE { started_ = true; }
+  void CancelAndIgnore() override {}
+  void CancelWithError(int error_code) override {}
+  void Resume() override { started_ = true; }
 
  private:
   bool started_;
@@ -95,7 +96,7 @@ class CancelingTestRequest : public TestRequest {
   }
 
  private:
-  virtual void Resume() OVERRIDE {
+  void Resume() override {
     TestRequest::Resume();
     request_to_cancel_.reset();
   }
@@ -105,8 +106,8 @@ class CancelingTestRequest : public TestRequest {
 
 class FakeResourceContext : public ResourceContext {
  private:
-  virtual net::HostResolver* GetHostResolver() OVERRIDE { return NULL; }
-  virtual net::URLRequestContext* GetRequestContext() OVERRIDE { return NULL; }
+  net::HostResolver* GetHostResolver() override { return NULL; }
+  net::URLRequestContext* GetRequestContext() override { return NULL; }
 };
 
 class FakeResourceMessageFilter : public ResourceMessageFilter {
@@ -124,7 +125,7 @@ class FakeResourceMessageFilter : public ResourceMessageFilter {
   }
 
  private:
-  virtual ~FakeResourceMessageFilter() {}
+  ~FakeResourceMessageFilter() override {}
 
   void GetContexts(const ResourceHostMsg_Request& request,
                    ResourceContext** resource_context,
@@ -149,12 +150,13 @@ class ResourceSchedulerTest : public testing::Test {
     scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
                                             false /* should_coalesce */);
 
-    scheduler_.OnClientCreated(kChildId, kRouteId, true);
-    scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
+    scheduler_.OnClientCreated(kChildId, kRouteId, true, false);
+    scheduler_.OnClientCreated(
+        kBackgroundChildId, kBackgroundRouteId, false, false);
     context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
   }
 
-  virtual ~ResourceSchedulerTest() {
+  ~ResourceSchedulerTest() override {
     scheduler_.OnClientDeleted(kChildId, kRouteId);
     scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
   }
@@ -185,6 +187,7 @@ class ResourceSchedulerTest : public testing::Test {
         true,                                    // allow_download
         false,                                   // has_user_gesture
         false,                                   // enable_load_timing
+        false,                                   // enable_upload_progress
         blink::WebReferrerPolicyDefault,         // referrer_policy
         blink::WebPageVisibilityStateVisible,    // visibility_state
         NULL,                                    // context
@@ -325,6 +328,18 @@ TEST_F(ResourceSchedulerTest, OneLowLoadsUntilCriticalComplete) {
   EXPECT_TRUE(low2->started());
 }
 
+TEST_F(ResourceSchedulerTest, LowDoesNotBlockCriticalComplete) {
+  scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOW));
+  scoped_ptr<TestRequest> lowest(NewRequest("http://host/lowest", net::LOWEST));
+  scoped_ptr<TestRequest> lowest2(
+      NewRequest("http://host/lowest", net::LOWEST));
+  EXPECT_TRUE(low->started());
+  EXPECT_TRUE(lowest->started());
+  EXPECT_FALSE(lowest2->started());
+  scheduler_.OnWillInsertBody(kChildId, kRouteId);
+  EXPECT_TRUE(lowest2->started());
+}
+
 TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) {
   http_server_properties_.SetSupportsSpdy(
       net::HostPortPair("spdyhost", 443), true);
@@ -661,7 +676,8 @@ TEST_F(ResourceSchedulerTest, ThrottledClientCreation) {
   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
                                           false /* should_coalesce */);
   EXPECT_TRUE(scheduler_.should_throttle());
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
 
   EXPECT_EQ(ResourceScheduler::THROTTLED,
             scheduler_.GetClientStateForTesting(kBackgroundChildId2,
@@ -1045,8 +1061,9 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
@@ -1101,8 +1118,9 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
   scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
@@ -1158,8 +1176,9 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
@@ -1213,8 +1232,9 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
@@ -1269,8 +1289,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
 
@@ -1337,13 +1358,13 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
   scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
   scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
-  scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
   // 2 audible, 2 hidden
   EXPECT_FALSE(scheduler_.active_clients_loaded());
   EXPECT_EQ(ResourceScheduler::THROTTLED,
@@ -1407,8 +1428,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
   scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
@@ -1475,14 +1497,14 @@ 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, false);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   scheduler_.OnLoadingStateChanged(
       kBackgroundChildId2, kBackgroundRouteId2, true);
   scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
   scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
   scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
-  scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
   // 2 audible, 2 hidden
   EXPECT_FALSE(scheduler_.active_clients_loaded());
   EXPECT_EQ(ResourceScheduler::THROTTLED,
@@ -1546,8 +1568,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
 
   // 1 visible and 2 hidden loading, 1 visible loaded
   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
@@ -1616,8 +1639,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
 
   // 2 visible loading, 1 hidden loading, 1 hidden loaded
   scheduler_.OnLoadingStateChanged(
@@ -1670,8 +1694,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
 
   // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
   scheduler_.OnLoadingStateChanged(
@@ -1736,8 +1761,9 @@ 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, true);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
 
   // 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
   scheduler_.OnLoadingStateChanged(
@@ -1873,7 +1899,8 @@ TEST_F(ResourceSchedulerTest, CoalescedClientBecomesAudibleStopsTimer) {
 TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
                                           true /* should_coalesce */);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   EXPECT_FALSE(mock_timer_->IsRunning());
   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
   EXPECT_FALSE(mock_timer_->IsRunning());
@@ -1896,13 +1923,15 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
   EXPECT_FALSE(mock_timer_->IsRunning());
 
   // To avoid errors on test tear down.
-  scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId, kBackgroundRouteId, false, false);
 }
 
 TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
                                           true /* should_coalesce */);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   EXPECT_FALSE(mock_timer_->IsRunning());
   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
   EXPECT_FALSE(mock_timer_->IsRunning());
@@ -1933,7 +1962,8 @@ TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
 TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
   scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
                                           true /* should_coalesce */);
-  scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+  scheduler_.OnClientCreated(
+      kBackgroundChildId2, kBackgroundRouteId2, false, false);
   EXPECT_FALSE(mock_timer_->IsRunning());
   scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
   EXPECT_FALSE(mock_timer_->IsRunning());
@@ -2116,11 +2146,14 @@ TEST_F(ResourceSchedulerTest, CoalescedRequestsWaitForNextTimer) {
 
 TEST_F(ResourceSchedulerTest, GetVisualSignalFromRenderViewHost) {
   scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory;
+  scoped_ptr<TestRenderViewHostFactory> render_view_host_factory;
   scoped_ptr<TestBrowserContext> browser_context;
   scoped_ptr<TestWebContents> web_contents_1;
   scoped_ptr<TestWebContents> web_contents_2;
-
   render_process_host_factory.reset(new MockRenderProcessHostFactory());
+  render_view_host_factory.reset(
+      new TestRenderViewHostFactory(render_process_host_factory.get()));
+
   browser_context.reset(new TestBrowserContext());
   scoped_refptr<SiteInstance> site_instance_1 =
       SiteInstance::Create(browser_context.get());