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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/navigation_controller_impl.h" | 8 #include "content/browser/frame_host/navigation_controller_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/frame_host/navigator.h" | 10 #include "content/browser/frame_host/navigator.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 | 118 |
119 private: | 119 private: |
120 int process_id_; | 120 int process_id_; |
121 int routing_id_; | 121 int routing_id_; |
122 bool deleted_; | 122 bool deleted_; |
123 | 123 |
124 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); | 124 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); |
125 }; | 125 }; |
126 | 126 |
127 | 127 |
128 // This observer keeps track of the last deleted RenderViewHost to avoid | |
129 // accessing it and causing use-after-free condition. | |
130 class RenderFrameHostDeletedObserver : public WebContentsObserver { | |
131 public: | |
132 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) | |
133 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), | |
134 process_id_(rfh->GetProcess()->GetID()), | |
135 routing_id_(rfh->GetRoutingID()), | |
136 deleted_(false) { | |
137 } | |
138 | |
139 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE { | |
140 if (render_frame_host->GetProcess()->GetID() == process_id_ && | |
141 render_frame_host->GetRoutingID() == routing_id_) { | |
142 deleted_ = true; | |
143 } | |
144 } | |
145 | |
146 bool deleted() { | |
147 return deleted_; | |
148 } | |
149 | |
150 private: | |
151 int process_id_; | |
152 int routing_id_; | |
153 bool deleted_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); | |
156 }; | |
157 | |
158 | |
128 // This observer is used to check whether IPC messages are being filtered for | 159 // This observer is used to check whether IPC messages are being filtered for |
129 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon | 160 // swapped out RenderFrameHost objects. It observes the plugin crash and favicon |
130 // update events, which the FilterMessagesWhileSwappedOut test simulates being | 161 // update events, which the FilterMessagesWhileSwappedOut test simulates being |
131 // sent. The test is successful if the event is not observed. | 162 // sent. The test is successful if the event is not observed. |
132 // See http://crbug.com/351815 | 163 // See http://crbug.com/351815 |
133 class PluginFaviconMessageObserver : public WebContentsObserver { | 164 class PluginFaviconMessageObserver : public WebContentsObserver { |
134 public: | 165 public: |
135 PluginFaviconMessageObserver(WebContents* web_contents) | 166 PluginFaviconMessageObserver(WebContents* web_contents) |
136 : WebContentsObserver(web_contents), | 167 : WebContentsObserver(web_contents), |
137 plugin_crashed_(false), | 168 plugin_crashed_(false), |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1758 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh1->rvh_state()); | 1789 EXPECT_EQ(RenderViewHostImpl::STATE_PENDING_SWAP_OUT, rvh1->rvh_state()); |
1759 | 1790 |
1760 // Simulate the swap out ack. | 1791 // Simulate the swap out ack. |
1761 rvh1->OnSwappedOut(false); | 1792 rvh1->OnSwappedOut(false); |
1762 | 1793 |
1763 // rvh1 should be swapped out. | 1794 // rvh1 should be swapped out. |
1764 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1795 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
1765 EXPECT_TRUE(rvh1->IsSwappedOut()); | 1796 EXPECT_TRUE(rvh1->IsSwappedOut()); |
1766 } | 1797 } |
1767 | 1798 |
1799 // Test that a RenderFrameHost is properly deleted or swapped out when a | |
1800 // cross-site navigation is cancelled. | |
1801 TEST_F(RenderFrameHostManagerTest, | |
1802 CancelPendingProperlyDeletesOrSwaps) { | |
1803 const GURL kUrl1("http://www.google.com/"); | |
1804 const GURL kUrl2("http://www.chromium.org/"); | |
1805 RenderFrameHostImpl* pending_rfh; | |
Charlie Reis
2014/04/11 17:42:53
= NULL;
nasko
2014/04/11 18:11:21
Done.
| |
1806 base::TimeTicks now = base::TimeTicks::Now(); | |
1807 | |
1808 // Navigate to the first page. | |
1809 contents()->NavigateAndCommit(kUrl1); | |
1810 TestRenderViewHost* rvh1 = test_rvh(); | |
1811 EXPECT_EQ(RenderViewHostImpl::STATE_DEFAULT, rvh1->rvh_state()); | |
1812 | |
1813 // Navigate to a new site, starting a cross-site navigation. | |
1814 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1815 { | |
1816 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | |
1817 ->pending_frame_host(); | |
Charlie Reis
2014/04/11 17:42:53
I would have put -> on the previous line, but I de
nasko
2014/04/11 18:11:21
clang-format dictates this :( I dislike it too.
| |
1818 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | |
1819 | |
1820 // Cancel the navigation by simulating user cancelled through beforeunload | |
Charlie Reis
2014/04/11 17:42:53
by simulating a declined beforeunload dialog.
nasko
2014/04/11 18:11:21
Done.
| |
1821 // event handler. | |
1822 main_test_rfh()->OnMessageReceived( | |
1823 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | |
1824 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
1825 | |
1826 // Since the pending RFH is the only one for the new SiteInstance, it should | |
1827 // be deleted. | |
1828 EXPECT_TRUE(rvh_deleted_observer.deleted()); | |
1829 } | |
1830 | |
1831 // Start another cross-site navigation | |
Charlie Reis
2014/04/11 17:42:53
nit: End with period.
nasko
2014/04/11 18:11:21
Done.
| |
1832 controller().LoadURL(kUrl2, Referrer(), PAGE_TRANSITION_LINK, std::string()); | |
1833 { | |
1834 pending_rfh = contents()->GetFrameTree()->root()->render_manager() | |
1835 ->pending_frame_host(); | |
1836 RenderFrameHostDeletedObserver rvh_deleted_observer(pending_rfh); | |
1837 | |
1838 // Increment the number of active views in the new SiteInstance, which will | |
1839 // cause the pending RFH to be swapped out instead of deleted. | |
1840 static_cast<SiteInstanceImpl*>( | |
1841 pending_rfh->GetSiteInstance())->increment_active_view_count(); | |
1842 | |
1843 main_test_rfh()->OnMessageReceived( | |
1844 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | |
1845 EXPECT_FALSE(contents()->cross_navigation_pending()); | |
1846 EXPECT_FALSE(rvh_deleted_observer.deleted()); | |
1847 } | |
1848 } | |
1849 | |
1768 } // namespace content | 1850 } // namespace content |
OLD | NEW |