Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 497183003: Fix DisownOpener and related tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 EXPECT_TRUE(ExecuteScriptAndExtractBool( 404 EXPECT_TRUE(ExecuteScriptAndExtractBool(
405 shell()->web_contents(), 405 shell()->web_contents(),
406 "window.domAutomationController.send(testCloseWindow());", 406 "window.domAutomationController.send(testCloseWindow());",
407 &success)); 407 &success));
408 EXPECT_TRUE(success); 408 EXPECT_TRUE(success);
409 close_watcher.Wait(); 409 close_watcher.Wait();
410 } 410 }
411 411
412 // Test that setting the opener to null in a window affects cross-process 412 // Test that setting the opener to null in a window affects cross-process
413 // navigations, including those to existing entries. http://crbug.com/156669. 413 // navigations, including those to existing entries. http://crbug.com/156669.
414 // Flaky on android: http://crbug.com/397185 414 // This test crashes under ThreadSanitizer, http://crbug.com/356758.
415 // Flaky on windows and mac: http://crbug.com/291249 415 #if defined(THREAD_SANITIZER)
Charlie Reis 2014/08/22 19:41:23 I don't think I've fixed the ThreadSanitizer issue
416 // This test also crashes under ThreadSanitizer, http://crbug.com/356758.
417 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(THREAD_SANITIZER) || defin ed(OS_MACOSX)
418 #define MAYBE_DisownOpener DISABLED_DisownOpener 416 #define MAYBE_DisownOpener DISABLED_DisownOpener
419 #else 417 #else
420 #define MAYBE_DisownOpener DisownOpener 418 #define MAYBE_DisownOpener DisownOpener
421 #endif 419 #endif
422 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) { 420 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, MAYBE_DisownOpener) {
423 StartServer(); 421 StartServer();
424 422
425 // Load a page with links that open in a new window. 423 // Load a page with links that open in a new window.
426 std::string replacement_path; 424 std::string replacement_path;
427 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( 425 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
428 "files/click-noreferrer-links.html", 426 "files/click-noreferrer-links.html",
429 foo_host_port_, 427 foo_host_port_,
430 &replacement_path)); 428 &replacement_path));
431 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); 429 NavigateToURL(shell(), test_server()->GetURL(replacement_path));
432 430
433 // Get the original SiteInstance for later comparison. 431 // Get the original SiteInstance for later comparison.
434 scoped_refptr<SiteInstance> orig_site_instance( 432 scoped_refptr<SiteInstance> orig_site_instance(
435 shell()->web_contents()->GetSiteInstance()); 433 shell()->web_contents()->GetSiteInstance());
436 EXPECT_TRUE(orig_site_instance.get() != NULL); 434 EXPECT_TRUE(orig_site_instance.get() != NULL);
437 435
438 // Test clicking a target=_blank link. 436 // Test clicking a target=_blank link.
439 ShellAddedObserver new_shell_observer; 437 ShellAddedObserver new_shell_observer;
440 bool success = false; 438 bool success = false;
441 EXPECT_TRUE(ExecuteScriptAndExtractBool( 439 EXPECT_TRUE(ExecuteScriptAndExtractBool(
442 shell()->web_contents(), 440 shell()->web_contents(),
443 "window.domAutomationController.send(clickSameSiteTargetBlankLink());", 441 "window.domAutomationController.send(clickSameSiteTargetBlankLink());",
444 &success)); 442 &success));
445 EXPECT_TRUE(success); 443 EXPECT_TRUE(success);
446 Shell* new_shell = new_shell_observer.GetShell(); 444 Shell* new_shell = new_shell_observer.GetShell();
445 EXPECT_TRUE(new_shell->web_contents()->HasOpener());
447 446
448 // Wait for the navigation in the new tab to finish, if it hasn't. 447 // Wait for the navigation in the new tab to finish, if it hasn't.
449 WaitForLoadStop(new_shell->web_contents()); 448 WaitForLoadStop(new_shell->web_contents());
450 EXPECT_EQ("/files/title2.html", 449 EXPECT_EQ("/files/title2.html",
451 new_shell->web_contents()->GetLastCommittedURL().path()); 450 new_shell->web_contents()->GetLastCommittedURL().path());
452 451
453 // Should have the same SiteInstance. 452 // Should have the same SiteInstance.
454 scoped_refptr<SiteInstance> blank_site_instance( 453 scoped_refptr<SiteInstance> blank_site_instance(
455 new_shell->web_contents()->GetSiteInstance()); 454 new_shell->web_contents()->GetSiteInstance());
456 EXPECT_EQ(orig_site_instance, blank_site_instance); 455 EXPECT_EQ(orig_site_instance, blank_site_instance);
457 456
458 // Now navigate the new tab to a different site. 457 // Now navigate the new tab to a different site.
459 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); 458 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html"));
460 scoped_refptr<SiteInstance> new_site_instance( 459 scoped_refptr<SiteInstance> new_site_instance(
461 new_shell->web_contents()->GetSiteInstance()); 460 new_shell->web_contents()->GetSiteInstance());
462 EXPECT_NE(orig_site_instance, new_site_instance); 461 EXPECT_NE(orig_site_instance, new_site_instance);
462 EXPECT_TRUE(new_shell->web_contents()->HasOpener());
463 463
464 // Now disown the opener. 464 // Now disown the opener.
465 EXPECT_TRUE(ExecuteScript(new_shell->web_contents(), 465 EXPECT_TRUE(ExecuteScript(new_shell->web_contents(),
466 "window.opener = null;")); 466 "window.opener = null;"));
467 EXPECT_FALSE(new_shell->web_contents()->HasOpener());
Charlie Reis 2014/08/22 19:41:23 I'm still not sure why the original test was faili
nasko 2014/08/22 20:24:34 ExecuteScript waits until the script is executed b
467 468
468 // Go back and ensure the opener is still null. 469 // Go back and ensure the opener is still null.
469 { 470 {
470 TestNavigationObserver back_nav_load_observer(new_shell->web_contents()); 471 TestNavigationObserver back_nav_load_observer(new_shell->web_contents());
471 new_shell->web_contents()->GetController().GoBack(); 472 new_shell->web_contents()->GetController().GoBack();
472 back_nav_load_observer.Wait(); 473 back_nav_load_observer.Wait();
473 } 474 }
474 success = false; 475 success = false;
475 EXPECT_TRUE(ExecuteScriptAndExtractBool( 476 EXPECT_TRUE(ExecuteScriptAndExtractBool(
476 new_shell->web_contents(), 477 new_shell->web_contents(),
477 "window.domAutomationController.send(window.opener == null);", 478 "window.domAutomationController.send(window.opener == null);",
478 &success)); 479 &success));
479 EXPECT_TRUE(success); 480 EXPECT_TRUE(success);
481 EXPECT_FALSE(new_shell->web_contents()->HasOpener());
480 482
481 // Now navigate forward again (creating a new process) and check opener. 483 // Now navigate forward again (creating a new process) and check opener.
482 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html")); 484 NavigateToURL(new_shell, GetCrossSiteURL("files/title1.html"));
483 success = false; 485 success = false;
484 EXPECT_TRUE(ExecuteScriptAndExtractBool( 486 EXPECT_TRUE(ExecuteScriptAndExtractBool(
485 new_shell->web_contents(), 487 new_shell->web_contents(),
486 "window.domAutomationController.send(window.opener == null);", 488 "window.domAutomationController.send(window.opener == null);",
487 &success)); 489 &success));
488 EXPECT_TRUE(success); 490 EXPECT_TRUE(success);
491 EXPECT_FALSE(new_shell->web_contents()->HasOpener());
489 } 492 }
490 493
491 // Test that subframes can disown their openers. http://crbug.com/225528. 494 // Test that subframes can disown their openers. http://crbug.com/225528.
492 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, DisownSubframeOpener) { 495 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, DisownSubframeOpener) {
493 const GURL frame_url("data:text/html,<iframe name=\"foo\"></iframe>"); 496 const GURL frame_url("data:text/html,<iframe name=\"foo\"></iframe>");
494 NavigateToURL(shell(), frame_url); 497 NavigateToURL(shell(), frame_url);
495 498
496 // Give the frame an opener using window.open. 499 // Give the frame an opener using window.open.
497 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 500 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
498 "window.open('about:blank','foo');")); 501 "window.open('about:blank','foo');"));
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 // Navigate to url1 and check bindings. 1460 // Navigate to url1 and check bindings.
1458 NavigateToURL(new_shell, url1); 1461 NavigateToURL(new_shell, url1);
1459 // The navigation should have used the first SiteInstance, otherwise 1462 // The navigation should have used the first SiteInstance, otherwise
1460 // |initial_rvh| did not have a chance to be used. 1463 // |initial_rvh| did not have a chance to be used.
1461 EXPECT_EQ(new_web_contents->GetSiteInstance(), site_instance1); 1464 EXPECT_EQ(new_web_contents->GetSiteInstance(), site_instance1);
1462 EXPECT_EQ(BINDINGS_POLICY_WEB_UI, 1465 EXPECT_EQ(BINDINGS_POLICY_WEB_UI,
1463 new_web_contents->GetRenderViewHost()->GetEnabledBindings()); 1466 new_web_contents->GetRenderViewHost()->GetEnabledBindings());
1464 } 1467 }
1465 1468
1466 } // namespace content 1469 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698