| 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 net::URLRequest* request, | 1018 net::URLRequest* request, |
| 1019 content::ResourceContext* resource_context, | 1019 content::ResourceContext* resource_context, |
| 1020 content::AppCacheService* appcache_service, | 1020 content::AppCacheService* appcache_service, |
| 1021 ResourceType resource_type, | 1021 ResourceType resource_type, |
| 1022 ScopedVector<content::ResourceThrottle>* throttles) override { | 1022 ScopedVector<content::ResourceThrottle>* throttles) override { |
| 1023 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 1023 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 1024 throttles->push_back(new HttpThrottle); | 1024 throttles->push_back(new HttpThrottle); |
| 1025 } | 1025 } |
| 1026 }; | 1026 }; |
| 1027 | 1027 |
| 1028 } // namespace | 1028 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is |
| 1029 | 1029 // stalled, an in-page navigation happens. Make sure that all the navigations |
| 1030 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1030 // are properly classified. |
| 1031 NavigationTypeClassification_InPageWhilePending) { | 1031 void DoReplaceStateWhilePending(Shell* shell, |
| 1032 const GURL& start_url, |
| 1033 const GURL& stalled_url, |
| 1034 const std::string& replace_state_filename) { |
| 1032 NavigationControllerImpl& controller = | 1035 NavigationControllerImpl& controller = |
| 1033 static_cast<NavigationControllerImpl&>( | 1036 static_cast<NavigationControllerImpl&>( |
| 1034 shell()->web_contents()->GetController()); | 1037 shell->web_contents()->GetController()); |
| 1035 | 1038 |
| 1036 FrameTreeNode* root = | 1039 FrameTreeNode* root = |
| 1037 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1040 static_cast<WebContentsImpl*>(shell->web_contents())-> |
| 1038 GetFrameTree()->root(); | 1041 GetFrameTree()->root(); |
| 1039 | 1042 |
| 1040 // Start with a normal page. | 1043 // Start with one page. |
| 1041 GURL url1(embedded_test_server()->GetURL( | 1044 EXPECT_TRUE(NavigateToURL(shell, start_url)); |
| 1042 "/navigation_controller/simple_page_1.html")); | |
| 1043 EXPECT_TRUE(NavigateToURL(shell(), url1)); | |
| 1044 | 1045 |
| 1045 // Have the user decide to go to a different page which is very slow. | 1046 // Have the user decide to go to a different page which is very slow. |
| 1046 StallDelegate stall_delegate; | 1047 StallDelegate stall_delegate; |
| 1047 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); | 1048 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); |
| 1048 GURL url2(embedded_test_server()->GetURL( | 1049 controller.LoadURL( |
| 1049 "/navigation_controller/simple_page_2.html")); | 1050 stalled_url, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1050 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | |
| 1051 | 1051 |
| 1052 // That should be the pending entry. | 1052 // That should be the pending entry. |
| 1053 NavigationEntryImpl* entry = controller.GetPendingEntry(); | 1053 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
| 1054 ASSERT_NE(nullptr, entry); | 1054 ASSERT_NE(nullptr, entry); |
| 1055 EXPECT_EQ(url2, entry->GetURL()); | 1055 EXPECT_EQ(stalled_url, entry->GetURL()); |
| 1056 | 1056 |
| 1057 { | 1057 { |
| 1058 // Now the existing page uses history.replaceState(). | 1058 // Now the existing page uses history.replaceState(). |
| 1059 FrameNavigateParamsCapturer capturer(root); | 1059 FrameNavigateParamsCapturer capturer(root); |
| 1060 capturer.set_wait_for_load(false); | 1060 capturer.set_wait_for_load(false); |
| 1061 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), | 1061 std::string script = |
| 1062 "history.replaceState({}, '', 'x')")); | 1062 "history.replaceState({}, '', '" + replace_state_filename + "')"; |
| 1063 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1063 capturer.Wait(); | 1064 capturer.Wait(); |
| 1064 | 1065 |
| 1065 // The fact that there was a pending entry shouldn't interfere with the | 1066 // The fact that there was a pending entry shouldn't interfere with the |
| 1066 // classification. | 1067 // classification. |
| 1067 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); | 1068 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 1071 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1074 } // namespace |
| 1075 |
| 1076 IN_PROC_BROWSER_TEST_F( |
| 1077 NavigationControllerBrowserTest, |
| 1078 NavigationTypeClassification_On1InPageToXWhile2Pending) { |
| 1079 GURL url1(embedded_test_server()->GetURL( |
| 1080 "/navigation_controller/simple_page_1.html")); |
| 1081 GURL url2(embedded_test_server()->GetURL( |
| 1082 "/navigation_controller/simple_page_2.html")); |
| 1083 DoReplaceStateWhilePending(shell(), url1, url2, "x"); |
| 1084 } |
| 1085 |
| 1086 IN_PROC_BROWSER_TEST_F( |
| 1087 NavigationControllerBrowserTest, |
| 1088 NavigationTypeClassification_On1InPageTo2While2Pending) { |
| 1089 GURL url1(embedded_test_server()->GetURL( |
| 1090 "/navigation_controller/simple_page_1.html")); |
| 1091 GURL url2(embedded_test_server()->GetURL( |
| 1092 "/navigation_controller/simple_page_2.html")); |
| 1093 DoReplaceStateWhilePending(shell(), url1, url2, "simple_page_2.html"); |
| 1094 } |
| 1095 |
| 1096 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1097 NavigationTypeClassification_On1InPageToXWhile1Pending) { |
| 1098 GURL url(embedded_test_server()->GetURL( |
| 1099 "/navigation_controller/simple_page_1.html")); |
| 1100 DoReplaceStateWhilePending(shell(), url, url, "x"); |
| 1101 } |
| 1102 |
| 1103 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1104 NavigationTypeClassification_On1InPageTo1While1Pending) { |
| 1105 GURL url(embedded_test_server()->GetURL( |
| 1106 "/navigation_controller/simple_page_1.html")); |
| 1107 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); |
| 1108 } |
| 1109 |
| 1073 // Ensure the renderer process does not get confused about the current entry | 1110 // Ensure the renderer process does not get confused about the current entry |
| 1074 // due to subframes and replaced entries. See https://crbug.com/480201. | 1111 // due to subframes and replaced entries. See https://crbug.com/480201. |
| 1075 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1112 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1076 PreventSpoofFromSubframeAndReplace) { | 1113 PreventSpoofFromSubframeAndReplace) { |
| 1077 // Start at an initial URL. | 1114 // Start at an initial URL. |
| 1078 GURL url1(embedded_test_server()->GetURL( | 1115 GURL url1(embedded_test_server()->GetURL( |
| 1079 "/navigation_controller/simple_page_1.html")); | 1116 "/navigation_controller/simple_page_1.html")); |
| 1080 NavigateToURL(shell(), url1); | 1117 NavigateToURL(shell(), url1); |
| 1081 | 1118 |
| 1082 // Now go to a page with a real iframe. | 1119 // Now go to a page with a real iframe. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 | 1201 |
| 1165 // Make sure the URL is correct for both the entry and the main frame, and | 1202 // Make sure the URL is correct for both the entry and the main frame, and |
| 1166 // that the process hasn't been killed for showing a spoof. | 1203 // that the process hasn't been killed for showing a spoof. |
| 1167 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 1204 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 1168 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL()); | 1205 EXPECT_EQ(url3, shell()->web_contents()->GetLastCommittedURL()); |
| 1169 EXPECT_EQ(url3, root->current_url()); | 1206 EXPECT_EQ(url3, root->current_url()); |
| 1170 } | 1207 } |
| 1171 } | 1208 } |
| 1172 | 1209 |
| 1173 } // namespace content | 1210 } // namespace content |
| OLD | NEW |