Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / web_contents_impl_unittest.cc
index 8ac7161..e04b441 100644 (file)
@@ -6,9 +6,11 @@
 #include "base/strings/utf_string_conversions.h"
 #include "content/browser/frame_host/interstitial_page_impl.h"
 #include "content/browser/frame_host/navigation_entry_impl.h"
+#include "content/browser/renderer_host/cross_site_transferring_request.h"
 #include "content/browser/renderer_host/render_view_host_impl.h"
 #include "content/browser/site_instance_impl.h"
 #include "content/browser/webui/web_ui_controller_factory_registry.h"
+#include "content/common/frame_messages.h"
 #include "content/common/view_messages.h"
 #include "content/public/browser/global_request_id.h"
 #include "content/public/browser/interstitial_page_delegate.h"
@@ -23,7 +25,6 @@
 #include "content/public/common/url_constants.h"
 #include "content/public/common/url_utils.h"
 #include "content/public/test/mock_render_process_host.h"
-#include "content/public/test/test_browser_thread.h"
 #include "content/public/test/test_utils.h"
 #include "content/test/test_content_browser_client.h"
 #include "content/test/test_content_client.h"
@@ -151,7 +152,7 @@ class TestInterstitialPage : public InterstitialPageImpl {
   }
 
   void TestDidNavigate(int page_id, const GURL& url) {
-    ViewHostMsg_FrameNavigate_Params params;
+    FrameHostMsg_DidCommitProvisionalLoad_Params params;
     InitNavigateParams(&params, page_id, url, PAGE_TRANSITION_TYPED);
     DidNavigate(GetRenderViewHostForTesting(), params);
   }
@@ -298,7 +299,7 @@ class TestWebContentsObserver : public WebContentsObserver {
 TEST_F(WebContentsImplTest, UpdateTitle) {
   NavigationControllerImpl& cont =
       static_cast<NavigationControllerImpl&>(controller());
-  ViewHostMsg_FrameNavigate_Params params;
+  FrameHostMsg_DidCommitProvisionalLoad_Params params;
   InitNavigateParams(&params, 0, GURL(kAboutBlankURL), PAGE_TRANSITION_TYPED);
 
   LoadCommittedDetails details;
@@ -346,7 +347,7 @@ TEST_F(WebContentsImplTest, NTPViewSource) {
   EXPECT_TRUE(process()->sink().GetFirstMessageMatching(
       ViewMsg_EnableViewSourceMode::ID));
 
-  ViewHostMsg_FrameNavigate_Params params;
+  FrameHostMsg_DidCommitProvisionalLoad_Params params;
   InitNavigateParams(&params, 0, kGURL, PAGE_TRANSITION_TYPED);
   LoadCommittedDetails details;
   cont.RendererDidNavigate(test_rvh(), params, &details);
@@ -512,6 +513,7 @@ TEST_F(WebContentsImplTest, CrossSiteBoundaries) {
   EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
       IsOnSwappedOutList(pending_rfh));
   EXPECT_EQ(pending_rvh_delete_count, 0);
+  pending_rvh->OnSwappedOut(false);
 
   // Close contents and ensure RVHs are deleted.
   DeleteContents();
@@ -709,6 +711,7 @@ TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) {
   EXPECT_TRUE(contents()->GetRenderManagerForTesting()->IsOnSwappedOutList(
       orig_rfh));
   EXPECT_EQ(orig_rvh_delete_count, 0);
+  orig_rvh->OnSwappedOut(false);
 
   // Close contents and ensure RVHs are deleted.
   DeleteContents();
@@ -1086,14 +1089,15 @@ TEST_F(WebContentsImplTest, CrossSiteCantPreemptAfterUnload) {
   std::vector<GURL> url_chain;
   url_chain.push_back(GURL());
   contents()->GetRenderManagerForTesting()->OnCrossSiteResponse(
-      pending_rvh, GlobalRequestID(0, 0), false, url_chain, Referrer(),
-      PAGE_TRANSITION_TYPED, 1, false);
+      pending_rvh, GlobalRequestID(0, 0),
+      scoped_ptr<CrossSiteTransferringRequest>(), url_chain,
+      Referrer(), PAGE_TRANSITION_TYPED, 1, false);
 
   // Suppose the original renderer navigates now, while the unload request is in
   // flight.  We should ignore it, wait for the unload ack, and let the pending
   // request continue.  Otherwise, the contents may close spontaneously or stop
   // responding to navigation requests.  (See bug 23942.)
-  ViewHostMsg_FrameNavigate_Params params1a;
+  FrameHostMsg_DidCommitProvisionalLoad_Params params1a;
   InitNavigateParams(&params1a, 2, GURL("http://www.google.com/foo"),
                      PAGE_TRANSITION_TYPED);
   orig_rvh->SendNavigate(2, GURL("http://www.google.com/foo"));
@@ -1136,7 +1140,7 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
   EXPECT_TRUE(contents()->cross_navigation_pending());
 
   // Simulate swap out message when the response arrives.
-  orig_rvh->set_is_swapped_out(true);
+  orig_rvh->OnSwappedOut(false);
 
   // Suppose the navigation doesn't get a chance to commit, and the user
   // navigates in the current RVH's SiteInstance.
@@ -1148,7 +1152,7 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) {
   SiteInstance* instance2 = contents()->GetSiteInstance();
   EXPECT_FALSE(contents()->cross_navigation_pending());
   EXPECT_EQ(orig_rvh, rvh());
-  EXPECT_FALSE(orig_rvh->is_swapped_out());
+  EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, orig_rvh->rvh_state());
   EXPECT_EQ(instance1, instance2);
   EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL);
 }
