OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 | 196 |
197 private: | 197 private: |
198 int process_id_; | 198 int process_id_; |
199 int routing_id_; | 199 int routing_id_; |
200 bool deleted_; | 200 bool deleted_; |
201 | 201 |
202 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); | 202 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); |
203 }; | 203 }; |
204 | 204 |
| 205 // This WebContents observer keep track of its RVH change. |
| 206 class RenderViewHostChangedObserver : public WebContentsObserver { |
| 207 public: |
| 208 RenderViewHostChangedObserver(WebContents* web_contents) |
| 209 : WebContentsObserver(web_contents), host_changed_(false) {} |
| 210 |
| 211 // WebContentsObserver. |
| 212 void RenderViewHostChanged(RenderViewHost* old_host, |
| 213 RenderViewHost* new_host) override { |
| 214 host_changed_ = true; |
| 215 } |
| 216 |
| 217 bool DidHostChange() { |
| 218 bool host_changed = host_changed_; |
| 219 Reset(); |
| 220 return host_changed; |
| 221 } |
| 222 |
| 223 void Reset() { host_changed_ = false; } |
| 224 |
| 225 private: |
| 226 bool host_changed_; |
| 227 DISALLOW_COPY_AND_ASSIGN(RenderViewHostChangedObserver); |
| 228 }; |
| 229 |
205 // This observer is used to check whether IPC messages are being filtered for | 230 // This observer is used to check whether IPC messages are being filtered for |
206 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon | 231 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon |
207 // update events, which the FilterMessagesWhileSwappedOut test simulates being | 232 // update events, which the FilterMessagesWhileSwappedOut test simulates being |
208 // sent. The test is successful if the event is not observed. | 233 // sent. The test is successful if the event is not observed. |
209 // See http://crbug.com/351815 | 234 // See http://crbug.com/351815 |
210 class PluginFaviconMessageObserver : public WebContentsObserver { | 235 class PluginFaviconMessageObserver : public WebContentsObserver { |
211 public: | 236 public: |
212 PluginFaviconMessageObserver(WebContents* web_contents) | 237 PluginFaviconMessageObserver(WebContents* web_contents) |
213 : WebContentsObserver(web_contents), | 238 : WebContentsObserver(web_contents), |
214 plugin_crashed_(false), | 239 plugin_crashed_(false), |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 EXPECT_EQ(instance, rvh->GetSiteInstance()); | 950 EXPECT_EQ(instance, rvh->GetSiteInstance()); |
926 EXPECT_EQ(web_contents.get(), rvh->GetDelegate()); | 951 EXPECT_EQ(web_contents.get(), rvh->GetDelegate()); |
927 EXPECT_EQ(web_contents.get(), rfh->delegate()); | 952 EXPECT_EQ(web_contents.get(), rfh->delegate()); |
928 EXPECT_TRUE(manager->GetRenderWidgetHostView()); | 953 EXPECT_TRUE(manager->GetRenderWidgetHostView()); |
929 EXPECT_FALSE(manager->pending_render_view_host()); | 954 EXPECT_FALSE(manager->pending_render_view_host()); |
930 } | 955 } |
931 | 956 |
932 // Tests the Navigate function. We navigate three sites consecutively and check | 957 // Tests the Navigate function. We navigate three sites consecutively and check |
933 // how the pending/committed RenderViewHost are modified. | 958 // how the pending/committed RenderViewHost are modified. |
934 TEST_F(RenderFrameHostManagerTest, Navigate) { | 959 TEST_F(RenderFrameHostManagerTest, Navigate) { |
935 TestNotificationTracker notifications; | |
936 | |
937 SiteInstance* instance = SiteInstance::Create(browser_context()); | 960 SiteInstance* instance = SiteInstance::Create(browser_context()); |
938 | 961 |
939 scoped_ptr<TestWebContents> web_contents( | 962 scoped_ptr<TestWebContents> web_contents( |
940 TestWebContents::Create(browser_context(), instance)); | 963 TestWebContents::Create(browser_context(), instance)); |
941 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 964 RenderViewHostChangedObserver change_observer(web_contents.get()); |
942 Source<WebContents>(web_contents.get())); | |
943 | 965 |
944 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 966 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
945 RenderFrameHostImpl* host = NULL; | 967 RenderFrameHostImpl* host = NULL; |
946 | 968 |
947 // 1) The first navigation. -------------------------- | 969 // 1) The first navigation. -------------------------- |
948 const GURL kUrl1("http://www.google.com/"); | 970 const GURL kUrl1("http://www.google.com/"); |
949 NavigationEntryImpl entry1( | 971 NavigationEntryImpl entry1( |
950 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), | 972 NULL /* instance */, -1 /* page_id */, kUrl1, Referrer(), |
951 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, | 973 base::string16() /* title */, ui::PAGE_TRANSITION_TYPED, |
952 false /* is_renderer_init */); | 974 false /* is_renderer_init */); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 NULL /* instance */, -1 /* page_id */, kUrl3, | 1011 NULL /* instance */, -1 /* page_id */, kUrl3, |
990 Referrer(kUrl2, blink::WebReferrerPolicyDefault), | 1012 Referrer(kUrl2, blink::WebReferrerPolicyDefault), |
991 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, | 1013 base::string16() /* title */, ui::PAGE_TRANSITION_LINK, |
992 false /* is_renderer_init */); | 1014 false /* is_renderer_init */); |
993 host = NavigateToEntry(manager, entry3); | 1015 host = NavigateToEntry(manager, entry3); |
994 | 1016 |
995 // A new RenderFrameHost should be created. | 1017 // A new RenderFrameHost should be created. |
996 EXPECT_TRUE(GetPendingFrameHost(manager)); | 1018 EXPECT_TRUE(GetPendingFrameHost(manager)); |
997 ASSERT_EQ(host, GetPendingFrameHost(manager)); | 1019 ASSERT_EQ(host, GetPendingFrameHost(manager)); |
998 | 1020 |
999 notifications.Reset(); | 1021 change_observer.Reset(); |
1000 | 1022 |
1001 // Commit. | 1023 // Commit. |
1002 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); | 1024 manager->DidNavigateFrame(GetPendingFrameHost(manager), true); |
1003 EXPECT_TRUE(host == manager->current_frame_host()); | 1025 EXPECT_TRUE(host == manager->current_frame_host()); |
1004 ASSERT_TRUE(host); | 1026 ASSERT_TRUE(host); |
1005 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); | 1027 EXPECT_TRUE(host->GetSiteInstance()->HasSite()); |
1006 // Check the pending RenderFrameHost has been committed. | 1028 // Check the pending RenderFrameHost has been committed. |
1007 EXPECT_FALSE(GetPendingFrameHost(manager)); | 1029 EXPECT_FALSE(GetPendingFrameHost(manager)); |
1008 | 1030 |
1009 // We should observe a notification. | 1031 // We should observe RVH changed event. |
1010 EXPECT_TRUE( | 1032 EXPECT_TRUE(change_observer.DidHostChange()); |
1011 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | |
1012 } | 1033 } |
1013 | 1034 |
1014 // Tests WebUI creation. | 1035 // Tests WebUI creation. |
1015 TEST_F(RenderFrameHostManagerTest, WebUI) { | 1036 TEST_F(RenderFrameHostManagerTest, WebUI) { |
1016 set_should_create_webui(true); | 1037 set_should_create_webui(true); |
1017 SiteInstance* instance = SiteInstance::Create(browser_context()); | 1038 SiteInstance* instance = SiteInstance::Create(browser_context()); |
1018 | 1039 |
1019 scoped_ptr<TestWebContents> web_contents( | 1040 scoped_ptr<TestWebContents> web_contents( |
1020 TestWebContents::Create(browser_context(), instance)); | 1041 TestWebContents::Create(browser_context(), instance)); |
1021 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1042 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); | 1626 EXPECT_TRUE(opener1_manager->IsRVHOnSwappedOutList(opener1_rvh)); |
1606 EXPECT_TRUE(opener1_rfh->is_swapped_out()); | 1627 EXPECT_TRUE(opener1_rfh->is_swapped_out()); |
1607 EXPECT_FALSE(opener1_rvh->is_active()); | 1628 EXPECT_FALSE(opener1_rvh->is_active()); |
1608 | 1629 |
1609 // Ensure the new RVH has WebUI bindings. | 1630 // Ensure the new RVH has WebUI bindings. |
1610 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); | 1631 EXPECT_TRUE(rvh2->GetEnabledBindings() & BINDINGS_POLICY_WEB_UI); |
1611 } | 1632 } |
1612 | 1633 |
1613 // Test that we reuse the same guest SiteInstance if we navigate across sites. | 1634 // Test that we reuse the same guest SiteInstance if we navigate across sites. |
1614 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { | 1635 TEST_F(RenderFrameHostManagerTest, NoSwapOnGuestNavigations) { |
1615 TestNotificationTracker notifications; | |
1616 | |
1617 GURL guest_url(std::string(kGuestScheme).append("://abc123")); | 1636 GURL guest_url(std::string(kGuestScheme).append("://abc123")); |
1618 SiteInstance* instance = | 1637 SiteInstance* instance = |
1619 SiteInstance::CreateForURL(browser_context(), guest_url); | 1638 SiteInstance::CreateForURL(browser_context(), guest_url); |
1620 scoped_ptr<TestWebContents> web_contents( | 1639 scoped_ptr<TestWebContents> web_contents( |
1621 TestWebContents::Create(browser_context(), instance)); | 1640 TestWebContents::Create(browser_context(), instance)); |
1622 | 1641 |
1623 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1642 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1624 | 1643 |
1625 RenderFrameHostImpl* host = NULL; | 1644 RenderFrameHostImpl* host = NULL; |
1626 | 1645 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 // Test that we cancel a pending RVH if we close the tab while it's pending. | 1687 // Test that we cancel a pending RVH if we close the tab while it's pending. |
1669 // http://crbug.com/294697. | 1688 // http://crbug.com/294697. |
1670 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyClose) { | 1689 TEST_F(RenderFrameHostManagerTest, NavigateWithEarlyClose) { |
1671 TestNotificationTracker notifications; | 1690 TestNotificationTracker notifications; |
1672 | 1691 |
1673 SiteInstance* instance = SiteInstance::Create(browser_context()); | 1692 SiteInstance* instance = SiteInstance::Create(browser_context()); |
1674 | 1693 |
1675 BeforeUnloadFiredWebContentsDelegate delegate; | 1694 BeforeUnloadFiredWebContentsDelegate delegate; |
1676 scoped_ptr<TestWebContents> web_contents( | 1695 scoped_ptr<TestWebContents> web_contents( |
1677 TestWebContents::Create(browser_context(), instance)); | 1696 TestWebContents::Create(browser_context(), instance)); |
| 1697 RenderViewHostChangedObserver change_observer(web_contents.get()); |
1678 web_contents->SetDelegate(&delegate); | 1698 web_contents->SetDelegate(&delegate); |
1679 notifications.ListenFor(NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
1680 Source<WebContents>(web_contents.get())); | |
1681 | 1699 |
1682 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); | 1700 RenderFrameHostManager* manager = web_contents->GetRenderManagerForTesting(); |
1683 | 1701 |
1684 // 1) The first navigation. -------------------------- | 1702 // 1) The first navigation. -------------------------- |
1685 const GURL kUrl1("http://www.google.com/"); | 1703 const GURL kUrl1("http://www.google.com/"); |
1686 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, | 1704 NavigationEntryImpl entry1(NULL /* instance */, -1 /* page_id */, kUrl1, |
1687 Referrer(), base::string16() /* title */, | 1705 Referrer(), base::string16() /* title */, |
1688 ui::PAGE_TRANSITION_TYPED, | 1706 ui::PAGE_TRANSITION_TYPED, |
1689 false /* is_renderer_init */); | 1707 false /* is_renderer_init */); |
1690 RenderFrameHostImpl* host = NavigateToEntry(manager, entry1); | 1708 RenderFrameHostImpl* host = NavigateToEntry(manager, entry1); |
1691 | 1709 |
1692 // The RenderFrameHost created in Init will be reused. | 1710 // The RenderFrameHost created in Init will be reused. |
1693 EXPECT_EQ(host, manager->current_frame_host()); | 1711 EXPECT_EQ(host, manager->current_frame_host()); |
1694 EXPECT_FALSE(GetPendingFrameHost(manager)); | 1712 EXPECT_FALSE(GetPendingFrameHost(manager)); |
1695 | 1713 |
1696 // We should observe a notification. | 1714 // We should observe RVH changed event. |
1697 EXPECT_TRUE( | 1715 EXPECT_TRUE(change_observer.DidHostChange()); |
1698 notifications.Check1AndReset(NOTIFICATION_RENDER_VIEW_HOST_CHANGED)); | |
1699 notifications.Reset(); | |
1700 | 1716 |
1701 // Commit. | 1717 // Commit. |
1702 manager->DidNavigateFrame(host, true); | 1718 manager->DidNavigateFrame(host, true); |
1703 | 1719 |
1704 // Commit to SiteInstance should be delayed until RenderFrame commits. | 1720 // Commit to SiteInstance should be delayed until RenderFrame commits. |
1705 EXPECT_EQ(host, manager->current_frame_host()); | 1721 EXPECT_EQ(host, manager->current_frame_host()); |
1706 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); | 1722 EXPECT_FALSE(host->GetSiteInstance()->HasSite()); |
1707 host->GetSiteInstance()->SetSite(kUrl1); | 1723 host->GetSiteInstance()->SetSite(kUrl1); |
1708 | 1724 |
1709 // 2) Cross-site navigate to next site. ------------------------- | 1725 // 2) Cross-site navigate to next site. ------------------------- |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2142 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2127 contents2->NavigateAndCommit(kUrl3); | 2143 contents2->NavigateAndCommit(kUrl3); |
2128 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2144 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2129 EXPECT_NE(nullptr, | 2145 EXPECT_NE(nullptr, |
2130 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2146 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
2131 EXPECT_EQ(nullptr, | 2147 EXPECT_EQ(nullptr, |
2132 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2148 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
2133 } | 2149 } |
2134 | 2150 |
2135 } // namespace content | 2151 } // namespace content |
OLD | NEW |