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/command_line.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); | 943 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); |
944 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); | 944 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); |
945 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 945 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
946 params[1].transition); | 946 params[1].transition); |
947 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); | 947 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); |
948 } | 948 } |
949 } | 949 } |
950 | 950 |
951 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME | 951 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME |
952 // commits. | 952 // commits. |
953 // TODO(creis): Test cross-site and nested iframes. | 953 // TODO(creis): Test cross-site iframes. |
954 // TODO(creis): Test updating entries for history auto subframe navigations. | 954 // TODO(creis): Test updating entries for history auto subframe navigations. |
955 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 955 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
956 FrameNavigationEntry_AutoSubframe) { | 956 FrameNavigationEntry_AutoSubframe) { |
957 GURL main_url(embedded_test_server()->GetURL( | 957 GURL main_url(embedded_test_server()->GetURL( |
958 "/navigation_controller/simple_page_1.html")); | 958 "/navigation_controller/simple_page_1.html")); |
959 NavigateToURL(shell(), main_url); | 959 NavigateToURL(shell(), main_url); |
960 const NavigationControllerImpl& controller = | 960 const NavigationControllerImpl& controller = |
961 static_cast<const NavigationControllerImpl&>( | 961 static_cast<const NavigationControllerImpl&>( |
962 shell()->web_contents()->GetController()); | 962 shell()->web_contents()->GetController()); |
963 FrameTreeNode* root = | 963 FrameTreeNode* root = |
(...skipping 25 matching lines...) Expand all Loading... |
989 switches::kSitePerProcess)) { | 989 switches::kSitePerProcess)) { |
990 // The entry should now have a subframe FrameNavigationEntry. | 990 // The entry should now have a subframe FrameNavigationEntry. |
991 ASSERT_EQ(1U, entry->root_node()->children.size()); | 991 ASSERT_EQ(1U, entry->root_node()->children.size()); |
992 FrameNavigationEntry* frame_entry = | 992 FrameNavigationEntry* frame_entry = |
993 entry->root_node()->children[0]->frame_entry.get(); | 993 entry->root_node()->children[0]->frame_entry.get(); |
994 EXPECT_EQ(frame_url, frame_entry->url()); | 994 EXPECT_EQ(frame_url, frame_entry->url()); |
995 } else { | 995 } else { |
996 // There are no subframe FrameNavigationEntries by default. | 996 // There are no subframe FrameNavigationEntries by default. |
997 EXPECT_EQ(0U, entry->root_node()->children.size()); | 997 EXPECT_EQ(0U, entry->root_node()->children.size()); |
998 } | 998 } |
| 999 |
| 1000 // Create a second iframe. |
| 1001 { |
| 1002 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1003 std::string script = "var iframe = document.createElement('iframe');" |
| 1004 "iframe.src = '" + frame_url.spec() + "';" |
| 1005 "document.body.appendChild(iframe);"; |
| 1006 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1007 capturer.Wait(); |
| 1008 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1009 } |
| 1010 |
| 1011 // The last committed NavigationEntry shouldn't have changed. |
| 1012 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1013 entry = controller.GetLastCommittedEntry(); |
| 1014 EXPECT_EQ(main_url, entry->GetURL()); |
| 1015 root_entry = entry->root_node()->frame_entry.get(); |
| 1016 EXPECT_EQ(main_url, root_entry->url()); |
| 1017 |
| 1018 // Verify subframe entries if we're in --site-per-process mode. |
| 1019 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1020 switches::kSitePerProcess)) { |
| 1021 // The entry should now have 2 subframe FrameNavigationEntries. |
| 1022 ASSERT_EQ(2U, entry->root_node()->children.size()); |
| 1023 FrameNavigationEntry* frame_entry = |
| 1024 entry->root_node()->children[1]->frame_entry.get(); |
| 1025 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1026 } else { |
| 1027 // There are no subframe FrameNavigationEntries by default. |
| 1028 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1029 } |
| 1030 |
| 1031 // Create a nested iframe in the second subframe. |
| 1032 { |
| 1033 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1034 std::string script = "var iframe = document.createElement('iframe');" |
| 1035 "iframe.src = '" + frame_url.spec() + "';" |
| 1036 "document.body.appendChild(iframe);"; |
| 1037 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), |
| 1038 script)); |
| 1039 capturer.Wait(); |
| 1040 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1041 } |
| 1042 |
| 1043 // The last committed NavigationEntry shouldn't have changed. |
| 1044 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1045 entry = controller.GetLastCommittedEntry(); |
| 1046 EXPECT_EQ(main_url, entry->GetURL()); |
| 1047 root_entry = entry->root_node()->frame_entry.get(); |
| 1048 EXPECT_EQ(main_url, root_entry->url()); |
| 1049 |
| 1050 // Verify subframe entries if we're in --site-per-process mode. |
| 1051 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1052 switches::kSitePerProcess)) { |
| 1053 // The entry should now have 2 subframe FrameNavigationEntries. |
| 1054 ASSERT_EQ(2U, entry->root_node()->children.size()); |
| 1055 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); |
| 1056 FrameNavigationEntry* frame_entry = |
| 1057 entry->root_node()->children[1]->children[0]->frame_entry.get(); |
| 1058 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1059 } else { |
| 1060 // There are no subframe FrameNavigationEntries by default. |
| 1061 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1062 } |
999 } | 1063 } |
1000 | 1064 |
1001 namespace { | 1065 namespace { |
1002 | 1066 |
1003 class HttpThrottle : public ResourceThrottle { | 1067 class HttpThrottle : public ResourceThrottle { |
1004 public: | 1068 public: |
1005 // ResourceThrottle | 1069 // ResourceThrottle |
1006 void WillStartRequest(bool* defer) override { | 1070 void WillStartRequest(bool* defer) override { |
1007 *defer = true; | 1071 *defer = true; |
1008 } | 1072 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 // tricky. | 1357 // tricky. |
1294 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 1358 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
1295 shell()->web_contents()->Stop(); | 1359 shell()->web_contents()->Stop(); |
1296 watcher.Wait(); | 1360 watcher.Wait(); |
1297 } | 1361 } |
1298 | 1362 |
1299 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1363 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
1300 } | 1364 } |
1301 | 1365 |
1302 } // namespace content | 1366 } // namespace content |
OLD | NEW |