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

Side by Side Diff: trunk/src/chrome/browser/net/dns_probe_browsertest.cc

Issue 185003002: Revert 254207 "Switch to using the new Link Doctor API." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return delayed_probes_.size(); 103 return delayed_probes_.size();
104 } 104 }
105 105
106 private: 106 private:
107 std::vector<ProbeCallback> delayed_probes_; 107 std::vector<ProbeCallback> delayed_probes_;
108 }; 108 };
109 109
110 FilePath GetMockLinkDoctorFilePath() { 110 FilePath GetMockLinkDoctorFilePath() {
111 FilePath root_http; 111 FilePath root_http;
112 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 112 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
113 return root_http.AppendASCII("mock-link-doctor.json"); 113 return root_http.AppendASCII("mock-link-doctor.html");
114 } 114 }
115 115
116 // A request that can be delayed until Resume() is called. Can also run a 116 // A request that can be delayed until Resume() is called. Can also run a
117 // callback if destroyed without being resumed. Resume can be called either 117 // callback if destroyed without being resumed. Resume can be called either
118 // before or after a the request is started. 118 // before or after a the request is started.
119 class DelayableRequest { 119 class DelayableRequest {
120 public: 120 public:
121 // Called by a DelayableRequest if it was set to be delayed, and has been 121 // Called by a DelayableRequest if it was set to be delayed, and has been
122 // destroyed without Undelay being called. 122 // destroyed without Undelay being called.
123 typedef base::Callback<void(DelayableRequest* request)> DestructionCallback; 123 typedef base::Callback<void(DelayableRequest* request)> DestructionCallback;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 virtual ~DelayableURLRequestMockHTTPJob() { 208 virtual ~DelayableURLRequestMockHTTPJob() {
209 if (should_delay_) 209 if (should_delay_)
210 destruction_callback_.Run(this); 210 destruction_callback_.Run(this);
211 } 211 }
212 212
213 bool should_delay_; 213 bool should_delay_;
214 bool start_delayed_; 214 bool start_delayed_;
215 const DestructionCallback destruction_callback_; 215 const DestructionCallback destruction_callback_;
216 }; 216 };
217 217
218 // ProtocolHandler for navigation correction requests. Can cause requests to 218 // ProtocolHandler for Link Doctor requests. Can cause requests to fail with
219 // fail with an error, and/or delay a request until a test allows to continue. 219 // an error, and/or delay a request until a test allows to continue. Also can
220 // Also can run a callback when a delayed request is cancelled. 220 // run a callback when a delayed request is cancelled.
221 class BreakableCorrectionProtocolHandler 221 class BreakableLinkDoctorProtocolHandler
222 : public URLRequestJobFactory::ProtocolHandler { 222 : public URLRequestJobFactory::ProtocolHandler {
223 public: 223 public:
224 explicit BreakableCorrectionProtocolHandler( 224 explicit BreakableLinkDoctorProtocolHandler(
225 const FilePath& mock_corrections_file_path) 225 const FilePath& mock_link_doctor_file_path)
226 : mock_corrections_file_path_(mock_corrections_file_path), 226 : mock_link_doctor_file_path_(mock_link_doctor_file_path),
227 net_error_(net::OK), 227 net_error_(net::OK),
228 delay_requests_(false), 228 delay_requests_(false),
229 on_request_destroyed_callback_( 229 on_request_destroyed_callback_(
230 base::Bind(&BreakableCorrectionProtocolHandler::OnRequestDestroyed, 230 base::Bind(&BreakableLinkDoctorProtocolHandler::OnRequestDestroyed,
231 base::Unretained(this))) { 231 base::Unretained(this))) {
232 } 232 }
233 233
234 virtual ~BreakableCorrectionProtocolHandler() { 234 virtual ~BreakableLinkDoctorProtocolHandler() {
235 // All delayed requests should have been resumed or cancelled by this point. 235 // All delayed requests should have been resumed or cancelled by this point.
236 EXPECT_TRUE(delayed_requests_.empty()); 236 EXPECT_TRUE(delayed_requests_.empty());
237 } 237 }
238 238
239 virtual URLRequestJob* MaybeCreateJob( 239 virtual URLRequestJob* MaybeCreateJob(
240 URLRequest* request, 240 URLRequest* request,
241 NetworkDelegate* network_delegate) const OVERRIDE { 241 NetworkDelegate* network_delegate) const OVERRIDE {
242 if (net_error_ != net::OK) { 242 if (net_error_ != net::OK) {
243 DelayableURLRequestFailedJob* job = 243 DelayableURLRequestFailedJob* job =
244 new DelayableURLRequestFailedJob( 244 new DelayableURLRequestFailedJob(
245 request, network_delegate, net_error_, delay_requests_, 245 request, network_delegate, net_error_, delay_requests_,
246 on_request_destroyed_callback_); 246 on_request_destroyed_callback_);
247 if (delay_requests_) 247 if (delay_requests_)
248 delayed_requests_.insert(job); 248 delayed_requests_.insert(job);
249 return job; 249 return job;
250 } else { 250 } else {
251 DelayableURLRequestMockHTTPJob* job = 251 DelayableURLRequestMockHTTPJob* job =
252 new DelayableURLRequestMockHTTPJob( 252 new DelayableURLRequestMockHTTPJob(
253 request, network_delegate, mock_corrections_file_path_, 253 request, network_delegate, mock_link_doctor_file_path_,
254 delay_requests_, on_request_destroyed_callback_); 254 delay_requests_, on_request_destroyed_callback_);
255 if (delay_requests_) 255 if (delay_requests_)
256 delayed_requests_.insert(job); 256 delayed_requests_.insert(job);
257 return job; 257 return job;
258 } 258 }
259 } 259 }
260 260
261 void set_net_error(int net_error) { net_error_ = net_error; } 261 void set_net_error(int net_error) { net_error_ = net_error; }
262 262
263 void SetDelayRequests(bool delay_requests) { 263 void SetDelayRequests(bool delay_requests) {
(...skipping 24 matching lines...) Expand all
288 ASSERT_EQ(1u, delayed_requests_.count(request)); 288 ASSERT_EQ(1u, delayed_requests_.count(request));
289 delayed_requests_.erase(request); 289 delayed_requests_.erase(request);
290 if (delayed_requests_.empty() && 290 if (delayed_requests_.empty() &&
291 !delayed_request_destruction_callback_.is_null()) { 291 !delayed_request_destruction_callback_.is_null()) {
292 delayed_request_destruction_callback_.Run(); 292 delayed_request_destruction_callback_.Run();
293 delayed_request_destruction_callback_.Reset(); 293 delayed_request_destruction_callback_.Reset();
294 } 294 }
295 } 295 }
296 296
297 private: 297 private:
298 const FilePath mock_corrections_file_path_; 298 const FilePath mock_link_doctor_file_path_;
299 int net_error_; 299 int net_error_;
300 bool delay_requests_; 300 bool delay_requests_;
301 301
302 // Called when a request is destroyed. Memeber variable because 302 // Called when a request is destroyed. Memeber variable because
303 // MaybeCreateJob is "const", so calling base::Bind in that function does 303 // MaybeCreateJob is "const", so calling base::Bind in that function does
304 // not work well. 304 // not work well.
305 const DelayableRequest::DestructionCallback on_request_destroyed_callback_; 305 const DelayableRequest::DestructionCallback on_request_destroyed_callback_;
306 306
307 // Mutable is needed because MaybeCreateJob is const. 307 // Mutable is needed because MaybeCreateJob is const.
308 mutable std::set<DelayableRequest*> delayed_requests_; 308 mutable std::set<DelayableRequest*> delayed_requests_;
309 309
310 base::Closure delayed_request_destruction_callback_; 310 base::Closure delayed_request_destruction_callback_;
311 }; 311 };
312 312
313 class DnsProbeBrowserTestIOThreadHelper { 313 class DnsProbeBrowserTestIOThreadHelper {
314 public: 314 public:
315 DnsProbeBrowserTestIOThreadHelper(); 315 DnsProbeBrowserTestIOThreadHelper();
316 316
317 void SetUpOnIOThread(IOThread* io_thread); 317 void SetUpOnIOThread(IOThread* io_thread);
318 void CleanUpOnIOThreadAndDeleteHelper(); 318 void CleanUpOnIOThreadAndDeleteHelper();
319 319
320 void SetMockDnsClientRules(MockDnsClientRule::Result system_good_result, 320 void SetMockDnsClientRules(MockDnsClientRule::Result system_good_result,
321 MockDnsClientRule::Result public_good_result); 321 MockDnsClientRule::Result public_good_result);
322 void SetCorrectionServiceNetError(int net_error); 322 void SetLinkDoctorNetError(int link_doctor_net_error);
323 void SetCorrectionServiceDelayRequests(bool delay_requests); 323 void SetLinkDoctorDelayRequests(bool delay_requests);
324 void SetRequestDestructionCallback(const base::Closure& callback); 324 void SetRequestDestructionCallback(const base::Closure& callback);
325 void StartDelayedProbes(int expected_delayed_probe_count); 325 void StartDelayedProbes(int expected_delayed_probe_count);
326 326
327 private: 327 private:
328 IOThread* io_thread_; 328 IOThread* io_thread_;
329 DnsProbeService* original_dns_probe_service_; 329 DnsProbeService* original_dns_probe_service_;
330 DelayingDnsProbeService* delaying_dns_probe_service_; 330 DelayingDnsProbeService* delaying_dns_probe_service_;
331 BreakableCorrectionProtocolHandler* protocol_handler_; 331 BreakableLinkDoctorProtocolHandler* protocol_handler_;
332 FilePath mock_corrections_file_path_; 332 FilePath mock_link_doctor_file_path_;
333 }; 333 };
334 334
335 DnsProbeBrowserTestIOThreadHelper::DnsProbeBrowserTestIOThreadHelper() 335 DnsProbeBrowserTestIOThreadHelper::DnsProbeBrowserTestIOThreadHelper()
336 : io_thread_(NULL), 336 : io_thread_(NULL),
337 original_dns_probe_service_(NULL), 337 original_dns_probe_service_(NULL),
338 delaying_dns_probe_service_(NULL), 338 delaying_dns_probe_service_(NULL),
339 protocol_handler_(NULL), 339 protocol_handler_(NULL),
340 mock_corrections_file_path_(GetMockLinkDoctorFilePath()) {} 340 mock_link_doctor_file_path_(GetMockLinkDoctorFilePath()) {}
341 341
342 void DnsProbeBrowserTestIOThreadHelper::SetUpOnIOThread(IOThread* io_thread) { 342 void DnsProbeBrowserTestIOThreadHelper::SetUpOnIOThread(IOThread* io_thread) {
343 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 343 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
344 CHECK(io_thread); 344 CHECK(io_thread);
345 CHECK(!io_thread_); 345 CHECK(!io_thread_);
346 CHECK(!original_dns_probe_service_); 346 CHECK(!original_dns_probe_service_);
347 CHECK(!delaying_dns_probe_service_); 347 CHECK(!delaying_dns_probe_service_);
348 CHECK(!protocol_handler_); 348 CHECK(!protocol_handler_);
349 349
350 io_thread_ = io_thread; 350 io_thread_ = io_thread;
351 351
352 delaying_dns_probe_service_ = new DelayingDnsProbeService(); 352 delaying_dns_probe_service_ = new DelayingDnsProbeService();
353 353
354 IOThread::Globals* globals = io_thread_->globals(); 354 IOThread::Globals* globals = io_thread_->globals();
355 original_dns_probe_service_ = globals->dns_probe_service.release(); 355 original_dns_probe_service_ = globals->dns_probe_service.release();
356 globals->dns_probe_service.reset(delaying_dns_probe_service_); 356 globals->dns_probe_service.reset(delaying_dns_probe_service_);
357 357
358 URLRequestFailedJob::AddUrlHandler(); 358 URLRequestFailedJob::AddUrlHandler();
359 359
360 scoped_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler( 360 scoped_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler(
361 new BreakableCorrectionProtocolHandler(mock_corrections_file_path_)); 361 new BreakableLinkDoctorProtocolHandler(mock_link_doctor_file_path_));
362 protocol_handler_ = 362 protocol_handler_ =
363 static_cast<BreakableCorrectionProtocolHandler*>(protocol_handler.get()); 363 static_cast<BreakableLinkDoctorProtocolHandler*>(protocol_handler.get());
364 URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 364 const GURL link_doctor_base_url = LinkDoctorBaseURL();
365 LinkDoctorBaseURL(), protocol_handler.Pass()); 365 const std::string link_doctor_host = link_doctor_base_url.host();
366 URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
367 "http", link_doctor_host, protocol_handler.Pass());
366 } 368 }
367 369
368 void DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper() { 370 void DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper() {
369 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 371 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
370 372
371 URLRequestFilter::GetInstance()->ClearHandlers(); 373 URLRequestFilter::GetInstance()->ClearHandlers();
372 374
373 IOThread::Globals* globals = io_thread_->globals(); 375 IOThread::Globals* globals = io_thread_->globals();
374 scoped_ptr<DnsProbeService> delaying_dns_probe_service( 376 scoped_ptr<DnsProbeService> delaying_dns_probe_service(
375 globals->dns_probe_service.release()); 377 globals->dns_probe_service.release());
376 globals->dns_probe_service.reset(original_dns_probe_service_); 378 globals->dns_probe_service.reset(original_dns_probe_service_);
377 379
378 CHECK_EQ(delaying_dns_probe_service_, delaying_dns_probe_service.get()); 380 CHECK_EQ(delaying_dns_probe_service_, delaying_dns_probe_service.get());
379 381
380 delete this; 382 delete this;
381 } 383 }
382 384
383 void DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules( 385 void DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules(
384 MockDnsClientRule::Result system_result, 386 MockDnsClientRule::Result system_result,
385 MockDnsClientRule::Result public_result) { 387 MockDnsClientRule::Result public_result) {
386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 388 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
387 389
388 DnsProbeService* service = io_thread_->globals()->dns_probe_service.get(); 390 DnsProbeService* service = io_thread_->globals()->dns_probe_service.get();
389 service->SetSystemClientForTesting( 391 service->SetSystemClientForTesting(
390 CreateMockDnsClientForProbes(system_result)); 392 CreateMockDnsClientForProbes(system_result));
391 service->SetPublicClientForTesting( 393 service->SetPublicClientForTesting(
392 CreateMockDnsClientForProbes(public_result)); 394 CreateMockDnsClientForProbes(public_result));
393 } 395 }
394 396
395 void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError( 397 void DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorNetError(
396 int net_error) { 398 int link_doctor_net_error) {
397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 399 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
398 400
399 protocol_handler_->set_net_error(net_error); 401 protocol_handler_->set_net_error(link_doctor_net_error);
400 } 402 }
401 403
402 void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceDelayRequests( 404 void DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorDelayRequests(
403 bool delay_requests) { 405 bool delay_requests) {
404 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 406 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
405 407
406 protocol_handler_->SetDelayRequests(delay_requests); 408 protocol_handler_->SetDelayRequests(delay_requests);
407 } 409 }
408 410
409 void DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback( 411 void DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback(
410 const base::Closure& callback) { 412 const base::Closure& callback) {
411 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 413 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
412 414
(...skipping 19 matching lines...) Expand all
432 virtual ~DnsProbeBrowserTest(); 434 virtual ~DnsProbeBrowserTest();
433 435
434 virtual void SetUpOnMainThread() OVERRIDE; 436 virtual void SetUpOnMainThread() OVERRIDE;
435 virtual void CleanUpOnMainThread() OVERRIDE; 437 virtual void CleanUpOnMainThread() OVERRIDE;
436 438
437 protected: 439 protected:
438 // Sets the browser object that other methods apply to, and that has the 440 // Sets the browser object that other methods apply to, and that has the
439 // DnsProbeStatus messages of its currently active tab monitored. 441 // DnsProbeStatus messages of its currently active tab monitored.
440 void SetActiveBrowser(Browser* browser); 442 void SetActiveBrowser(Browser* browser);
441 443
442 void SetCorrectionServiceBroken(bool broken); 444 void SetLinkDoctorBroken(bool broken);
443 void SetCorrectionServiceDelayRequests(bool delay_requests); 445 void SetLinkDoctorDelayRequests(bool delay_requests);
444 void WaitForDelayedRequestDestruction(); 446 void WaitForDelayedRequestDestruction();
445 void SetMockDnsClientRules(MockDnsClientRule::Result system_result, 447 void SetMockDnsClientRules(MockDnsClientRule::Result system_result,
446 MockDnsClientRule::Result public_result); 448 MockDnsClientRule::Result public_result);
447 449
448 // These functions are often used to wait for two navigations because two 450 // These functions are often used to wait for two navigations because the Link
449 // pages are loaded when navigation corrections are enabled: a blank page, so 451 // Doctor loads two pages: a blank page, so the user stops seeing the previous
450 // the user stops seeing the previous page, and then the error page, either 452 // page, and then either the Link Doctor page or a regular error page. Often
451 // with navigation corrections or without them (If the request failed). 453 // need to wait for both to finish in a row.
452 void NavigateToDnsError(int num_navigations); 454 void NavigateToDnsError(int num_navigations);
453 void NavigateToOtherError(int num_navigations); 455 void NavigateToOtherError(int num_navigations);
454 456
455 void StartDelayedProbes(int expected_delayed_probe_count); 457 void StartDelayedProbes(int expected_delayed_probe_count);
456 DnsProbeStatus WaitForSentStatus(); 458 DnsProbeStatus WaitForSentStatus();
457 int pending_status_count() const { return dns_probe_status_queue_.size(); } 459 int pending_status_count() const { return dns_probe_status_queue_.size(); }
458 460
459 std::string Title(); 461 std::string Title();
460 bool PageContains(const std::string& expected); 462 bool PageContains(const std::string& expected);
461 463
462 // Checks that the local error page is being displayed, without navigation
463 // corrections, and with the specified status text. The status text should be
464 // either a network error or DNS probe status.
465 void ExpectDisplayingLocalErrorPage(const std::string& status_text);
466
467 // Checks that an error page with mock navigation corrections is being
468 // displayed, with the specified status text. The status text should be either
469 // a network error or DNS probe status.
470 void ExpectDisplayingCorrections(const std::string& status_text);
471
472 private: 464 private:
473 void OnDnsProbeStatusSent(DnsProbeStatus dns_probe_status); 465 void OnDnsProbeStatusSent(DnsProbeStatus dns_probe_status);
474 466
475 DnsProbeBrowserTestIOThreadHelper* helper_; 467 DnsProbeBrowserTestIOThreadHelper* helper_;
476 468
477 // Browser that methods apply to. 469 // Browser that methods apply to.
478 Browser* active_browser_; 470 Browser* active_browser_;
479 // Helper that current has its DnsProbeStatus messages monitored. 471 // Helper that current has its DnsProbeStatus messages monitored.
480 NetErrorTabHelper* monitored_tab_helper_; 472 NetErrorTabHelper* monitored_tab_helper_;
481 473
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( 521 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing(
530 NetErrorTabHelper::DnsProbeStatusSnoopCallback()); 522 NetErrorTabHelper::DnsProbeStatusSnoopCallback());
531 } 523 }
532 active_browser_ = browser; 524 active_browser_ = browser;
533 monitored_tab_helper_ = NetErrorTabHelper::FromWebContents( 525 monitored_tab_helper_ = NetErrorTabHelper::FromWebContents(
534 active_browser_->tab_strip_model()->GetActiveWebContents()); 526 active_browser_->tab_strip_model()->GetActiveWebContents());
535 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( 527 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing(
536 Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this))); 528 Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this)));
537 } 529 }
538 530
539 void DnsProbeBrowserTest::SetCorrectionServiceBroken(bool broken) { 531 void DnsProbeBrowserTest::SetLinkDoctorBroken(bool broken) {
540 int net_error = broken ? net::ERR_NAME_NOT_RESOLVED : net::OK; 532 int net_error = broken ? net::ERR_NAME_NOT_RESOLVED : net::OK;
541 533
542 BrowserThread::PostTask( 534 BrowserThread::PostTask(
543 BrowserThread::IO, FROM_HERE, 535 BrowserThread::IO, FROM_HERE,
544 Bind(&DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError, 536 Bind(&DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorNetError,
545 Unretained(helper_), 537 Unretained(helper_),
546 net_error)); 538 net_error));
547 } 539 }
548 540
549 void DnsProbeBrowserTest::SetCorrectionServiceDelayRequests( 541 void DnsProbeBrowserTest::SetLinkDoctorDelayRequests(bool delay_requests) {
550 bool delay_requests) {
551 BrowserThread::PostTask( 542 BrowserThread::PostTask(
552 BrowserThread::IO, FROM_HERE, 543 BrowserThread::IO, FROM_HERE,
553 Bind(&DnsProbeBrowserTestIOThreadHelper:: 544 Bind(&DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorDelayRequests,
554 SetCorrectionServiceDelayRequests,
555 Unretained(helper_), 545 Unretained(helper_),
556 delay_requests)); 546 delay_requests));
557 } 547 }
558 548
559 void DnsProbeBrowserTest::WaitForDelayedRequestDestruction() { 549 void DnsProbeBrowserTest::WaitForDelayedRequestDestruction() {
560 base::RunLoop run_loop; 550 base::RunLoop run_loop;
561 BrowserThread::PostTask( 551 BrowserThread::PostTask(
562 BrowserThread::IO, FROM_HERE, 552 BrowserThread::IO, FROM_HERE,
563 Bind(&DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback, 553 Bind(&DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback,
564 Unretained(helper_), 554 Unretained(helper_),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 bool rv = content::ExecuteScriptAndExtractString( 631 bool rv = content::ExecuteScriptAndExtractString(
642 active_browser_->tab_strip_model()->GetActiveWebContents(), 632 active_browser_->tab_strip_model()->GetActiveWebContents(),
643 "domAutomationController.send(document.body.textContent);", 633 "domAutomationController.send(document.body.textContent);",
644 &text_content); 634 &text_content);
645 if (!rv) 635 if (!rv)
646 return false; 636 return false;
647 637
648 return text_content.find(expected) != std::string::npos; 638 return text_content.find(expected) != std::string::npos;
649 } 639 }
650 640
651 void DnsProbeBrowserTest::ExpectDisplayingLocalErrorPage(
652 const std::string& status_text) {
653 EXPECT_FALSE(PageContains("http://correction1/"));
654 EXPECT_FALSE(PageContains("http://correction2/"));
655 EXPECT_TRUE(PageContains(status_text));
656 }
657
658 void DnsProbeBrowserTest::ExpectDisplayingCorrections(
659 const std::string& status_text) {
660 EXPECT_TRUE(PageContains("http://correction1/"));
661 EXPECT_TRUE(PageContains("http://correction2/"));
662 EXPECT_TRUE(PageContains(status_text));
663 }
664
665 void DnsProbeBrowserTest::OnDnsProbeStatusSent( 641 void DnsProbeBrowserTest::OnDnsProbeStatusSent(
666 DnsProbeStatus dns_probe_status) { 642 DnsProbeStatus dns_probe_status) {
667 dns_probe_status_queue_.push_back(dns_probe_status); 643 dns_probe_status_queue_.push_back(dns_probe_status);
668 if (awaiting_dns_probe_status_) 644 if (awaiting_dns_probe_status_)
669 MessageLoop::current()->Quit(); 645 MessageLoop::current()->Quit();
670 } 646 }
671 647
672 // Make sure probes don't break non-DNS error pages when corrections load. 648 // Make sure probes don't break non-DNS error pages when Link Doctor loads.
673 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsSuccess) { 649 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithWorkingLinkDoctor) {
674 SetCorrectionServiceBroken(false); 650 SetLinkDoctorBroken(false);
675 651
676 NavigateToOtherError(2); 652 NavigateToOtherError(2);
677 ExpectDisplayingCorrections("ERR_CONNECTION_REFUSED"); 653 EXPECT_EQ("Mock Link Doctor", Title());
678 } 654 }
679 655
680 // Make sure probes don't break non-DNS error pages when corrections failed to 656 // Make sure probes don't break non-DNS error pages when Link Doctor doesn't
681 // load. 657 // load.
682 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsFailure) { 658 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithBrokenLinkDoctor) {
683 SetCorrectionServiceBroken(true); 659 SetLinkDoctorBroken(true);
684 660
685 NavigateToOtherError(2); 661 NavigateToOtherError(2);
686 ExpectDisplayingLocalErrorPage("ERR_CONNECTION_REFUSED"); 662 EXPECT_TRUE(PageContains("CONNECTION_REFUSED"));
687 } 663 }
688 664
689 // Make sure probes don't break DNS error pages when corrections load. 665 // Make sure probes don't break DNS error pages when Link doctor loads.
690 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, 666 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest,
691 NxdomainProbeResultWithWorkingCorrections) { 667 NxdomainProbeResultWithWorkingLinkDoctor) {
692 SetCorrectionServiceBroken(false); 668 SetLinkDoctorBroken(false);
693 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); 669 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK);
694 670
695 NavigateToDnsError(2); 671 NavigateToDnsError(2);
696 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); 672 EXPECT_EQ("Mock Link Doctor", Title());
697 673
698 // One status for committing a blank page before the corrections, and one for 674 // One status for committing a blank page before the Link Doctor, and one for
699 // when the error page with corrections is committed. 675 // when the Link Doctor is committed.
700 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 676 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
701 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 677 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
702 EXPECT_EQ(0, pending_status_count()); 678 EXPECT_EQ(0, pending_status_count());
703 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); 679 EXPECT_EQ("Mock Link Doctor", Title());
704 680
705 StartDelayedProbes(1); 681 StartDelayedProbes(1);
706 682
707 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, 683 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
708 WaitForSentStatus()); 684 WaitForSentStatus());
709 EXPECT_EQ(0, pending_status_count()); 685 EXPECT_EQ(0, pending_status_count());
710 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); 686 EXPECT_EQ("Mock Link Doctor", Title());
711 } 687 }
712 688
713 // Make sure probes don't break corrections when probes complete before the 689 // Make sure probes don't break Link Doctor when probes complete before the
714 // corrections load. 690 // Link Doctor loads.
715 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, 691 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest,
716 NxdomainProbeResultWithWorkingSlowCorrections) { 692 NxdomainProbeResultWithWorkingSlowLinkDoctor) {
717 SetCorrectionServiceBroken(false); 693 SetLinkDoctorBroken(false);
718 SetCorrectionServiceDelayRequests(true); 694 SetLinkDoctorDelayRequests(true);
719 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); 695 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK);
720 696
721 NavigateToDnsError(1); 697 NavigateToDnsError(1);
722 // A blank page should be displayed while the corrections are loaded. 698 // A blank page should be displayed while the Link Doctor page loads.
723 EXPECT_EQ("", Title()); 699 EXPECT_EQ("", Title());
724 700
725 // A single probe should be triggered by the error page load, and it should 701 // A single probe should be triggered by the error page load, and it should
726 // be ignored. 702 // be ignored.
727 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 703 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
728 EXPECT_EQ(0, pending_status_count()); 704 EXPECT_EQ(0, pending_status_count());
729 EXPECT_EQ("", Title()); 705 EXPECT_EQ("", Title());
730 706
731 StartDelayedProbes(1); 707 StartDelayedProbes(1);
732 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, 708 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
733 WaitForSentStatus()); 709 WaitForSentStatus());
734 EXPECT_EQ(0, pending_status_count()); 710 EXPECT_EQ(0, pending_status_count());
735 EXPECT_EQ("", Title()); 711 EXPECT_EQ("", Title());
736 712
737 content::TestNavigationObserver observer( 713 content::TestNavigationObserver observer(
738 browser()->tab_strip_model()->GetActiveWebContents(), 1); 714 browser()->tab_strip_model()->GetActiveWebContents(), 1);
739 // The corrections finish loading. 715 // The Link Doctor page finishes loading.
740 SetCorrectionServiceDelayRequests(false); 716 SetLinkDoctorDelayRequests(false);
741 // Wait for it to commit. 717 // Wait for it to commit.
742 observer.Wait(); 718 observer.Wait();
743 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); 719 EXPECT_EQ("Mock Link Doctor", Title());
744 720
745 // Committing the corections page should trigger sending the probe result 721 // Committing the Link Doctor page should trigger sending the probe result
746 // again. 722 // again.
747 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, 723 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN,
748 WaitForSentStatus()); 724 WaitForSentStatus());
749 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); 725 EXPECT_EQ("Mock Link Doctor", Title());
750 } 726 }
751 727
752 // Make sure probes update DNS error page properly when they're supposed to. 728 // Make sure probes update DNS error page properly when they're supposed to.
753 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, 729 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest,
754 NoInternetProbeResultWithBrokenCorrections) { 730 NoInternetProbeResultWithBrokenLinkDoctor) {
755 SetCorrectionServiceBroken(true); 731 SetLinkDoctorBroken(true);
756 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, 732 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT,
757 MockDnsClientRule::TIMEOUT); 733 MockDnsClientRule::TIMEOUT);
758 734
759 NavigateToDnsError(2); 735 NavigateToDnsError(2);
760 736
761 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 737 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
762 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 738 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
763 739
764 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 740 // PageContains runs the RunLoop, so make sure nothing hairy happens.
765 EXPECT_EQ(0, pending_status_count()); 741 EXPECT_EQ(0, pending_status_count());
766 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); 742 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED"));
767 EXPECT_EQ(0, pending_status_count()); 743 EXPECT_EQ(0, pending_status_count());
768 744
769 StartDelayedProbes(1); 745 StartDelayedProbes(1);
770 746
771 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, 747 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
772 WaitForSentStatus()); 748 WaitForSentStatus());
773 749
774 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 750 // PageContains runs the RunLoop, so make sure nothing hairy happens.
775 EXPECT_EQ(0, pending_status_count()); 751 EXPECT_EQ(0, pending_status_count());
776 ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); 752 EXPECT_TRUE(PageContains("DNS_PROBE_FINISHED_NO_INTERNET"));
777 } 753 }
778 754
779 // Make sure probes don't break corrections when probes complete before the 755 // Make sure probes don't break Link Doctor when probes complete before the
780 // corrections request returns an error. 756 // Link Doctor request returns an error.
781 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, 757 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest,
782 NoInternetProbeResultWithSlowBrokenCorrections) { 758 NoInternetProbeResultWithSlowBrokenLinkDoctor) {
783 SetCorrectionServiceBroken(true); 759 SetLinkDoctorBroken(true);
784 SetCorrectionServiceDelayRequests(true); 760 SetLinkDoctorDelayRequests(true);
785 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, 761 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT,
786 MockDnsClientRule::TIMEOUT); 762 MockDnsClientRule::TIMEOUT);
787 763
788 NavigateToDnsError(1); 764 NavigateToDnsError(1);
789 // A blank page should be displayed while the corrections load. 765 // A blank page should be displayed while the Link Doctor page loads.
790 EXPECT_EQ("", Title()); 766 EXPECT_EQ("", Title());
791 767
792 // A single probe should be triggered by the error page load, and it should 768 // A single probe should be triggered by the error page load, and it should
793 // be ignored. 769 // be ignored.
794 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 770 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
795 EXPECT_EQ(0, pending_status_count()); 771 EXPECT_EQ(0, pending_status_count());
796 EXPECT_EQ("", Title()); 772 EXPECT_EQ("", Title());
797 773
798 StartDelayedProbes(1); 774 StartDelayedProbes(1);
799 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, 775 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
800 WaitForSentStatus()); 776 WaitForSentStatus());
801 EXPECT_EQ("", Title()); 777 EXPECT_EQ("", Title());
802 EXPECT_EQ(0, pending_status_count()); 778 EXPECT_EQ(0, pending_status_count());
803 779
804 content::TestNavigationObserver observer( 780 content::TestNavigationObserver observer(
805 browser()->tab_strip_model()->GetActiveWebContents(), 1); 781 browser()->tab_strip_model()->GetActiveWebContents(), 1);
806 // The corrections request fails. 782 // The Link Doctor request fails.
807 SetCorrectionServiceDelayRequests(false); 783 SetLinkDoctorDelayRequests(false);
808 // Wait for the DNS error page to load instead. 784 // Wait for the DNS error page to load instead.
809 observer.Wait(); 785 observer.Wait();
810 // The page committing should result in sending the probe results again. 786 // The page committing should result in sending the probe results again.
811 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, 787 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
812 WaitForSentStatus()); 788 WaitForSentStatus());
813 789
814 EXPECT_EQ(0, pending_status_count()); 790 EXPECT_EQ(0, pending_status_count());
815 ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); 791 EXPECT_TRUE(PageContains("DNS_PROBE_FINISHED_NO_INTERNET"));
816 } 792 }
817 793
818 // Double-check to make sure sync failures don't explode. 794 // Double-check to make sure sync failures don't explode.
819 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, SyncFailureWithBrokenCorrections) { 795 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, SyncFailureWithBrokenLinkDoctor) {
820 SetCorrectionServiceBroken(true); 796 SetLinkDoctorBroken(true);
821 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); 797 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL);
822 798
823 NavigateToDnsError(2); 799 NavigateToDnsError(2);
824 800
825 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 801 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
826 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 802 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
827 803
828 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 804 // PageContains runs the RunLoop, so make sure nothing hairy happens.
829 EXPECT_EQ(0, pending_status_count()); 805 EXPECT_EQ(0, pending_status_count());
830 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); 806 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED"));
831 EXPECT_EQ(0, pending_status_count()); 807 EXPECT_EQ(0, pending_status_count());
832 808
833 StartDelayedProbes(1); 809 StartDelayedProbes(1);
834 810
835 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, 811 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE,
836 WaitForSentStatus()); 812 WaitForSentStatus());
837 813
838 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 814 // PageContains runs the RunLoop, so make sure nothing hairy happens.
839 EXPECT_EQ(0, pending_status_count()); 815 EXPECT_EQ(0, pending_status_count());
840 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); 816 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED"));
841 EXPECT_EQ(0, pending_status_count()); 817 EXPECT_EQ(0, pending_status_count());
842 } 818 }
843 819
844 // Test that pressing the stop button cancels loading corrections. 820 // Test that pressing the stop button cancels loading the Link Doctor page.
845 // TODO(mmenke): Add a test for the cross process navigation case. 821 // TODO(mmenke): Add a test for the cross process navigation case.
846 // TODO(mmenke): This test could flakily pass due to the timeout on downloading 822 // TODO(mmenke): This test could flakily pass due to the timeout on downloading
847 // the corrections. Disable that timeout for browser tests. 823 // the Link Doctor page. Disable that timeout for browser tests.
848 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStopped) { 824 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorLoadStopped) {
849 SetCorrectionServiceDelayRequests(true); 825 SetLinkDoctorDelayRequests(true);
850 SetCorrectionServiceBroken(true); 826 SetLinkDoctorBroken(true);
851 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); 827 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT);
852 828
853 NavigateToDnsError(1); 829 NavigateToDnsError(1);
854 830
855 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 831 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
856 StartDelayedProbes(1); 832 StartDelayedProbes(1);
857 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, 833 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
858 WaitForSentStatus()); 834 WaitForSentStatus());
859 835
860 EXPECT_EQ("", Title()); 836 EXPECT_EQ("", Title());
861 EXPECT_EQ(0, pending_status_count()); 837 EXPECT_EQ(0, pending_status_count());
862 838
863 chrome::Stop(browser()); 839 chrome::Stop(browser());
864 WaitForDelayedRequestDestruction(); 840 WaitForDelayedRequestDestruction();
865 841
866 // End up displaying a blank page. 842 // End up displaying a blank page.
867 EXPECT_EQ("", Title()); 843 EXPECT_EQ("", Title());
868 } 844 }
869 845
870 // Test that pressing the stop button cancels the load of corrections, and 846 // Test that pressing the stop button cancels the load of the Link Doctor error
871 // receiving a probe result afterwards does not swap in a DNS error page. 847 // page, and receiving a probe result afterwards does not swap in a DNS error
872 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStoppedSlowProbe) { 848 // page.
873 SetCorrectionServiceDelayRequests(true); 849 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorLoadStoppedSlowProbe) {
874 SetCorrectionServiceBroken(true); 850 SetLinkDoctorDelayRequests(true);
851 SetLinkDoctorBroken(true);
875 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); 852 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT);
876 853
877 NavigateToDnsError(1); 854 NavigateToDnsError(1);
878 855
879 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 856 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
880 857
881 EXPECT_EQ("", Title()); 858 EXPECT_EQ("", Title());
882 EXPECT_EQ(0, pending_status_count()); 859 EXPECT_EQ(0, pending_status_count());
883 860
884 chrome::Stop(browser()); 861 chrome::Stop(browser());
885 WaitForDelayedRequestDestruction(); 862 WaitForDelayedRequestDestruction();
886 863
887 EXPECT_EQ("", Title()); 864 EXPECT_EQ("", Title());
888 EXPECT_EQ(0, pending_status_count()); 865 EXPECT_EQ(0, pending_status_count());
889 866
890 StartDelayedProbes(1); 867 StartDelayedProbes(1);
891 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, 868 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET,
892 WaitForSentStatus()); 869 WaitForSentStatus());
893 870
894 EXPECT_EQ("", Title()); 871 EXPECT_EQ("", Title());
895 } 872 }
896 873
897 // Make sure probes don't run for subframe DNS errors. 874 // Make sure probes don't run for subframe DNS errors.
898 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, NoProbeInSubframe) { 875 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, NoProbeInSubframe) {
899 SetCorrectionServiceBroken(false); 876 SetLinkDoctorBroken(false);
900 877
901 const FilePath::CharType kIframeDnsErrorHtmlName[] = 878 const FilePath::CharType kIframeDnsErrorHtmlName[] =
902 FILE_PATH_LITERAL("iframe_dns_error.html"); 879 FILE_PATH_LITERAL("iframe_dns_error.html");
903 880
904 NavigateToURL( 881 NavigateToURL(
905 browser(), 882 browser(),
906 URLRequestMockHTTPJob::GetMockUrl(FilePath(kIframeDnsErrorHtmlName))); 883 URLRequestMockHTTPJob::GetMockUrl(FilePath(kIframeDnsErrorHtmlName)));
907 884
908 // By the time NavigateToURL returns, the browser will have seen the failed 885 // By the time NavigateToURL returns, the browser will have seen the failed
909 // provisional load. If a probe was started (or considered but not run), 886 // provisional load. If a probe was started (or considered but not run),
910 // then the NetErrorTabHelper would have sent a NetErrorInfo message. Thus, 887 // then the NetErrorTabHelper would have sent a NetErrorInfo message. Thus,
911 // if one hasn't been sent by now, the NetErrorTabHelper has not (and won't) 888 // if one hasn't been sent by now, the NetErrorTabHelper has not (and won't)
912 // start a probe for this DNS error. 889 // start a probe for this DNS error.
913 EXPECT_EQ(0, pending_status_count()); 890 EXPECT_EQ(0, pending_status_count());
914 } 891 }
915 892
916 // Make sure browser sends NOT_RUN properly when probes are disabled. 893 // Make sure browser sends NOT_RUN properly when probes are disabled.
917 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, ProbesDisabled) { 894 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, ProbesDisabled) {
918 // Disable probes (And corrections). 895 // Disable probes (And Link Doctor).
919 browser()->profile()->GetPrefs()->SetBoolean( 896 browser()->profile()->GetPrefs()->SetBoolean(
920 prefs::kAlternateErrorPagesEnabled, false); 897 prefs::kAlternateErrorPagesEnabled, false);
921 898
922 SetCorrectionServiceBroken(true); 899 SetLinkDoctorBroken(true);
923 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); 900 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT);
924 901
925 NavigateToDnsError(1); 902 NavigateToDnsError(1);
926 903
927 EXPECT_EQ(chrome_common_net::DNS_PROBE_NOT_RUN, WaitForSentStatus()); 904 EXPECT_EQ(chrome_common_net::DNS_PROBE_NOT_RUN, WaitForSentStatus());
928 905
929 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 906 // PageContains runs the RunLoop, so make sure nothing hairy happens.
930 EXPECT_EQ(0, pending_status_count()); 907 EXPECT_EQ(0, pending_status_count());
931 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); 908 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED"));
932 } 909 }
933 910
934 // Test the case that corrections are disabled, but DNS probes are enabled. 911 // Test the case that Link Doctor is disabled, but DNS probes are enabled. This
935 // This is the case with Chromium builds. 912 // is the case with Chromium builds.
936 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsDisabled) { 913 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorDisabled) {
937 // Disable corrections. 914 // Disable Link Doctor.
938 browser()->profile()->GetPrefs()->SetBoolean( 915 browser()->profile()->GetPrefs()->SetBoolean(
939 prefs::kAlternateErrorPagesEnabled, false); 916 prefs::kAlternateErrorPagesEnabled, false);
940 // Requests to the correction service should work if any are made, so the test 917 // Requests to the Link Doctor should work if any are made, so the test fails
941 // fails if that happens unexpectedly. 918 // if that happens unexpectedly.
942 SetCorrectionServiceBroken(false); 919 SetLinkDoctorBroken(false);
943 // Normally disabling corrections disables DNS probes, so force DNS probes 920 // Normally disabling the LinkDoctor disables DNS probes, so force DNS probes
944 // to be enabled. 921 // to be enabled.
945 NetErrorTabHelper::set_state_for_testing( 922 NetErrorTabHelper::set_state_for_testing(
946 NetErrorTabHelper::TESTING_FORCE_ENABLED); 923 NetErrorTabHelper::TESTING_FORCE_ENABLED);
947 924
948 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); 925 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL);
949 926
950 // Just one commit and one sent status, since corrections are disabled. 927 // Just one commit and one sent status, since the Link Doctor is disabled.
951 NavigateToDnsError(1); 928 NavigateToDnsError(1);
952 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 929 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
953 930
954 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 931 // PageContains runs the RunLoop, so make sure nothing hairy happens.
955 EXPECT_EQ(0, pending_status_count()); 932 EXPECT_EQ(0, pending_status_count());
956 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); 933 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED"));
957 EXPECT_EQ(0, pending_status_count()); 934 EXPECT_EQ(0, pending_status_count());
958 935
959 StartDelayedProbes(1); 936 StartDelayedProbes(1);
960 937
961 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, 938 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE,
962 WaitForSentStatus()); 939 WaitForSentStatus());
963 EXPECT_EQ(0, pending_status_count()); 940 EXPECT_EQ(0, pending_status_count());
964 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); 941 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED"));
965 } 942 }
966 943
967 // Test incognito mode. Corrections should be disabled, but DNS probes are 944 // Test incognito mode. Link Doctor should be disabled, but DNS probes are
968 // still enabled. 945 // still enabled.
969 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, Incognito) { 946 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, Incognito) {
970 // Requests to the correction service should work if any are made, so the test 947 // Requests to the Link Doctor should work if any are made, so the test will
971 // will fail if one is requested unexpectedly. 948 // fail if one is requested unexpectedly.
972 SetCorrectionServiceBroken(false); 949 SetLinkDoctorBroken(false);
973 950
974 Browser* incognito = CreateIncognitoBrowser(); 951 Browser* incognito = CreateIncognitoBrowser();
975 SetActiveBrowser(incognito); 952 SetActiveBrowser(incognito);
976 953
977 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); 954 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL);
978 955
979 // Just one commit and one sent status, since the corrections are disabled. 956 // Just one commit and one sent status, since the Link Doctor is disabled.
980 NavigateToDnsError(1); 957 NavigateToDnsError(1);
981 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); 958 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus());
982 959
983 // Checking the page runs the RunLoop, so make sure nothing hairy happens. 960 // PageContains runs the RunLoop, so make sure nothing hairy happens.
984 EXPECT_EQ(0, pending_status_count()); 961 EXPECT_EQ(0, pending_status_count());
985 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); 962 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED"));
986 EXPECT_EQ(0, pending_status_count()); 963 EXPECT_EQ(0, pending_status_count());
987 964
988 StartDelayedProbes(1); 965 StartDelayedProbes(1);
989 966
990 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, 967 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE,
991 WaitForSentStatus()); 968 WaitForSentStatus());
992 EXPECT_EQ(0, pending_status_count()); 969 EXPECT_EQ(0, pending_status_count());
993 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); 970 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED"));
994 } 971 }
995 972
996 } // namespace 973 } // namespace
997 974
998 } // namespace chrome_browser_net 975 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/google/google_util.cc ('k') | trunk/src/chrome/browser/net/url_request_mock_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698