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/content_switches.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" |
20 #include "net/test/url_request/url_request_failed_job.h" | |
19 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
20 #include "url/url_constants.h" | 22 #include "url/url_constants.h" |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // Gathers data from the NavigationHandle assigned to navigations that start | 28 // Gathers data from the NavigationHandle assigned to navigations that start |
27 // with the expected URL. | 29 // with the expected URL. |
28 class NavigationHandleObserver : public WebContentsObserver { | 30 class NavigationHandleObserver : public WebContentsObserver { |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 shell()->web_contents(), NavigationThrottle::PROCEED, | 1052 shell()->web_contents(), NavigationThrottle::PROCEED, |
1051 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | 1053 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); |
1052 NavigationHandleObserver observer(shell()->web_contents(), url); | 1054 NavigationHandleObserver observer(shell()->web_contents(), url); |
1053 EXPECT_TRUE(NavigateToURL(shell(), url)); | 1055 EXPECT_TRUE(NavigateToURL(shell(), url)); |
1054 EXPECT_EQ(1, installer.will_start_called()); | 1056 EXPECT_EQ(1, installer.will_start_called()); |
1055 EXPECT_EQ(1, installer.will_process_called()); | 1057 EXPECT_EQ(1, installer.will_process_called()); |
1056 EXPECT_FALSE(observer.is_same_page()); | 1058 EXPECT_FALSE(observer.is_same_page()); |
1057 } | 1059 } |
1058 } | 1060 } |
1059 | 1061 |
1062 // This class allows running tests with PlzNavigate enabled, regardless of | |
1063 // default test configuration. | |
1064 class PlzNavigateNavigationHandleImplBrowserTest : public ContentBrowserTest { | |
1065 public: | |
1066 PlzNavigateNavigationHandleImplBrowserTest() {} | |
1067 | |
1068 void SetUpCommandLine(base::CommandLine* command_line) override { | |
1069 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation); | |
1070 } | |
1071 }; | |
1072 | |
1073 // Test to verify that error pages caused by NavigationThrottle blocking a | |
1074 // request from being made are properly committed in the original process | |
1075 // that requested the navigation. | |
1076 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest, | |
1077 ErrorPageBlockedNavigation) { | |
nasko
2017/03/07 03:03:16
I put these tests here, since it has the TestNavig
| |
1078 host_resolver()->AddRule("*", "127.0.0.1"); | |
1079 SetupCrossSiteRedirector(embedded_test_server()); | |
1080 ASSERT_TRUE(embedded_test_server()->Start()); | |
1081 | |
1082 GURL start_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | |
1083 GURL blocked_url(embedded_test_server()->GetURL("bar.com", "/title2.html")); | |
1084 | |
1085 { | |
1086 NavigationHandleObserver observer(shell()->web_contents(), start_url); | |
1087 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | |
1088 EXPECT_TRUE(observer.has_committed()); | |
1089 EXPECT_FALSE(observer.is_error()); | |
1090 } | |
1091 | |
1092 SiteInstance* site_instance = | |
Charlie Reis
2017/03/09 00:43:34
scoped_refptr would be safer (since in theory it c
nasko
2017/03/09 07:24:09
Done.
| |
1093 shell()->web_contents()->GetMainFrame()->GetSiteInstance(); | |
1094 | |
1095 TestNavigationThrottleInstaller installer( | |
1096 shell()->web_contents(), NavigationThrottle::BLOCK_REQUEST, | |
nasko
2017/03/07 03:03:16
This tests only WillStartRequest, as blocking duri
| |
1097 NavigationThrottle::PROCEED, NavigationThrottle::PROCEED); | |
1098 | |
1099 { | |
1100 NavigationHandleObserver observer(shell()->web_contents(), blocked_url); | |
1101 EXPECT_FALSE(NavigateToURL(shell(), blocked_url)); | |
1102 EXPECT_TRUE(observer.has_committed()); | |
1103 EXPECT_TRUE(observer.is_error()); | |
1104 EXPECT_EQ(site_instance, | |
1105 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | |
1106 } | |
1107 } | |
1108 | |
1109 // Test to verify that error pages caused by network error or other | |
1110 // recoverable error are properly committed in the process for the | |
1111 // destination URL. | |
1112 IN_PROC_BROWSER_TEST_F(PlzNavigateNavigationHandleImplBrowserTest, | |
1113 ErrorPageNetworkError) { | |
1114 host_resolver()->AddRule("*", "127.0.0.1"); | |
1115 SetupCrossSiteRedirector(embedded_test_server()); | |
1116 ASSERT_TRUE(embedded_test_server()->Start()); | |
1117 | |
1118 GURL start_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | |
1119 GURL error_url( | |
1120 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); | |
1121 EXPECT_NE(start_url.host(), error_url.host()); | |
1122 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
1123 base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); | |
1124 | |
1125 { | |
1126 NavigationHandleObserver observer(shell()->web_contents(), start_url); | |
1127 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | |
1128 EXPECT_TRUE(observer.has_committed()); | |
1129 EXPECT_FALSE(observer.is_error()); | |
1130 } | |
1131 | |
1132 SiteInstance* site_instance = | |
Charlie Reis
2017/03/09 00:43:34
Same here.
nasko
2017/03/09 07:24:09
Done.
| |
1133 shell()->web_contents()->GetMainFrame()->GetSiteInstance(); | |
1134 { | |
1135 NavigationHandleObserver observer(shell()->web_contents(), error_url); | |
1136 EXPECT_FALSE(NavigateToURL(shell(), error_url)); | |
1137 EXPECT_TRUE(observer.has_committed()); | |
1138 EXPECT_TRUE(observer.is_error()); | |
1139 EXPECT_NE(site_instance, | |
1140 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | |
1141 } | |
1142 } | |
1143 | |
1060 } // namespace content | 1144 } // namespace content |
OLD | NEW |