@@ -2170,4 +2174,62 @@ TEST_F(WebContentsImplTest, PendingContents) {
   EXPECT_EQ(NULL, contents()->GetCreatedWindow(route_id));
 }
 
+TEST_F(WebContentsImplTest, CapturerOverridesPreferredSize) {
+  const gfx::Size original_preferred_size(1024, 768);
+  contents()->UpdatePreferredSize(original_preferred_size);
+
+  // With no capturers, expect the preferred size to be the one propagated into
+  // WebContentsImpl via the RenderViewHostDelegate interface.
+  EXPECT_EQ(contents()->GetCapturerCount(), 0);
+  EXPECT_EQ(original_preferred_size, contents()->GetPreferredSize());
+
+  // Increment capturer count, but without specifying a capture size.  Expect
+  // a "not set" preferred size.
+  contents()->IncrementCapturerCount(gfx::Size());
+  EXPECT_EQ(1, contents()->GetCapturerCount());
+  EXPECT_EQ(gfx::Size(), contents()->GetPreferredSize());
+
+  // Increment capturer count again, but with an overriding capture size.
+  // Expect preferred size to now be overridden to the capture size.
+  const gfx::Size capture_size(1280, 720);
+  contents()->IncrementCapturerCount(capture_size);
+  EXPECT_EQ(2, contents()->GetCapturerCount());
+  EXPECT_EQ(capture_size, contents()->GetPreferredSize());
+
+  // Increment capturer count a third time, but the expect that the preferred
+  // size is still the first capture size.
+  const gfx::Size another_capture_size(720, 480);
+  contents()->IncrementCapturerCount(another_capture_size);
+  EXPECT_EQ(3, contents()->GetCapturerCount());
+  EXPECT_EQ(capture_size, contents()->GetPreferredSize());
+
+  // Decrement capturer count twice, but expect the preferred size to still be
+  // overridden.
+  contents()->DecrementCapturerCount();
+  contents()->DecrementCapturerCount();
+  EXPECT_EQ(1, contents()->GetCapturerCount());
+  EXPECT_EQ(capture_size, contents()->GetPreferredSize());
+
+  // Decrement capturer count, and since the count has dropped to zero, the
+  // original preferred size should be restored.
+  contents()->DecrementCapturerCount();
+  EXPECT_EQ(0, contents()->GetCapturerCount());
+  EXPECT_EQ(original_preferred_size, contents()->GetPreferredSize());
+}
+
+// Tests that GetLastActiveTime starts with a real, non-zero time and updates
+// on activity.
+TEST_F(WebContentsImplTest, GetLastActiveTime) {
+  // The WebContents starts with a valid creation time.
+  EXPECT_FALSE(contents()->GetLastActiveTime().is_null());
+
+  // Reset the last active time to a known-bad value.
+  contents()->last_active_time_ = base::TimeTicks();
+  ASSERT_TRUE(contents()->GetLastActiveTime().is_null());
+
+  // Simulate activating the WebContents. The active time should update.
+  contents()->WasShown();
+  EXPECT_FALSE(contents()->GetLastActiveTime().is_null());
+}
+
 }  // namespace content