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