OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
7 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
8 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
14 #include "content/public/common/bindings_policy.h" | 16 #include "content/public/common/bindings_policy.h" |
| 17 #include "content/public/common/content_switches.h" |
15 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
16 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
17 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
18 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
19 #include "content/public/test/test_navigation_observer.h" | 22 #include "content/public/test/test_navigation_observer.h" |
20 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
21 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
22 #include "content/test/content_browser_test_utils_internal.h" | 25 #include "content/test/content_browser_test_utils_internal.h" |
23 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
24 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 ASSERT_EQ(2U, params.size()); | 849 ASSERT_EQ(2U, params.size()); |
847 ASSERT_EQ(2U, details.size()); | 850 ASSERT_EQ(2U, details.size()); |
848 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); | 851 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); |
849 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); | 852 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); |
850 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 853 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
851 params[1].transition); | 854 params[1].transition); |
852 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); | 855 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); |
853 } | 856 } |
854 } | 857 } |
855 | 858 |
| 859 |
| 860 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME |
| 861 // commits. |
| 862 // TODO(creis): Test cross-site and nested iframes. |
| 863 // TODO(creis): Test updating entries for history auto subframe navigations. |
| 864 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 865 FrameNavigationEntry_AutoSubframe) { |
| 866 GURL main_url(embedded_test_server()->GetURL( |
| 867 "/navigation_controller/simple_page_1.html")); |
| 868 NavigateToURL(shell(), main_url); |
| 869 const NavigationControllerImpl& controller = |
| 870 static_cast<const NavigationControllerImpl&>( |
| 871 shell()->web_contents()->GetController()); |
| 872 FrameTreeNode* root = |
| 873 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 874 GetFrameTree()->root(); |
| 875 |
| 876 // Create an iframe. |
| 877 GURL frame_url(embedded_test_server()->GetURL( |
| 878 "/navigation_controller/simple_page_2.html")); |
| 879 { |
| 880 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 881 std::string script = "var iframe = document.createElement('iframe');" |
| 882 "iframe.src = '" + frame_url.spec() + "';" |
| 883 "document.body.appendChild(iframe);"; |
| 884 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 885 capturer.Wait(); |
| 886 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 887 } |
| 888 |
| 889 // Check last committed NavigationEntry. |
| 890 EXPECT_EQ(1, controller.GetEntryCount()); |
| 891 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 892 EXPECT_EQ(main_url, entry->GetURL()); |
| 893 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
| 894 EXPECT_EQ(main_url, root_entry->url()); |
| 895 |
| 896 // Verify subframe entries if we're in --site-per-process mode. |
| 897 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 898 switches::kSitePerProcess)) { |
| 899 // The entry should now have a subframe FrameNavigationEntry. |
| 900 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 901 FrameNavigationEntry* frame_entry = |
| 902 entry->root_node()->children[0]->frame_entry.get(); |
| 903 EXPECT_EQ(frame_url, frame_entry->url()); |
| 904 } else { |
| 905 // There are no subframe FrameNavigationEntries by default. |
| 906 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 907 } |
| 908 } |
| 909 |
856 } // namespace content | 910 } // namespace content |
OLD | NEW |