Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 1148953014: Fix the commit type for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix failing tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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());
1007 1148
1008 // Verify subframe entries if we're in --site-per-process mode. 1149 // Verify subframe entries if we're in --site-per-process mode.
1009 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1150 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1010 switches::kSitePerProcess)) { 1151 switches::kSitePerProcess)) {
1011 // The entry should now have a subframe FrameNavigationEntry. 1152 // The entry should now have a subframe FrameNavigationEntry.
1012 ASSERT_EQ(1U, entry->root_node()->children.size()); 1153 ASSERT_EQ(1U, entry->root_node()->children.size());
1013 FrameNavigationEntry* frame_entry = 1154 FrameNavigationEntry* frame_entry =
1014 entry->root_node()->children[0]->frame_entry.get(); 1155 entry->root_node()->children[0]->frame_entry.get();
1015 EXPECT_EQ(frame_url, frame_entry->url()); 1156 EXPECT_EQ(frame_url, frame_entry->url());
1157 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(0)));
1016 } else { 1158 } else {
1017 // There are no subframe FrameNavigationEntries by default. 1159 // There are no subframe FrameNavigationEntries by default.
1018 EXPECT_EQ(0U, entry->root_node()->children.size()); 1160 EXPECT_EQ(0U, entry->root_node()->children.size());
1019 } 1161 }
1020 1162
1021 // Create a second iframe. 1163 // 2. Create a second, initially cross-site iframe.
1164 GURL foo_url(embedded_test_server()->GetURL(
1165 "foo.com", "/navigation_controller/simple_page_1.html"));
1022 { 1166 {
1023 LoadCommittedCapturer capturer(shell()->web_contents()); 1167 LoadCommittedCapturer capturer(shell()->web_contents());
1024 std::string script = "var iframe = document.createElement('iframe');" 1168 std::string script = "var iframe = document.createElement('iframe');"
1025 "iframe.src = '" + frame_url.spec() + "';" 1169 "iframe.src = '" + foo_url.spec() + "';"
1026 "document.body.appendChild(iframe);"; 1170 "document.body.appendChild(iframe);";
1027 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 1171 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1028 capturer.Wait(); 1172 capturer.Wait();
1029 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 1173 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1030 } 1174 }
1031 1175
1032 // The last committed NavigationEntry shouldn't have changed. 1176 // The last committed NavigationEntry shouldn't have changed.
1033 EXPECT_EQ(1, controller.GetEntryCount()); 1177 EXPECT_EQ(1, controller.GetEntryCount());
1034 entry = controller.GetLastCommittedEntry(); 1178 entry = controller.GetLastCommittedEntry();
1035 EXPECT_EQ(main_url, entry->GetURL()); 1179 EXPECT_EQ(main_url, entry->GetURL());
1036 root_entry = entry->root_node()->frame_entry.get(); 1180 root_entry = entry->root_node()->frame_entry.get();
1037 EXPECT_EQ(main_url, root_entry->url()); 1181 EXPECT_EQ(main_url, root_entry->url());
1038 1182
1039 // Verify subframe entries if we're in --site-per-process mode. 1183 // Verify subframe entries if we're in --site-per-process mode.
1040 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1184 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1041 switches::kSitePerProcess)) { 1185 switches::kSitePerProcess)) {
1042 // The entry should now have 2 subframe FrameNavigationEntries. 1186 // The entry should now have 2 subframe FrameNavigationEntries.
1043 ASSERT_EQ(2U, entry->root_node()->children.size()); 1187 ASSERT_EQ(2U, entry->root_node()->children.size());
1044 FrameNavigationEntry* frame_entry = 1188 FrameNavigationEntry* frame_entry =
1045 entry->root_node()->children[1]->frame_entry.get(); 1189 entry->root_node()->children[1]->frame_entry.get();
1046 EXPECT_EQ(frame_url, frame_entry->url()); 1190 EXPECT_EQ(foo_url, frame_entry->url());
1191 EXPECT_TRUE(controller.HasCommittedRealLoad(root->child_at(1)));
1047 } else { 1192 } else {
1048 // There are no subframe FrameNavigationEntries by default. 1193 // There are no subframe FrameNavigationEntries by default.
1049 EXPECT_EQ(0U, entry->root_node()->children.size()); 1194 EXPECT_EQ(0U, entry->root_node()->children.size());
1050 } 1195 }
1051 1196
1052 // Create a nested iframe in the second subframe. 1197 // 3. Create a nested iframe in the second subframe.
1053 { 1198 {
1054 LoadCommittedCapturer capturer(shell()->web_contents()); 1199 LoadCommittedCapturer capturer(shell()->web_contents());
1055 std::string script = "var iframe = document.createElement('iframe');" 1200 std::string script = "var iframe = document.createElement('iframe');"
1056 "iframe.src = '" + frame_url.spec() + "';" 1201 "iframe.src = '" + foo_url.spec() + "';"
1057 "document.body.appendChild(iframe);"; 1202 "document.body.appendChild(iframe);";
1058 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), 1203 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(),
1059 script)); 1204 script));
1060 capturer.Wait(); 1205 capturer.Wait();
1061 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 1206 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1062 } 1207 }
1063 1208
1064 // The last committed NavigationEntry shouldn't have changed. 1209 // The last committed NavigationEntry shouldn't have changed.
1065 EXPECT_EQ(1, controller.GetEntryCount()); 1210 EXPECT_EQ(1, controller.GetEntryCount());
1066 entry = controller.GetLastCommittedEntry(); 1211 entry = controller.GetLastCommittedEntry();
1067 EXPECT_EQ(main_url, entry->GetURL()); 1212 EXPECT_EQ(main_url, entry->GetURL());
1068 root_entry = entry->root_node()->frame_entry.get(); 1213 root_entry = entry->root_node()->frame_entry.get();
1069 EXPECT_EQ(main_url, root_entry->url()); 1214 EXPECT_EQ(main_url, root_entry->url());
1070 1215
1071 // Verify subframe entries if we're in --site-per-process mode. 1216 // Verify subframe entries if we're in --site-per-process mode.
1072 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1217 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1073 switches::kSitePerProcess)) { 1218 switches::kSitePerProcess)) {
1074 // The entry should now have 2 subframe FrameNavigationEntries. 1219 // The entry should now have 2 subframe FrameNavigationEntries.
1075 ASSERT_EQ(2U, entry->root_node()->children.size()); 1220 ASSERT_EQ(2U, entry->root_node()->children.size());
1076 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); 1221 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size());
1077 FrameNavigationEntry* frame_entry = 1222 FrameNavigationEntry* frame_entry =
1078 entry->root_node()->children[1]->children[0]->frame_entry.get(); 1223 entry->root_node()->children[1]->children[0]->frame_entry.get();
1079 EXPECT_EQ(frame_url, frame_entry->url()); 1224 EXPECT_EQ(foo_url, frame_entry->url());
1080 } else { 1225 } else {
1081 // There are no subframe FrameNavigationEntries by default. 1226 // There are no subframe FrameNavigationEntries by default.
1082 EXPECT_EQ(0U, entry->root_node()->children.size()); 1227 EXPECT_EQ(0U, entry->root_node()->children.size());
1083 } 1228 }
1229
1230 // TODO(creis): Add tests for another subframe on B, and for a subframe on A
1231 // within it. Both are currently broken.
1232
1233 // Check the end result of the frame tree.
1234 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1235 switches::kSitePerProcess)) {
1236 FrameTreeVisualizer visualizer;
1237 EXPECT_EQ(
1238 " Site A ------------ proxies for B\n"
1239 " |--Site A ------- proxies for B\n"
1240 " +--Site B ------- proxies for A\n"
1241 " +--Site B -- proxies for A\n"
1242 "Where A = http://127.0.0.1/\n"
1243 " B = http://foo.com/",
1244 visualizer.DepictFrameTree(root));
1245 }
1246 }
1247
1248 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME
1249 // commits.
1250 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1251 FrameNavigationEntry_NewSubframe) {
1252 GURL main_url(embedded_test_server()->GetURL(
1253 "/navigation_controller/simple_page_1.html"));
1254 NavigateToURL(shell(), main_url);
1255 FrameTreeNode* root =
1256 static_cast<WebContentsImpl*>(shell()->web_contents())->
1257 GetFrameTree()->root();
1258
1259 // 1. Create a same-site iframe.
1260 GURL frame_url(embedded_test_server()->GetURL(
1261 "/navigation_controller/simple_page_2.html"));
1262 {
1263 LoadCommittedCapturer capturer(shell()->web_contents());
1264 std::string script = "var iframe = document.createElement('iframe');"
1265 "iframe.src = '" + frame_url.spec() + "';"
1266 "document.body.appendChild(iframe);";
1267 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1268 capturer.Wait();
1269 }
1270
1271 // 2. Navigate in the first subframe same-site.
1272 GURL frame_url2(embedded_test_server()->GetURL(
1273 "/navigation_controller/page_with_links.html"));
1274 {
1275 FrameNavigateParamsCapturer capturer(root->child_at(0));
1276 NavigateFrameToURL(root->child_at(0), frame_url2);
1277 capturer.Wait();
1278 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1279 capturer.params().transition);
1280 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1281 }
1282
1283 // 3. Create a second, initially cross-site iframe.
1284 GURL foo_url(embedded_test_server()->GetURL(
1285 "foo.com", "/navigation_controller/simple_page_1.html"));
1286 {
1287 LoadCommittedCapturer capturer(shell()->web_contents());
1288 std::string script = "var iframe = document.createElement('iframe');"
1289 "iframe.src = '" + foo_url.spec() + "';"
1290 "document.body.appendChild(iframe);";
1291 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1292 capturer.Wait();
1293 }
1294
1295 // 4. Navigate in the second subframe cross-site.
1296 GURL bar_url(embedded_test_server()->GetURL(
1297 "bar.com", "/navigation_controller/simple_page_1.html"));
1298 {
1299 FrameNavigateParamsCapturer capturer(root->child_at(1));
1300 std::string script = "var frames = document.getElementsByTagName('iframe');"
1301 "frames[1].src = '" + bar_url.spec() + "';";
1302 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1303 // NavigateFrameToURL(root->child_at(1), bar_url);
1304 capturer.Wait();
1305 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1306 capturer.params().transition);
1307 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1308 }
1309
1310 // TODO(creis): Expand this test once we clone FrameNavigationEntries for
1311 // NEW_SUBFRAME navigations.
1312
1313 // Check the end result of the frame tree.
1314 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1315 switches::kSitePerProcess)) {
1316 FrameTreeVisualizer visualizer;
1317 EXPECT_EQ(
1318 " Site A ------------ proxies for B\n"
1319 " |--Site A ------- proxies for B\n"
1320 " +--Site B ------- proxies for A\n"
1321 "Where A = http://127.0.0.1/\n"
1322 " B = http://bar.com/",
1323 visualizer.DepictFrameTree(root));
1324 }
1084 } 1325 }
1085 1326
1086 namespace { 1327 namespace {
1087 1328
1088 class HttpThrottle : public ResourceThrottle { 1329 class HttpThrottle : public ResourceThrottle {
1089 public: 1330 public:
1090 // ResourceThrottle 1331 // ResourceThrottle
1091 void WillStartRequest(bool* defer) override { 1332 void WillStartRequest(bool* defer) override {
1092 *defer = true; 1333 *defer = true;
1093 } 1334 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 // tricky. 1671 // tricky.
1431 EXPECT_EQ(nullptr, controller.GetPendingEntry()); 1672 EXPECT_EQ(nullptr, controller.GetPendingEntry());
1432 shell()->web_contents()->Stop(); 1673 shell()->web_contents()->Stop();
1433 watcher.Wait(); 1674 watcher.Wait();
1434 } 1675 }
1435 1676
1436 ResourceDispatcherHost::Get()->SetDelegate(nullptr); 1677 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
1437 } 1678 }
1438 1679
1439 } // namespace content 1680 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698