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 <set> | 5 #include <set> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 static_cast<WebContentsImpl*>(new_shell->web_contents()); | 291 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
292 EXPECT_FALSE( | 292 EXPECT_FALSE( |
293 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); | 293 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
294 | 294 |
295 // Should have a new SiteInstance. | 295 // Should have a new SiteInstance. |
296 scoped_refptr<SiteInstance> noopener_blank_site_instance( | 296 scoped_refptr<SiteInstance> noopener_blank_site_instance( |
297 new_shell->web_contents()->GetSiteInstance()); | 297 new_shell->web_contents()->GetSiteInstance()); |
298 EXPECT_NE(orig_site_instance, noopener_blank_site_instance); | 298 EXPECT_NE(orig_site_instance, noopener_blank_site_instance); |
299 } | 299 } |
300 | 300 |
| 301 // 'noopener' also works from 'window.open' |
| 302 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 303 SwapProcessWithWindowOpenAndNoopener) { |
| 304 StartEmbeddedServer(); |
| 305 |
| 306 NavigateToPageWithLinks(shell()); |
| 307 |
| 308 // Get the original SiteInstance for later comparison. |
| 309 scoped_refptr<SiteInstance> orig_site_instance( |
| 310 shell()->web_contents()->GetSiteInstance()); |
| 311 EXPECT_TRUE(orig_site_instance.get()); |
| 312 |
| 313 // Test opening a window with the 'noopener' feature. |
| 314 ShellAddedObserver new_shell_observer; |
| 315 bool hasWindowReference = true; |
| 316 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 317 shell()->web_contents(), |
| 318 "window.domAutomationController.send(" |
| 319 " openWindowWithTargetAndFeatures('/title2.html', '', 'noopener')" |
| 320 ");", |
| 321 &hasWindowReference)); |
| 322 // We should not get a reference to the opened window. |
| 323 EXPECT_FALSE(hasWindowReference); |
| 324 |
| 325 // Wait for the window to open. |
| 326 Shell* new_shell = new_shell_observer.GetShell(); |
| 327 |
| 328 // Wait for the cross-site transition in the new tab to finish. |
| 329 WaitForLoadStop(new_shell->web_contents()); |
| 330 WebContentsImpl* web_contents = |
| 331 static_cast<WebContentsImpl*>(new_shell->web_contents()); |
| 332 EXPECT_FALSE( |
| 333 web_contents->GetRenderManagerForTesting()->pending_render_view_host()); |
| 334 |
| 335 EXPECT_EQ("/title2.html", |
| 336 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 337 |
| 338 // Check that `window.opener` is not set. |
| 339 bool success = false; |
| 340 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 341 new_shell->web_contents(), |
| 342 "window.domAutomationController.send(window.opener == null);", &success)); |
| 343 EXPECT_TRUE(success); |
| 344 |
| 345 // Should have a new SiteInstance. |
| 346 scoped_refptr<SiteInstance> noopener_blank_site_instance( |
| 347 new_shell->web_contents()->GetSiteInstance()); |
| 348 EXPECT_NE(orig_site_instance, noopener_blank_site_instance); |
| 349 } |
| 350 |
301 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) | 351 // As of crbug.com/69267, we create a new BrowsingInstance (and SiteInstance) |
302 // for rel=noreferrer links in new windows, even to same site pages and named | 352 // for rel=noreferrer links in new windows, even to same site pages and named |
303 // targets. | 353 // targets. |
304 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 354 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
305 SwapProcessWithSameSiteRelNoreferrer) { | 355 SwapProcessWithSameSiteRelNoreferrer) { |
306 StartEmbeddedServer(); | 356 StartEmbeddedServer(); |
307 | 357 |
308 // Load a page with links that open in a new window. | 358 // Load a page with links that open in a new window. |
309 NavigateToPageWithLinks(shell()); | 359 NavigateToPageWithLinks(shell()); |
310 | 360 |
(...skipping 2043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 2404 popup_root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
2355 | 2405 |
2356 // Navigate the main tab to the site of the popup. This will cause the | 2406 // Navigate the main tab to the site of the popup. This will cause the |
2357 // RenderView for b.com in the main tab to be recreated. If the issue | 2407 // RenderView for b.com in the main tab to be recreated. If the issue |
2358 // is not fixed, this will result in process crash and failing test. | 2408 // is not fixed, this will result in process crash and failing test. |
2359 EXPECT_TRUE(NavigateToURL( | 2409 EXPECT_TRUE(NavigateToURL( |
2360 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); | 2410 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); |
2361 } | 2411 } |
2362 | 2412 |
2363 } // namespace content | 2413 } // namespace content |
OLD | NEW |