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

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

Issue 2982623002: Revert of Block redirects to renderer-debug urls. (Closed)
Patch Set: Created 3 years, 5 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 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"
8 #include "content/browser/frame_host/navigation_handle_impl.h" 7 #include "content/browser/frame_host/navigation_handle_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_observer.h" 10 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/common/bindings_policy.h" 11 #include "content/public/common/bindings_policy.h"
13 #include "content/public/common/browser_side_navigation_policy.h" 12 #include "content/public/common/browser_side_navigation_policy.h"
14 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
15 #include "content/public/common/request_context_type.h" 14 #include "content/public/common/request_context_type.h"
16 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
17 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 // Record and list the navigations that are started and finished. 1239 // Record and list the navigations that are started and finished.
1241 class NavigationLogger : public WebContentsObserver { 1240 class NavigationLogger : public WebContentsObserver {
1242 public: 1241 public:
1243 NavigationLogger(WebContents* web_contents) 1242 NavigationLogger(WebContents* web_contents)
1244 : WebContentsObserver(web_contents) {} 1243 : WebContentsObserver(web_contents) {}
1245 1244
1246 void DidStartNavigation(NavigationHandle* navigation_handle) override { 1245 void DidStartNavigation(NavigationHandle* navigation_handle) override {
1247 started_navigation_urls_.push_back(navigation_handle->GetURL()); 1246 started_navigation_urls_.push_back(navigation_handle->GetURL());
1248 } 1247 }
1249 1248
1250 void DidRedirectNavigation(NavigationHandle* navigation_handle) override {
1251 redirected_navigation_urls_.push_back(navigation_handle->GetURL());
1252 }
1253
1254 void DidFinishNavigation(NavigationHandle* navigation_handle) override { 1249 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
1255 finished_navigation_urls_.push_back(navigation_handle->GetURL()); 1250 finished_navigation_urls_.push_back(navigation_handle->GetURL());
1256 } 1251 }
1257 1252
1258 const std::vector<GURL>& started_navigation_urls() const { 1253 const std::vector<GURL>& started_navigation_urls() const {
1259 return started_navigation_urls_; 1254 return started_navigation_urls_;
1260 } 1255 }
1261 const std::vector<GURL>& redirected_navigation_urls() const {
1262 return redirected_navigation_urls_;
1263 }
1264 const std::vector<GURL>& finished_navigation_urls() const { 1256 const std::vector<GURL>& finished_navigation_urls() const {
1265 return finished_navigation_urls_; 1257 return finished_navigation_urls_;
1266 } 1258 }
1267 1259
1268 private: 1260 private:
1269 std::vector<GURL> started_navigation_urls_; 1261 std::vector<GURL> started_navigation_urls_;
1270 std::vector<GURL> redirected_navigation_urls_;
1271 std::vector<GURL> finished_navigation_urls_; 1262 std::vector<GURL> finished_navigation_urls_;
1272 }; 1263 };
1273 1264
1274 // There was a bug without PlzNavigate that happened when a navigation was 1265 // There was a bug without PlzNavigate that happened when a navigation was
1275 // blocked after a redirect. Blink didn't know about the redirect and tried 1266 // blocked after a redirect. Blink didn't know about the redirect and tried
1276 // to commit an error page to the pre-redirect URL. The result was that the 1267 // to commit an error page to the pre-redirect URL. The result was that the
1277 // NavigationHandle was not found on the browser-side and a new NavigationHandle 1268 // NavigationHandle was not found on the browser-side and a new NavigationHandle
1278 // created for committing the error page. This test makes sure that only one 1269 // created for committing the error page. This test makes sure that only one
1279 // NavigationHandle is used for committing the error page. 1270 // NavigationHandle is used for committing the error page.
1280 // See https://crbug.com/695421 1271 // See https://crbug.com/695421
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 web_contents->GetController().GetLastCommittedEntry(); 1504 web_contents->GetController().GetLastCommittedEntry();
1514 EXPECT_TRUE(last_committed); 1505 EXPECT_TRUE(last_committed);
1515 EXPECT_EQ(blocked_url, last_committed->GetVirtualURL()); 1506 EXPECT_EQ(blocked_url, last_committed->GetVirtualURL());
1516 EXPECT_EQ(PAGE_TYPE_ERROR, last_committed->GetPageType()); 1507 EXPECT_EQ(PAGE_TYPE_ERROR, last_committed->GetPageType());
1517 EXPECT_NE(web_ui_process.get(), web_contents->GetSiteInstance()); 1508 EXPECT_NE(web_ui_process.get(), web_contents->GetSiteInstance());
1518 EXPECT_TRUE(commit_observer.has_committed()); 1509 EXPECT_TRUE(commit_observer.has_committed());
1519 EXPECT_TRUE(commit_observer.is_error()); 1510 EXPECT_TRUE(commit_observer.is_error());
1520 EXPECT_FALSE(commit_observer.is_renderer_initiated()); 1511 EXPECT_FALSE(commit_observer.is_renderer_initiated());
1521 } 1512 }
1522 1513
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
1570 } // namespace content 1514 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/browser/frame_host/navigation_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698