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_); | |
380 RenderFrameHostImpl* rfh = | 377 RenderFrameHostImpl* rfh = |
381 static_cast<RenderFrameHostImpl*>(render_frame_host); | 378 static_cast<RenderFrameHostImpl*>(render_frame_host); |
382 frame_tree_node_id_ = rfh->frame_tree_node()->frame_tree_node_id(); | 379 |
| 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; |
383 } | 396 } |
384 | 397 |
385 void DidCommitProvisionalLoadForFrame( | 398 void DidCommitProvisionalLoadForFrame( |
386 RenderFrameHost* render_frame_host, | 399 RenderFrameHost* render_frame_host, |
387 const GURL& url, | 400 const GURL& url, |
388 ui::PageTransition transition_type) override { | 401 ui::PageTransition transition_type) override { |
389 DCHECK_NE(0, frame_tree_node_id_); | 402 DCHECK_NE(0, frame_tree_node_id_); |
390 RenderFrameHostImpl* rfh = | 403 RenderFrameHostImpl* rfh = |
391 static_cast<RenderFrameHostImpl*>(render_frame_host); | 404 static_cast<RenderFrameHostImpl*>(render_frame_host); |
392 if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) | 405 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... |
962 ASSERT_EQ(2U, params.size()); | 975 ASSERT_EQ(2U, params.size()); |
963 ASSERT_EQ(2U, details.size()); | 976 ASSERT_EQ(2U, details.size()); |
964 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); | 977 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); |
965 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); | 978 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); |
966 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 979 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
967 params[1].transition); | 980 params[1].transition); |
968 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); | 981 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); |
969 } | 982 } |
970 } | 983 } |
971 | 984 |
| 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 |
972 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME | 1114 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_AUTO_SUBFRAME |
973 // commits. | 1115 // commits. |
974 // TODO(creis): Test cross-site iframes. | |
975 // TODO(creis): Test updating entries for history auto subframe navigations. | 1116 // TODO(creis): Test updating entries for history auto subframe navigations. |
976 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1117 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
977 FrameNavigationEntry_AutoSubframe) { | 1118 FrameNavigationEntry_AutoSubframe) { |
978 GURL main_url(embedded_test_server()->GetURL( | 1119 GURL main_url(embedded_test_server()->GetURL( |
979 "/navigation_controller/simple_page_1.html")); | 1120 "/navigation_controller/simple_page_1.html")); |
980 NavigateToURL(shell(), main_url); | 1121 NavigateToURL(shell(), main_url); |
981 const NavigationControllerImpl& controller = | 1122 const NavigationControllerImpl& controller = |
982 static_cast<const NavigationControllerImpl&>( | 1123 static_cast<const NavigationControllerImpl&>( |
983 shell()->web_contents()->GetController()); | 1124 shell()->web_contents()->GetController()); |
984 FrameTreeNode* root = | 1125 FrameTreeNode* root = |
985 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1126 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
986 GetFrameTree()->root(); | 1127 GetFrameTree()->root(); |
987 | 1128 |
988 // Create an iframe. | 1129 // 1. Create a same-site iframe. |
989 GURL frame_url(embedded_test_server()->GetURL( | 1130 GURL frame_url(embedded_test_server()->GetURL( |
990 "/navigation_controller/simple_page_2.html")); | 1131 "/navigation_controller/simple_page_2.html")); |
991 { | 1132 { |
992 LoadCommittedCapturer capturer(shell()->web_contents()); | 1133 LoadCommittedCapturer capturer(shell()->web_contents()); |
993 std::string script = "var iframe = document.createElement('iframe');" | 1134 std::string script = "var iframe = document.createElement('iframe');" |
994 "iframe.src = '" + frame_url.spec() + "';" | 1135 "iframe.src = '" + frame_url.spec() + "';" |
995 "document.body.appendChild(iframe);"; | 1136 "document.body.appendChild(iframe);"; |
996 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 1137 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
997 capturer.Wait(); | 1138 capturer.Wait(); |
998 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1139 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
999 } | 1140 } |
1000 | 1141 |
1001 // Check last committed NavigationEntry. | 1142 // Check last committed NavigationEntry. |
1002 EXPECT_EQ(1, controller.GetEntryCount()); | 1143 EXPECT_EQ(1, controller.GetEntryCount()); |
1003 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 1144 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
1004 EXPECT_EQ(main_url, entry->GetURL()); | 1145 EXPECT_EQ(main_url, entry->GetURL()); |
1005 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); | 1146 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); |
1006 EXPECT_EQ(main_url, root_entry->url()); | 1147 EXPECT_EQ(main_url, root_entry->url()); |
| 1148 EXPECT_FALSE(controller.GetPendingEntry()); |
1007 | 1149 |
1008 // Verify subframe entries if we're in --site-per-process mode. | 1150 // Verify subframe entries if we're in --site-per-process mode. |
1009 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1151 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1010 switches::kSitePerProcess)) { | 1152 switches::kSitePerProcess)) { |
1011 // The entry should now have a subframe FrameNavigationEntry. | 1153 // The entry should now have a subframe FrameNavigationEntry. |
1012 ASSERT_EQ(1U, entry->root_node()->children.size()); | 1154 ASSERT_EQ(1U, entry->root_node()->children.size()); |
1013 FrameNavigationEntry* frame_entry = | 1155 FrameNavigationEntry* frame_entry = |
1014 entry->root_node()->children[0]->frame_entry.get(); | 1156 entry->root_node()->children[0]->frame_entry.get(); |
1015 EXPECT_EQ(frame_url, frame_entry->url()); | 1157 EXPECT_EQ(frame_url, frame_entry->url()); |
| 1158 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(0))); |
1016 } else { | 1159 } else { |
1017 // There are no subframe FrameNavigationEntries by default. | 1160 // There are no subframe FrameNavigationEntries by default. |
1018 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1161 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1019 } | 1162 } |
1020 | 1163 |
1021 // Create a second iframe. | 1164 // 2. Create a second, initially cross-site iframe. |
| 1165 GURL foo_url(embedded_test_server()->GetURL( |
| 1166 "foo.com", "/navigation_controller/simple_page_1.html")); |
1022 { | 1167 { |
1023 LoadCommittedCapturer capturer(shell()->web_contents()); | 1168 LoadCommittedCapturer capturer(shell()->web_contents()); |
1024 std::string script = "var iframe = document.createElement('iframe');" | 1169 std::string script = "var iframe = document.createElement('iframe');" |
1025 "iframe.src = '" + frame_url.spec() + "';" | 1170 "iframe.src = '" + foo_url.spec() + "';" |
1026 "document.body.appendChild(iframe);"; | 1171 "document.body.appendChild(iframe);"; |
1027 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 1172 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
1028 capturer.Wait(); | 1173 capturer.Wait(); |
1029 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1174 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
1030 } | 1175 } |
1031 | 1176 |
1032 // The last committed NavigationEntry shouldn't have changed. | 1177 // The last committed NavigationEntry shouldn't have changed. |
1033 EXPECT_EQ(1, controller.GetEntryCount()); | 1178 EXPECT_EQ(1, controller.GetEntryCount()); |
1034 entry = controller.GetLastCommittedEntry(); | 1179 entry = controller.GetLastCommittedEntry(); |
1035 EXPECT_EQ(main_url, entry->GetURL()); | 1180 EXPECT_EQ(main_url, entry->GetURL()); |
1036 root_entry = entry->root_node()->frame_entry.get(); | 1181 root_entry = entry->root_node()->frame_entry.get(); |
1037 EXPECT_EQ(main_url, root_entry->url()); | 1182 EXPECT_EQ(main_url, root_entry->url()); |
| 1183 EXPECT_FALSE(controller.GetPendingEntry()); |
1038 | 1184 |
1039 // Verify subframe entries if we're in --site-per-process mode. | 1185 // Verify subframe entries if we're in --site-per-process mode. |
1040 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1186 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1041 switches::kSitePerProcess)) { | 1187 switches::kSitePerProcess)) { |
1042 // The entry should now have 2 subframe FrameNavigationEntries. | 1188 // The entry should now have 2 subframe FrameNavigationEntries. |
1043 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1189 ASSERT_EQ(2U, entry->root_node()->children.size()); |
1044 FrameNavigationEntry* frame_entry = | 1190 FrameNavigationEntry* frame_entry = |
1045 entry->root_node()->children[1]->frame_entry.get(); | 1191 entry->root_node()->children[1]->frame_entry.get(); |
1046 EXPECT_EQ(frame_url, frame_entry->url()); | 1192 EXPECT_EQ(foo_url, frame_entry->url()); |
| 1193 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(1))); |
1047 } else { | 1194 } else { |
1048 // There are no subframe FrameNavigationEntries by default. | 1195 // There are no subframe FrameNavigationEntries by default. |
1049 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1196 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1050 } | 1197 } |
1051 | 1198 |
1052 // Create a nested iframe in the second subframe. | 1199 // 3. Create a nested iframe in the second subframe. |
1053 { | 1200 { |
1054 LoadCommittedCapturer capturer(shell()->web_contents()); | 1201 LoadCommittedCapturer capturer(shell()->web_contents()); |
1055 std::string script = "var iframe = document.createElement('iframe');" | 1202 std::string script = "var iframe = document.createElement('iframe');" |
1056 "iframe.src = '" + frame_url.spec() + "';" | 1203 "iframe.src = '" + foo_url.spec() + "';" |
1057 "document.body.appendChild(iframe);"; | 1204 "document.body.appendChild(iframe);"; |
1058 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), | 1205 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), |
1059 script)); | 1206 script)); |
1060 capturer.Wait(); | 1207 capturer.Wait(); |
1061 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1208 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
1062 } | 1209 } |
1063 | 1210 |
1064 // The last committed NavigationEntry shouldn't have changed. | 1211 // The last committed NavigationEntry shouldn't have changed. |
1065 EXPECT_EQ(1, controller.GetEntryCount()); | 1212 EXPECT_EQ(1, controller.GetEntryCount()); |
1066 entry = controller.GetLastCommittedEntry(); | 1213 entry = controller.GetLastCommittedEntry(); |
1067 EXPECT_EQ(main_url, entry->GetURL()); | 1214 EXPECT_EQ(main_url, entry->GetURL()); |
1068 root_entry = entry->root_node()->frame_entry.get(); | 1215 root_entry = entry->root_node()->frame_entry.get(); |
1069 EXPECT_EQ(main_url, root_entry->url()); | 1216 EXPECT_EQ(main_url, root_entry->url()); |
1070 | 1217 |
1071 // Verify subframe entries if we're in --site-per-process mode. | 1218 // Verify subframe entries if we're in --site-per-process mode. |
1072 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1219 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1073 switches::kSitePerProcess)) { | 1220 switches::kSitePerProcess)) { |
1074 // The entry should now have 2 subframe FrameNavigationEntries. | 1221 // The entry should now have 2 subframe FrameNavigationEntries. |
1075 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1222 ASSERT_EQ(2U, entry->root_node()->children.size()); |
1076 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); | 1223 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); |
1077 FrameNavigationEntry* frame_entry = | 1224 FrameNavigationEntry* frame_entry = |
1078 entry->root_node()->children[1]->children[0]->frame_entry.get(); | 1225 entry->root_node()->children[1]->children[0]->frame_entry.get(); |
1079 EXPECT_EQ(frame_url, frame_entry->url()); | 1226 EXPECT_EQ(foo_url, frame_entry->url()); |
1080 } else { | 1227 } else { |
1081 // There are no subframe FrameNavigationEntries by default. | 1228 // There are no subframe FrameNavigationEntries by default. |
1082 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1229 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1083 } | 1230 } |
| 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 } |
| 1249 |
| 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 } |
1084 } | 1326 } |
1085 | 1327 |
1086 namespace { | 1328 namespace { |
1087 | 1329 |
1088 class HttpThrottle : public ResourceThrottle { | 1330 class HttpThrottle : public ResourceThrottle { |
1089 public: | 1331 public: |
1090 // ResourceThrottle | 1332 // ResourceThrottle |
1091 void WillStartRequest(bool* defer) override { | 1333 void WillStartRequest(bool* defer) override { |
1092 *defer = true; | 1334 *defer = true; |
1093 } | 1335 } |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 // tricky. | 1672 // tricky. |
1431 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 1673 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
1432 shell()->web_contents()->Stop(); | 1674 shell()->web_contents()->Stop(); |
1433 watcher.Wait(); | 1675 watcher.Wait(); |
1434 } | 1676 } |
1435 | 1677 |
1436 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1678 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
1437 } | 1679 } |
1438 | 1680 |
1439 } // namespace content | 1681 } // namespace content |
OLD | NEW |