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

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

Issue 1143653002: Create FrameNavigationEntries for manual subframe navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use MatchesFrame Created 5 years, 7 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ASSERT_EQ(2U, params.size()); 941 ASSERT_EQ(2U, params.size());
942 ASSERT_EQ(2U, details.size()); 942 ASSERT_EQ(2U, details.size());
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_NEW_SUBFRAME
952 // commits. 952 // and NAVIGATION_TYPE_AUTO_SUBFRAME commits. Steps:
953 // 1. Create an iframe.
954 // 2. Create a second iframe.
955 // 3. Create a nested iframe in the second iframe.
956 // 4. Navigate in the first iframe.
957 // 5. Navigate in the nested subframe.
958 // 6. Navigate in the second subframe, clearing its existing subtree.
959 //
953 // TODO(creis): Test cross-site iframes. 960 // TODO(creis): Test cross-site iframes.
954 // TODO(creis): Test updating entries for history auto subframe navigations. 961 // TODO(creis): Test updating entries for history auto subframe navigations.
955 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 962 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
956 FrameNavigationEntry_AutoSubframe) { 963 FrameNavigationEntry_NewAndAutoSubframe) {
957 GURL main_url(embedded_test_server()->GetURL( 964 GURL main_url(embedded_test_server()->GetURL(
958 "/navigation_controller/simple_page_1.html")); 965 "/navigation_controller/simple_page_1.html"));
959 NavigateToURL(shell(), main_url); 966 NavigateToURL(shell(), main_url);
960 const NavigationControllerImpl& controller = 967 const NavigationControllerImpl& controller =
961 static_cast<const NavigationControllerImpl&>( 968 static_cast<const NavigationControllerImpl&>(
962 shell()->web_contents()->GetController()); 969 shell()->web_contents()->GetController());
963 FrameTreeNode* root = 970 FrameTreeNode* root =
964 static_cast<WebContentsImpl*>(shell()->web_contents())-> 971 static_cast<WebContentsImpl*>(shell()->web_contents())->
965 GetFrameTree()->root(); 972 GetFrameTree()->root();
966 973
967 // Create an iframe. 974 // 1. Create an iframe.
968 GURL frame_url(embedded_test_server()->GetURL( 975 GURL frame_url(embedded_test_server()->GetURL(
969 "/navigation_controller/simple_page_2.html")); 976 "/navigation_controller/simple_page_2.html"));
970 { 977 {
971 LoadCommittedCapturer capturer(shell()->web_contents()); 978 LoadCommittedCapturer capturer(shell()->web_contents());
972 std::string script = "var iframe = document.createElement('iframe');" 979 std::string script = "var iframe = document.createElement('iframe');"
973 "iframe.src = '" + frame_url.spec() + "';" 980 "iframe.src = '" + frame_url.spec() + "';"
974 "document.body.appendChild(iframe);"; 981 "document.body.appendChild(iframe);";
975 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 982 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
976 capturer.Wait(); 983 capturer.Wait();
977 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 984 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
(...skipping 12 matching lines...) Expand all
990 // The entry should now have a subframe FrameNavigationEntry. 997 // The entry should now have a subframe FrameNavigationEntry.
991 ASSERT_EQ(1U, entry->root_node()->children.size()); 998 ASSERT_EQ(1U, entry->root_node()->children.size());
992 FrameNavigationEntry* frame_entry = 999 FrameNavigationEntry* frame_entry =
993 entry->root_node()->children[0]->frame_entry.get(); 1000 entry->root_node()->children[0]->frame_entry.get();
994 EXPECT_EQ(frame_url, frame_entry->url()); 1001 EXPECT_EQ(frame_url, frame_entry->url());
995 } else { 1002 } else {
996 // There are no subframe FrameNavigationEntries by default. 1003 // There are no subframe FrameNavigationEntries by default.
997 EXPECT_EQ(0U, entry->root_node()->children.size()); 1004 EXPECT_EQ(0U, entry->root_node()->children.size());
998 } 1005 }
999 1006
1000 // Create a second iframe. 1007 // 2. Create a second iframe.
1001 { 1008 {
1002 LoadCommittedCapturer capturer(shell()->web_contents()); 1009 LoadCommittedCapturer capturer(shell()->web_contents());
1003 std::string script = "var iframe = document.createElement('iframe');" 1010 std::string script = "var iframe = document.createElement('iframe');"
1004 "iframe.src = '" + frame_url.spec() + "';" 1011 "iframe.src = '" + frame_url.spec() + "';"
1005 "document.body.appendChild(iframe);"; 1012 "document.body.appendChild(iframe);";
1006 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 1013 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1007 capturer.Wait(); 1014 capturer.Wait();
1008 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 1015 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1009 } 1016 }
1010 1017
(...skipping 10 matching lines...) Expand all
1021 // The entry should now have 2 subframe FrameNavigationEntries. 1028 // The entry should now have 2 subframe FrameNavigationEntries.
1022 ASSERT_EQ(2U, entry->root_node()->children.size()); 1029 ASSERT_EQ(2U, entry->root_node()->children.size());
1023 FrameNavigationEntry* frame_entry = 1030 FrameNavigationEntry* frame_entry =
1024 entry->root_node()->children[1]->frame_entry.get(); 1031 entry->root_node()->children[1]->frame_entry.get();
1025 EXPECT_EQ(frame_url, frame_entry->url()); 1032 EXPECT_EQ(frame_url, frame_entry->url());
1026 } else { 1033 } else {
1027 // There are no subframe FrameNavigationEntries by default. 1034 // There are no subframe FrameNavigationEntries by default.
1028 EXPECT_EQ(0U, entry->root_node()->children.size()); 1035 EXPECT_EQ(0U, entry->root_node()->children.size());
1029 } 1036 }
1030 1037
1031 // Create a nested iframe in the second subframe. 1038 // 3. Create a nested iframe in the second subframe.
1032 { 1039 {
1033 LoadCommittedCapturer capturer(shell()->web_contents()); 1040 LoadCommittedCapturer capturer(shell()->web_contents());
1034 std::string script = "var iframe = document.createElement('iframe');" 1041 std::string script = "var iframe = document.createElement('iframe');"
1035 "iframe.src = '" + frame_url.spec() + "';" 1042 "iframe.src = '" + frame_url.spec() + "';"
1036 "document.body.appendChild(iframe);"; 1043 "document.body.appendChild(iframe);";
1037 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(), 1044 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(),
1038 script)); 1045 script));
1039 capturer.Wait(); 1046 capturer.Wait();
1040 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); 1047 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
1041 } 1048 }
(...skipping 11 matching lines...) Expand all
1053 // The entry should now have 2 subframe FrameNavigationEntries. 1060 // The entry should now have 2 subframe FrameNavigationEntries.
1054 ASSERT_EQ(2U, entry->root_node()->children.size()); 1061 ASSERT_EQ(2U, entry->root_node()->children.size());
1055 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); 1062 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size());
1056 FrameNavigationEntry* frame_entry = 1063 FrameNavigationEntry* frame_entry =
1057 entry->root_node()->children[1]->children[0]->frame_entry.get(); 1064 entry->root_node()->children[1]->children[0]->frame_entry.get();
1058 EXPECT_EQ(frame_url, frame_entry->url()); 1065 EXPECT_EQ(frame_url, frame_entry->url());
1059 } else { 1066 } else {
1060 // There are no subframe FrameNavigationEntries by default. 1067 // There are no subframe FrameNavigationEntries by default.
1061 EXPECT_EQ(0U, entry->root_node()->children.size()); 1068 EXPECT_EQ(0U, entry->root_node()->children.size());
1062 } 1069 }
1070
1071 // 4. Navigate in the first subframe.
1072 GURL frame_url2(embedded_test_server()->GetURL(
1073 "/navigation_controller/page_with_links.html"));
1074 {
1075 FrameNavigateParamsCapturer capturer(root->child_at(0));
1076 NavigateFrameToURL(root->child_at(0), frame_url2);
1077 capturer.Wait();
1078 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1079 capturer.params().transition);
1080 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1081 }
1082
1083 // We should create a new NavigationEntry with the same main frame URL.
1084 EXPECT_EQ(2, controller.GetEntryCount());
1085 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1086 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
1087 EXPECT_NE(entry, entry2);
1088 EXPECT_EQ(main_url, entry2->GetURL());
1089 FrameNavigationEntry* root_entry2 = entry2->root_node()->frame_entry.get();
1090 EXPECT_EQ(main_url, root_entry2->url());
1091
1092 // Verify subframe entries if we're in --site-per-process mode.
1093 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1094 switches::kSitePerProcess)) {
1095 // The entry should still have FrameNavigationEntries for all 3 subframes.
1096 ASSERT_EQ(2U, entry2->root_node()->children.size());
1097 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url());
1098 EXPECT_EQ(frame_url, entry2->root_node()->children[1]->frame_entry->url());
1099 ASSERT_EQ(1U, entry2->root_node()->children[1]->children.size());
1100 EXPECT_EQ(
1101 frame_url,
1102 entry2->root_node()->children[1]->children[0]->frame_entry->url());
1103 } else {
1104 // There are no subframe FrameNavigationEntries by default.
1105 EXPECT_EQ(0U, entry2->root_node()->children.size());
1106 }
1107
1108 // 5. Navigate in the nested subframe.
1109 {
1110 FrameNavigateParamsCapturer capturer(root->child_at(1)->child_at(0));
1111 NavigateFrameToURL(root->child_at(1)->child_at(0), frame_url2);
1112 capturer.Wait();
1113 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1114 capturer.params().transition);
1115 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1116 }
1117
1118 // We should create a new NavigationEntry with the same main frame URL.
Avi (use Gerrit) 2015/05/19 16:34:13 My preferred phrasing would be "We should have cre
Charlie Reis 2015/05/19 17:59:24 Done.
1119 EXPECT_EQ(3, controller.GetEntryCount());
1120 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
1121 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
1122 EXPECT_NE(entry, entry3);
1123 EXPECT_EQ(main_url, entry3->GetURL());
1124 FrameNavigationEntry* root_entry3 = entry3->root_node()->frame_entry.get();
1125 EXPECT_EQ(main_url, root_entry3->url());
1126
1127 // Verify subframe entries if we're in --site-per-process mode.
1128 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1129 switches::kSitePerProcess)) {
1130 // The entry should still have FrameNavigationEntries for all 3 subframes.
1131 ASSERT_EQ(2U, entry3->root_node()->children.size());
1132 EXPECT_EQ(frame_url2, entry3->root_node()->children[0]->frame_entry->url());
1133 EXPECT_EQ(frame_url, entry3->root_node()->children[1]->frame_entry->url());
1134 ASSERT_EQ(1U, entry3->root_node()->children[1]->children.size());
1135 EXPECT_EQ(
1136 frame_url2,
1137 entry3->root_node()->children[1]->children[0]->frame_entry->url());
1138 } else {
1139 // There are no subframe FrameNavigationEntries by default.
1140 EXPECT_EQ(0U, entry3->root_node()->children.size());
1141 }
1142
1143 // 6. Navigate in the second subframe, clearing its existing subtree.
1144 {
1145 FrameNavigateParamsCapturer capturer(root->child_at(1));
1146 NavigateFrameToURL(root->child_at(1), frame_url2);
1147 capturer.Wait();
1148 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1149 capturer.params().transition);
1150 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1151 }
1152
1153 // We should create a new NavigationEntry with the same main frame URL.
1154 EXPECT_EQ(4, controller.GetEntryCount());
1155 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex());
1156 NavigationEntryImpl* entry4 = controller.GetLastCommittedEntry();
1157 EXPECT_NE(entry, entry4);
1158 EXPECT_EQ(main_url, entry4->GetURL());
1159 FrameNavigationEntry* root_entry4 = entry4->root_node()->frame_entry.get();
1160 EXPECT_EQ(main_url, root_entry4->url());
1161
1162 // Verify subframe entries if we're in --site-per-process mode.
1163 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1164 switches::kSitePerProcess)) {
1165 // The entry should now only have FrameNavigationEntries for 2 frames.
1166 ASSERT_EQ(2U, entry4->root_node()->children.size());
1167 EXPECT_EQ(frame_url2, entry4->root_node()->children[0]->frame_entry->url());
1168 EXPECT_EQ(frame_url2, entry4->root_node()->children[1]->frame_entry->url());
1169 ASSERT_EQ(0U, entry4->root_node()->children[1]->children.size());
1170
1171 // The previous entry should be unchanged.
1172 EXPECT_EQ(frame_url, entry3->root_node()->children[1]->frame_entry->url());
1173 } else {
1174 // There are no subframe FrameNavigationEntries by default.
1175 EXPECT_EQ(0U, entry4->root_node()->children.size());
1176 }
1063 } 1177 }
1064 1178
1065 namespace { 1179 namespace {
1066 1180
1067 class HttpThrottle : public ResourceThrottle { 1181 class HttpThrottle : public ResourceThrottle {
1068 public: 1182 public:
1069 // ResourceThrottle 1183 // ResourceThrottle
1070 void WillStartRequest(bool* defer) override { 1184 void WillStartRequest(bool* defer) override {
1071 *defer = true; 1185 *defer = true;
1072 } 1186 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 // tricky. 1523 // tricky.
1410 EXPECT_EQ(nullptr, controller.GetPendingEntry()); 1524 EXPECT_EQ(nullptr, controller.GetPendingEntry());
1411 shell()->web_contents()->Stop(); 1525 shell()->web_contents()->Stop();
1412 watcher.Wait(); 1526 watcher.Wait();
1413 } 1527 }
1414 1528
1415 ResourceDispatcherHost::Get()->SetDelegate(nullptr); 1529 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
1416 } 1530 }
1417 1531
1418 } // namespace content 1532 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698