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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "content/browser/frame_host/debug_urls.h" |
7 #include "content/browser/frame_host/navigation_handle_impl.h" | 8 #include "content/browser/frame_host/navigation_handle_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
11 #include "content/public/common/bindings_policy.h" | 12 #include "content/public/common/bindings_policy.h" |
12 #include "content/public/common/browser_side_navigation_policy.h" | 13 #include "content/public/common/browser_side_navigation_policy.h" |
13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
14 #include "content/public/common/request_context_type.h" | 15 #include "content/public/common/request_context_type.h" |
15 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
16 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 // Record and list the navigations that are started and finished. | 1240 // Record and list the navigations that are started and finished. |
1240 class NavigationLogger : public WebContentsObserver { | 1241 class NavigationLogger : public WebContentsObserver { |
1241 public: | 1242 public: |
1242 NavigationLogger(WebContents* web_contents) | 1243 NavigationLogger(WebContents* web_contents) |
1243 : WebContentsObserver(web_contents) {} | 1244 : WebContentsObserver(web_contents) {} |
1244 | 1245 |
1245 void DidStartNavigation(NavigationHandle* navigation_handle) override { | 1246 void DidStartNavigation(NavigationHandle* navigation_handle) override { |
1246 started_navigation_urls_.push_back(navigation_handle->GetURL()); | 1247 started_navigation_urls_.push_back(navigation_handle->GetURL()); |
1247 } | 1248 } |
1248 | 1249 |
| 1250 void DidRedirectNavigation(NavigationHandle* navigation_handle) override { |
| 1251 redirected_navigation_urls_.push_back(navigation_handle->GetURL()); |
| 1252 } |
| 1253 |
1249 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 1254 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
1250 finished_navigation_urls_.push_back(navigation_handle->GetURL()); | 1255 finished_navigation_urls_.push_back(navigation_handle->GetURL()); |
1251 } | 1256 } |
1252 | 1257 |
1253 const std::vector<GURL>& started_navigation_urls() const { | 1258 const std::vector<GURL>& started_navigation_urls() const { |
1254 return started_navigation_urls_; | 1259 return started_navigation_urls_; |
1255 } | 1260 } |
| 1261 const std::vector<GURL>& redirected_navigation_urls() const { |
| 1262 return redirected_navigation_urls_; |
| 1263 } |
1256 const std::vector<GURL>& finished_navigation_urls() const { | 1264 const std::vector<GURL>& finished_navigation_urls() const { |
1257 return finished_navigation_urls_; | 1265 return finished_navigation_urls_; |
1258 } | 1266 } |
1259 | 1267 |
1260 private: | 1268 private: |
1261 std::vector<GURL> started_navigation_urls_; | 1269 std::vector<GURL> started_navigation_urls_; |
| 1270 std::vector<GURL> redirected_navigation_urls_; |
1262 std::vector<GURL> finished_navigation_urls_; | 1271 std::vector<GURL> finished_navigation_urls_; |
1263 }; | 1272 }; |
1264 | 1273 |
1265 // There was a bug without PlzNavigate that happened when a navigation was | 1274 // There was a bug without PlzNavigate that happened when a navigation was |
1266 // blocked after a redirect. Blink didn't know about the redirect and tried | 1275 // blocked after a redirect. Blink didn't know about the redirect and tried |
1267 // to commit an error page to the pre-redirect URL. The result was that the | 1276 // to commit an error page to the pre-redirect URL. The result was that the |
1268 // NavigationHandle was not found on the browser-side and a new NavigationHandle | 1277 // NavigationHandle was not found on the browser-side and a new NavigationHandle |
1269 // created for committing the error page. This test makes sure that only one | 1278 // created for committing the error page. This test makes sure that only one |
1270 // NavigationHandle is used for committing the error page. | 1279 // NavigationHandle is used for committing the error page. |
1271 // See https://crbug.com/695421 | 1280 // See https://crbug.com/695421 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 web_contents->GetController().GetLastCommittedEntry(); | 1513 web_contents->GetController().GetLastCommittedEntry(); |
1505 EXPECT_TRUE(last_committed); | 1514 EXPECT_TRUE(last_committed); |
1506 EXPECT_EQ(blocked_url, last_committed->GetVirtualURL()); | 1515 EXPECT_EQ(blocked_url, last_committed->GetVirtualURL()); |
1507 EXPECT_EQ(PAGE_TYPE_ERROR, last_committed->GetPageType()); | 1516 EXPECT_EQ(PAGE_TYPE_ERROR, last_committed->GetPageType()); |
1508 EXPECT_NE(web_ui_process.get(), web_contents->GetSiteInstance()); | 1517 EXPECT_NE(web_ui_process.get(), web_contents->GetSiteInstance()); |
1509 EXPECT_TRUE(commit_observer.has_committed()); | 1518 EXPECT_TRUE(commit_observer.has_committed()); |
1510 EXPECT_TRUE(commit_observer.is_error()); | 1519 EXPECT_TRUE(commit_observer.is_error()); |
1511 EXPECT_FALSE(commit_observer.is_renderer_initiated()); | 1520 EXPECT_FALSE(commit_observer.is_renderer_initiated()); |
1512 } | 1521 } |
1513 | 1522 |
| 1523 // Redirects to renderer debug URLs caused problems. |
| 1524 // See https://crbug.com/728398. |
| 1525 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, |
| 1526 RedirectToRendererDebugUrl) { |
| 1527 GURL url(embedded_test_server()->GetURL("/title1.html")); |
| 1528 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 1529 |
| 1530 const struct { |
| 1531 const GURL renderer_debug_url; |
| 1532 const net::Error error_code; |
| 1533 } kTestCases[] = { |
| 1534 {GURL("javascript:window.alert('hello')"), net::ERR_ABORTED}, |
| 1535 {GURL(kChromeUIBadCastCrashURL), net::ERR_UNSAFE_REDIRECT}, |
| 1536 {GURL(kChromeUICrashURL), net::ERR_UNSAFE_REDIRECT}, |
| 1537 {GURL(kChromeUIDumpURL), net::ERR_UNSAFE_REDIRECT}, |
| 1538 {GURL(kChromeUIKillURL), net::ERR_UNSAFE_REDIRECT}, |
| 1539 {GURL(kChromeUIHangURL), net::ERR_UNSAFE_REDIRECT}, |
| 1540 {GURL(kChromeUIShorthangURL), net::ERR_UNSAFE_REDIRECT}, |
| 1541 {GURL(kChromeUIMemoryExhaustURL), net::ERR_UNSAFE_REDIRECT}, |
| 1542 }; |
| 1543 |
| 1544 for (const auto& test_case : kTestCases) { |
| 1545 SCOPED_TRACE(testing::Message() |
| 1546 << "renderer_debug_url = " << test_case.renderer_debug_url); |
| 1547 |
| 1548 GURL redirecting_url = embedded_test_server()->GetURL( |
| 1549 "/server-redirect?" + test_case.renderer_debug_url.spec()); |
| 1550 |
| 1551 NavigationHandleObserver observer(shell()->web_contents(), redirecting_url); |
| 1552 NavigationLogger logger(shell()->web_contents()); |
| 1553 |
| 1554 // Try to navigate to the url. The navigation should be canceled and the |
| 1555 // NavigationHandle should have the right error code. |
| 1556 EXPECT_FALSE(NavigateToURL(shell(), redirecting_url)); |
| 1557 EXPECT_EQ(test_case.error_code, observer.net_error_code()); |
| 1558 |
| 1559 // Both WebContentsObserver::{DidStartNavigation, DidFinishNavigation} |
| 1560 // are called, but no WebContentsObserver::DidRedirectNavigation. |
| 1561 std::vector<GURL> started_navigation = {redirecting_url}; |
| 1562 std::vector<GURL> redirected_navigation = {}; |
| 1563 std::vector<GURL> finished_navigation = {redirecting_url}; |
| 1564 EXPECT_EQ(started_navigation, logger.started_navigation_urls()); |
| 1565 EXPECT_EQ(redirected_navigation, logger.redirected_navigation_urls()); |
| 1566 EXPECT_EQ(finished_navigation, logger.finished_navigation_urls()); |
| 1567 } |
| 1568 } |
| 1569 |
1514 } // namespace content | 1570 } // namespace content |
OLD | NEW |