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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 10 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 11 #include "content/browser/frame_host/frame_navigation_entry.h" |
11 #include "content/browser/frame_host/frame_tree.h" | 12 #include "content/browser/frame_host/frame_tree.h" |
| 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/frame_host/render_frame_proxy_host.h" | 15 #include "content/browser/frame_host/render_frame_proxy_host.h" |
14 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 16 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 18 #include "content/browser/web_contents/web_contents_impl.h" |
| 19 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_observer.h" |
20 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
21 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
22 #include "content/public/test/content_browser_test_utils.h" | 27 #include "content/public/test/content_browser_test_utils.h" |
23 #include "content/public/test/test_navigation_observer.h" | 28 #include "content/public/test/test_navigation_observer.h" |
24 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
25 #include "content/shell/browser/shell.h" | 30 #include "content/shell/browser/shell.h" |
26 #include "content/test/content_browser_test_utils_internal.h" | 31 #include "content/test/content_browser_test_utils_internal.h" |
27 #include "content/test/test_frame_navigation_observer.h" | 32 #include "content/test/test_frame_navigation_observer.h" |
28 #include "net/dns/mock_host_resolver.h" | 33 #include "net/dns/mock_host_resolver.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 EXPECT_FALSE(root->child_at(1)->render_manager()->GetRenderFrameProxyHost( | 644 EXPECT_FALSE(root->child_at(1)->render_manager()->GetRenderFrameProxyHost( |
640 site_instance_c.get())); | 645 site_instance_c.get())); |
641 // Make sure proxy B stays around in root and node3. | 646 // Make sure proxy B stays around in root and node3. |
642 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost( | 647 EXPECT_TRUE(root->render_manager()->GetRenderFrameProxyHost( |
643 site_instance_b)); | 648 site_instance_b)); |
644 EXPECT_TRUE(root->child_at(1)->render_manager()->GetRenderFrameProxyHost( | 649 EXPECT_TRUE(root->child_at(1)->render_manager()->GetRenderFrameProxyHost( |
645 site_instance_b)); | 650 site_instance_b)); |
646 } | 651 } |
647 } | 652 } |
648 | 653 |
| 654 // Test cross-process back/forward navigations in a subframe. |
| 655 // Session history entries: |
| 656 // 1) localhost with subframe localhost/title1 |
| 657 // 2) localhost with subframe foo/title2 |
| 658 // 3) localhost with subframe bar/title3 |
| 659 // Go back twice, then forward twice. |
| 660 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SubframeBackForward) { |
| 661 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 662 NavigateToURL(shell(), main_url); |
| 663 SiteInstance* main_site_instance = shell()->web_contents()->GetSiteInstance(); |
| 664 |
| 665 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 666 FrameTreeNode* root = |
| 667 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 668 GetFrameTree()->root(); |
| 669 |
| 670 TestNavigationObserver observer(shell()->web_contents()); |
| 671 |
| 672 // Load same-site page into iframe. |
| 673 FrameTreeNode* child = root->child_at(0); |
| 674 GURL frame_url1(embedded_test_server()->GetURL("/title1.html")); |
| 675 NavigateFrameToURL(child, frame_url1); |
| 676 EXPECT_EQ(frame_url1, observer.last_navigation_url()); |
| 677 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 678 |
| 679 // Load foo.com page into iframe. |
| 680 GURL frame_url2 = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 681 NavigateFrameToURL(root->child_at(0), frame_url2); |
| 682 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 683 EXPECT_EQ(frame_url2, observer.last_navigation_url()); |
| 684 SiteInstance* foo_site_instance = |
| 685 child->current_frame_host()->GetSiteInstance(); |
| 686 EXPECT_EQ(main_site_instance, shell()->web_contents()->GetSiteInstance()); |
| 687 EXPECT_NE(main_site_instance, foo_site_instance); |
| 688 |
| 689 // Load bar.com page into iframe. |
| 690 GURL frame_url3 = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 691 NavigateFrameToURL(root->child_at(0), frame_url3); |
| 692 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 693 EXPECT_EQ(frame_url3, observer.last_navigation_url()); |
| 694 SiteInstance* bar_site_instance = |
| 695 child->current_frame_host()->GetSiteInstance(); |
| 696 EXPECT_NE(main_site_instance, bar_site_instance); |
| 697 EXPECT_NE(foo_site_instance, bar_site_instance); |
| 698 |
| 699 // Go back to foo. |
| 700 { |
| 701 TestFrameNavigationObserver back_nav_load_observer(child); |
| 702 shell()->web_contents()->GetController().GoBack(); |
| 703 back_nav_load_observer.Wait(); |
| 704 } |
| 705 EXPECT_EQ(main_url, root->current_url()); |
| 706 EXPECT_EQ(frame_url2, child->current_url()); |
| 707 NavigationEntryImpl* entry = static_cast<NavigationEntryImpl*>( |
| 708 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 709 FrameNavigationEntry* frame_entry = |
| 710 entry->root_node()->children[0]->frame_entry.get(); |
| 711 EXPECT_EQ(main_url, entry->GetURL()); |
| 712 EXPECT_EQ(frame_url2, frame_entry->url()); |
| 713 EXPECT_EQ(foo_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 714 |
| 715 // Go back to localhost. |
| 716 { |
| 717 TestFrameNavigationObserver back_nav_load_observer(child); |
| 718 shell()->web_contents()->GetController().GoBack(); |
| 719 back_nav_load_observer.Wait(); |
| 720 } |
| 721 EXPECT_EQ(main_url, root->current_url()); |
| 722 EXPECT_EQ(frame_url1, child->current_url()); |
| 723 entry = static_cast<NavigationEntryImpl*>( |
| 724 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 725 frame_entry = entry->root_node()->children[0]->frame_entry.get(); |
| 726 EXPECT_EQ(main_url, entry->GetURL()); |
| 727 EXPECT_EQ(frame_url1, frame_entry->url()); |
| 728 EXPECT_EQ(main_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 729 |
| 730 /* |
| 731 // Go forward to foo. |
| 732 // TODO(creis): Why is the test crashing here in OnDeleteProxy? |
| 733 { |
| 734 TestFrameNavigationObserver forward_nav_load_observer(child); |
| 735 shell()->web_contents()->GetController().GoForward(); |
| 736 forward_nav_load_observer.Wait(); |
| 737 } |
| 738 EXPECT_EQ(main_url, root->current_url()); |
| 739 EXPECT_EQ(frame_url2, child->current_url()); |
| 740 entry = static_cast<NavigationEntryImpl*>( |
| 741 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 742 frame_entry = entry->root_node()->children.at(0)->frame_entry; |
| 743 EXPECT_EQ(main_url, entry->GetURL()); |
| 744 EXPECT_EQ(frame_url2, frame_entry->GetURL()); |
| 745 EXPECT_EQ(foo_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 746 |
| 747 // Go forward to bar. |
| 748 { |
| 749 TestFrameNavigationObserver forward_nav_load_observer(child); |
| 750 shell()->web_contents()->GetController().GoForward(); |
| 751 forward_nav_load_observer.Wait(); |
| 752 } |
| 753 EXPECT_EQ(main_url, root->current_url()); |
| 754 EXPECT_EQ(frame_url2, child->current_url()); |
| 755 entry = static_cast<NavigationEntryImpl*>( |
| 756 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 757 frame_entry = entry->root_node()->children.at(0)->frame_entry; |
| 758 EXPECT_EQ(main_url, entry->GetURL()); |
| 759 EXPECT_EQ(frame_url2, frame_entry->GetURL()); |
| 760 EXPECT_EQ(foo_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 761 */ |
| 762 } |
| 763 |
649 // Crash a subframe and ensures its children are cleared from the FrameTree. | 764 // Crash a subframe and ensures its children are cleared from the FrameTree. |
650 // See http://crbug.com/338508. | 765 // See http://crbug.com/338508. |
651 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. | 766 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. |
652 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { | 767 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { |
653 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 768 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
654 NavigateToURL(shell(), main_url); | 769 NavigateToURL(shell(), main_url); |
655 | 770 |
656 StartFrameAtDataURL(); | 771 StartFrameAtDataURL(); |
657 | 772 |
658 // These must stay in scope with replace_host. | 773 // These must stay in scope with replace_host. |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 1766 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
1652 TestNavigationObserver observer(shell()->web_contents()); | 1767 TestNavigationObserver observer(shell()->web_contents()); |
1653 NavigateFrameToURL(root->child_at(0), foo_url); | 1768 NavigateFrameToURL(root->child_at(0), foo_url); |
1654 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1769 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1655 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 1770 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
1656 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); | 1771 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); |
1657 } | 1772 } |
1658 } | 1773 } |
1659 | 1774 |
1660 } // namespace content | 1775 } // namespace content |
OLD | NEW |