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

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: Removed unused import 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,
220 root_http.AppendASCII("mock-link-doctor.json")); 220 network_delegate,
221 root_http.AppendASCII("mock-link-doctor.json"),
222 content::BrowserThread::GetBlockingPool()
223 ->GetTaskRunnerWithShutdownBehavior(
224 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
221 } 225 }
222 226
223 void WaitForRequests(int requests_to_wait_for) { 227 void WaitForRequests(int requests_to_wait_for) {
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
225 DCHECK_EQ(-1, requests_to_wait_for_); 229 DCHECK_EQ(-1, requests_to_wait_for_);
226 DCHECK(!run_loop_); 230 DCHECK(!run_loop_);
227 231
228 if (requests_to_wait_for >= num_requests_) 232 if (requests_to_wait_for >= num_requests_)
229 return; 233 return;
230 234
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 const GURL& search_url, 273 const GURL& search_url,
270 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) { 274 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) {
271 chrome_browser_net::SetUrlRequestMocksEnabled(true); 275 chrome_browser_net::SetUrlRequestMocksEnabled(true);
272 276
273 AddInterceptorForURL(google_util::LinkDoctorBaseURL(), 277 AddInterceptorForURL(google_util::LinkDoctorBaseURL(),
274 link_doctor_interceptor.Pass()); 278 link_doctor_interceptor.Pass());
275 279
276 // Add a mock for the search engine the error page will use. 280 // Add a mock for the search engine the error page will use.
277 base::FilePath root_http; 281 base::FilePath root_http;
278 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 282 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
279 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( 283 net::URLRequestMockHTTPJob::AddHostnameToFileHandler(
280 search_url.host(), root_http.AppendASCII("title3.html")); 284 search_url.host(),
285 root_http.AppendASCII("title3.html"),
286 content::BrowserThread::GetBlockingPool());
281 } 287 }
282 288
283 class ErrorPageTest : public InProcessBrowserTest { 289 class ErrorPageTest : public InProcessBrowserTest {
284 public: 290 public:
285 enum HistoryNavigationDirection { 291 enum HistoryNavigationDirection {
286 HISTORY_NAVIGATE_BACK, 292 HISTORY_NAVIGATE_BACK,
287 HISTORY_NAVIGATE_FORWARD, 293 HISTORY_NAVIGATE_FORWARD,
288 }; 294 };
289 295
290 ErrorPageTest() : link_doctor_interceptor_(NULL) {} 296 ErrorPageTest() : link_doctor_interceptor_(NULL) {}
291 virtual ~ErrorPageTest() {} 297 virtual ~ErrorPageTest() {}
292 298
293 // Navigates the active tab to a mock url created for the file at |file_path|. 299 // Navigates the active tab to a mock url created for the file at |file_path|.
294 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. 300 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests.
295 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 301 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
296 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); 302 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache);
297 } 303 }
298 304
299 // Navigates the active tab to a mock url created for the file at |file_path|. 305 // Navigates the active tab to a mock url created for the file at |file_path|.
300 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 306 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
301 ui_test_utils::NavigateToURL( 307 ui_test_utils::NavigateToURL(
302 browser(), 308 browser(),
303 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); 309 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
304 } 310 }
305 311
306 // Navigates to the given URL and waits for |num_navigations| to occur, and 312 // Navigates to the given URL and waits for |num_navigations| to occur, and
307 // the title to change to |expected_title|. 313 // the title to change to |expected_title|.
308 void NavigateToURLAndWaitForTitle(const GURL& url, 314 void NavigateToURLAndWaitForTitle(const GURL& url,
309 const std::string& expected_title, 315 const std::string& expected_title,
310 int num_navigations) { 316 int num_navigations) {
311 content::TitleWatcher title_watcher( 317 content::TitleWatcher title_watcher(
312 browser()->tab_strip_model()->GetActiveWebContents(), 318 browser()->tab_strip_model()->GetActiveWebContents(),
313 base::ASCIIToUTF16(expected_title)); 319 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 699 // to make sure to wait the tracking request, since the new page does not
694 // depend on it. 700 // depend on it.
695 link_doctor_interceptor()->WaitForRequests(2); 701 link_doctor_interceptor()->WaitForRequests(2);
696 EXPECT_EQ(2, link_doctor_interceptor()->num_requests()); 702 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
697 } 703 }
698 704
699 // Test that a DNS error occuring in an iframe does not result in showing 705 // Test that a DNS error occuring in an iframe does not result in showing
700 // navigation corrections. 706 // navigation corrections.
701 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 707 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
702 NavigateToURLAndWaitForTitle( 708 NavigateToURLAndWaitForTitle(
703 content::URLRequestMockHTTPJob::GetMockUrl( 709 net::URLRequestMockHTTPJob::GetMockUrl(
704 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 710 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
705 "Blah", 711 "Blah",
706 1); 712 1);
707 // We expect to have two history entries, since we started off with navigation 713 // 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". 714 // to "about:blank" and then navigated to "iframe_dns_error.html".
709 EXPECT_EQ(2, 715 EXPECT_EQ(2,
710 browser()->tab_strip_model()->GetActiveWebContents()-> 716 browser()->tab_strip_model()->GetActiveWebContents()->
711 GetController().GetEntryCount()); 717 GetController().GetEntryCount());
712 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 718 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
713 } 719 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 EXPECT_EQ(fail_url, fail_observer.fail_url()); 813 EXPECT_EQ(fail_url, fail_observer.fail_url());
808 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 814 EXPECT_EQ(2, wc->GetController().GetEntryCount());
809 } 815 }
810 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 816 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
811 } 817 }
812 818
813 // Checks that navigation corrections are not loaded when we receive an actual 819 // Checks that navigation corrections are not loaded when we receive an actual
814 // 404 page. 820 // 404 page.
815 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 821 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
816 NavigateToURLAndWaitForTitle( 822 NavigateToURLAndWaitForTitle(
817 content::URLRequestMockHTTPJob::GetMockUrl( 823 net::URLRequestMockHTTPJob::GetMockUrl(
818 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 824 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
819 "SUCCESS", 825 "SUCCESS",
820 1); 826 1);
821 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 827 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
822 } 828 }
823 829
824 // Checks that when an error occurs, the stale cache status of the page 830 // 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 831 // is correctly transferred, and that stale cached copied can be loaded
826 // from the javascript. 832 // from the javascript.
827 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 833 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 browser(), 1099 browser(),
1094 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1100 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1095 kHostname), 1101 kHostname),
1096 1); 1102 1);
1097 1103
1098 ToggleHelpBox(browser()); 1104 ToggleHelpBox(browser());
1099 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1105 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1100 } 1106 }
1101 1107
1102 } // namespace 1108 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698