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

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

Issue 300693005: Make URLRequestFilter use URLRequestInterceptors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge Created 6 years, 6 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 | Annotate | Revision Log
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 29 matching lines...) Expand all
40 #include "content/test/net/url_request_mock_http_job.h" 40 #include "content/test/net/url_request_mock_http_job.h"
41 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
42 #include "net/base/net_errors.h" 42 #include "net/base/net_errors.h"
43 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
44 #include "net/http/failing_http_transaction_factory.h" 44 #include "net/http/failing_http_transaction_factory.h"
45 #include "net/http/http_cache.h" 45 #include "net/http/http_cache.h"
46 #include "net/test/spawned_test_server/spawned_test_server.h" 46 #include "net/test/spawned_test_server/spawned_test_server.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_job.h" 51 #include "net/url_request/url_request_job.h"
51 #include "net/url_request/url_request_job_factory.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;
57 using content::NavigationController; 57 using content::NavigationController;
58 using content::URLRequestFailedJob; 58 using content::URLRequestFailedJob;
59 using net::URLRequestJobFactory;
60 using net::URLRequestTestJob; 59 using net::URLRequestTestJob;
61 60
62 namespace { 61 namespace {
63 62
64 // Returns true if |text| is displayed on the page |browser| is currently 63 // Returns true if |text| is displayed on the page |browser| is currently
65 // displaying. Uses "innerText", so will miss hidden text, and whitespace 64 // displaying. Uses "innerText", so will miss hidden text, and whitespace
66 // space handling may be weird. 65 // space handling may be weird.
67 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser, 66 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser,
68 const std::string& text) { 67 const std::string& text) {
69 std::string command = base::StringPrintf( 68 std::string command = base::StringPrintf(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 "var searchText = document.getElementById('search-box').value;" 139 "var searchText = document.getElementById('search-box').value;"
141 "domAutomationController.send(searchText == 'search query');", 140 "domAutomationController.send(searchText == 'search query');",
142 &search_box_populated)); 141 &search_box_populated));
143 EXPECT_TRUE(search_box_populated); 142 EXPECT_TRUE(search_box_populated);
144 } 143 }
145 144
146 std::string GetLoadStaleButtonLabel() { 145 std::string GetLoadStaleButtonLabel() {
147 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_LOAD_STALE); 146 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_LOAD_STALE);
148 } 147 }
149 148
150 void AddProtocolHandlerForURL( 149 void AddInterceptorForURL(
151 const GURL& url, 150 const GURL& url,
152 scoped_ptr<URLRequestJobFactory::ProtocolHandler> handler) { 151 scoped_ptr<net::URLRequestInterceptor> handler) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
154 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 153 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
155 url, handler.Pass()); 154 url, handler.Pass());
156 } 155 }
157 156
158 // A protocol handler that fails a configurable number of requests, then 157 // An interceptor that fails a configurable number of requests, then succeeds
159 // succeeds all requests after that, keeping count of failures and successes. 158 // all requests after that, keeping count of failures and successes.
160 class FailFirstNRequestsProtocolHandler 159 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor {
161 : public URLRequestJobFactory::ProtocolHandler {
162 public: 160 public:
163 explicit FailFirstNRequestsProtocolHandler(int requests_to_fail) 161 explicit FailFirstNRequestsInterceptor(int requests_to_fail)
164 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} 162 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {}
165 virtual ~FailFirstNRequestsProtocolHandler() {} 163 virtual ~FailFirstNRequestsInterceptor() {}
166 164
167 // net::URLRequestJobFactory::ProtocolHandler implementation 165 // net::URLRequestInterceptor implementation
168 virtual net::URLRequestJob* MaybeCreateJob( 166 virtual net::URLRequestJob* MaybeInterceptRequest(
169 net::URLRequest* request, 167 net::URLRequest* request,
170 net::NetworkDelegate* network_delegate) const OVERRIDE { 168 net::NetworkDelegate* network_delegate) const OVERRIDE {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
172 requests_++; 170 requests_++;
173 if (failures_ < requests_to_fail_) { 171 if (failures_ < requests_to_fail_) {
174 failures_++; 172 failures_++;
175 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see 173 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see
176 // NetErrorHelperCore::GetErrorPageURL. 174 // NetErrorHelperCore::GetErrorPageURL.
177 return new URLRequestFailedJob(request, 175 return new URLRequestFailedJob(request,
178 network_delegate, 176 network_delegate,
179 net::ERR_CONNECTION_RESET); 177 net::ERR_CONNECTION_RESET);
180 } else { 178 } else {
181 return new URLRequestTestJob(request, network_delegate, 179 return new URLRequestTestJob(request, network_delegate,
182 URLRequestTestJob::test_headers(), 180 URLRequestTestJob::test_headers(),
183 URLRequestTestJob::test_data_1(), 181 URLRequestTestJob::test_data_1(),
184 true); 182 true);
185 } 183 }
186 } 184 }
187 185
188 int requests() const { return requests_; } 186 int requests() const { return requests_; }
189 int failures() const { return failures_; } 187 int failures() const { return failures_; }
190 188
191 private: 189 private:
192 // These are mutable because MaybeCreateJob is const but we want this state 190 // These are mutable because MaybeCreateJob is const but we want this state
193 // for testing. 191 // for testing.
194 mutable int requests_; 192 mutable int requests_;
195 mutable int failures_; 193 mutable int failures_;
196 int requests_to_fail_; 194 int requests_to_fail_;
195
196 DISALLOW_COPY_AND_ASSIGN(FailFirstNRequestsInterceptor);
197 }; 197 };
198 198
199 // A protocol handler that serves LinkDoctor responses. It also allows waiting 199 // An interceptor that serves LinkDoctor responses. It also allows waiting
200 // until a certain number of requests have been sent. 200 // until a certain number of requests have been sent.
201 // TODO(mmenke): Wait until responses have been received instead. 201 // TODO(mmenke): Wait until responses have been received instead.
202 class LinkDoctorProtocolHandler 202 class LinkDoctorInterceptor : public net::URLRequestInterceptor {
203 : public URLRequestJobFactory::ProtocolHandler {
204 public: 203 public:
205 LinkDoctorProtocolHandler() 204 LinkDoctorInterceptor() : num_requests_(0),
206 : num_requests_(0), 205 requests_to_wait_for_(-1),
207 requests_to_wait_for_(-1), 206 weak_factory_(this) {
208 weak_factory_(this) {
209 } 207 }
210 208
211 virtual ~LinkDoctorProtocolHandler() {} 209 virtual ~LinkDoctorInterceptor() {}
212 210
213 // net::URLRequestJobFactory::ProtocolHandler implementation 211 // net::URLRequestInterceptor implementation
214 virtual net::URLRequestJob* MaybeCreateJob( 212 virtual net::URLRequestJob* MaybeInterceptRequest(
215 net::URLRequest* request, 213 net::URLRequest* request,
216 net::NetworkDelegate* network_delegate) const OVERRIDE { 214 net::NetworkDelegate* network_delegate) const OVERRIDE {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
218 216
219 BrowserThread::PostTask( 217 BrowserThread::PostTask(
220 BrowserThread::UI, FROM_HERE, 218 BrowserThread::UI, FROM_HERE,
221 base::Bind(&LinkDoctorProtocolHandler::RequestCreated, 219 base::Bind(&LinkDoctorInterceptor::RequestCreated,
222 weak_factory_.GetWeakPtr())); 220 weak_factory_.GetWeakPtr()));
223 221
224 base::FilePath root_http; 222 base::FilePath root_http;
225 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 223 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
226 return new content::URLRequestMockHTTPJob( 224 return new content::URLRequestMockHTTPJob(
227 request, network_delegate, 225 request, network_delegate,
228 root_http.AppendASCII("mock-link-doctor.json")); 226 root_http.AppendASCII("mock-link-doctor.json"));
229 } 227 }
230 228
231 void WaitForRequests(int requests_to_wait_for) { 229 void WaitForRequests(int requests_to_wait_for) {
(...skipping 29 matching lines...) Expand all
261 run_loop_->Quit(); 259 run_loop_->Quit();
262 } 260 }
263 261
264 // These are only used on the UI thread. 262 // These are only used on the UI thread.
265 int num_requests_; 263 int num_requests_;
266 int requests_to_wait_for_; 264 int requests_to_wait_for_;
267 scoped_ptr<base::RunLoop> run_loop_; 265 scoped_ptr<base::RunLoop> run_loop_;
268 266
269 // This prevents any risk of flake if any test doesn't wait for a request 267 // This prevents any risk of flake if any test doesn't wait for a request
270 // it sent. Mutable so it can be accessed from a const function. 268 // it sent. Mutable so it can be accessed from a const function.
271 mutable base::WeakPtrFactory<LinkDoctorProtocolHandler> weak_factory_; 269 mutable base::WeakPtrFactory<LinkDoctorInterceptor> weak_factory_;
270
271 DISALLOW_COPY_AND_ASSIGN(LinkDoctorInterceptor);
272 }; 272 };
273 273
274 void InstallMockProtocolHandlers( 274 void InstallMockInterceptors(
275 const GURL& search_url, 275 const GURL& search_url,
276 scoped_ptr<URLRequestJobFactory::ProtocolHandler> link_doctor_handler) { 276 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) {
277 chrome_browser_net::SetUrlRequestMocksEnabled(true); 277 chrome_browser_net::SetUrlRequestMocksEnabled(true);
278 278
279 AddProtocolHandlerForURL(google_util::LinkDoctorBaseURL(), 279 AddInterceptorForURL(google_util::LinkDoctorBaseURL(),
280 link_doctor_handler.Pass()); 280 link_doctor_interceptor.Pass());
281 281
282 // Add a mock for the search engine the error page will use. 282 // Add a mock for the search engine the error page will use.
283 base::FilePath root_http; 283 base::FilePath root_http;
284 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 284 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
285 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( 285 content::URLRequestMockHTTPJob::AddHostnameToFileHandler(
286 search_url.host(), root_http.AppendASCII("title3.html")); 286 search_url.host(), root_http.AppendASCII("title3.html"));
287 } 287 }
288 288
289 class ErrorPageTest : public InProcessBrowserTest { 289 class ErrorPageTest : public InProcessBrowserTest {
290 public: 290 public:
291 enum HistoryNavigationDirection { 291 enum HistoryNavigationDirection {
292 HISTORY_NAVIGATE_BACK, 292 HISTORY_NAVIGATE_BACK,
293 HISTORY_NAVIGATE_FORWARD, 293 HISTORY_NAVIGATE_FORWARD,
294 }; 294 };
295 295
296 ErrorPageTest() : link_doctor_handler_(NULL) {} 296 ErrorPageTest() : link_doctor_interceptor_(NULL) {}
297 virtual ~ErrorPageTest() {} 297 virtual ~ErrorPageTest() {}
298 298
299 // 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|.
300 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. 300 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests.
301 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 301 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
302 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); 302 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache);
303 } 303 }
304 304
305 // 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|.
306 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 306 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 browser()->tab_strip_model()->GetActiveWebContents(), 394 browser()->tab_strip_model()->GetActiveWebContents(),
395 js_reload_script, 395 js_reload_script,
396 &result); 396 &result);
397 EXPECT_TRUE(ret); 397 EXPECT_TRUE(ret);
398 if (!ret) 398 if (!ret)
399 return testing::AssertionFailure(); 399 return testing::AssertionFailure();
400 return ("success" == result ? testing::AssertionSuccess() : 400 return ("success" == result ? testing::AssertionSuccess() :
401 (testing::AssertionFailure() << "Exception message is " << result)); 401 (testing::AssertionFailure() << "Exception message is " << result));
402 } 402 }
403 403
404 LinkDoctorProtocolHandler* link_doctor_handler() { 404 LinkDoctorInterceptor* link_doctor_interceptor() {
405 return link_doctor_handler_; 405 return link_doctor_interceptor_;
406 } 406 }
407 407
408 protected: 408 protected:
409 virtual void SetUpOnMainThread() OVERRIDE { 409 virtual void SetUpOnMainThread() OVERRIDE {
410 link_doctor_handler_ = new LinkDoctorProtocolHandler(); 410 link_doctor_interceptor_ = new LinkDoctorInterceptor();
411 scoped_ptr<URLRequestJobFactory::ProtocolHandler> owned_handler( 411 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(
412 link_doctor_handler_); 412 link_doctor_interceptor_);
413 // Ownership of the |protocol_handler_| is passed to an object the IO 413 // Ownership of the |interceptor_| is passed to an object the IO thread, but
414 // thread, but a pointer is kept in the test fixture. As soon as anything 414 // a pointer is kept in the test fixture. As soon as anything calls
415 // calls URLRequestFilter::ClearHandlers(), |protocol_handler_| can become 415 // URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid.
416 // invalid.
417 BrowserThread::PostTask( 416 BrowserThread::PostTask(
418 BrowserThread::IO, 417 BrowserThread::IO, FROM_HERE,
419 FROM_HERE, 418 base::Bind(&InstallMockInterceptors,
420 base::Bind(&InstallMockProtocolHandlers,
421 google_util::GetGoogleSearchURL( 419 google_util::GetGoogleSearchURL(
422 google_profile_helper::GetGoogleHomePageURL( 420 google_profile_helper::GetGoogleHomePageURL(
423 browser()->profile())), 421 browser()->profile())),
424 base::Passed(&owned_handler))); 422 base::Passed(&owned_interceptor)));
425 } 423 }
426 424
427 // Returns a GURL that results in a DNS error. 425 // Returns a GURL that results in a DNS error.
428 GURL GetDnsErrorURL() const { 426 GURL GetDnsErrorURL() const {
429 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); 427 return URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED);
430 } 428 }
431 429
432 private: 430 private:
433 // Navigates the browser the indicated direction in the history and waits for 431 // Navigates the browser the indicated direction in the history and waits for
434 // |num_navigations| to occur and the title to change to |expected_title|. 432 // |num_navigations| to occur and the title to change to |expected_title|.
(...skipping 18 matching lines...) Expand all
453 if (direction == HISTORY_NAVIGATE_BACK) { 451 if (direction == HISTORY_NAVIGATE_BACK) {
454 chrome::GoBack(browser(), CURRENT_TAB); 452 chrome::GoBack(browser(), CURRENT_TAB);
455 } else if (direction == HISTORY_NAVIGATE_FORWARD) { 453 } else if (direction == HISTORY_NAVIGATE_FORWARD) {
456 chrome::GoForward(browser(), CURRENT_TAB); 454 chrome::GoForward(browser(), CURRENT_TAB);
457 } else { 455 } else {
458 FAIL(); 456 FAIL();
459 } 457 }
460 test_navigation_observer.Wait(); 458 test_navigation_observer.Wait();
461 } 459 }
462 460
463 LinkDoctorProtocolHandler* link_doctor_handler_; 461 LinkDoctorInterceptor* link_doctor_interceptor_;
464 }; 462 };
465 463
466 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { 464 class TestFailProvisionalLoadObserver : public content::WebContentsObserver {
467 public: 465 public:
468 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) 466 explicit TestFailProvisionalLoadObserver(content::WebContents* contents)
469 : content::WebContentsObserver(contents) {} 467 : content::WebContentsObserver(contents) {}
470 virtual ~TestFailProvisionalLoadObserver() {} 468 virtual ~TestFailProvisionalLoadObserver() {}
471 469
472 // This method is invoked when the provisional load failed. 470 // This method is invoked when the provisional load failed.
473 virtual void DidFailProvisionalLoad( 471 virtual void DidFailProvisionalLoad(
(...skipping 28 matching lines...) Expand all
502 cache->SetHttpNetworkTransactionFactoryForTesting(factory.Pass()); 500 cache->SetHttpNetworkTransactionFactoryForTesting(factory.Pass());
503 } 501 }
504 502
505 // Test that a DNS error occuring in the main frame redirects to an error page. 503 // Test that a DNS error occuring in the main frame redirects to an error page.
506 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_Basic) { 504 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_Basic) {
507 // The first navigation should fail, and the second one should be the error 505 // The first navigation should fail, and the second one should be the error
508 // page. 506 // page.
509 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 507 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
510 browser(), GetDnsErrorURL(), 2); 508 browser(), GetDnsErrorURL(), 2);
511 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 509 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
512 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 510 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
513 } 511 }
514 512
515 // Test that a DNS error occuring in the main frame does not result in an 513 // Test that a DNS error occuring in the main frame does not result in an
516 // additional session history entry. 514 // additional session history entry.
517 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack1) { 515 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack1) {
518 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 516 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
519 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 517 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
520 browser(), GetDnsErrorURL(), 2); 518 browser(), GetDnsErrorURL(), 2);
521 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 519 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
522 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 520 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
523 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 521 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
524 } 522 }
525 523
526 // Test that a DNS error occuring in the main frame does not result in an 524 // Test that a DNS error occuring in the main frame does not result in an
527 // additional session history entry. 525 // additional session history entry.
528 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) { 526 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2) {
529 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 527 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
530 528
531 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 529 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
532 browser(), GetDnsErrorURL(), 2); 530 browser(), GetDnsErrorURL(), 2);
533 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 531 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
534 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 532 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
535 533
536 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 534 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
537 535
538 GoBackAndWaitForNavigations(2); 536 GoBackAndWaitForNavigations(2);
539 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 537 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
540 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 538 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
541 539
542 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 540 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
543 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 541 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
544 } 542 }
545 543
546 // Test that a DNS error occuring in the main frame does not result in an 544 // Test that a DNS error occuring in the main frame does not result in an
547 // additional session history entry. 545 // additional session history entry.
548 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 546 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
549 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 547 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
550 548
551 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 549 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
552 browser(), GetDnsErrorURL(), 2); 550 browser(), GetDnsErrorURL(), 2);
553 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 551 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
554 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 552 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
555 553
556 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 554 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
557 555
558 GoBackAndWaitForNavigations(2); 556 GoBackAndWaitForNavigations(2);
559 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 557 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
560 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 558 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
561 559
562 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 560 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
563 561
564 GoForwardAndWaitForNavigations(2); 562 GoForwardAndWaitForNavigations(2);
565 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 563 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
566 EXPECT_EQ(3, link_doctor_handler()->num_requests()); 564 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
567 } 565 }
568 566
569 // Test that a DNS error occuring in the main frame does not result in an 567 // Test that a DNS error occuring in the main frame does not result in an
570 // additional session history entry. 568 // additional session history entry.
571 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 569 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
572 NavigateToFileURL(FILE_PATH_LITERAL("title3.html")); 570 NavigateToFileURL(FILE_PATH_LITERAL("title3.html"));
573 571
574 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 572 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
575 browser(), GetDnsErrorURL(), 2); 573 browser(), GetDnsErrorURL(), 2);
576 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 574 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
577 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 575 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
578 576
579 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 577 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
580 578
581 GoBackAndWaitForNavigations(2); 579 GoBackAndWaitForNavigations(2);
582 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 580 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
583 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 581 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
584 582
585 GoBackAndWaitForTitle("Title Of More Awesomeness", 1); 583 GoBackAndWaitForTitle("Title Of More Awesomeness", 1);
586 584
587 GoForwardAndWaitForNavigations(2); 585 GoForwardAndWaitForNavigations(2);
588 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 586 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
589 EXPECT_EQ(3, link_doctor_handler()->num_requests()); 587 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
590 588
591 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); 589 GoForwardAndWaitForTitle("Title Of Awesomeness", 1);
592 EXPECT_EQ(3, link_doctor_handler()->num_requests()); 590 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
593 } 591 }
594 592
595 // Test that the search button on a DNS error page works. 593 // Test that the search button on a DNS error page works.
596 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoSearch) { 594 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoSearch) {
597 // The first navigation should fail, and the second one should be the error 595 // The first navigation should fail, and the second one should be the error
598 // page. 596 // page.
599 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 597 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
600 browser(), GetDnsErrorURL(), 2); 598 browser(), GetDnsErrorURL(), 2);
601 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 599 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
602 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 600 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
603 601
604 content::WebContents* web_contents = 602 content::WebContents* web_contents =
605 browser()->tab_strip_model()->GetActiveWebContents(); 603 browser()->tab_strip_model()->GetActiveWebContents();
606 604
607 // Do a search and make sure the browser ends up at the right page. 605 // Do a search and make sure the browser ends up at the right page.
608 content::TestNavigationObserver nav_observer(web_contents, 1); 606 content::TestNavigationObserver nav_observer(web_contents, 1);
609 content::TitleWatcher title_watcher( 607 content::TitleWatcher title_watcher(
610 web_contents, 608 web_contents,
611 base::ASCIIToUTF16("Title Of More Awesomeness")); 609 base::ASCIIToUTF16("Title Of More Awesomeness"));
612 // Can't use content::ExecuteScript because it waits for scripts to send 610 // Can't use content::ExecuteScript because it waits for scripts to send
613 // notification that they've run, and scripts that trigger a navigation may 611 // notification that they've run, and scripts that trigger a navigation may
614 // not send that notification. 612 // not send that notification.
615 web_contents->GetMainFrame()->ExecuteJavaScript( 613 web_contents->GetMainFrame()->ExecuteJavaScript(
616 base::ASCIIToUTF16("document.getElementById('search-button').click();")); 614 base::ASCIIToUTF16("document.getElementById('search-button').click();"));
617 nav_observer.Wait(); 615 nav_observer.Wait();
618 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"), 616 EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
619 title_watcher.WaitAndGetTitle()); 617 title_watcher.WaitAndGetTitle());
620 618
621 // There should have been another Link Doctor request, for tracking purposes. 619 // There should have been another Link Doctor request, for tracking purposes.
622 // Have to wait for it, since the search page does not depend on having 620 // Have to wait for it, since the search page does not depend on having
623 // sent the tracking request. 621 // sent the tracking request.
624 link_doctor_handler()->WaitForRequests(2); 622 link_doctor_interceptor()->WaitForRequests(2);
625 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 623 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
626 624
627 // Check the path and query string. 625 // Check the path and query string.
628 std::string url; 626 std::string url;
629 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 627 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
630 browser()->tab_strip_model()->GetActiveWebContents(), 628 browser()->tab_strip_model()->GetActiveWebContents(),
631 "domAutomationController.send(window.location.href);", 629 "domAutomationController.send(window.location.href);",
632 &url)); 630 &url));
633 EXPECT_EQ("/search", GURL(url).path()); 631 EXPECT_EQ("/search", GURL(url).path());
634 EXPECT_EQ("q=search%20query", GURL(url).query()); 632 EXPECT_EQ("q=search%20query", GURL(url).query());
635 633
636 // Go back to the error page, to make sure the history is correct. 634 // Go back to the error page, to make sure the history is correct.
637 GoBackAndWaitForNavigations(2); 635 GoBackAndWaitForNavigations(2);
638 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 636 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
639 EXPECT_EQ(3, link_doctor_handler()->num_requests()); 637 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
640 } 638 }
641 639
642 // Test that the reload button on a DNS error page works. 640 // Test that the reload button on a DNS error page works.
643 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoReload) { 641 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoReload) {
644 // The first navigation should fail, and the second one should be the error 642 // The first navigation should fail, and the second one should be the error
645 // page. 643 // page.
646 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 644 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
647 browser(), GetDnsErrorURL(), 2); 645 browser(), GetDnsErrorURL(), 2);
648 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 646 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
649 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 647 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
650 648
651 content::WebContents* web_contents = 649 content::WebContents* web_contents =
652 browser()->tab_strip_model()->GetActiveWebContents(); 650 browser()->tab_strip_model()->GetActiveWebContents();
653 651
654 // Clicking the reload button should load the error page again, and there 652 // Clicking the reload button should load the error page again, and there
655 // should be two commits, as before. 653 // should be two commits, as before.
656 content::TestNavigationObserver nav_observer(web_contents, 2); 654 content::TestNavigationObserver nav_observer(web_contents, 2);
657 // Can't use content::ExecuteScript because it waits for scripts to send 655 // Can't use content::ExecuteScript because it waits for scripts to send
658 // notification that they've run, and scripts that trigger a navigation may 656 // notification that they've run, and scripts that trigger a navigation may
659 // not send that notification. 657 // not send that notification.
660 web_contents->GetMainFrame()->ExecuteJavaScript( 658 web_contents->GetMainFrame()->ExecuteJavaScript(
661 base::ASCIIToUTF16("document.getElementById('reload-button').click();")); 659 base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
662 nav_observer.Wait(); 660 nav_observer.Wait();
663 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 661 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
664 662
665 // There should have two more requests to the correction service: One for the 663 // There should have two more requests to the correction service: One for the
666 // new error page, and one for tracking purposes. Have to make sure to wait 664 // new error page, and one for tracking purposes. Have to make sure to wait
667 // for the tracking request, since the new error page does not depend on it. 665 // for the tracking request, since the new error page does not depend on it.
668 link_doctor_handler()->WaitForRequests(3); 666 link_doctor_interceptor()->WaitForRequests(3);
669 EXPECT_EQ(3, link_doctor_handler()->num_requests()); 667 EXPECT_EQ(3, link_doctor_interceptor()->num_requests());
670 } 668 }
671 669
672 // Test that clicking links on a DNS error page works. 670 // Test that clicking links on a DNS error page works.
673 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoClickLink) { 671 IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoClickLink) {
674 // The first navigation should fail, and the second one should be the error 672 // The first navigation should fail, and the second one should be the error
675 // page. 673 // page.
676 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 674 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
677 browser(), GetDnsErrorURL(), 2); 675 browser(), GetDnsErrorURL(), 2);
678 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED); 676 ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
679 EXPECT_EQ(1, link_doctor_handler()->num_requests()); 677 EXPECT_EQ(1, link_doctor_interceptor()->num_requests());
680 678
681 content::WebContents* web_contents = 679 content::WebContents* web_contents =
682 browser()->tab_strip_model()->GetActiveWebContents(); 680 browser()->tab_strip_model()->GetActiveWebContents();
683 681
684 // Simulate a click on a link. 682 // Simulate a click on a link.
685 683
686 content::TitleWatcher title_watcher( 684 content::TitleWatcher title_watcher(
687 web_contents, 685 web_contents,
688 base::ASCIIToUTF16("Title Of Awesomeness")); 686 base::ASCIIToUTF16("Title Of Awesomeness"));
689 std::string link_selector = 687 std::string link_selector =
690 "document.querySelector('a[href=\"http://mock.http/title2.html\"]')"; 688 "document.querySelector('a[href=\"http://mock.http/title2.html\"]')";
691 // The tracking request is triggered by onmousedown, so it catches middle 689 // The tracking request is triggered by onmousedown, so it catches middle
692 // mouse button clicks, as well as left clicks. 690 // mouse button clicks, as well as left clicks.
693 web_contents->GetMainFrame()->ExecuteJavaScript( 691 web_contents->GetMainFrame()->ExecuteJavaScript(
694 base::ASCIIToUTF16(link_selector + ".onmousedown();")); 692 base::ASCIIToUTF16(link_selector + ".onmousedown();"));
695 // Can't use content::ExecuteScript because it waits for scripts to send 693 // Can't use content::ExecuteScript because it waits for scripts to send
696 // notification that they've run, and scripts that trigger a navigation may 694 // notification that they've run, and scripts that trigger a navigation may
697 // not send that notification. 695 // not send that notification.
698 web_contents->GetMainFrame()->ExecuteJavaScript( 696 web_contents->GetMainFrame()->ExecuteJavaScript(
699 base::ASCIIToUTF16(link_selector + ".click();")); 697 base::ASCIIToUTF16(link_selector + ".click();"));
700 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"), 698 EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"),
701 title_watcher.WaitAndGetTitle()); 699 title_watcher.WaitAndGetTitle());
702 700
703 // There should have been a tracking request to the correction service. Have 701 // There should have been a tracking request to the correction service. Have
704 // to make sure to wait the tracking request, since the new page does not 702 // to make sure to wait the tracking request, since the new page does not
705 // depend on it. 703 // depend on it.
706 link_doctor_handler()->WaitForRequests(2); 704 link_doctor_interceptor()->WaitForRequests(2);
707 EXPECT_EQ(2, link_doctor_handler()->num_requests()); 705 EXPECT_EQ(2, link_doctor_interceptor()->num_requests());
708 } 706 }
709 707
710 // Test that a DNS error occuring in an iframe does not result in showing 708 // Test that a DNS error occuring in an iframe does not result in showing
711 // navigation corrections. 709 // navigation corrections.
712 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 710 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
713 NavigateToURLAndWaitForTitle( 711 NavigateToURLAndWaitForTitle(
714 content::URLRequestMockHTTPJob::GetMockUrl( 712 content::URLRequestMockHTTPJob::GetMockUrl(
715 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), 713 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))),
716 "Blah", 714 "Blah",
717 1); 715 1);
718 // We expect to have two history entries, since we started off with navigation 716 // We expect to have two history entries, since we started off with navigation
719 // to "about:blank" and then navigated to "iframe_dns_error.html". 717 // to "about:blank" and then navigated to "iframe_dns_error.html".
720 EXPECT_EQ(2, 718 EXPECT_EQ(2,
721 browser()->tab_strip_model()->GetActiveWebContents()-> 719 browser()->tab_strip_model()->GetActiveWebContents()->
722 GetController().GetEntryCount()); 720 GetController().GetEntryCount());
723 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 721 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
724 } 722 }
725 723
726 // This test fails regularly on win_rel trybots. See crbug.com/121540 724 // This test fails regularly on win_rel trybots. See crbug.com/121540
727 #if defined(OS_WIN) 725 #if defined(OS_WIN)
728 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack 726 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack
729 #else 727 #else
730 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack 728 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack
731 #endif 729 #endif
732 // Test that a DNS error occuring in an iframe does not result in an 730 // Test that a DNS error occuring in an iframe does not result in an
733 // additional session history entry. 731 // additional session history entry.
734 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBack) { 732 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBack) {
735 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 733 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
736 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); 734 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html"));
737 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 735 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
738 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 736 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
739 } 737 }
740 738
741 // This test fails regularly on win_rel trybots. See crbug.com/121540 739 // This test fails regularly on win_rel trybots. See crbug.com/121540
742 // 740 //
743 // This fails on linux_aura bringup: http://crbug.com/163931 741 // This fails on linux_aura bringup: http://crbug.com/163931
744 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA)) 742 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US E_AURA))
745 #define MAYBE_IFrameDNSError_GoBackAndForward DISABLED_IFrameDNSError_GoBackAndF orward 743 #define MAYBE_IFrameDNSError_GoBackAndForward DISABLED_IFrameDNSError_GoBackAndF orward
746 #else 744 #else
747 #define MAYBE_IFrameDNSError_GoBackAndForward IFrameDNSError_GoBackAndForward 745 #define MAYBE_IFrameDNSError_GoBackAndForward IFrameDNSError_GoBackAndForward
748 #endif 746 #endif
749 // Test that a DNS error occuring in an iframe does not result in an 747 // Test that a DNS error occuring in an iframe does not result in an
750 // additional session history entry. 748 // additional session history entry.
751 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { 749 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) {
752 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); 750 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
753 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); 751 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html"));
754 GoBackAndWaitForTitle("Title Of Awesomeness", 1); 752 GoBackAndWaitForTitle("Title Of Awesomeness", 1);
755 GoForwardAndWaitForTitle("Blah", 1); 753 GoForwardAndWaitForTitle("Blah", 1);
756 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 754 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
757 } 755 }
758 756
759 // Test that a DNS error occuring in an iframe, once the main document is 757 // Test that a DNS error occuring in an iframe, once the main document is
760 // completed loading, does not result in an additional session history entry. 758 // completed loading, does not result in an additional session history entry.
761 // To ensure that the main document has completed loading, JavaScript is used to 759 // To ensure that the main document has completed loading, JavaScript is used to
762 // inject an iframe after loading is done. 760 // inject an iframe after loading is done.
763 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) { 761 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
764 content::WebContents* wc = 762 content::WebContents* wc =
765 browser()->tab_strip_model()->GetActiveWebContents(); 763 browser()->tab_strip_model()->GetActiveWebContents();
766 GURL fail_url = 764 GURL fail_url =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 TestFailProvisionalLoadObserver fail_observer(wc); 809 TestFailProvisionalLoadObserver fail_observer(wc);
812 content::WindowedNotificationObserver load_observer( 810 content::WindowedNotificationObserver load_observer(
813 content::NOTIFICATION_LOAD_STOP, 811 content::NOTIFICATION_LOAD_STOP,
814 content::Source<NavigationController>(&wc->GetController())); 812 content::Source<NavigationController>(&wc->GetController()));
815 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script)); 813 wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
816 load_observer.Wait(); 814 load_observer.Wait();
817 815
818 EXPECT_EQ(fail_url, fail_observer.fail_url()); 816 EXPECT_EQ(fail_url, fail_observer.fail_url());
819 EXPECT_EQ(2, wc->GetController().GetEntryCount()); 817 EXPECT_EQ(2, wc->GetController().GetEntryCount());
820 } 818 }
821 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 819 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
822 } 820 }
823 821
824 // Checks that navigation corrections are not loaded when we receive an actual 822 // Checks that navigation corrections are not loaded when we receive an actual
825 // 404 page. 823 // 404 page.
826 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 824 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
827 NavigateToURLAndWaitForTitle( 825 NavigateToURLAndWaitForTitle(
828 content::URLRequestMockHTTPJob::GetMockUrl( 826 content::URLRequestMockHTTPJob::GetMockUrl(
829 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 827 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
830 "SUCCESS", 828 "SUCCESS",
831 1); 829 1);
832 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 830 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
833 } 831 }
834 832
835 // Checks that when an error occurs, the stale cache status of the page 833 // Checks that when an error occurs, the stale cache status of the page
836 // is correctly transferred, and that stale cached copied can be loaded 834 // is correctly transferred, and that stale cached copied can be loaded
837 // from the javascript. 835 // from the javascript.
838 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) { 836 IN_PROC_BROWSER_TEST_F(ErrorPageTest, StaleCacheStatus) {
839 ASSERT_TRUE(test_server()->Start()); 837 ASSERT_TRUE(test_server()->Start());
840 // Load cache with entry with "nocache" set, to create stale 838 // Load cache with entry with "nocache" set, to create stale
841 // cache. 839 // cache.
842 GURL test_url(test_server()->GetURL("files/nocache.html")); 840 GURL test_url(test_server()->GetURL("files/nocache.html"));
(...skipping 27 matching lines...) Expand all
870 // Clear the cache and reload the same URL; confirm the error page is told 868 // Clear the cache and reload the same URL; confirm the error page is told
871 // that there is no cached copy. 869 // that there is no cached copy.
872 BrowsingDataRemover* remover = 870 BrowsingDataRemover* remover =
873 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 871 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
874 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 872 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
875 BrowsingDataHelper::UNPROTECTED_WEB); 873 BrowsingDataHelper::UNPROTECTED_WEB);
876 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 874 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
877 browser(), test_url, 1); 875 browser(), test_url, 1);
878 EXPECT_TRUE(ProbeStaleCopyValue(false)); 876 EXPECT_TRUE(ProbeStaleCopyValue(false));
879 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 877 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel()));
880 EXPECT_EQ(0, link_doctor_handler()->num_requests()); 878 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
881 } 879 }
882 880
883 class ErrorPageAutoReloadTest : public InProcessBrowserTest { 881 class ErrorPageAutoReloadTest : public InProcessBrowserTest {
884 public: 882 public:
885 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 883 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
886 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); 884 command_line->AppendSwitch(switches::kEnableOfflineAutoReload);
887 } 885 }
888 886
889 void InstallProtocolHandler(const GURL& url, int requests_to_fail) { 887 void InstallInterceptor(const GURL& url, int requests_to_fail) {
890 protocol_handler_ = new FailFirstNRequestsProtocolHandler(requests_to_fail); 888 interceptor_ = new FailFirstNRequestsInterceptor(requests_to_fail);
891 scoped_ptr<URLRequestJobFactory::ProtocolHandler> owned_handler( 889 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_);
892 protocol_handler_);
893 890
894 // Tests don't need to wait for this task to complete before using the 891 // Tests don't need to wait for this task to complete before using the
895 // filter; any requests that might be affected by it will end up in the IO 892 // filter; any requests that might be affected by it will end up in the IO
896 // thread's message loop after this posted task anyway. 893 // thread's message loop after this posted task anyway.
897 // 894 //
898 // Ownership of the |protocol_handler_| is passed to an object the IO 895 // Ownership of the interceptor is passed to an object the IO thread, but a
899 // thread, but a pointer is kept in the test fixture. As soon as anything 896 // pointer is kept in the test fixture. As soon as anything calls
900 // calls URLRequestFilter::ClearHandlers(), |protocol_handler_| can become 897 // URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid.
901 // invalid.
902 BrowserThread::PostTask( 898 BrowserThread::PostTask(
903 BrowserThread::IO, FROM_HERE, 899 BrowserThread::IO, FROM_HERE,
904 base::Bind(&AddProtocolHandlerForURL, url, 900 base::Bind(&AddInterceptorForURL, url,
905 base::Passed(&owned_handler))); 901 base::Passed(&owned_interceptor)));
906 } 902 }
907 903
908 void NavigateToURLAndWaitForTitle(const GURL& url, 904 void NavigateToURLAndWaitForTitle(const GURL& url,
909 const std::string& expected_title, 905 const std::string& expected_title,
910 int num_navigations) { 906 int num_navigations) {
911 content::TitleWatcher title_watcher( 907 content::TitleWatcher title_watcher(
912 browser()->tab_strip_model()->GetActiveWebContents(), 908 browser()->tab_strip_model()->GetActiveWebContents(),
913 base::ASCIIToUTF16(expected_title)); 909 base::ASCIIToUTF16(expected_title));
914 910
915 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 911 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
916 browser(), url, num_navigations); 912 browser(), url, num_navigations);
917 913
918 EXPECT_EQ(base::ASCIIToUTF16(expected_title), 914 EXPECT_EQ(base::ASCIIToUTF16(expected_title),
919 title_watcher.WaitAndGetTitle()); 915 title_watcher.WaitAndGetTitle());
920 } 916 }
921 917
922 FailFirstNRequestsProtocolHandler* protocol_handler() { 918 FailFirstNRequestsInterceptor* interceptor() {
923 return protocol_handler_; 919 return interceptor_;
924 } 920 }
925 921
926 private: 922 private:
927 FailFirstNRequestsProtocolHandler* protocol_handler_; 923 FailFirstNRequestsInterceptor* interceptor_;
928 }; 924 };
929 925
930 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, AutoReload) { 926 IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, AutoReload) {
931 GURL test_url("http://error.page.auto.reload"); 927 GURL test_url("http://error.page.auto.reload");
932 const int kRequestsToFail = 2; 928 const int kRequestsToFail = 2;
933 InstallProtocolHandler(test_url, kRequestsToFail); 929 InstallInterceptor(test_url, kRequestsToFail);
934 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1); 930 NavigateToURLAndWaitForTitle(test_url, "Test One", kRequestsToFail + 1);
935 // Note that the protocol handler updates these variables on the IO thread, 931 // Note that the interceptor updates these variables on the IO thread,
936 // but this function reads them on the main thread. The requests have to be 932 // but this function reads them on the main thread. The requests have to be
937 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or 933 // created (on the IO thread) before NavigateToURLAndWaitForTitle returns or
938 // this becomes racey. 934 // this becomes racey.
939 EXPECT_EQ(kRequestsToFail, protocol_handler()->failures()); 935 EXPECT_EQ(kRequestsToFail, interceptor()->failures());
940 EXPECT_EQ(kRequestsToFail + 1, protocol_handler()->requests()); 936 EXPECT_EQ(kRequestsToFail + 1, interceptor()->requests());
941 } 937 }
942 938
943 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 939 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
944 class AddressUnreachableProtocolHandler 940 class AddressUnreachableInterceptor : public net::URLRequestInterceptor {
945 : public net::URLRequestJobFactory::ProtocolHandler {
946 public: 941 public:
947 AddressUnreachableProtocolHandler() {} 942 AddressUnreachableInterceptor() {}
948 virtual ~AddressUnreachableProtocolHandler() {} 943 virtual ~AddressUnreachableInterceptor() {}
949 944
950 // net::URLRequestJobFactory::ProtocolHandler: 945 // net::URLRequestInterceptor:
951 virtual net::URLRequestJob* MaybeCreateJob( 946 virtual net::URLRequestJob* MaybeInterceptRequest(
952 net::URLRequest* request, 947 net::URLRequest* request,
953 net::NetworkDelegate* network_delegate) const OVERRIDE { 948 net::NetworkDelegate* network_delegate) const OVERRIDE {
954 return new URLRequestFailedJob(request, 949 return new URLRequestFailedJob(request,
955 network_delegate, 950 network_delegate,
956 net::ERR_ADDRESS_UNREACHABLE); 951 net::ERR_ADDRESS_UNREACHABLE);
957 } 952 }
958 953
959 private: 954 private:
960 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableProtocolHandler); 955 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableInterceptor);
961 }; 956 };
962 957
963 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation 958 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation
964 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use 959 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use
965 // a different error for the correction service and the original page to 960 // a different error for the correction service and the original page to
966 // validate the right page is being displayed. 961 // validate the right page is being displayed.
967 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { 962 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest {
968 public: 963 public:
969 // InProcessBrowserTest: 964 // InProcessBrowserTest:
970 virtual void SetUpOnMainThread() OVERRIDE { 965 virtual void SetUpOnMainThread() OVERRIDE {
(...skipping 10 matching lines...) Expand all
981 976
982 private: 977 private:
983 // Adds a filter that causes all correction service requests to fail with 978 // Adds a filter that causes all correction service requests to fail with
984 // ERR_ADDRESS_UNREACHABLE. 979 // ERR_ADDRESS_UNREACHABLE.
985 // 980 //
986 // Also adds the content::URLRequestFailedJob filter. 981 // Also adds the content::URLRequestFailedJob filter.
987 static void AddFilters() { 982 static void AddFilters() {
988 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
989 content::URLRequestFailedJob::AddUrlHandler(); 984 content::URLRequestFailedJob::AddUrlHandler();
990 985
991 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 986 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
992 google_util::LinkDoctorBaseURL(), 987 google_util::LinkDoctorBaseURL(),
993 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( 988 scoped_ptr<net::URLRequestInterceptor>(
994 new AddressUnreachableProtocolHandler())); 989 new AddressUnreachableInterceptor()));
995 } 990 }
996 991
997 static void RemoveFilters() { 992 static void RemoveFilters() {
998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
999 net::URLRequestFilter::GetInstance()->ClearHandlers(); 994 net::URLRequestFilter::GetInstance()->ClearHandlers();
1000 } 995 }
1001 }; 996 };
1002 997
1003 // Make sure that when corrections fail to load, the network error page is 998 // Make sure that when corrections fail to load, the network error page is
1004 // successfully loaded. 999 // successfully loaded.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 browser(), 1102 browser(),
1108 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1103 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1109 kHostname), 1104 kHostname),
1110 1); 1105 1);
1111 1106
1112 ToggleHelpBox(browser()); 1107 ToggleHelpBox(browser());
1113 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1108 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1114 } 1109 }
1115 1110
1116 } // namespace 1111 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698