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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 GURL server_redirect_http_url(test_server()->GetURL( | 437 GURL server_redirect_http_url(test_server()->GetURL( |
438 "server-redirect?" + client_redirect_http_url.spec())); | 438 "server-redirect?" + client_redirect_http_url.spec())); |
439 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 439 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
440 | 440 |
441 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 441 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
442 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 442 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
443 EXPECT_FALSE(observer.navigation_succeeded()); | 443 EXPECT_FALSE(observer.navigation_succeeded()); |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
447 // Ensures FrameTree correctly reflects page structure during navigations. | |
448 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
449 FrameTreeShape) { | |
450 host_resolver()->AddRule("*", "127.0.0.1"); | |
451 ASSERT_TRUE(test_server()->Start()); | |
452 | |
453 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
454 GURL::Replacements replace_host; | |
455 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
456 replace_host.SetHostStr(host_str); | |
457 base_url = base_url.ReplaceComponents(replace_host); | |
458 | |
459 // Load doc without iframes. Verify FrameTree just has root. | |
460 // Frame tree: | |
461 // Site-A Root | |
462 NavigateToURL(shell(), base_url.Resolve("blank.html")); | |
463 FrameTreeNode* root = | |
464 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
465 GetFrameTree()->root(); | |
466 EXPECT_EQ(0U, root->child_count()); | |
467 | |
468 // Add 2 same-site frames. Verify 3 nodes in tree with proper names. | |
469 // Frame tree: | |
470 // Site-A Root -- Site-A frame1 | |
471 // \-- Site-A frame2 | |
472 WindowedNotificationObserver observer1( | |
473 content::NOTIFICATION_LOAD_STOP, | |
474 content::Source<NavigationController>( | |
475 &shell()->web_contents()->GetController())); | |
476 NavigateToURL(shell(), base_url.Resolve("frames-X-X.html")); | |
477 observer1.Wait(); | |
478 ASSERT_EQ(2U, root->child_count()); | |
479 EXPECT_EQ(0U, root->child_at(0)->child_count()); | |
480 EXPECT_EQ(0U, root->child_at(1)->child_count()); | |
481 } | |
482 | |
483 // TODO(ajwong): Talk with nasko and merge this functionality with | |
484 // FrameTreeShape. | |
485 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
486 FrameTreeShape2) { | |
487 host_resolver()->AddRule("*", "127.0.0.1"); | |
488 ASSERT_TRUE(test_server()->Start()); | |
489 | |
490 NavigateToURL(shell(), | |
491 test_server()->GetURL("files/frame_tree/top.html")); | |
492 | |
493 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
494 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
495 wc->GetRenderViewHost()); | |
496 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
497 | |
498 // Check that the root node is properly created with the frame id of the | |
499 // initial navigation. | |
500 ASSERT_EQ(3UL, root->child_count()); | |
501 EXPECT_EQ(std::string(), root->frame_name()); | |
502 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
503 | |
504 ASSERT_EQ(2UL, root->child_at(0)->child_count()); | |
505 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | |
506 | |
507 // Verify the deepest node exists and has the right name. | |
508 ASSERT_EQ(2UL, root->child_at(2)->child_count()); | |
509 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | |
510 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); | |
511 EXPECT_STREQ("3-1-id", | |
512 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | |
513 | |
514 // Navigate to about:blank, which should leave only the root node of the frame | |
515 // tree in the browser process. | |
516 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
517 | |
518 root = wc->GetFrameTree()->root(); | |
519 EXPECT_EQ(0UL, root->child_count()); | |
520 EXPECT_EQ(std::string(), root->frame_name()); | |
521 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
522 } | |
523 | |
524 // Test that we can navigate away if the previous renderer doesn't clean up its | |
525 // child frames. | |
526 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, FrameTreeAfterCrash) { | |
527 ASSERT_TRUE(test_server()->Start()); | |
528 NavigateToURL(shell(), | |
529 test_server()->GetURL("files/frame_tree/top.html")); | |
530 | |
531 // Crash the renderer so that it doesn't send any FrameDetached messages. | |
532 RenderProcessHostWatcher crash_observer( | |
533 shell()->web_contents(), | |
534 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
535 NavigateToURL(shell(), GURL(kChromeUICrashURL)); | |
536 crash_observer.Wait(); | |
537 | |
538 // The frame tree should be cleared, and the frame ID should be reset. | |
539 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
540 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
541 wc->GetRenderViewHost()); | |
542 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
543 EXPECT_EQ(0UL, root->child_count()); | |
544 EXPECT_EQ(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
545 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
546 | |
547 // Navigate to a new URL. | |
548 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | |
549 | |
550 // The frame ID should now be set. | |
551 EXPECT_EQ(0UL, root->child_count()); | |
552 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
553 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | |
554 } | |
555 | |
556 // Test that we can navigate away if the previous renderer doesn't clean up its | |
557 // child frames. | |
558 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateWithLeftoverFrames) { | |
559 host_resolver()->AddRule("*", "127.0.0.1"); | |
560 ASSERT_TRUE(test_server()->Start()); | |
561 | |
562 GURL base_url = test_server()->GetURL("files/site_isolation/"); | |
563 GURL::Replacements replace_host; | |
564 std::string host_str("A.com"); // Must stay in scope with replace_host. | |
565 replace_host.SetHostStr(host_str); | |
566 base_url = base_url.ReplaceComponents(replace_host); | |
567 | |
568 NavigateToURL(shell(), | |
569 test_server()->GetURL("files/frame_tree/top.html")); | |
570 | |
571 // Hang the renderer so that it doesn't send any FrameDetached messages. | |
572 // (This navigation will never complete, so don't wait for it.) | |
573 shell()->LoadURL(GURL(kChromeUIHangURL)); | |
574 | |
575 // Check that the frame tree still has children. | |
576 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
577 FrameTreeNode* root = wc->GetFrameTree()->root(); | |
578 ASSERT_EQ(3UL, root->child_count()); | |
579 | |
580 // Navigate to a new URL. We use LoadURL because NavigateToURL will try to | |
581 // wait for the previous navigation to stop. | |
582 TestNavigationObserver tab_observer(wc, 1); | |
583 shell()->LoadURL(base_url.Resolve("blank.html")); | |
584 tab_observer.Wait(); | |
585 | |
586 // The frame tree should now be cleared, and the frame ID should be valid. | |
587 EXPECT_EQ(0UL, root->child_count()); | |
588 EXPECT_NE(FrameTreeNode::kInvalidFrameId, root->frame_id()); | |
589 } | |
590 | |
591 // Tests that the |should_replace_current_entry| flag persists correctly across | 447 // Tests that the |should_replace_current_entry| flag persists correctly across |
592 // request transfers that began with a cross-process navigation. | 448 // request transfers that began with a cross-process navigation. |
593 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 449 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
594 ReplaceEntryCrossProcessThenTranfers) { | 450 ReplaceEntryCrossProcessThenTranfers) { |
595 const NavigationController& controller = | 451 const NavigationController& controller = |
596 shell()->web_contents()->GetController(); | 452 shell()->web_contents()->GetController(); |
597 host_resolver()->AddRule("*", "127.0.0.1"); | 453 host_resolver()->AddRule("*", "127.0.0.1"); |
598 ASSERT_TRUE(test_server()->Start()); | 454 ASSERT_TRUE(test_server()->Start()); |
599 | 455 |
600 // These must all stay in scope with replace_host. | 456 // These must all stay in scope with replace_host. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 // There should be two history entries. url2b should have replaced url1. url2b | 594 // There should be two history entries. url2b should have replaced url1. url2b |
739 // should not have replaced url3b. | 595 // should not have replaced url3b. |
740 EXPECT_TRUE(controller.GetPendingEntry() == NULL); | 596 EXPECT_TRUE(controller.GetPendingEntry() == NULL); |
741 EXPECT_EQ(2, controller.GetEntryCount()); | 597 EXPECT_EQ(2, controller.GetEntryCount()); |
742 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 598 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
743 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); | 599 EXPECT_EQ(url2b, controller.GetEntryAtIndex(0)->GetURL()); |
744 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); | 600 EXPECT_EQ(url3b, controller.GetEntryAtIndex(1)->GetURL()); |
745 } | 601 } |
746 | 602 |
747 } // namespace content | 603 } // namespace content |
OLD | NEW |