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

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

Powered by Google App Engine
This is Rietveld 408576698