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

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 541743002: Move url_request_mock_http_job to net/test/url_request/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_types.h" 33 #include "content/public/browser/notification_types.h"
34 #include "content/public/browser/render_frame_host.h" 34 #include "content/public/browser/render_frame_host.h"
35 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
37 #include "content/public/browser/web_contents_observer.h" 37 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/test/browser_test_utils.h" 38 #include "content/public/test/browser_test_utils.h"
39 #include "content/public/test/test_navigation_observer.h" 39 #include "content/public/test/test_navigation_observer.h"
40 #include "content/test/net/url_request_failed_job.h" 40 #include "content/test/net/url_request_failed_job.h"
41 #include "content/test/net/url_request_mock_http_job.h"
42 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
43 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
44 #include "net/http/failing_http_transaction_factory.h" 43 #include "net/http/failing_http_transaction_factory.h"
45 #include "net/http/http_cache.h" 44 #include "net/http/http_cache.h"
46 #include "net/test/spawned_test_server/spawned_test_server.h" 45 #include "net/test/spawned_test_server/spawned_test_server.h"
46 #include "net/test/url_request/url_request_mock_http_job.h"
47 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
48 #include "net/url_request/url_request_context_getter.h" 48 #include "net/url_request/url_request_context_getter.h"
49 #include "net/url_request/url_request_filter.h" 49 #include "net/url_request/url_request_filter.h"
50 #include "net/url_request/url_request_interceptor.h" 50 #include "net/url_request/url_request_interceptor.h"
51 #include "net/url_request/url_request_job.h" 51 #include "net/url_request/url_request_job.h"
52 #include "net/url_request/url_request_test_job.h" 52 #include "net/url_request/url_request_test_job.h"
53 #include "net/url_request/url_request_test_util.h" 53 #include "net/url_request/url_request_test_util.h"
54 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
55 55
56 using content::BrowserThread; 56 using content::BrowserThread;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 net::NetworkDelegate* network_delegate) const OVERRIDE { 208 net::NetworkDelegate* network_delegate) const OVERRIDE {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
210 210
211 BrowserThread::PostTask( 211 BrowserThread::PostTask(
212 BrowserThread::UI, FROM_HERE, 212 BrowserThread::UI, FROM_HERE,
213 base::Bind(&LinkDoctorInterceptor::RequestCreated, 213 base::Bind(&LinkDoctorInterceptor::RequestCreated,
214 weak_factory_.GetWeakPtr())); 214 weak_factory_.GetWeakPtr()));
215 215
216 base::FilePath root_http; 216 base::FilePath root_http;
217 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 217 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
218 return new content::URLRequestMockHTTPJob( 218 return new net::URLRequestMockHTTPJob(
219 request, network_delegate, 219 request, network_delegate,
220 root_http.AppendASCII("mock-link-doctor.json")); 220 root_http.AppendASCII("mock-link-doctor.json"),
221 content::BrowserThread::GetBlockingPool());
221 } 222 }
222 223
223 void WaitForRequests(int requests_to_wait_for) { 224 void WaitForRequests(int requests_to_wait_for) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
225 DCHECK_EQ(-1, requests_to_wait_for_); 226 DCHECK_EQ(-1, requests_to_wait_for_);
226 DCHECK(!run_loop_); 227 DCHECK(!run_loop_);
227 228
228 if (requests_to_wait_for >= num_requests_) 229 if (requests_to_wait_for >= num_requests_)
229 return; 230 return;
230 231
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 const GURL& search_url, 270 const GURL& search_url,
270 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) { 271 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) {
271 chrome_browser_net::SetUrlRequestMocksEnabled(true); 272 chrome_browser_net::SetUrlRequestMocksEnabled(true);
272 273
273 AddInterceptorForURL(google_util::LinkDoctorBaseURL(), 274 AddInterceptorForURL(google_util::LinkDoctorBaseURL(),
274 link_doctor_interceptor.Pass()); 275 link_doctor_interceptor.Pass());
275 276
276 // Add a mock for the search engine the error page will use. 277 // Add a mock for the search engine the error page will use.
277 base::FilePath root_http; 278 base::FilePath root_http;
278 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 279 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
279 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( 280 net::URLRequestMockHTTPJob::AddHostnameToFileHandler(
280 search_url.host(), root_http.AppendASCII("title3.html")); 281 search_url.host(), root_http.AppendASCII("title3.html"),
282 content::BrowserThread::GetBlockingPool());
281 } 283 }
282 284
283 class ErrorPageTest : public InProcessBrowserTest { 285 class ErrorPageTest : public InProcessBrowserTest {
284 public: 286 public:
285 enum HistoryNavigationDirection { 287 enum HistoryNavigationDirection {
286 HISTORY_NAVIGATE_BACK, 288 HISTORY_NAVIGATE_BACK,
287 HISTORY_NAVIGATE_FORWARD, 289 HISTORY_NAVIGATE_FORWARD,
288 }; 290 };
289 291
290 ErrorPageTest() : link_doctor_interceptor_(NULL) {} 292 ErrorPageTest() : link_doctor_interceptor_(NULL) {}
291 virtual ~ErrorPageTest() {} 293 virtual ~ErrorPageTest() {}
292 294
293 // Navigates the active tab to a mock url created for the file at |file_path|. 295 // Navigates the active tab to a mock url created for the file at |file_path|.
294 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. 296 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests.
295 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 297 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
296 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); 298 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache);
297 } 299 }
298 300
299 // Navigates the active tab to a mock url created for the file at |file_path|. 301 // Navigates the active tab to a mock url created for the file at |file_path|.
300 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 302 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
301 ui_test_utils::NavigateToURL( 303 ui_test_utils::NavigateToURL(
302 browser(), 304 browser(),
303 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); 305 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
304 } 306 }
305 307
306 // Navigates to the given URL and waits for |num_navigations| to occur, and 308 // Navigates to the given URL and waits for |num_navigations| to occur, and
307 // the title to change to |expected_title|. 309 // the title to change to |expected_title|.
308 void NavigateToURLAndWaitForTitle(const GURL& url, 310 void NavigateToURLAndWaitForTitle(const GURL& url,
309 const std::string& expected_title, 311 const std::string& expected_title,
310 int num_navigations) { 312 int num_navigations) {
311 content::TitleWatcher title_watcher( 313 content::TitleWatcher title_watcher(
312 browser()->tab_strip_model()->GetActiveWebContents(), 314 browser()->tab_strip_model()->GetActiveWebContents(),
313 base::ASCIIToUTF16(expected_title)); 315 base::ASCIIToUTF16(expected_title));
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // to make sure to wait the tracking request, since the new page does not 695 // to make sure to wait the tracking request, since the new page does not
694 // depend on it. 696 // depend on it.
695 link_doctor_interceptor()->WaitForRequests(2); 697 link_doctor_interceptor()->WaitForRequests(2);
696 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 698 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
697 } 699 }
698 700
699 // Test that a DNS error occuring in an iframe does not result in showing 701 // Test that a DNS error occuring in an iframe does not result in showing
700 // navigation corrections. 702 // navigation corrections.
701 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 703 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
702 NavigateToURLAndWaitForTitle( 704 NavigateToURLAndWaitForTitle(
703 content::URLRequestMockHTTPJob::GetMockUrl( 705 net::URLRequestMockHTTPJob::GetMockUrl(
704 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 706 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
705 "Blah", 707 "Blah",
706 1); 708 1);
707 // We expect to have two history entries, since we started off with navigation 709 // We expect to have two history entries, since we started off with navigation
708 // to "about:blank" and then navigated to "iframe_dns_error.html". 710 // to "about:blank" and then navigated to "iframe_dns_error.html".
709 EXPECT_EQ(2, 711 EXPECT_EQ(2,
710 browser()->tab_strip_model()->GetActiveWebContents()-> 712 browser()->tab_strip_model()->GetActiveWebContents()->
711 GetController().GetEntryCount()); 713 GetController().GetEntryCount());
712 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 714 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
713 } 715 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 EXPECT_EQ(fail_url, fail_observer.fail_url()); 809 EXPECT_EQ(fail_url, fail_observer.fail_url());
808 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 810 EXPECT_EQ(2, wc->GetController().GetEntryCount());
809 } 811 }
810 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 812 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
811 } 813 }
812 814
813 // Checks that navigation corrections are not loaded when we receive an actual 815 // Checks that navigation corrections are not loaded when we receive an actual
814 // 404 page. 816 // 404 page.
815 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 817 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
816 NavigateToURLAndWaitForTitle( 818 NavigateToURLAndWaitForTitle(
817 content::URLRequestMockHTTPJob::GetMockUrl( 819 net::URLRequestMockHTTPJob::GetMockUrl(
818 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 820 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
819 "SUCCESS", 821 "SUCCESS",
820 1); 822 1);
821 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 823 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
822 } 824 }
823 825
824 // Checks that when an error occurs, the stale cache status of the page 826 // Checks that when an error occurs, the stale cache status of the page
825 // is correctly transferred, and that stale cached copied can be loaded 827 // is correctly transferred, and that stale cached copied can be loaded
826 // from the javascript. 828 // from the javascript.
827 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 829 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 browser(), 1095 browser(),
1094 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1096 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1095 kHostname), 1097 kHostname),
1096 1); 1098 1);
1097 1099
1098 ToggleHelpBox(browser()); 1100 ToggleHelpBox(browser());
1099 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1101 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1100 } 1102 }
1101 1103
1102 } // namespace 1104 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698