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

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

Issue 2738643002: Implement error page commit policy in PlzNavigate. (Closed)
Patch Set: Add comment. 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/browser_side_navigation_policy.h"
11 #include "content/public/common/content_switches.h"
11 #include "content/public/common/request_context_type.h" 12 #include "content/public/common/request_context_type.h"
12 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/public/test/test_navigation_observer.h" 16 #include "content/public/test/test_navigation_observer.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
18 #include "content/test/content_browser_test_utils_internal.h" 19 #include "content/test/content_browser_test_utils_internal.h"
19 #include "net/dns/mock_host_resolver.h" 20 #include "net/dns/mock_host_resolver.h"
21 #include "net/test/url_request/url_request_failed_job.h"
20 #include "ui/base/page_transition_types.h" 22 #include "ui/base/page_transition_types.h"
21 #include "url/url_constants.h" 23 #include "url/url_constants.h"
22 24
23 namespace content { 25 namespace content {
24 26
25 namespace { 27 namespace {
26 28
27 // Gathers data from the NavigationHandle assigned to navigations that start 29 // Gathers data from the NavigationHandle assigned to navigations that start
28 // with the expected URL. 30 // with the expected URL.
29 class NavigationHandleObserver : public WebContentsObserver { 31 class NavigationHandleObserver : public WebContentsObserver {
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 // EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code()); 1113 // EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, observer.net_error_code());
1112 1114
1113 // Only one navigation is expected to happen. 1115 // Only one navigation is expected to happen.
1114 std::vector<GURL> started_navigation = {kRedirectingUrl}; 1116 std::vector<GURL> started_navigation = {kRedirectingUrl};
1115 EXPECT_EQ(started_navigation, logger.started_navigation_urls()); 1117 EXPECT_EQ(started_navigation, logger.started_navigation_urls());
1116 1118
1117 std::vector<GURL> finished_navigation = {kUrl}; 1119 std::vector<GURL> finished_navigation = {kUrl};
1118 EXPECT_EQ(finished_navigation, logger.finished_navigation_urls()); 1120 EXPECT_EQ(finished_navigation, logger.finished_navigation_urls());
1119 } 1121 }
1120 1122
1123 // This class allows running tests with PlzNavigate enabled, regardless of
1124 // default test configuration.
1125 class PlzNavigateNavigationHandleImplBrowserTest : public ContentBrowserTest {
1126 public:
1127 PlzNavigateNavigationHandleImplBrowserTest() {}
1128
1129 void SetUpCommandLine(base::CommandLine* command_line) override {
1130 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation);
1131 }
1132 };
1133
1134 // Test to verify that error pages caused by NavigationThrottle blocking a
1135 // request from being made are properly committed in the original process
1136 // that requested the navigation.
1137 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest,
1138 ErrorPageBlockedNavigation) {
1139 host_resolver()->AddRule("*", "127.0.0.1");
1140 SetupCrossSiteRedirector(embedded_test_server());
1141 ASSERT_TRUE(embedded_test_server()->Start());
1142
1143 GURL start_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
1144 GURL blocked_url(embedded_test_server()->GetURL("bar.com", "/title2.html"));
1145
1146 {
1147 NavigationHandleObserver observer(shell()->web_contents(), start_url);
1148 EXPECT_TRUE(NavigateToURL(shell(), start_url));
1149 EXPECT_TRUE(observer.has_committed());
1150 EXPECT_FALSE(observer.is_error());
1151 }
1152
1153 scoped_refptr<SiteInstance> site_instance =
1154 shell()->web_contents()->GetMainFrame()->GetSiteInstance();
1155
1156 TestNavigationThrottleInstaller installer(
1157 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST,
1158 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED);
1159
1160 {
1161 NavigationHandleObserver observer(shell()->web_contents(), blocked_url);
1162 EXPECT_FALSE(NavigateToURL(shell(), blocked_url));
1163 EXPECT_TRUE(observer.has_committed());
1164 EXPECT_TRUE(observer.is_error());
1165 EXPECT_EQ(site_instance,
1166 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
1167 }
1168 }
1169
1170 // Test to verify that error pages caused by network error or other
1171 // recoverable error are properly committed in the process for the
1172 // destination URL.
1173 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest,
1174 ErrorPageNetworkError) {
1175 host_resolver()->AddRule("*", "127.0.0.1");
1176 SetupCrossSiteRedirector(embedded_test_server());
1177 ASSERT_TRUE(embedded_test_server()->Start());
1178
1179 GURL start_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
1180 GURL error_url(
1181 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET));
1182 EXPECT_NE(start_url.host(), error_url.host());
1183 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1184 base::Bind(&net::URLRequestFailedJob::AddUrlHandler));
1185
1186 {
1187 NavigationHandleObserver observer(shell()->web_contents(), start_url);
1188 EXPECT_TRUE(NavigateToURL(shell(), start_url));
1189 EXPECT_TRUE(observer.has_committed());
1190 EXPECT_FALSE(observer.is_error());
1191 }
1192
1193 scoped_refptr<SiteInstance> site_instance =
1194 shell()->web_contents()->GetMainFrame()->GetSiteInstance();
1195 {
1196 NavigationHandleObserver observer(shell()->web_contents(), error_url);
1197 EXPECT_FALSE(NavigateToURL(shell(), error_url));
1198 EXPECT_TRUE(observer.has_committed());
1199 EXPECT_TRUE(observer.is_error());
1200 EXPECT_NE(site_instance,
1201 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
1202 }
1203 }
1204
1121 } // namespace content 1205 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/webrequest/test_blocking.js ('k') | content/browser/frame_host/navigation_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698