OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
10 #include "content/public/common/browser_side_navigation_policy.h" | 10 #include "content/public/common/browser_side_navigation_policy.h" |
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 { | 1167 { |
1168 NavigationHandleObserver observer(shell()->web_contents(), start_url); | 1168 NavigationHandleObserver observer(shell()->web_contents(), start_url); |
1169 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 1169 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
1170 EXPECT_TRUE(observer.has_committed()); | 1170 EXPECT_TRUE(observer.has_committed()); |
1171 EXPECT_FALSE(observer.is_error()); | 1171 EXPECT_FALSE(observer.is_error()); |
1172 } | 1172 } |
1173 | 1173 |
1174 scoped_refptr<SiteInstance> site_instance = | 1174 scoped_refptr<SiteInstance> site_instance = |
1175 shell()->web_contents()->GetMainFrame()->GetSiteInstance(); | 1175 shell()->web_contents()->GetMainFrame()->GetSiteInstance(); |
1176 | 1176 |
1177 TestNavigationThrottleInstaller installer( | 1177 auto installer = base::MakeUnique<TestNavigationThrottleInstaller>( |
1178 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, | 1178 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, |
1179 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 1179 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
1180 | 1180 |
1181 { | 1181 { |
| 1182 // A blocked, renderer-initiated navigation should commit an error page |
| 1183 // in the process that originated the navigation. |
1182 NavigationHandleObserver observer(shell()->web_contents(), blocked_url); | 1184 NavigationHandleObserver observer(shell()->web_contents(), blocked_url); |
1183 EXPECT_FALSE(NavigateToURL(shell(), blocked_url)); | 1185 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 1186 EXPECT_TRUE( |
| 1187 ExecuteScript(shell(), base::StringPrintf("location.href = '%s'", |
| 1188 blocked_url.spec().c_str()))); |
| 1189 navigation_observer.Wait(); |
1184 EXPECT_TRUE(observer.has_committed()); | 1190 EXPECT_TRUE(observer.has_committed()); |
1185 EXPECT_TRUE(observer.is_error()); | 1191 EXPECT_TRUE(observer.is_error()); |
1186 EXPECT_EQ(site_instance, | 1192 EXPECT_EQ(site_instance, |
1187 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | 1193 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
1188 } | 1194 } |
| 1195 |
| 1196 { |
| 1197 // Reloading the page should not transfer processes. |
| 1198 NavigationHandleObserver observer(shell()->web_contents(), blocked_url); |
| 1199 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 1200 |
| 1201 shell()->Reload(); |
| 1202 navigation_observer.Wait(); |
| 1203 EXPECT_TRUE(observer.has_committed()); |
| 1204 EXPECT_TRUE(observer.is_error()); |
| 1205 EXPECT_EQ(site_instance, |
| 1206 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
| 1207 } |
| 1208 |
| 1209 installer.reset(); |
| 1210 |
| 1211 { |
| 1212 // With the throttle uninstalled, going back should return to |start_url| in |
| 1213 // the same process, and clear the error page. |
| 1214 NavigationHandleObserver observer(shell()->web_contents(), start_url); |
| 1215 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 1216 |
| 1217 shell()->GoBackOrForward(-1); |
| 1218 navigation_observer.Wait(); |
| 1219 EXPECT_TRUE(observer.has_committed()); |
| 1220 EXPECT_FALSE(observer.is_error()); |
| 1221 EXPECT_EQ(site_instance, |
| 1222 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
| 1223 } |
| 1224 |
| 1225 installer = base::MakeUnique<TestNavigationThrottleInstaller>( |
| 1226 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, |
| 1227 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
| 1228 |
| 1229 { |
| 1230 // A blocked, browser-initiated navigation should commit an error page in a |
| 1231 // different process. |
| 1232 NavigationHandleObserver observer(shell()->web_contents(), blocked_url); |
| 1233 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 1234 |
| 1235 EXPECT_FALSE(NavigateToURL(shell(), blocked_url)); |
| 1236 |
| 1237 navigation_observer.Wait(); |
| 1238 EXPECT_TRUE(observer.has_committed()); |
| 1239 EXPECT_TRUE(observer.is_error()); |
| 1240 EXPECT_NE(site_instance, |
| 1241 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
| 1242 } |
1189 } | 1243 } |
1190 | 1244 |
1191 // Test to verify that error pages caused by network error or other | 1245 // Test to verify that error pages caused by network error or other |
1192 // recoverable error are properly committed in the process for the | 1246 // recoverable error are properly committed in the process for the |
1193 // destination URL. | 1247 // destination URL. |
1194 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest, | 1248 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest, |
1195 ErrorPageNetworkError) { | 1249 ErrorPageNetworkError) { |
1196 SetupCrossSiteRedirector(embedded_test_server()); | 1250 SetupCrossSiteRedirector(embedded_test_server()); |
1197 ASSERT_TRUE(embedded_test_server()->Start()); | 1251 ASSERT_TRUE(embedded_test_server()->Start()); |
1198 | 1252 |
(...skipping 17 matching lines...) Expand all Loading... |
1216 NavigationHandleObserver observer(shell()->web_contents(), error_url); | 1270 NavigationHandleObserver observer(shell()->web_contents(), error_url); |
1217 EXPECT_FALSE(NavigateToURL(shell(), error_url)); | 1271 EXPECT_FALSE(NavigateToURL(shell(), error_url)); |
1218 EXPECT_TRUE(observer.has_committed()); | 1272 EXPECT_TRUE(observer.has_committed()); |
1219 EXPECT_TRUE(observer.is_error()); | 1273 EXPECT_TRUE(observer.is_error()); |
1220 EXPECT_NE(site_instance, | 1274 EXPECT_NE(site_instance, |
1221 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | 1275 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
1222 } | 1276 } |
1223 } | 1277 } |
1224 | 1278 |
1225 } // namespace content | 1279 } // namespace content |
OLD | NEW |