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

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

Issue 2698623006: PlzNavigate: add support for BLOCK_REQUEST during redirects (Closed)
Patch Set: Abandon support of BLOCK_REQUEST on redirect without PlzNavigate. Created 3 years, 9 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/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/request_context_type.h" 11 #include "content/public/common/request_context_type.h"
11 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test.h" 13 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h" 14 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/public/test/test_navigation_observer.h" 15 #include "content/public/test/test_navigation_observer.h"
15 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
16 #include "content/shell/browser/shell.h" 17 #include "content/shell/browser/shell.h"
17 #include "content/test/content_browser_test_utils_internal.h" 18 #include "content/test/content_browser_test_utils_internal.h"
18 #include "net/dns/mock_host_resolver.h" 19 #include "net/dns/mock_host_resolver.h"
19 #include "ui/base/page_transition_types.h" 20 #include "ui/base/page_transition_types.h"
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 TestNavigationThrottleInstaller installer( 896 TestNavigationThrottleInstaller installer(
896 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, 897 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST,
897 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); 898 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
898 NavigationHandleObserver observer(shell()->web_contents(), kUrl); 899 NavigationHandleObserver observer(shell()->web_contents(), kUrl);
899 900
900 // Try to navigate to the url. The navigation should be canceled and the 901 // Try to navigate to the url. The navigation should be canceled and the
901 // NavigationHandle should have the right error code. 902 // NavigationHandle should have the right error code.
902 EXPECT_FALSE(NavigateToURL(shell(), kUrl)); 903 EXPECT_FALSE(NavigateToURL(shell(), kUrl));
903 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); 904 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code());
904 } 905 }
906
907 // Using BLOCK_REQUEST on redirect is available only with PlzNavigate.
908 if (IsBrowserSideNavigationEnabled()) {
909 // Set up a NavigationThrottle that will block the navigation in
910 // WillRedirectRequest.
911 TestNavigationThrottleInstaller installer(
912 shell()->web_contents(), NavigationThrottle::PROCEED,
913 NavigationThrottle::BLOCK_REQUEST, NavigationThrottle::PROCEED);
914 NavigationHandleObserver observer(shell()->web_contents(), kRedirectingUrl);
915
916 // Try to navigate to the url. The navigation should be canceled and the
917 // NavigationHandle should have the right error code.
918 EXPECT_FALSE(NavigateToURL(shell(), kRedirectingUrl));
919 EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code());
920 }
905 } 921 }
906 922
907 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded 923 // Specialized test that verifies the NavigationHandle gets the HTTPS upgraded
908 // URL from the very beginning of the navigation. 924 // URL from the very beginning of the navigation.
909 class NavigationHandleImplHttpsUpgradeBrowserTest 925 class NavigationHandleImplHttpsUpgradeBrowserTest
910 : public NavigationHandleImplBrowserTest { 926 : public NavigationHandleImplBrowserTest {
911 public: 927 public:
912 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url, 928 void CheckHttpsUpgradedIframeNavigation(const GURL& start_url,
913 const GURL& iframe_secure_url) { 929 const GURL& iframe_secure_url) {
914 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme)); 930 ASSERT_TRUE(start_url.SchemeIs(url::kHttpScheme));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 shell()->web_contents(), NavigationThrottle::PROCEED, 1045 shell()->web_contents(), NavigationThrottle::PROCEED,
1030 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); 1046 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
1031 NavigationHandleObserver observer(shell()->web_contents(), url); 1047 NavigationHandleObserver observer(shell()->web_contents(), url);
1032 EXPECT_TRUE(NavigateToURL(shell(), url)); 1048 EXPECT_TRUE(NavigateToURL(shell(), url));
1033 EXPECT_EQ(1, installer.will_start_called()); 1049 EXPECT_EQ(1, installer.will_start_called());
1034 EXPECT_EQ(1, installer.will_process_called()); 1050 EXPECT_EQ(1, installer.will_process_called());
1035 EXPECT_FALSE(observer.is_same_document()); 1051 EXPECT_FALSE(observer.is_same_document());
1036 } 1052 }
1037 } 1053 }
1038 1054
1055 // Record and list the navigations that are started and finished.
1056 class NavigationLogger : public WebContentsObserver {
1057 public:
1058 NavigationLogger(WebContents* web_contents)
1059 : WebContentsObserver(web_contents) {}
1060
1061 void DidStartNavigation(NavigationHandle* navigation_handle) override {
1062 started_navigation_urls_.push_back(navigation_handle->GetURL());
1063 }
1064
1065 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
1066 finished_navigation_urls_.push_back(navigation_handle->GetURL());
1067 }
1068
1069 const std::vector<GURL>& started_navigation_urls() const {
1070 return started_navigation_urls_;
1071 }
1072 const std::vector<GURL>& finished_navigation_urls() const {
1073 return finished_navigation_urls_;
1074 }
1075
1076 private:
1077 std::vector<GURL> started_navigation_urls_;
1078 std::vector<GURL> finished_navigation_urls_;
1079 };
1080
1081 // There was a bug without PlzNavigate that happened when a navigation was
1082 // blocked after a redirect. Blink didn't know about the redirect and tried
1083 // to commit an error page to the pre-redirect URL. The result was that the
1084 // NavigationHandle was not found on the browser-side and a new NavigationHandle
1085 // created for committing the error page. This test makes sure that only one
1086 // NavigationHandle is used for committing the error page.
1087 // See https://crbug.com/695421
1088 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest, BlockedOnRedirect) {
1089 // Returning BLOCK_REQUEST is not supported yet without PlzNavigate. It will
1090 // call a CHECK(false).
1091 // TODO(arthursonzogni) Provide support for BLOCK_REQUEST without PlzNavigate
1092 // once https://crbug.com/695421 is fixed.
1093 if (!IsBrowserSideNavigationEnabled())
1094 return;
1095
1096 const GURL kUrl = embedded_test_server()->GetURL("/title1.html");
1097 const GURL kRedirectingUrl =
1098 embedded_test_server()->GetURL("/server-redirect?" + kUrl.spec());
1099
1100 // Set up a NavigationThrottle that will block the navigation in
1101 // WillRedirectRequest.
1102 TestNavigationThrottleInstaller installer(
1103 shell()->web_contents(), NavigationThrottle::PROCEED,
1104 NavigationThrottle::BLOCK_REQUEST, NavigationThrottle::PROCEED);
1105 NavigationHandleObserver observer(shell()->web_contents(), kRedirectingUrl);
1106 NavigationLogger logger(shell()->web_contents());
1107
1108 // Try to navigate to the url. The navigation should be canceled and the
1109 // NavigationHandle should have the right error code.
1110 EXPECT_FALSE(NavigateToURL(shell(), kRedirectingUrl));
1111 // EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code());
1112
1113 // Only one navigation is expected to happen.
1114 std::vector<GURL> started_navigation = {kRedirectingUrl};
1115 EXPECT_EQ(started_navigation, logger.started_navigation_urls());
1116
1117 std::vector<GURL> finished_navigation = {kUrl};
1118 EXPECT_EQ(finished_navigation, logger.finished_navigation_urls());
1119 }
1120
1039 } // namespace content 1121 } // 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