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 4082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4093 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 4093 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
4094 } | 4094 } |
4095 | 4095 |
4096 // Test for https://crbug.com/515302. Perform two navigations, A->B->A, and | 4096 // Test for https://crbug.com/515302. Perform two navigations, A->B->A, and |
4097 // delay the SwapOut ACK from the A->B navigation, so that the second B->A | 4097 // delay the SwapOut ACK from the A->B navigation, so that the second B->A |
4098 // navigation is initiated before the first page receives the SwapOut ACK. | 4098 // navigation is initiated before the first page receives the SwapOut ACK. |
4099 // Ensure that the RVH(A) that's pending deletion is not reused in that case. | 4099 // Ensure that the RVH(A) that's pending deletion is not reused in that case. |
4100 // crbug.com/554825 | 4100 // crbug.com/554825 |
4101 #if defined(THREAD_SANITIZER) | 4101 #if defined(THREAD_SANITIZER) |
4102 #define MAYBE_RenderViewHostPendingDeletionIsNotReused \ | 4102 #define MAYBE_RenderViewHostPendingDeletionIsNotReused \ |
4103 DISABLED_RenderViewHostPendingDeletionIsNotReused | 4103 DISABLED_RenderViewHostPendingDeletionIsNotReused |
Charlie Reis
2016/03/28 19:06:37
There's a chance I fixed the problem in https://cr
alexmos
2016/03/29 18:43:01
Agreed that you may have fixed it -- and sounds go
| |
4104 #else | 4104 #else |
4105 #define MAYBE_RenderViewHostPendingDeletionIsNotReused \ | 4105 #define MAYBE_RenderViewHostPendingDeletionIsNotReused \ |
4106 RenderViewHostPendingDeletionIsNotReused | 4106 RenderViewHostPendingDeletionIsNotReused |
4107 #endif | 4107 #endif |
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(); | |
Charlie Reis
2016/03/28 19:06:37
Have to grab these in advance to avoid a UaF below
| |
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. |
4124 // TODO(creis): This will be flaky, since there's still a 1 second timeout. | |
Charlie Reis
2016/03/28 19:06:37
Oops, I forgot to take this TODO out. I fixed thi
Charlie Reis
2016/03/29 04:19:01
Done.
| |
4122 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); | 4125 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); |
4123 rfh->GetProcess()->AddFilter(filter.get()); | 4126 rfh->GetProcess()->AddFilter(filter.get()); |
4124 | 4127 |
4125 // Navigate to B. This must wait for DidCommitProvisionalLoad, as opposed to | 4128 // Navigate to B. This must wait for DidCommitProvisionalLoad, as opposed to |
4126 // DidStopLoading, since otherwise the SwapOut timer might call OnSwappedOut | 4129 // DidStopLoading, since otherwise the SwapOut timer might call OnSwappedOut |
4127 // and destroy |rvh| before its pending deletion status is checked. | 4130 // and destroy |rvh| before its pending deletion status is checked. |
4128 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 4131 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
4129 TestFrameNavigationObserver commit_observer(root); | 4132 TestFrameNavigationObserver commit_observer(root); |
4130 shell()->LoadURL(b_url); | 4133 shell()->LoadURL(b_url); |
4131 commit_observer.WaitForCommit(); | 4134 commit_observer.WaitForCommit(); |
4135 EXPECT_FALSE(deleted_observer.deleted()); | |
4136 rfh->ResetSwapOutTimerForTesting(); | |
4132 | 4137 |
4133 // Since the SwapOut ACK for A->B is dropped, the first page's | 4138 // Since the SwapOut ACK for A->B is dropped, the first page's |
4134 // RenderFrameHost and RenderViewHost should be pending deletion after the | 4139 // RenderFrameHost and RenderViewHost should be pending deletion after the |
4135 // last navigation. | 4140 // last navigation. |
4136 EXPECT_TRUE(root->render_manager()->IsPendingDeletion(rfh)); | 4141 EXPECT_TRUE(root->render_manager()->IsPendingDeletion(rfh)); |
4137 EXPECT_TRUE(rvh->is_pending_deletion()); | 4142 EXPECT_TRUE(root->render_manager()->IsViewPendingDeletion(rvh)); |
4138 | 4143 |
4139 // Wait for process A to exit so we can reinitialize it cleanly for the next | 4144 // 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. | 4145 // navigation. This can be removed once https://crbug.com/535246 is fixed. |
Charlie Reis
2016/03/28 19:06:37
I'd like to remove this as well, but I think this
| |
4141 RenderProcessHostWatcher process_exit_observer( | 4146 RenderProcessHostWatcher process_exit_observer( |
4142 rvh->GetProcess(), | 4147 rvh->GetProcess(), |
4143 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 4148 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
4144 process_exit_observer.Wait(); | 4149 process_exit_observer.Wait(); |
4145 | 4150 |
4146 // Start a navigation back to A and check that the RenderViewHost wasn't | 4151 // Start a navigation back to A and check that the RenderViewHost wasn't |
4147 // reused. | 4152 // reused. |
4148 TestNavigationObserver navigation_observer(shell()->web_contents()); | 4153 TestNavigationObserver navigation_observer(shell()->web_contents()); |
4149 shell()->LoadURL(a_url); | 4154 shell()->LoadURL(a_url); |
4150 RenderViewHostImpl* pending_rvh = | 4155 RenderViewHostImpl* pending_rvh = |
4151 IsBrowserSideNavigationEnabled() | 4156 IsBrowserSideNavigationEnabled() |
4152 ? root->render_manager()->speculative_frame_host()->render_view_host() | 4157 ? root->render_manager()->speculative_frame_host()->render_view_host() |
4153 : root->render_manager()->pending_render_view_host(); | 4158 : root->render_manager()->pending_render_view_host(); |
4154 EXPECT_EQ(rvh->GetSiteInstance(), pending_rvh->GetSiteInstance()); | 4159 EXPECT_EQ(site_instance, pending_rvh->GetSiteInstance()); |
4155 EXPECT_NE(rvh, pending_rvh); | 4160 EXPECT_NE(rvh_routing_id, pending_rvh->GetRoutingID()); |
4156 | 4161 |
4157 // Simulate that the dropped SwapOut ACK message arrives now on the original | 4162 // TODO(alexmos, creis): Once https://crbug.com/535246 is fixed and the |
4158 // RenderFrameHost, which should now get deleted. | 4163 // process_exit_observer is not needed above, we'll need to simulate that the |
4159 rfh->OnSwappedOut(); | 4164 // dropped SwapOut ACK message arrives now on the original RenderFrameHost, |
4165 // causing it to be deleted. | |
4160 EXPECT_TRUE(deleted_observer.deleted()); | 4166 EXPECT_TRUE(deleted_observer.deleted()); |
4161 | 4167 |
4162 // Make sure the last navigation finishes without crashing. | 4168 // Make sure the last navigation finishes without crashing. |
4163 navigation_observer.Wait(); | 4169 navigation_observer.Wait(); |
4164 } | 4170 } |
4165 | 4171 |
4172 // Test for https://crbug.com/591478, where navigating to a cross-site page with | |
4173 // a subframe on the old site could cause the old RenderViewHost (now pending | |
4174 // deletion) to be reused. | |
4175 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
4176 DontReusePendingDeleteRenderViewHostForSubframe) { | |
4177 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
4178 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
4179 | |
4180 std::string script = | |
4181 "window.onunload = function() { " | |
4182 " var start = Date.now();" | |
4183 " while (Date.now() - start < 1000);" | |
4184 "}"; | |
4185 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
4186 | |
4187 GURL second_url(embedded_test_server()->GetURL( | |
4188 "b.com", "/cross_site_iframe_factory.html?b(a)")); | |
4189 EXPECT_TRUE(NavigateToURL(shell(), second_url)); | |
4190 } | |
4191 | |
4166 // Check that when a cross-process frame acquires focus, the old focused frame | 4192 // 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 | 4193 // 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 | 4194 // subframe, simulate mouse clicks to switch focus from root frame to subframe |
4169 // and then back to root frame. | 4195 // and then back to root frame. |
4170 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4196 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
4171 CrossProcessFocusChangeFiresBlurEvents) { | 4197 CrossProcessFocusChangeFiresBlurEvents) { |
4172 GURL main_url( | 4198 GURL main_url( |
4173 embedded_test_server()->GetURL("a.com", "/page_with_input_field.html")); | 4199 embedded_test_server()->GetURL("a.com", "/page_with_input_field.html")); |
4174 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4200 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
4175 | 4201 |
(...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6256 EXPECT_EQ(b_url, root->current_url()); | 6282 EXPECT_EQ(b_url, root->current_url()); |
6257 | 6283 |
6258 // Verify that the same RenderViewHost is preserved and that it is no longer | 6284 // Verify that the same RenderViewHost is preserved and that it is no longer |
6259 // in swapped out state. | 6285 // in swapped out state. |
6260 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( | 6286 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( |
6261 root->current_frame_host()->GetSiteInstance())); | 6287 root->current_frame_host()->GetSiteInstance())); |
6262 EXPECT_FALSE(rvh->is_swapped_out_); | 6288 EXPECT_FALSE(rvh->is_swapped_out_); |
6263 } | 6289 } |
6264 | 6290 |
6265 } // namespace content | 6291 } // namespace content |
OLD | NEW |