| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 void Wait() { | 367 void Wait() { |
| 368 message_loop_runner_->Run(); | 368 message_loop_runner_->Run(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 ui::PageTransition transition_type() const { | 371 ui::PageTransition transition_type() const { |
| 372 return transition_type_; | 372 return transition_type_; |
| 373 } | 373 } |
| 374 | 374 |
| 375 private: | 375 private: |
| 376 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { | 376 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { |
| 377 // If this object was created with a specified tree frame node, there |
| 378 // shouldn't be any frames being created. |
| 379 DCHECK_EQ(0, frame_tree_node_id_); |
| 377 RenderFrameHostImpl* rfh = | 380 RenderFrameHostImpl* rfh = |
| 378 static_cast<RenderFrameHostImpl*>(render_frame_host); | 381 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 379 | 382 frame_tree_node_id_ = rfh->frame_tree_node()->frame_tree_node_id(); |
| 380 // Don't pay attention to swapped out RenderFrameHosts in the main frame. | |
| 381 // TODO(nasko): Remove once swappedout:// is gone. | |
| 382 // See https://crbug.com/357747. | |
| 383 if (!RenderFrameHostImpl::IsRFHStateActive(rfh->rfh_state())) { | |
| 384 DLOG(INFO) << "Skipping swapped out RFH: " | |
| 385 << rfh->GetSiteInstance()->GetSiteURL(); | |
| 386 return; | |
| 387 } | |
| 388 | |
| 389 // If this object was not created with a specified frame tree node, then use | |
| 390 // the first created active RenderFrameHost. Once a node is selected, there | |
| 391 // shouldn't be any other frames being created. | |
| 392 int frame_tree_node_id = rfh->frame_tree_node()->frame_tree_node_id(); | |
| 393 DCHECK(frame_tree_node_id_ == 0 || | |
| 394 frame_tree_node_id_ == frame_tree_node_id); | |
| 395 frame_tree_node_id_ = frame_tree_node_id; | |
| 396 } | 383 } |
| 397 | 384 |
| 398 void DidCommitProvisionalLoadForFrame( | 385 void DidCommitProvisionalLoadForFrame( |
| 399 RenderFrameHost* render_frame_host, | 386 RenderFrameHost* render_frame_host, |
| 400 const GURL& url, | 387 const GURL& url, |
| 401 ui::PageTransition transition_type) override { | 388 ui::PageTransition transition_type) override { |
| 402 DCHECK_NE(0, frame_tree_node_id_); | 389 DCHECK_NE(0, frame_tree_node_id_); |
| 403 RenderFrameHostImpl* rfh = | 390 RenderFrameHostImpl* rfh = |
| 404 static_cast<RenderFrameHostImpl*>(render_frame_host); | 391 static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 405 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | 392 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 ASSERT_EQ(2U, params.size()); | 962 ASSERT_EQ(2U, params.size()); |
| 976 ASSERT_EQ(2U, details.size()); | 963 ASSERT_EQ(2U, details.size()); |
| 977 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); | 964 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); |
| 978 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); | 965 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); |
| 979 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 966 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 980 params[1].transition); | 967 params[1].transition); |
| 981 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); | 968 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); |
| 982 } | 969 } |
| 983 } | 970 } |
| 984 | 971 |
| 985 // Verify the tree of FrameNavigationEntries after initial about:blank commits | |
| 986 // in subframes, which should not count as real committed loads. | |
| 987 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 988 FrameNavigationEntry_BlankAutoSubframe) { | |
| 989 GURL main_url(embedded_test_server()->GetURL( | |
| 990 "/navigation_controller/simple_page_1.html")); | |
| 991 NavigateToURL(shell(), main_url); | |
| 992 const NavigationControllerImpl& controller = | |
| 993 static_cast<const NavigationControllerImpl&>( | |
| 994 shell()->web_contents()->GetController()); | |
| 995 FrameTreeNode* root = | |
| 996 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 997 GetFrameTree()->root(); | |
| 998 | |
| 999 // 1. Create a iframe with no URL. | |
| 1000 { | |
| 1001 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1002 std::string script = "var iframe = document.createElement('iframe');" | |
| 1003 "document.body.appendChild(iframe);"; | |
| 1004 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1005 capturer.Wait(); | |
| 1006 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1007 } | |
| 1008 | |
| 1009 // Check last committed NavigationEntry. | |
| 1010 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 1011 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | |
| 1012 EXPECT_EQ(main_url, entry->GetURL()); | |
| 1013 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); | |
| 1014 EXPECT_EQ(main_url, root_entry->url()); | |
| 1015 | |
| 1016 // Verify no subframe entries are created. | |
| 1017 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
| 1018 EXPECT_FALSE(controller.HasCommittedRealLoad(root->child_at(0))); | |
| 1019 | |
| 1020 // 2. Create another iframe with an about:blank URL. | |
| 1021 { | |
| 1022 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1023 std::string script = "var iframe = document.createElement('iframe');" | |
| 1024 "iframe.src = 'about:blank';" | |
| 1025 "document.body.appendChild(iframe);"; | |
| 1026 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1027 capturer.Wait(); | |
| 1028 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1029 } | |
| 1030 | |
| 1031 // Check last committed NavigationEntry. | |
| 1032 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 1033 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); | |
| 1034 | |
| 1035 // Verify no subframe entries are created. | |
| 1036 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
| 1037 EXPECT_FALSE(controller.HasCommittedRealLoad(root->child_at(1))); | |
| 1038 | |
| 1039 // 3. A real same-site navigation in the first iframe should be AUTO. | |
| 1040 GURL frame_url(embedded_test_server()->GetURL( | |
| 1041 "/navigation_controller/simple_page_1.html")); | |
| 1042 { | |
| 1043 LoadCommittedCapturer capturer(root->child_at(0)); | |
| 1044 std::string script = "var frames = document.getElementsByTagName('iframe');" | |
| 1045 "frames[0].src = '" + frame_url.spec() + "';"; | |
| 1046 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1047 capturer.Wait(); | |
| 1048 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1049 } | |
| 1050 | |
| 1051 // Check last committed NavigationEntry. | |
| 1052 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 1053 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); | |
| 1054 | |
| 1055 // Verify subframe entries if we're in --site-per-process mode. | |
| 1056 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1057 switches::kSitePerProcess)) { | |
| 1058 // The entry should now have one subframe FrameNavigationEntry. | |
| 1059 ASSERT_EQ(1U, entry->root_node()->children.size()); | |
| 1060 FrameNavigationEntry* frame_entry = | |
| 1061 entry->root_node()->children[0]->frame_entry.get(); | |
| 1062 EXPECT_EQ(frame_url, frame_entry->url()); | |
| 1063 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(0))); | |
| 1064 EXPECT_FALSE(controller.HasCommittedRealLoad(root->child_at(1))); | |
| 1065 } else { | |
| 1066 // There are no subframe FrameNavigationEntries by default. | |
| 1067 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
| 1068 } | |
| 1069 | |
| 1070 // 4. A real cross-site navigation in the second iframe should be AUTO. | |
| 1071 GURL foo_url(embedded_test_server()->GetURL( | |
| 1072 "foo.com", "/navigation_controller/simple_page_2.html")); | |
| 1073 { | |
| 1074 LoadCommittedCapturer capturer(root->child_at(1)); | |
| 1075 std::string script = "var frames = document.getElementsByTagName('iframe');" | |
| 1076 "frames[1].src = '" + foo_url.spec() + "';"; | |
| 1077 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1078 capturer.Wait(); | |
| 1079 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1080 } | |
| 1081 | |
| 1082 // Check last committed NavigationEntry. | |
| 1083 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 1084 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); | |
| 1085 | |
| 1086 // Verify subframe entries if we're in --site-per-process mode. | |
| 1087 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1088 switches::kSitePerProcess)) { | |
| 1089 // The entry should now have two subframe FrameNavigationEntries. | |
| 1090 ASSERT_EQ(2U, entry->root_node()->children.size()); | |
| 1091 FrameNavigationEntry* frame_entry = | |
| 1092 entry->root_node()->children[1]->frame_entry.get(); | |
| 1093 EXPECT_EQ(foo_url, frame_entry->url()); | |
| 1094 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(1))); | |
| 1095 } else { | |
| 1096 // There are no subframe FrameNavigationEntries by default. | |
| 1097 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
| 1098 } | |
| 1099 | |
| 1100 // Check the end result of the frame tree. | |
| 1101 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1102 switches::kSitePerProcess)) { | |
| 1103 FrameTreeVisualizer visualizer; | |
| 1104 EXPECT_EQ( | |
| 1105 " Site A ------------ proxies for B\n" | |
| 1106 " |--Site A ------- proxies for B\n" | |
| 1107 " +--Site B ------- proxies for A\n" | |
| 1108 "Where A = http://127.0.0.1/\n" | |
| 1109 " B = http://foo.com/", | |
| 1110 visualizer.DepictFrameTree(root)); | |
| 1111 } | |
| 1112 } | |
| 1113 | |
| 1114 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME | 972 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME |
| 1115 // commits. | 973 // commits. |
| 974 // TODO(creis): Test cross-site iframes. |
| 1116 // TODO(creis): Test updating entries for history auto subframe navigations. | 975 // TODO(creis): Test updating entries for history auto subframe navigations. |
| 1117 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 976 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1118 FrameNavigationEntry_AutoSubframe) { | 977 FrameNavigationEntry_AutoSubframe) { |
| 1119 GURL main_url(embedded_test_server()->GetURL( | 978 GURL main_url(embedded_test_server()->GetURL( |
| 1120 "/navigation_controller/simple_page_1.html")); | 979 "/navigation_controller/simple_page_1.html")); |
| 1121 NavigateToURL(shell(), main_url); | 980 NavigateToURL(shell(), main_url); |
| 1122 const NavigationControllerImpl& controller = | 981 const NavigationControllerImpl& controller = |
| 1123 static_cast<const NavigationControllerImpl&>( | 982 static_cast<const NavigationControllerImpl&>( |
| 1124 shell()->web_contents()->GetController()); | 983 shell()->web_contents()->GetController()); |
| 1125 FrameTreeNode* root = | 984 FrameTreeNode* root = |
| 1126 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 985 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1127 GetFrameTree()->root(); | 986 GetFrameTree()->root(); |
| 1128 | 987 |
| 1129 // 1. Create a same-site iframe. | 988 // Create an iframe. |
| 1130 GURL frame_url(embedded_test_server()->GetURL( | 989 GURL frame_url(embedded_test_server()->GetURL( |
| 1131 "/navigation_controller/simple_page_2.html")); | 990 "/navigation_controller/simple_page_2.html")); |
| 1132 { | 991 { |
| 1133 LoadCommittedCapturer capturer(shell()->web_contents()); | 992 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1134 std::string script = "var iframe = document.createElement('iframe');" | 993 std::string script = "var iframe = document.createElement('iframe');" |
| 1135 "iframe.src = '" + frame_url.spec() + "';" | 994 "iframe.src = '" + frame_url.spec() + "';" |
| 1136 "document.body.appendChild(iframe);"; | 995 "document.body.appendChild(iframe);"; |
| 1137 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 996 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1138 capturer.Wait(); | 997 capturer.Wait(); |
| 1139 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 998 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1140 } | 999 } |
| 1141 | 1000 |
| 1142 // Check last committed NavigationEntry. | 1001 // Check last committed NavigationEntry. |
| 1143 EXPECT_EQ(1, controller.GetEntryCount()); | 1002 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1144 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 1003 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 1145 EXPECT_EQ(main_url, entry->GetURL()); | 1004 EXPECT_EQ(main_url, entry->GetURL()); |
| 1146 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); | 1005 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
| 1147 EXPECT_EQ(main_url, root_entry->url()); | 1006 EXPECT_EQ(main_url, root_entry->url()); |
| 1148 EXPECT_FALSE(controller.GetPendingEntry()); | |
| 1149 | 1007 |
| 1150 // Verify subframe entries if we're in --site-per-process mode. | 1008 // Verify subframe entries if we're in --site-per-process mode. |
| 1151 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1009 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1152 switches::kSitePerProcess)) { | 1010 switches::kSitePerProcess)) { |
| 1153 // The entry should now have a subframe FrameNavigationEntry. | 1011 // The entry should now have a subframe FrameNavigationEntry. |
| 1154 ASSERT_EQ(1U, entry->root_node()->children.size()); | 1012 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 1155 FrameNavigationEntry* frame_entry = | 1013 FrameNavigationEntry* frame_entry = |
| 1156 entry->root_node()->children[0]->frame_entry.get(); | 1014 entry->root_node()->children[0]->frame_entry.get(); |
| 1157 EXPECT_EQ(frame_url, frame_entry->url()); | 1015 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1158 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(0))); | |
| 1159 } else { | 1016 } else { |
| 1160 // There are no subframe FrameNavigationEntries by default. | 1017 // There are no subframe FrameNavigationEntries by default. |
| 1161 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1018 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1162 } | 1019 } |
| 1163 | 1020 |
| 1164 // 2. Create a second, initially cross-site iframe. | 1021 // Create a second iframe. |
| 1165 GURL foo_url(embedded_test_server()->GetURL( | |
| 1166 "foo.com", "/navigation_controller/simple_page_1.html")); | |
| 1167 { | 1022 { |
| 1168 LoadCommittedCapturer capturer(shell()->web_contents()); | 1023 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1169 std::string script = "var iframe = document.createElement('iframe');" | 1024 std::string script = "var iframe = document.createElement('iframe');" |
| 1170 "iframe.src = '" + foo_url.spec() + "';" | 1025 "iframe.src = '" + frame_url.spec() + "';" |
| 1171 "document.body.appendChild(iframe);"; | 1026 "document.body.appendChild(iframe);"; |
| 1172 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 1027 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1173 capturer.Wait(); | 1028 capturer.Wait(); |
| 1174 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1029 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1175 } | 1030 } |
| 1176 | 1031 |
| 1177 // The last committed NavigationEntry shouldn't have changed. | 1032 // The last committed NavigationEntry shouldn't have changed. |
| 1178 EXPECT_EQ(1, controller.GetEntryCount()); | 1033 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1179 entry = controller.GetLastCommittedEntry(); | 1034 entry = controller.GetLastCommittedEntry(); |
| 1180 EXPECT_EQ(main_url, entry->GetURL()); | 1035 EXPECT_EQ(main_url, entry->GetURL()); |
| 1181 root_entry = entry->root_node()->frame_entry.get(); | 1036 root_entry = entry->root_node()->frame_entry.get(); |
| 1182 EXPECT_EQ(main_url, root_entry->url()); | 1037 EXPECT_EQ(main_url, root_entry->url()); |
| 1183 EXPECT_FALSE(controller.GetPendingEntry()); | |
| 1184 | 1038 |
| 1185 // Verify subframe entries if we're in --site-per-process mode. | 1039 // Verify subframe entries if we're in --site-per-process mode. |
| 1186 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1040 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1187 switches::kSitePerProcess)) { | 1041 switches::kSitePerProcess)) { |
| 1188 // The entry should now have 2 subframe FrameNavigationEntries. | 1042 // The entry should now have 2 subframe FrameNavigationEntries. |
| 1189 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1043 ASSERT_EQ(2U, entry->root_node()->children.size()); |
| 1190 FrameNavigationEntry* frame_entry = | 1044 FrameNavigationEntry* frame_entry = |
| 1191 entry->root_node()->children[1]->frame_entry.get(); | 1045 entry->root_node()->children[1]->frame_entry.get(); |
| 1192 EXPECT_EQ(foo_url, frame_entry->url()); | 1046 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1193 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(1))); | |
| 1194 } else { | 1047 } else { |
| 1195 // There are no subframe FrameNavigationEntries by default. | 1048 // There are no subframe FrameNavigationEntries by default. |
| 1196 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1049 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1197 } | 1050 } |
| 1198 | 1051 |
| 1199 // 3. Create a nested iframe in the second subframe. | 1052 // Create a nested iframe in the second subframe. |
| 1200 { | 1053 { |
| 1201 LoadCommittedCapturer capturer(shell()->web_contents()); | 1054 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1202 std::string script = "var iframe = document.createElement('iframe');" | 1055 std::string script = "var iframe = document.createElement('iframe');" |
| 1203 "iframe.src = '" + foo_url.spec() + "';" | 1056 "iframe.src = '" + frame_url.spec() + "';" |
| 1204 "document.body.appendChild(iframe);"; | 1057 "document.body.appendChild(iframe);"; |
| 1205 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), | 1058 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), |
| 1206 script)); | 1059 script)); |
| 1207 capturer.Wait(); | 1060 capturer.Wait(); |
| 1208 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1061 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1209 } | 1062 } |
| 1210 | 1063 |
| 1211 // The last committed NavigationEntry shouldn't have changed. | 1064 // The last committed NavigationEntry shouldn't have changed. |
| 1212 EXPECT_EQ(1, controller.GetEntryCount()); | 1065 EXPECT_EQ(1, controller.GetEntryCount()); |
| 1213 entry = controller.GetLastCommittedEntry(); | 1066 entry = controller.GetLastCommittedEntry(); |
| 1214 EXPECT_EQ(main_url, entry->GetURL()); | 1067 EXPECT_EQ(main_url, entry->GetURL()); |
| 1215 root_entry = entry->root_node()->frame_entry.get(); | 1068 root_entry = entry->root_node()->frame_entry.get(); |
| 1216 EXPECT_EQ(main_url, root_entry->url()); | 1069 EXPECT_EQ(main_url, root_entry->url()); |
| 1217 | 1070 |
| 1218 // Verify subframe entries if we're in --site-per-process mode. | 1071 // Verify subframe entries if we're in --site-per-process mode. |
| 1219 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1072 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1220 switches::kSitePerProcess)) { | 1073 switches::kSitePerProcess)) { |
| 1221 // The entry should now have 2 subframe FrameNavigationEntries. | 1074 // The entry should now have 2 subframe FrameNavigationEntries. |
| 1222 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1075 ASSERT_EQ(2U, entry->root_node()->children.size()); |
| 1223 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); | 1076 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); |
| 1224 FrameNavigationEntry* frame_entry = | 1077 FrameNavigationEntry* frame_entry = |
| 1225 entry->root_node()->children[1]->children[0]->frame_entry.get(); | 1078 entry->root_node()->children[1]->children[0]->frame_entry.get(); |
| 1226 EXPECT_EQ(foo_url, frame_entry->url()); | 1079 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1227 } else { | 1080 } else { |
| 1228 // There are no subframe FrameNavigationEntries by default. | 1081 // There are no subframe FrameNavigationEntries by default. |
| 1229 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1082 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1230 } | 1083 } |
| 1231 | |
| 1232 // TODO(creis): Add tests for another subframe on B, and for a subframe on A | |
| 1233 // within it. Both are currently broken. | |
| 1234 | |
| 1235 // Check the end result of the frame tree. | |
| 1236 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1237 switches::kSitePerProcess)) { | |
| 1238 FrameTreeVisualizer visualizer; | |
| 1239 EXPECT_EQ( | |
| 1240 " Site A ------------ proxies for B\n" | |
| 1241 " |--Site A ------- proxies for B\n" | |
| 1242 " +--Site B ------- proxies for A\n" | |
| 1243 " +--Site B -- proxies for A\n" | |
| 1244 "Where A = http://127.0.0.1/\n" | |
| 1245 " B = http://foo.com/", | |
| 1246 visualizer.DepictFrameTree(root)); | |
| 1247 } | |
| 1248 } | 1084 } |
| 1249 | 1085 |
| 1250 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME | |
| 1251 // commits. | |
| 1252 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 1253 FrameNavigationEntry_NewSubframe) { | |
| 1254 GURL main_url(embedded_test_server()->GetURL( | |
| 1255 "/navigation_controller/simple_page_1.html")); | |
| 1256 NavigateToURL(shell(), main_url); | |
| 1257 FrameTreeNode* root = | |
| 1258 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 1259 GetFrameTree()->root(); | |
| 1260 | |
| 1261 // 1. Create a same-site iframe. | |
| 1262 GURL frame_url(embedded_test_server()->GetURL( | |
| 1263 "/navigation_controller/simple_page_2.html")); | |
| 1264 { | |
| 1265 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1266 std::string script = "var iframe = document.createElement('iframe');" | |
| 1267 "iframe.src = '" + frame_url.spec() + "';" | |
| 1268 "document.body.appendChild(iframe);"; | |
| 1269 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1270 capturer.Wait(); | |
| 1271 } | |
| 1272 | |
| 1273 // 2. Navigate in the first subframe same-site. | |
| 1274 GURL frame_url2(embedded_test_server()->GetURL( | |
| 1275 "/navigation_controller/page_with_links.html")); | |
| 1276 { | |
| 1277 FrameNavigateParamsCapturer capturer(root->child_at(0)); | |
| 1278 NavigateFrameToURL(root->child_at(0), frame_url2); | |
| 1279 capturer.Wait(); | |
| 1280 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | |
| 1281 capturer.params().transition); | |
| 1282 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | |
| 1283 } | |
| 1284 | |
| 1285 // 3. Create a second, initially cross-site iframe. | |
| 1286 GURL foo_url(embedded_test_server()->GetURL( | |
| 1287 "foo.com", "/navigation_controller/simple_page_1.html")); | |
| 1288 { | |
| 1289 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1290 std::string script = "var iframe = document.createElement('iframe');" | |
| 1291 "iframe.src = '" + foo_url.spec() + "';" | |
| 1292 "document.body.appendChild(iframe);"; | |
| 1293 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1294 capturer.Wait(); | |
| 1295 } | |
| 1296 | |
| 1297 // 4. Navigate in the second subframe cross-site. | |
| 1298 GURL bar_url(embedded_test_server()->GetURL( | |
| 1299 "bar.com", "/navigation_controller/simple_page_1.html")); | |
| 1300 { | |
| 1301 FrameNavigateParamsCapturer capturer(root->child_at(1)); | |
| 1302 std::string script = "var frames = document.getElementsByTagName('iframe');" | |
| 1303 "frames[1].src = '" + bar_url.spec() + "';"; | |
| 1304 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1305 capturer.Wait(); | |
| 1306 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | |
| 1307 capturer.params().transition); | |
| 1308 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | |
| 1309 } | |
| 1310 | |
| 1311 // TODO(creis): Expand this test once we clone FrameNavigationEntries for | |
| 1312 // NEW_SUBFRAME navigations. | |
| 1313 | |
| 1314 // Check the end result of the frame tree. | |
| 1315 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1316 switches::kSitePerProcess)) { | |
| 1317 FrameTreeVisualizer visualizer; | |
| 1318 EXPECT_EQ( | |
| 1319 " Site A ------------ proxies for B\n" | |
| 1320 " |--Site A ------- proxies for B\n" | |
| 1321 " +--Site B ------- proxies for A\n" | |
| 1322 "Where A = http://127.0.0.1/\n" | |
| 1323 " B = http://bar.com/", | |
| 1324 visualizer.DepictFrameTree(root)); | |
| 1325 } | |
| 1326 } | |
| 1327 | |
| 1328 namespace { | 1086 namespace { |
| 1329 | 1087 |
| 1330 class HttpThrottle : public ResourceThrottle { | 1088 class HttpThrottle : public ResourceThrottle { |
| 1331 public: | 1089 public: |
| 1332 // ResourceThrottle | 1090 // ResourceThrottle |
| 1333 void WillStartRequest(bool* defer) override { | 1091 void WillStartRequest(bool* defer) override { |
| 1334 *defer = true; | 1092 *defer = true; |
| 1335 } | 1093 } |
| 1336 | 1094 |
| 1337 const char* GetNameForLogging() const override { | 1095 const char* GetNameForLogging() const override { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 // tricky. | 1430 // tricky. |
| 1673 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 1431 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
| 1674 shell()->web_contents()->Stop(); | 1432 shell()->web_contents()->Stop(); |
| 1675 watcher.Wait(); | 1433 watcher.Wait(); |
| 1676 } | 1434 } |
| 1677 | 1435 |
| 1678 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1436 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 1679 } | 1437 } |
| 1680 | 1438 |
| 1681 } // namespace content | 1439 } // namespace content |
| OLD | NEW |