OLD | NEW |
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 Loading... |
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.html"); | 113 return root_http.AppendASCII("mock-link-doctor.json"); |
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 Loading... |
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 Link Doctor requests. Can cause requests to fail with | 218 // ProtocolHandler for navigation correction requests. Can cause requests to |
219 // an error, and/or delay a request until a test allows to continue. Also can | 219 // fail with an error, and/or delay a request until a test allows to continue. |
220 // run a callback when a delayed request is cancelled. | 220 // Also can run a callback when a delayed request is cancelled. |
221 class BreakableLinkDoctorProtocolHandler | 221 class BreakableCorrectionProtocolHandler |
222 : public URLRequestJobFactory::ProtocolHandler { | 222 : public URLRequestJobFactory::ProtocolHandler { |
223 public: | 223 public: |
224 explicit BreakableLinkDoctorProtocolHandler( | 224 explicit BreakableCorrectionProtocolHandler( |
225 const FilePath& mock_link_doctor_file_path) | 225 const FilePath& mock_corrections_file_path) |
226 : mock_link_doctor_file_path_(mock_link_doctor_file_path), | 226 : mock_corrections_file_path_(mock_corrections_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(&BreakableLinkDoctorProtocolHandler::OnRequestDestroyed, | 230 base::Bind(&BreakableCorrectionProtocolHandler::OnRequestDestroyed, |
231 base::Unretained(this))) { | 231 base::Unretained(this))) { |
232 } | 232 } |
233 | 233 |
234 virtual ~BreakableLinkDoctorProtocolHandler() { | 234 virtual ~BreakableCorrectionProtocolHandler() { |
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_link_doctor_file_path_, | 253 request, network_delegate, mock_corrections_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 Loading... |
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_link_doctor_file_path_; | 298 const FilePath mock_corrections_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 SetLinkDoctorNetError(int link_doctor_net_error); | 322 void SetCorrectionServiceNetError(int net_error); |
323 void SetLinkDoctorDelayRequests(bool delay_requests); | 323 void SetCorrectionServiceDelayRequests(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 BreakableLinkDoctorProtocolHandler* protocol_handler_; | 331 BreakableCorrectionProtocolHandler* protocol_handler_; |
332 FilePath mock_link_doctor_file_path_; | 332 FilePath mock_corrections_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_link_doctor_file_path_(GetMockLinkDoctorFilePath()) {} | 340 mock_corrections_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 BreakableLinkDoctorProtocolHandler(mock_link_doctor_file_path_)); | 361 new BreakableCorrectionProtocolHandler(mock_corrections_file_path_)); |
362 protocol_handler_ = | 362 protocol_handler_ = |
363 static_cast<BreakableLinkDoctorProtocolHandler*>(protocol_handler.get()); | 363 static_cast<BreakableCorrectionProtocolHandler*>(protocol_handler.get()); |
364 const GURL link_doctor_base_url = LinkDoctorBaseURL(); | 364 URLRequestFilter::GetInstance()->AddUrlProtocolHandler( |
365 const std::string link_doctor_host = link_doctor_base_url.host(); | 365 LinkDoctorBaseURL(), protocol_handler.Pass()); |
366 URLRequestFilter::GetInstance()->AddHostnameProtocolHandler( | |
367 "http", link_doctor_host, protocol_handler.Pass()); | |
368 } | 366 } |
369 | 367 |
370 void DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper() { | 368 void DnsProbeBrowserTestIOThreadHelper::CleanUpOnIOThreadAndDeleteHelper() { |
371 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 369 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
372 | 370 |
373 URLRequestFilter::GetInstance()->ClearHandlers(); | 371 URLRequestFilter::GetInstance()->ClearHandlers(); |
374 | 372 |
375 IOThread::Globals* globals = io_thread_->globals(); | 373 IOThread::Globals* globals = io_thread_->globals(); |
376 scoped_ptr<DnsProbeService> delaying_dns_probe_service( | 374 scoped_ptr<DnsProbeService> delaying_dns_probe_service( |
377 globals->dns_probe_service.release()); | 375 globals->dns_probe_service.release()); |
378 globals->dns_probe_service.reset(original_dns_probe_service_); | 376 globals->dns_probe_service.reset(original_dns_probe_service_); |
379 | 377 |
380 CHECK_EQ(delaying_dns_probe_service_, delaying_dns_probe_service.get()); | 378 CHECK_EQ(delaying_dns_probe_service_, delaying_dns_probe_service.get()); |
381 | 379 |
382 delete this; | 380 delete this; |
383 } | 381 } |
384 | 382 |
385 void DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules( | 383 void DnsProbeBrowserTestIOThreadHelper::SetMockDnsClientRules( |
386 MockDnsClientRule::Result system_result, | 384 MockDnsClientRule::Result system_result, |
387 MockDnsClientRule::Result public_result) { | 385 MockDnsClientRule::Result public_result) { |
388 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
389 | 387 |
390 DnsProbeService* service = io_thread_->globals()->dns_probe_service.get(); | 388 DnsProbeService* service = io_thread_->globals()->dns_probe_service.get(); |
391 service->SetSystemClientForTesting( | 389 service->SetSystemClientForTesting( |
392 CreateMockDnsClientForProbes(system_result)); | 390 CreateMockDnsClientForProbes(system_result)); |
393 service->SetPublicClientForTesting( | 391 service->SetPublicClientForTesting( |
394 CreateMockDnsClientForProbes(public_result)); | 392 CreateMockDnsClientForProbes(public_result)); |
395 } | 393 } |
396 | 394 |
397 void DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorNetError( | 395 void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError( |
398 int link_doctor_net_error) { | 396 int net_error) { |
399 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
400 | 398 |
401 protocol_handler_->set_net_error(link_doctor_net_error); | 399 protocol_handler_->set_net_error(net_error); |
402 } | 400 } |
403 | 401 |
404 void DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorDelayRequests( | 402 void DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceDelayRequests( |
405 bool delay_requests) { | 403 bool delay_requests) { |
406 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 404 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
407 | 405 |
408 protocol_handler_->SetDelayRequests(delay_requests); | 406 protocol_handler_->SetDelayRequests(delay_requests); |
409 } | 407 } |
410 | 408 |
411 void DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback( | 409 void DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback( |
412 const base::Closure& callback) { | 410 const base::Closure& callback) { |
413 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 411 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
414 | 412 |
(...skipping 19 matching lines...) Expand all Loading... |
434 virtual ~DnsProbeBrowserTest(); | 432 virtual ~DnsProbeBrowserTest(); |
435 | 433 |
436 virtual void SetUpOnMainThread() OVERRIDE; | 434 virtual void SetUpOnMainThread() OVERRIDE; |
437 virtual void CleanUpOnMainThread() OVERRIDE; | 435 virtual void CleanUpOnMainThread() OVERRIDE; |
438 | 436 |
439 protected: | 437 protected: |
440 // Sets the browser object that other methods apply to, and that has the | 438 // Sets the browser object that other methods apply to, and that has the |
441 // DnsProbeStatus messages of its currently active tab monitored. | 439 // DnsProbeStatus messages of its currently active tab monitored. |
442 void SetActiveBrowser(Browser* browser); | 440 void SetActiveBrowser(Browser* browser); |
443 | 441 |
444 void SetLinkDoctorBroken(bool broken); | 442 void SetCorrectionServiceBroken(bool broken); |
445 void SetLinkDoctorDelayRequests(bool delay_requests); | 443 void SetCorrectionServiceDelayRequests(bool delay_requests); |
446 void WaitForDelayedRequestDestruction(); | 444 void WaitForDelayedRequestDestruction(); |
447 void SetMockDnsClientRules(MockDnsClientRule::Result system_result, | 445 void SetMockDnsClientRules(MockDnsClientRule::Result system_result, |
448 MockDnsClientRule::Result public_result); | 446 MockDnsClientRule::Result public_result); |
449 | 447 |
450 // These functions are often used to wait for two navigations because the Link | 448 // These functions are often used to wait for two navigations because two |
451 // Doctor loads two pages: a blank page, so the user stops seeing the previous | 449 // pages are loaded when navigation corrections are enabled: a blank page, so |
452 // page, and then either the Link Doctor page or a regular error page. Often | 450 // the user stops seeing the previous page, and then the error page, either |
453 // need to wait for both to finish in a row. | 451 // with navigation corrections or without them (If the request failed). |
454 void NavigateToDnsError(int num_navigations); | 452 void NavigateToDnsError(int num_navigations); |
455 void NavigateToOtherError(int num_navigations); | 453 void NavigateToOtherError(int num_navigations); |
456 | 454 |
457 void StartDelayedProbes(int expected_delayed_probe_count); | 455 void StartDelayedProbes(int expected_delayed_probe_count); |
458 DnsProbeStatus WaitForSentStatus(); | 456 DnsProbeStatus WaitForSentStatus(); |
459 int pending_status_count() const { return dns_probe_status_queue_.size(); } | 457 int pending_status_count() const { return dns_probe_status_queue_.size(); } |
460 | 458 |
461 std::string Title(); | 459 std::string Title(); |
462 bool PageContains(const std::string& expected); | 460 bool PageContains(const std::string& expected); |
463 | 461 |
| 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 |
464 private: | 472 private: |
465 void OnDnsProbeStatusSent(DnsProbeStatus dns_probe_status); | 473 void OnDnsProbeStatusSent(DnsProbeStatus dns_probe_status); |
466 | 474 |
467 DnsProbeBrowserTestIOThreadHelper* helper_; | 475 DnsProbeBrowserTestIOThreadHelper* helper_; |
468 | 476 |
469 // Browser that methods apply to. | 477 // Browser that methods apply to. |
470 Browser* active_browser_; | 478 Browser* active_browser_; |
471 // Helper that current has its DnsProbeStatus messages monitored. | 479 // Helper that current has its DnsProbeStatus messages monitored. |
472 NetErrorTabHelper* monitored_tab_helper_; | 480 NetErrorTabHelper* monitored_tab_helper_; |
473 | 481 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( | 529 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( |
522 NetErrorTabHelper::DnsProbeStatusSnoopCallback()); | 530 NetErrorTabHelper::DnsProbeStatusSnoopCallback()); |
523 } | 531 } |
524 active_browser_ = browser; | 532 active_browser_ = browser; |
525 monitored_tab_helper_ = NetErrorTabHelper::FromWebContents( | 533 monitored_tab_helper_ = NetErrorTabHelper::FromWebContents( |
526 active_browser_->tab_strip_model()->GetActiveWebContents()); | 534 active_browser_->tab_strip_model()->GetActiveWebContents()); |
527 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( | 535 monitored_tab_helper_->set_dns_probe_status_snoop_callback_for_testing( |
528 Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this))); | 536 Bind(&DnsProbeBrowserTest::OnDnsProbeStatusSent, Unretained(this))); |
529 } | 537 } |
530 | 538 |
531 void DnsProbeBrowserTest::SetLinkDoctorBroken(bool broken) { | 539 void DnsProbeBrowserTest::SetCorrectionServiceBroken(bool broken) { |
532 int net_error = broken ? net::ERR_NAME_NOT_RESOLVED : net::OK; | 540 int net_error = broken ? net::ERR_NAME_NOT_RESOLVED : net::OK; |
533 | 541 |
534 BrowserThread::PostTask( | 542 BrowserThread::PostTask( |
535 BrowserThread::IO, FROM_HERE, | 543 BrowserThread::IO, FROM_HERE, |
536 Bind(&DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorNetError, | 544 Bind(&DnsProbeBrowserTestIOThreadHelper::SetCorrectionServiceNetError, |
537 Unretained(helper_), | 545 Unretained(helper_), |
538 net_error)); | 546 net_error)); |
539 } | 547 } |
540 | 548 |
541 void DnsProbeBrowserTest::SetLinkDoctorDelayRequests(bool delay_requests) { | 549 void DnsProbeBrowserTest::SetCorrectionServiceDelayRequests( |
| 550 bool delay_requests) { |
542 BrowserThread::PostTask( | 551 BrowserThread::PostTask( |
543 BrowserThread::IO, FROM_HERE, | 552 BrowserThread::IO, FROM_HERE, |
544 Bind(&DnsProbeBrowserTestIOThreadHelper::SetLinkDoctorDelayRequests, | 553 Bind(&DnsProbeBrowserTestIOThreadHelper:: |
| 554 SetCorrectionServiceDelayRequests, |
545 Unretained(helper_), | 555 Unretained(helper_), |
546 delay_requests)); | 556 delay_requests)); |
547 } | 557 } |
548 | 558 |
549 void DnsProbeBrowserTest::WaitForDelayedRequestDestruction() { | 559 void DnsProbeBrowserTest::WaitForDelayedRequestDestruction() { |
550 base::RunLoop run_loop; | 560 base::RunLoop run_loop; |
551 BrowserThread::PostTask( | 561 BrowserThread::PostTask( |
552 BrowserThread::IO, FROM_HERE, | 562 BrowserThread::IO, FROM_HERE, |
553 Bind(&DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback, | 563 Bind(&DnsProbeBrowserTestIOThreadHelper::SetRequestDestructionCallback, |
554 Unretained(helper_), | 564 Unretained(helper_), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 bool rv = content::ExecuteScriptAndExtractString( | 641 bool rv = content::ExecuteScriptAndExtractString( |
632 active_browser_->tab_strip_model()->GetActiveWebContents(), | 642 active_browser_->tab_strip_model()->GetActiveWebContents(), |
633 "domAutomationController.send(document.body.textContent);", | 643 "domAutomationController.send(document.body.textContent);", |
634 &text_content); | 644 &text_content); |
635 if (!rv) | 645 if (!rv) |
636 return false; | 646 return false; |
637 | 647 |
638 return text_content.find(expected) != std::string::npos; | 648 return text_content.find(expected) != std::string::npos; |
639 } | 649 } |
640 | 650 |
| 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 |
641 void DnsProbeBrowserTest::OnDnsProbeStatusSent( | 665 void DnsProbeBrowserTest::OnDnsProbeStatusSent( |
642 DnsProbeStatus dns_probe_status) { | 666 DnsProbeStatus dns_probe_status) { |
643 dns_probe_status_queue_.push_back(dns_probe_status); | 667 dns_probe_status_queue_.push_back(dns_probe_status); |
644 if (awaiting_dns_probe_status_) | 668 if (awaiting_dns_probe_status_) |
645 MessageLoop::current()->Quit(); | 669 MessageLoop::current()->Quit(); |
646 } | 670 } |
647 | 671 |
648 // Make sure probes don't break non-DNS error pages when Link Doctor loads. | 672 // Make sure probes don't break non-DNS error pages when corrections load. |
649 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithWorkingLinkDoctor) { | 673 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsSuccess) { |
650 SetLinkDoctorBroken(false); | 674 SetCorrectionServiceBroken(false); |
651 | 675 |
652 NavigateToOtherError(2); | 676 NavigateToOtherError(2); |
653 EXPECT_EQ("Mock Link Doctor", Title()); | 677 ExpectDisplayingCorrections("ERR_CONNECTION_REFUSED"); |
654 } | 678 } |
655 | 679 |
656 // Make sure probes don't break non-DNS error pages when Link Doctor doesn't | 680 // Make sure probes don't break non-DNS error pages when corrections failed to |
657 // load. | 681 // load. |
658 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithBrokenLinkDoctor) { | 682 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, OtherErrorWithCorrectionsFailure) { |
659 SetLinkDoctorBroken(true); | 683 SetCorrectionServiceBroken(true); |
660 | 684 |
661 NavigateToOtherError(2); | 685 NavigateToOtherError(2); |
662 EXPECT_TRUE(PageContains("CONNECTION_REFUSED")); | 686 ExpectDisplayingLocalErrorPage("ERR_CONNECTION_REFUSED"); |
663 } | 687 } |
664 | 688 |
665 // Make sure probes don't break DNS error pages when Link doctor loads. | 689 // Make sure probes don't break DNS error pages when corrections load. |
666 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, | 690 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
667 NxdomainProbeResultWithWorkingLinkDoctor) { | 691 NxdomainProbeResultWithWorkingCorrections) { |
668 SetLinkDoctorBroken(false); | 692 SetCorrectionServiceBroken(false); |
669 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); | 693 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); |
670 | 694 |
671 NavigateToDnsError(2); | 695 NavigateToDnsError(2); |
672 EXPECT_EQ("Mock Link Doctor", Title()); | 696 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
673 | 697 |
674 // One status for committing a blank page before the Link Doctor, and one for | 698 // One status for committing a blank page before the corrections, and one for |
675 // when the Link Doctor is committed. | 699 // when the error page with corrections is committed. |
676 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 700 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
677 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 701 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
678 EXPECT_EQ(0, pending_status_count()); | 702 EXPECT_EQ(0, pending_status_count()); |
679 EXPECT_EQ("Mock Link Doctor", Title()); | 703 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
680 | 704 |
681 StartDelayedProbes(1); | 705 StartDelayedProbes(1); |
682 | 706 |
683 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, | 707 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, |
684 WaitForSentStatus()); | 708 WaitForSentStatus()); |
685 EXPECT_EQ(0, pending_status_count()); | 709 EXPECT_EQ(0, pending_status_count()); |
686 EXPECT_EQ("Mock Link Doctor", Title()); | 710 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
687 } | 711 } |
688 | 712 |
689 // Make sure probes don't break Link Doctor when probes complete before the | 713 // Make sure probes don't break corrections when probes complete before the |
690 // Link Doctor loads. | 714 // corrections load. |
691 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, | 715 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
692 NxdomainProbeResultWithWorkingSlowLinkDoctor) { | 716 NxdomainProbeResultWithWorkingSlowCorrections) { |
693 SetLinkDoctorBroken(false); | 717 SetCorrectionServiceBroken(false); |
694 SetLinkDoctorDelayRequests(true); | 718 SetCorrectionServiceDelayRequests(true); |
695 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); | 719 SetMockDnsClientRules(MockDnsClientRule::OK, MockDnsClientRule::OK); |
696 | 720 |
697 NavigateToDnsError(1); | 721 NavigateToDnsError(1); |
698 // A blank page should be displayed while the Link Doctor page loads. | 722 // A blank page should be displayed while the corrections are loaded. |
699 EXPECT_EQ("", Title()); | 723 EXPECT_EQ("", Title()); |
700 | 724 |
701 // A single probe should be triggered by the error page load, and it should | 725 // A single probe should be triggered by the error page load, and it should |
702 // be ignored. | 726 // be ignored. |
703 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 727 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
704 EXPECT_EQ(0, pending_status_count()); | 728 EXPECT_EQ(0, pending_status_count()); |
705 EXPECT_EQ("", Title()); | 729 EXPECT_EQ("", Title()); |
706 | 730 |
707 StartDelayedProbes(1); | 731 StartDelayedProbes(1); |
708 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, | 732 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, |
709 WaitForSentStatus()); | 733 WaitForSentStatus()); |
710 EXPECT_EQ(0, pending_status_count()); | 734 EXPECT_EQ(0, pending_status_count()); |
711 EXPECT_EQ("", Title()); | 735 EXPECT_EQ("", Title()); |
712 | 736 |
713 content::TestNavigationObserver observer( | 737 content::TestNavigationObserver observer( |
714 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 738 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
715 // The Link Doctor page finishes loading. | 739 // The corrections finish loading. |
716 SetLinkDoctorDelayRequests(false); | 740 SetCorrectionServiceDelayRequests(false); |
717 // Wait for it to commit. | 741 // Wait for it to commit. |
718 observer.Wait(); | 742 observer.Wait(); |
719 EXPECT_EQ("Mock Link Doctor", Title()); | 743 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
720 | 744 |
721 // Committing the Link Doctor page should trigger sending the probe result | 745 // Committing the corections page should trigger sending the probe result |
722 // again. | 746 // again. |
723 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, | 747 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NXDOMAIN, |
724 WaitForSentStatus()); | 748 WaitForSentStatus()); |
725 EXPECT_EQ("Mock Link Doctor", Title()); | 749 ExpectDisplayingCorrections("ERR_NAME_NOT_RESOLVED"); |
726 } | 750 } |
727 | 751 |
728 // Make sure probes update DNS error page properly when they're supposed to. | 752 // Make sure probes update DNS error page properly when they're supposed to. |
729 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, | 753 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
730 NoInternetProbeResultWithBrokenLinkDoctor) { | 754 NoInternetProbeResultWithBrokenCorrections) { |
731 SetLinkDoctorBroken(true); | 755 SetCorrectionServiceBroken(true); |
732 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, | 756 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, |
733 MockDnsClientRule::TIMEOUT); | 757 MockDnsClientRule::TIMEOUT); |
734 | 758 |
735 NavigateToDnsError(2); | 759 NavigateToDnsError(2); |
736 | 760 |
737 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 761 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
738 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 762 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
739 | 763 |
740 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 764 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
741 EXPECT_EQ(0, pending_status_count()); | 765 EXPECT_EQ(0, pending_status_count()); |
742 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED")); | 766 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
743 EXPECT_EQ(0, pending_status_count()); | 767 EXPECT_EQ(0, pending_status_count()); |
744 | 768 |
745 StartDelayedProbes(1); | 769 StartDelayedProbes(1); |
746 | 770 |
747 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, | 771 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
748 WaitForSentStatus()); | 772 WaitForSentStatus()); |
749 | 773 |
750 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 774 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
751 EXPECT_EQ(0, pending_status_count()); | 775 EXPECT_EQ(0, pending_status_count()); |
752 EXPECT_TRUE(PageContains("DNS_PROBE_FINISHED_NO_INTERNET")); | 776 ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); |
753 } | 777 } |
754 | 778 |
755 // Make sure probes don't break Link Doctor when probes complete before the | 779 // Make sure probes don't break corrections when probes complete before the |
756 // Link Doctor request returns an error. | 780 // corrections request returns an error. |
757 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, | 781 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, |
758 NoInternetProbeResultWithSlowBrokenLinkDoctor) { | 782 NoInternetProbeResultWithSlowBrokenCorrections) { |
759 SetLinkDoctorBroken(true); | 783 SetCorrectionServiceBroken(true); |
760 SetLinkDoctorDelayRequests(true); | 784 SetCorrectionServiceDelayRequests(true); |
761 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, | 785 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, |
762 MockDnsClientRule::TIMEOUT); | 786 MockDnsClientRule::TIMEOUT); |
763 | 787 |
764 NavigateToDnsError(1); | 788 NavigateToDnsError(1); |
765 // A blank page should be displayed while the Link Doctor page loads. | 789 // A blank page should be displayed while the corrections load. |
766 EXPECT_EQ("", Title()); | 790 EXPECT_EQ("", Title()); |
767 | 791 |
768 // A single probe should be triggered by the error page load, and it should | 792 // A single probe should be triggered by the error page load, and it should |
769 // be ignored. | 793 // be ignored. |
770 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 794 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
771 EXPECT_EQ(0, pending_status_count()); | 795 EXPECT_EQ(0, pending_status_count()); |
772 EXPECT_EQ("", Title()); | 796 EXPECT_EQ("", Title()); |
773 | 797 |
774 StartDelayedProbes(1); | 798 StartDelayedProbes(1); |
775 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, | 799 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
776 WaitForSentStatus()); | 800 WaitForSentStatus()); |
777 EXPECT_EQ("", Title()); | 801 EXPECT_EQ("", Title()); |
778 EXPECT_EQ(0, pending_status_count()); | 802 EXPECT_EQ(0, pending_status_count()); |
779 | 803 |
780 content::TestNavigationObserver observer( | 804 content::TestNavigationObserver observer( |
781 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 805 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
782 // The Link Doctor request fails. | 806 // The corrections request fails. |
783 SetLinkDoctorDelayRequests(false); | 807 SetCorrectionServiceDelayRequests(false); |
784 // Wait for the DNS error page to load instead. | 808 // Wait for the DNS error page to load instead. |
785 observer.Wait(); | 809 observer.Wait(); |
786 // The page committing should result in sending the probe results again. | 810 // The page committing should result in sending the probe results again. |
787 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, | 811 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
788 WaitForSentStatus()); | 812 WaitForSentStatus()); |
789 | 813 |
790 EXPECT_EQ(0, pending_status_count()); | 814 EXPECT_EQ(0, pending_status_count()); |
791 EXPECT_TRUE(PageContains("DNS_PROBE_FINISHED_NO_INTERNET")); | 815 ExpectDisplayingLocalErrorPage("DNS_PROBE_FINISHED_NO_INTERNET"); |
792 } | 816 } |
793 | 817 |
794 // Double-check to make sure sync failures don't explode. | 818 // Double-check to make sure sync failures don't explode. |
795 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, SyncFailureWithBrokenLinkDoctor) { | 819 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, SyncFailureWithBrokenCorrections) { |
796 SetLinkDoctorBroken(true); | 820 SetCorrectionServiceBroken(true); |
797 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); | 821 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
798 | 822 |
799 NavigateToDnsError(2); | 823 NavigateToDnsError(2); |
800 | 824 |
801 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 825 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
802 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 826 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
803 | 827 |
804 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 828 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
805 EXPECT_EQ(0, pending_status_count()); | 829 EXPECT_EQ(0, pending_status_count()); |
806 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED")); | 830 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
807 EXPECT_EQ(0, pending_status_count()); | 831 EXPECT_EQ(0, pending_status_count()); |
808 | 832 |
809 StartDelayedProbes(1); | 833 StartDelayedProbes(1); |
810 | 834 |
811 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, | 835 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, |
812 WaitForSentStatus()); | 836 WaitForSentStatus()); |
813 | 837 |
814 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 838 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
815 EXPECT_EQ(0, pending_status_count()); | 839 EXPECT_EQ(0, pending_status_count()); |
816 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED")); | 840 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
817 EXPECT_EQ(0, pending_status_count()); | 841 EXPECT_EQ(0, pending_status_count()); |
818 } | 842 } |
819 | 843 |
820 // Test that pressing the stop button cancels loading the Link Doctor page. | 844 // Test that pressing the stop button cancels loading corrections. |
821 // TODO(mmenke): Add a test for the cross process navigation case. | 845 // TODO(mmenke): Add a test for the cross process navigation case. |
822 // TODO(mmenke): This test could flakily pass due to the timeout on downloading | 846 // TODO(mmenke): This test could flakily pass due to the timeout on downloading |
823 // the Link Doctor page. Disable that timeout for browser tests. | 847 // the corrections. Disable that timeout for browser tests. |
824 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorLoadStopped) { | 848 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStopped) { |
825 SetLinkDoctorDelayRequests(true); | 849 SetCorrectionServiceDelayRequests(true); |
826 SetLinkDoctorBroken(true); | 850 SetCorrectionServiceBroken(true); |
827 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); | 851 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
828 | 852 |
829 NavigateToDnsError(1); | 853 NavigateToDnsError(1); |
830 | 854 |
831 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 855 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
832 StartDelayedProbes(1); | 856 StartDelayedProbes(1); |
833 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, | 857 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
834 WaitForSentStatus()); | 858 WaitForSentStatus()); |
835 | 859 |
836 EXPECT_EQ("", Title()); | 860 EXPECT_EQ("", Title()); |
837 EXPECT_EQ(0, pending_status_count()); | 861 EXPECT_EQ(0, pending_status_count()); |
838 | 862 |
839 chrome::Stop(browser()); | 863 chrome::Stop(browser()); |
840 WaitForDelayedRequestDestruction(); | 864 WaitForDelayedRequestDestruction(); |
841 | 865 |
842 // End up displaying a blank page. | 866 // End up displaying a blank page. |
843 EXPECT_EQ("", Title()); | 867 EXPECT_EQ("", Title()); |
844 } | 868 } |
845 | 869 |
846 // Test that pressing the stop button cancels the load of the Link Doctor error | 870 // Test that pressing the stop button cancels the load of corrections, and |
847 // page, and receiving a probe result afterwards does not swap in a DNS error | 871 // receiving a probe result afterwards does not swap in a DNS error page. |
848 // page. | 872 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsLoadStoppedSlowProbe) { |
849 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorLoadStoppedSlowProbe) { | 873 SetCorrectionServiceDelayRequests(true); |
850 SetLinkDoctorDelayRequests(true); | 874 SetCorrectionServiceBroken(true); |
851 SetLinkDoctorBroken(true); | |
852 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); | 875 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
853 | 876 |
854 NavigateToDnsError(1); | 877 NavigateToDnsError(1); |
855 | 878 |
856 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 879 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
857 | 880 |
858 EXPECT_EQ("", Title()); | 881 EXPECT_EQ("", Title()); |
859 EXPECT_EQ(0, pending_status_count()); | 882 EXPECT_EQ(0, pending_status_count()); |
860 | 883 |
861 chrome::Stop(browser()); | 884 chrome::Stop(browser()); |
862 WaitForDelayedRequestDestruction(); | 885 WaitForDelayedRequestDestruction(); |
863 | 886 |
864 EXPECT_EQ("", Title()); | 887 EXPECT_EQ("", Title()); |
865 EXPECT_EQ(0, pending_status_count()); | 888 EXPECT_EQ(0, pending_status_count()); |
866 | 889 |
867 StartDelayedProbes(1); | 890 StartDelayedProbes(1); |
868 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, | 891 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_NO_INTERNET, |
869 WaitForSentStatus()); | 892 WaitForSentStatus()); |
870 | 893 |
871 EXPECT_EQ("", Title()); | 894 EXPECT_EQ("", Title()); |
872 } | 895 } |
873 | 896 |
874 // Make sure probes don't run for subframe DNS errors. | 897 // Make sure probes don't run for subframe DNS errors. |
875 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, NoProbeInSubframe) { | 898 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, NoProbeInSubframe) { |
876 SetLinkDoctorBroken(false); | 899 SetCorrectionServiceBroken(false); |
877 | 900 |
878 const FilePath::CharType kIframeDnsErrorHtmlName[] = | 901 const FilePath::CharType kIframeDnsErrorHtmlName[] = |
879 FILE_PATH_LITERAL("iframe_dns_error.html"); | 902 FILE_PATH_LITERAL("iframe_dns_error.html"); |
880 | 903 |
881 NavigateToURL( | 904 NavigateToURL( |
882 browser(), | 905 browser(), |
883 URLRequestMockHTTPJob::GetMockUrl(FilePath(kIframeDnsErrorHtmlName))); | 906 URLRequestMockHTTPJob::GetMockUrl(FilePath(kIframeDnsErrorHtmlName))); |
884 | 907 |
885 // By the time NavigateToURL returns, the browser will have seen the failed | 908 // By the time NavigateToURL returns, the browser will have seen the failed |
886 // provisional load. If a probe was started (or considered but not run), | 909 // provisional load. If a probe was started (or considered but not run), |
887 // then the NetErrorTabHelper would have sent a NetErrorInfo message. Thus, | 910 // then the NetErrorTabHelper would have sent a NetErrorInfo message. Thus, |
888 // if one hasn't been sent by now, the NetErrorTabHelper has not (and won't) | 911 // if one hasn't been sent by now, the NetErrorTabHelper has not (and won't) |
889 // start a probe for this DNS error. | 912 // start a probe for this DNS error. |
890 EXPECT_EQ(0, pending_status_count()); | 913 EXPECT_EQ(0, pending_status_count()); |
891 } | 914 } |
892 | 915 |
893 // Make sure browser sends NOT_RUN properly when probes are disabled. | 916 // Make sure browser sends NOT_RUN properly when probes are disabled. |
894 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, ProbesDisabled) { | 917 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, ProbesDisabled) { |
895 // Disable probes (And Link Doctor). | 918 // Disable probes (And corrections). |
896 browser()->profile()->GetPrefs()->SetBoolean( | 919 browser()->profile()->GetPrefs()->SetBoolean( |
897 prefs::kAlternateErrorPagesEnabled, false); | 920 prefs::kAlternateErrorPagesEnabled, false); |
898 | 921 |
899 SetLinkDoctorBroken(true); | 922 SetCorrectionServiceBroken(true); |
900 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); | 923 SetMockDnsClientRules(MockDnsClientRule::TIMEOUT, MockDnsClientRule::TIMEOUT); |
901 | 924 |
902 NavigateToDnsError(1); | 925 NavigateToDnsError(1); |
903 | 926 |
904 EXPECT_EQ(chrome_common_net::DNS_PROBE_NOT_RUN, WaitForSentStatus()); | 927 EXPECT_EQ(chrome_common_net::DNS_PROBE_NOT_RUN, WaitForSentStatus()); |
905 | 928 |
906 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 929 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
907 EXPECT_EQ(0, pending_status_count()); | 930 EXPECT_EQ(0, pending_status_count()); |
908 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED")); | 931 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
909 } | 932 } |
910 | 933 |
911 // Test the case that Link Doctor is disabled, but DNS probes are enabled. This | 934 // Test the case that corrections are disabled, but DNS probes are enabled. |
912 // is the case with Chromium builds. | 935 // This is the case with Chromium builds. |
913 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, LinkDoctorDisabled) { | 936 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, CorrectionsDisabled) { |
914 // Disable Link Doctor. | 937 // Disable corrections. |
915 browser()->profile()->GetPrefs()->SetBoolean( | 938 browser()->profile()->GetPrefs()->SetBoolean( |
916 prefs::kAlternateErrorPagesEnabled, false); | 939 prefs::kAlternateErrorPagesEnabled, false); |
917 // Requests to the Link Doctor should work if any are made, so the test fails | 940 // Requests to the correction service should work if any are made, so the test |
918 // if that happens unexpectedly. | 941 // fails if that happens unexpectedly. |
919 SetLinkDoctorBroken(false); | 942 SetCorrectionServiceBroken(false); |
920 // Normally disabling the LinkDoctor disables DNS probes, so force DNS probes | 943 // Normally disabling corrections disables DNS probes, so force DNS probes |
921 // to be enabled. | 944 // to be enabled. |
922 NetErrorTabHelper::set_state_for_testing( | 945 NetErrorTabHelper::set_state_for_testing( |
923 NetErrorTabHelper::TESTING_FORCE_ENABLED); | 946 NetErrorTabHelper::TESTING_FORCE_ENABLED); |
924 | 947 |
925 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); | 948 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
926 | 949 |
927 // Just one commit and one sent status, since the Link Doctor is disabled. | 950 // Just one commit and one sent status, since corrections are disabled. |
928 NavigateToDnsError(1); | 951 NavigateToDnsError(1); |
929 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 952 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
930 | 953 |
931 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 954 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
932 EXPECT_EQ(0, pending_status_count()); | 955 EXPECT_EQ(0, pending_status_count()); |
933 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED")); | 956 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
934 EXPECT_EQ(0, pending_status_count()); | 957 EXPECT_EQ(0, pending_status_count()); |
935 | 958 |
936 StartDelayedProbes(1); | 959 StartDelayedProbes(1); |
937 | 960 |
938 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, | 961 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, |
939 WaitForSentStatus()); | 962 WaitForSentStatus()); |
940 EXPECT_EQ(0, pending_status_count()); | 963 EXPECT_EQ(0, pending_status_count()); |
941 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED")); | 964 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
942 } | 965 } |
943 | 966 |
944 // Test incognito mode. Link Doctor should be disabled, but DNS probes are | 967 // Test incognito mode. Corrections should be disabled, but DNS probes are |
945 // still enabled. | 968 // still enabled. |
946 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, Incognito) { | 969 IN_PROC_BROWSER_TEST_F(DnsProbeBrowserTest, Incognito) { |
947 // Requests to the Link Doctor should work if any are made, so the test will | 970 // Requests to the correction service should work if any are made, so the test |
948 // fail if one is requested unexpectedly. | 971 // will fail if one is requested unexpectedly. |
949 SetLinkDoctorBroken(false); | 972 SetCorrectionServiceBroken(false); |
950 | 973 |
951 Browser* incognito = CreateIncognitoBrowser(); | 974 Browser* incognito = CreateIncognitoBrowser(); |
952 SetActiveBrowser(incognito); | 975 SetActiveBrowser(incognito); |
953 | 976 |
954 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); | 977 SetMockDnsClientRules(MockDnsClientRule::FAIL, MockDnsClientRule::FAIL); |
955 | 978 |
956 // Just one commit and one sent status, since the Link Doctor is disabled. | 979 // Just one commit and one sent status, since the corrections are disabled. |
957 NavigateToDnsError(1); | 980 NavigateToDnsError(1); |
958 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); | 981 EXPECT_EQ(chrome_common_net::DNS_PROBE_STARTED, WaitForSentStatus()); |
959 | 982 |
960 // PageContains runs the RunLoop, so make sure nothing hairy happens. | 983 // Checking the page runs the RunLoop, so make sure nothing hairy happens. |
961 EXPECT_EQ(0, pending_status_count()); | 984 EXPECT_EQ(0, pending_status_count()); |
962 EXPECT_TRUE(PageContains("DNS_PROBE_STARTED")); | 985 ExpectDisplayingLocalErrorPage("DNS_PROBE_STARTED"); |
963 EXPECT_EQ(0, pending_status_count()); | 986 EXPECT_EQ(0, pending_status_count()); |
964 | 987 |
965 StartDelayedProbes(1); | 988 StartDelayedProbes(1); |
966 | 989 |
967 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, | 990 EXPECT_EQ(chrome_common_net::DNS_PROBE_FINISHED_INCONCLUSIVE, |
968 WaitForSentStatus()); | 991 WaitForSentStatus()); |
969 EXPECT_EQ(0, pending_status_count()); | 992 EXPECT_EQ(0, pending_status_count()); |
970 EXPECT_TRUE(PageContains("NAME_NOT_RESOLVED")); | 993 ExpectDisplayingLocalErrorPage("ERR_NAME_NOT_RESOLVED"); |
971 } | 994 } |
972 | 995 |
973 } // namespace | 996 } // namespace |
974 | 997 |
975 } // namespace chrome_browser_net | 998 } // namespace chrome_browser_net |
OLD | NEW |