Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 4097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4108 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4108 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4109 MAYBE_RenderViewHostPendingDeletionIsNotReused) { | 4109 MAYBE_RenderViewHostPendingDeletionIsNotReused) { |
| 4110 GURL a_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 4110 GURL a_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 4111 NavigateToURL(shell(), a_url); | 4111 NavigateToURL(shell(), a_url); |
| 4112 | 4112 |
| 4113 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 4113 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 4114 ->GetFrameTree() | 4114 ->GetFrameTree() |
| 4115 ->root(); | 4115 ->root(); |
| 4116 RenderFrameHostImpl* rfh = root->current_frame_host(); | 4116 RenderFrameHostImpl* rfh = root->current_frame_host(); |
| 4117 RenderViewHostImpl* rvh = rfh->render_view_host(); | 4117 RenderViewHostImpl* rvh = rfh->render_view_host(); |
| 4118 int rvh_routing_id = rvh->GetRoutingID(); | |
| 4119 SiteInstanceImpl* site_instance = rfh->GetSiteInstance(); | |
| 4118 RenderFrameDeletedObserver deleted_observer(rfh); | 4120 RenderFrameDeletedObserver deleted_observer(rfh); |
| 4119 | 4121 |
| 4120 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's | 4122 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's |
| 4121 // process. | 4123 // process. |
| 4122 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); | 4124 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); |
| 4123 rfh->GetProcess()->AddFilter(filter.get()); | 4125 rfh->GetProcess()->AddFilter(filter.get()); |
| 4124 | 4126 |
| 4125 // Navigate to B. This must wait for DidCommitProvisionalLoad, as opposed to | 4127 // Navigate to B. This must wait for DidCommitProvisionalLoad, as opposed to |
| 4126 // DidStopLoading, since otherwise the SwapOut timer might call OnSwappedOut | 4128 // DidStopLoading, since otherwise the SwapOut timer might call OnSwappedOut |
| 4127 // and destroy |rvh| before its pending deletion status is checked. | 4129 // and destroy |rvh| before its pending deletion status is checked. |
| 4128 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 4130 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 4129 TestFrameNavigationObserver commit_observer(root); | 4131 TestFrameNavigationObserver commit_observer(root); |
| 4130 shell()->LoadURL(b_url); | 4132 shell()->LoadURL(b_url); |
| 4131 commit_observer.WaitForCommit(); | 4133 commit_observer.WaitForCommit(); |
| 4134 EXPECT_FALSE(deleted_observer.deleted()); | |
| 4135 rfh->ResetSwapOutTimerForTesting(); | |
| 4132 | 4136 |
| 4133 // Since the SwapOut ACK for A->B is dropped, the first page's | 4137 // Since the SwapOut ACK for A->B is dropped, the first page's |
| 4134 // RenderFrameHost and RenderViewHost should be pending deletion after the | 4138 // RenderFrameHost and RenderViewHost should be pending deletion after the |
| 4135 // last navigation. | 4139 // last navigation. |
| 4136 EXPECT_TRUE(root->render_manager()->IsPendingDeletion(rfh)); | 4140 EXPECT_TRUE(root->render_manager()->IsPendingDeletion(rfh)); |
| 4137 EXPECT_TRUE(rvh->is_pending_deletion()); | 4141 EXPECT_TRUE(root->render_manager()->IsViewPendingDeletion(rvh)); |
| 4138 | 4142 |
| 4139 // Wait for process A to exit so we can reinitialize it cleanly for the next | 4143 // Wait for process A to exit so we can reinitialize it cleanly for the next |
| 4140 // navigation. This can be removed once https://crbug.com/535246 is fixed. | 4144 // navigation. This can be removed once https://crbug.com/535246 is fixed. |
| 4141 RenderProcessHostWatcher process_exit_observer( | 4145 RenderProcessHostWatcher process_exit_observer( |
| 4142 rvh->GetProcess(), | 4146 rvh->GetProcess(), |
| 4143 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 4147 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 4144 process_exit_observer.Wait(); | 4148 process_exit_observer.Wait(); |
| 4145 | 4149 |
| 4146 // Start a navigation back to A and check that the RenderViewHost wasn't | 4150 // Start a navigation back to A and check that the RenderViewHost wasn't |
| 4147 // reused. | 4151 // reused. |
| 4148 TestNavigationObserver navigation_observer(shell()->web_contents()); | 4152 TestNavigationObserver navigation_observer(shell()->web_contents()); |
| 4149 shell()->LoadURL(a_url); | 4153 shell()->LoadURL(a_url); |
| 4150 RenderViewHostImpl* pending_rvh = | 4154 RenderViewHostImpl* pending_rvh = |
| 4151 IsBrowserSideNavigationEnabled() | 4155 IsBrowserSideNavigationEnabled() |
| 4152 ? root->render_manager()->speculative_frame_host()->render_view_host() | 4156 ? root->render_manager()->speculative_frame_host()->render_view_host() |
| 4153 : root->render_manager()->pending_render_view_host(); | 4157 : root->render_manager()->pending_render_view_host(); |
| 4154 EXPECT_EQ(rvh->GetSiteInstance(), pending_rvh->GetSiteInstance()); | 4158 EXPECT_EQ(site_instance, pending_rvh->GetSiteInstance()); |
| 4155 EXPECT_NE(rvh, pending_rvh); | 4159 EXPECT_NE(rvh_routing_id, pending_rvh->GetRoutingID()); |
| 4156 | 4160 |
| 4157 // Simulate that the dropped SwapOut ACK message arrives now on the original | 4161 // TODO(alexmos, creis): Once https://crbug.com/535246 is fixed and the |
| 4158 // RenderFrameHost, which should now get deleted. | 4162 // process_exit_observer is not needed above, we'll need to simulate that the |
| 4159 rfh->OnSwappedOut(); | 4163 // dropped SwapOut ACK message arrives now on the original RenderFrameHost, |
| 4164 // causing it to be deleted. | |
| 4160 EXPECT_TRUE(deleted_observer.deleted()); | 4165 EXPECT_TRUE(deleted_observer.deleted()); |
| 4161 | 4166 |
| 4162 // Make sure the last navigation finishes without crashing. | 4167 // Make sure the last navigation finishes without crashing. |
| 4163 navigation_observer.Wait(); | 4168 navigation_observer.Wait(); |
| 4164 } | 4169 } |
| 4165 | 4170 |
| 4171 // Test for https://crbug.com/591478, where navigating to a cross-site page with | |
| 4172 // a subframe on the old site could cause the old RenderViewHost (now pending | |
| 4173 // deletion) to be reused. | |
| 4174 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 4175 DontReusePendingDeleteRenderViewHostForSubframe) { | |
| 4176 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
| 4177 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 4178 | |
| 4179 std::string script = | |
| 4180 "window.onunload = function() { " | |
| 4181 " var start = Date.now();" | |
| 4182 " while (Date.now() - start < 1000);" | |
| 4183 "}"; | |
| 4184 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
| 4185 | |
| 4186 GURL second_url(embedded_test_server()->GetURL( | |
| 4187 "b.com", "/cross_site_iframe_factory.html?b(a)")); | |
| 4188 EXPECT_TRUE(NavigateToURL(shell(), second_url)); | |
|
alexmos
2016/03/29 18:43:02
There's a chance that the script will finish befor
Charlie Reis
2016/03/29 20:29:03
Yeah, there's a chance it could be a flaky failure
| |
| 4189 } | |
| 4190 | |
| 4166 // Check that when a cross-process frame acquires focus, the old focused frame | 4191 // Check that when a cross-process frame acquires focus, the old focused frame |
| 4167 // loses focus and fires blur events. Starting on a page with a cross-site | 4192 // loses focus and fires blur events. Starting on a page with a cross-site |
| 4168 // subframe, simulate mouse clicks to switch focus from root frame to subframe | 4193 // subframe, simulate mouse clicks to switch focus from root frame to subframe |
| 4169 // and then back to root frame. | 4194 // and then back to root frame. |
| 4170 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4195 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4171 CrossProcessFocusChangeFiresBlurEvents) { | 4196 CrossProcessFocusChangeFiresBlurEvents) { |
| 4172 GURL main_url( | 4197 GURL main_url( |
| 4173 embedded_test_server()->GetURL("a.com", "/page_with_input_field.html")); | 4198 embedded_test_server()->GetURL("a.com", "/page_with_input_field.html")); |
| 4174 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4199 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4175 | 4200 |
| (...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6256 EXPECT_EQ(b_url, root->current_url()); | 6281 EXPECT_EQ(b_url, root->current_url()); |
| 6257 | 6282 |
| 6258 // Verify that the same RenderViewHost is preserved and that it is no longer | 6283 // Verify that the same RenderViewHost is preserved and that it is no longer |
| 6259 // in swapped out state. | 6284 // in swapped out state. |
| 6260 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( | 6285 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( |
| 6261 root->current_frame_host()->GetSiteInstance())); | 6286 root->current_frame_host()->GetSiteInstance())); |
| 6262 EXPECT_FALSE(rvh->is_swapped_out_); | 6287 EXPECT_FALSE(rvh->is_swapped_out_); |
| 6263 } | 6288 } |
| 6264 | 6289 |
| 6265 } // namespace content | 6290 } // namespace content |
| OLD | NEW |