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

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_impl_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/captive_portal/captive_portal_detector.h" 9 #include "chrome/browser/captive_portal/captive_portal_detector.h"
10 #include "chrome/browser/captive_portal/testing_utils.h" 10 #include "chrome/browser/captive_portal/testing_utils.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 void set_time_ticks(const base::TimeTicks& time_ticks) { 161 void set_time_ticks(const base::TimeTicks& time_ticks) {
162 network_portal_detector()->set_time_ticks_for_testing(time_ticks); 162 network_portal_detector()->set_time_ticks_for_testing(time_ticks);
163 } 163 }
164 164
165 void SetBehindPortal(const std::string& service_path) { 165 void SetBehindPortal(const std::string& service_path) {
166 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 166 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
167 dbus::ObjectPath(service_path), 167 dbus::ObjectPath(service_path),
168 flimflam::kStateProperty, base::StringValue(flimflam::kStatePortal), 168 flimflam::kStateProperty, base::StringValue(flimflam::kStatePortal),
169 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 169 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
170 MessageLoop::current()->RunUntilIdle(); 170 base::MessageLoop::current()->RunUntilIdle();
171 } 171 }
172 172
173 void SetNetworkDeviceEnabled(const std::string& type, bool enabled) { 173 void SetNetworkDeviceEnabled(const std::string& type, bool enabled) {
174 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 174 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
175 type, enabled, network_handler::ErrorCallback()); 175 type, enabled, network_handler::ErrorCallback());
176 MessageLoop::current()->RunUntilIdle(); 176 base::MessageLoop::current()->RunUntilIdle();
177 } 177 }
178 178
179 void SetConnected(const std::string& service_path) { 179 void SetConnected(const std::string& service_path) {
180 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 180 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
181 dbus::ObjectPath(service_path), 181 dbus::ObjectPath(service_path),
182 flimflam::kStateProperty, base::StringValue(flimflam::kStateOnline), 182 flimflam::kStateProperty, base::StringValue(flimflam::kStateOnline),
183 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 183 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
184 MessageLoop::current()->RunUntilIdle(); 184 base::MessageLoop::current()->RunUntilIdle();
185 } 185 }
186 186
187 private: 187 private:
188 void SetupDefaultShillState() { 188 void SetupDefaultShillState() {
189 MessageLoop::current()->RunUntilIdle(); 189 base::MessageLoop::current()->RunUntilIdle();
190 ShillServiceClient::TestInterface* service_test = 190 ShillServiceClient::TestInterface* service_test =
191 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 191 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
192 service_test->ClearServices(); 192 service_test->ClearServices();
193 const bool add_to_watchlist = true; 193 const bool add_to_watchlist = true;
194 service_test->AddService(kStubEthernet, 194 service_test->AddService(kStubEthernet,
195 kStubEthernet, 195 kStubEthernet,
196 flimflam::kTypeEthernet, flimflam::kStateIdle, 196 flimflam::kTypeEthernet, flimflam::kStateIdle,
197 add_to_watchlist); 197 add_to_watchlist);
198 service_test->AddService(kStubWireless1, 198 service_test->AddService(kStubWireless1,
199 kStubWireless1, 199 kStubWireless1,
200 flimflam::kTypeWifi, flimflam::kStateIdle, 200 flimflam::kTypeWifi, flimflam::kStateIdle,
201 add_to_watchlist); 201 add_to_watchlist);
202 service_test->AddService(kStubWireless2, 202 service_test->AddService(kStubWireless2,
203 kStubWireless2, 203 kStubWireless2,
204 flimflam::kTypeWifi, flimflam::kStateIdle, 204 flimflam::kTypeWifi, flimflam::kStateIdle,
205 add_to_watchlist); 205 add_to_watchlist);
206 service_test->AddService(kStubCellular, 206 service_test->AddService(kStubCellular,
207 kStubCellular, 207 kStubCellular,
208 flimflam::kTypeCellular, flimflam::kStateIdle, 208 flimflam::kTypeCellular, flimflam::kStateIdle,
209 add_to_watchlist); 209 add_to_watchlist);
210 } 210 }
211 211
212 void SetupNetworkHandler() { 212 void SetupNetworkHandler() {
213 SetupDefaultShillState(); 213 SetupDefaultShillState();
214 NetworkHandler::Initialize(); 214 NetworkHandler::Initialize();
215 } 215 }
216 216
217 MessageLoop message_loop_; 217 base::MessageLoop message_loop_;
218 scoped_ptr<TestingProfile> profile_; 218 scoped_ptr<TestingProfile> profile_;
219 scoped_ptr<NetworkPortalDetectorImpl> network_portal_detector_; 219 scoped_ptr<NetworkPortalDetectorImpl> network_portal_detector_;
220 }; 220 };
221 221
222 TEST_F(NetworkPortalDetectorImplTest, NoPortal) { 222 TEST_F(NetworkPortalDetectorImplTest, NoPortal) {
223 ASSERT_TRUE(is_state_idle()); 223 ASSERT_TRUE(is_state_idle());
224 224
225 SetConnected(kStubWireless1); 225 SetConnected(kStubWireless1);
226 226
227 ASSERT_TRUE(is_state_checking_for_portal()); 227 ASSERT_TRUE(is_state_checking_for_portal());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 TEST_F(NetworkPortalDetectorImplTest, PortalDetectionTimeout) { 370 TEST_F(NetworkPortalDetectorImplTest, PortalDetectionTimeout) {
371 ASSERT_TRUE(is_state_idle()); 371 ASSERT_TRUE(is_state_idle());
372 372
373 // For instantaneous timeout. 373 // For instantaneous timeout.
374 set_request_timeout(base::TimeDelta::FromSeconds(0)); 374 set_request_timeout(base::TimeDelta::FromSeconds(0));
375 375
376 ASSERT_TRUE(is_state_idle()); 376 ASSERT_TRUE(is_state_idle());
377 ASSERT_EQ(0, attempt_count()); 377 ASSERT_EQ(0, attempt_count());
378 378
379 SetConnected(kStubWireless1); 379 SetConnected(kStubWireless1);
380 MessageLoop::current()->RunUntilIdle(); 380 base::MessageLoop::current()->RunUntilIdle();
381 381
382 // First portal detection timeouts, next portal detection is 382 // First portal detection timeouts, next portal detection is
383 // scheduled. 383 // scheduled.
384 ASSERT_TRUE(is_state_portal_detection_pending()); 384 ASSERT_TRUE(is_state_portal_detection_pending());
385 ASSERT_EQ(1, attempt_count()); 385 ASSERT_EQ(1, attempt_count());
386 ASSERT_EQ(base::TimeDelta::FromSeconds(3), next_attempt_delay()); 386 ASSERT_EQ(base::TimeDelta::FromSeconds(3), next_attempt_delay());
387 } 387 }
388 388
389 TEST_F(NetworkPortalDetectorImplTest, PortalDetectionRetryAfter) { 389 TEST_F(NetworkPortalDetectorImplTest, PortalDetectionRetryAfter) {
390 ASSERT_TRUE(is_state_idle()); 390 ASSERT_TRUE(is_state_idle());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ASSERT_EQ(0, attempt_count()); 433 ASSERT_EQ(0, attempt_count());
434 434
435 SetConnected(kStubWireless1); 435 SetConnected(kStubWireless1);
436 436
437 CompleteURLFetch(net::OK, 503, retry_after); 437 CompleteURLFetch(net::OK, 503, retry_after);
438 ASSERT_TRUE(is_state_portal_detection_pending()); 438 ASSERT_TRUE(is_state_portal_detection_pending());
439 ASSERT_EQ(1, attempt_count()); 439 ASSERT_EQ(1, attempt_count());
440 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay()); 440 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
441 441
442 // To run CaptivePortalDetector::DetectCaptivePortal(). 442 // To run CaptivePortalDetector::DetectCaptivePortal().
443 MessageLoop::current()->RunUntilIdle(); 443 base::MessageLoop::current()->RunUntilIdle();
444 444
445 CompleteURLFetch(net::OK, 204, NULL); 445 CompleteURLFetch(net::OK, 204, NULL);
446 ASSERT_TRUE(is_state_idle()); 446 ASSERT_TRUE(is_state_idle());
447 ASSERT_EQ(2, attempt_count()); 447 ASSERT_EQ(2, attempt_count());
448 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, 448 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204,
449 kStubWireless1); 449 kStubWireless1);
450 } 450 }
451 451
452 TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) { 452 TEST_F(NetworkPortalDetectorImplTest, AllAttemptsFailed) {
453 ASSERT_TRUE(is_state_idle()); 453 ASSERT_TRUE(is_state_idle());
454 454
455 set_min_time_between_attempts(base::TimeDelta()); 455 set_min_time_between_attempts(base::TimeDelta());
456 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 0\n\n"; 456 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 0\n\n";
457 457
458 ASSERT_TRUE(is_state_idle()); 458 ASSERT_TRUE(is_state_idle());
459 ASSERT_EQ(0, attempt_count()); 459 ASSERT_EQ(0, attempt_count());
460 460
461 SetConnected(kStubWireless1); 461 SetConnected(kStubWireless1);
462 462
463 CompleteURLFetch(net::OK, 503, retry_after); 463 CompleteURLFetch(net::OK, 503, retry_after);
464 ASSERT_TRUE(is_state_portal_detection_pending()); 464 ASSERT_TRUE(is_state_portal_detection_pending());
465 ASSERT_EQ(1, attempt_count()); 465 ASSERT_EQ(1, attempt_count());
466 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay()); 466 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
467 467
468 // To run CaptivePortalDetector::DetectCaptivePortal(). 468 // To run CaptivePortalDetector::DetectCaptivePortal().
469 MessageLoop::current()->RunUntilIdle(); 469 base::MessageLoop::current()->RunUntilIdle();
470 470
471 CompleteURLFetch(net::OK, 503, retry_after); 471 CompleteURLFetch(net::OK, 503, retry_after);
472 ASSERT_TRUE(is_state_portal_detection_pending()); 472 ASSERT_TRUE(is_state_portal_detection_pending());
473 ASSERT_EQ(2, attempt_count()); 473 ASSERT_EQ(2, attempt_count());
474 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay()); 474 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
475 475
476 // To run CaptivePortalDetector::DetectCaptivePortal(). 476 // To run CaptivePortalDetector::DetectCaptivePortal().
477 MessageLoop::current()->RunUntilIdle(); 477 base::MessageLoop::current()->RunUntilIdle();
478 478
479 CompleteURLFetch(net::OK, 503, retry_after); 479 CompleteURLFetch(net::OK, 503, retry_after);
480 ASSERT_TRUE(is_state_idle()); 480 ASSERT_TRUE(is_state_idle());
481 ASSERT_EQ(3, attempt_count()); 481 ASSERT_EQ(3, attempt_count());
482 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE, 503, 482 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE, 503,
483 kStubWireless1); 483 kStubWireless1);
484 } 484 }
485 485
486 TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) { 486 TEST_F(NetworkPortalDetectorImplTest, ProxyAuthRequired) {
487 ASSERT_TRUE(is_state_idle()); 487 ASSERT_TRUE(is_state_idle());
488 set_min_time_between_attempts(base::TimeDelta()); 488 set_min_time_between_attempts(base::TimeDelta());
489 489
490 SetConnected(kStubWireless1); 490 SetConnected(kStubWireless1);
491 CompleteURLFetch(net::OK, 407, NULL); 491 CompleteURLFetch(net::OK, 407, NULL);
492 ASSERT_EQ(1, attempt_count()); 492 ASSERT_EQ(1, attempt_count());
493 ASSERT_TRUE(is_state_portal_detection_pending()); 493 ASSERT_TRUE(is_state_portal_detection_pending());
494 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, 494 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1,
495 kStubWireless1); 495 kStubWireless1);
496 496
497 // To run CaptivePortalDetector::DetectCaptivePortal(). 497 // To run CaptivePortalDetector::DetectCaptivePortal().
498 MessageLoop::current()->RunUntilIdle(); 498 base::MessageLoop::current()->RunUntilIdle();
499 499
500 CompleteURLFetch(net::OK, 407, NULL); 500 CompleteURLFetch(net::OK, 407, NULL);
501 ASSERT_EQ(2, attempt_count()); 501 ASSERT_EQ(2, attempt_count());
502 ASSERT_TRUE(is_state_portal_detection_pending()); 502 ASSERT_TRUE(is_state_portal_detection_pending());
503 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, 503 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1,
504 kStubWireless1); 504 kStubWireless1);
505 505
506 // To run CaptivePortalDetector::DetectCaptivePortal(). 506 // To run CaptivePortalDetector::DetectCaptivePortal().
507 MessageLoop::current()->RunUntilIdle(); 507 base::MessageLoop::current()->RunUntilIdle();
508 508
509 CompleteURLFetch(net::OK, 407, NULL); 509 CompleteURLFetch(net::OK, 407, NULL);
510 ASSERT_EQ(3, attempt_count()); 510 ASSERT_EQ(3, attempt_count());
511 ASSERT_TRUE(is_state_idle()); 511 ASSERT_TRUE(is_state_idle());
512 CheckPortalState( 512 CheckPortalState(
513 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED, 407, 513 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED, 407,
514 kStubWireless1); 514 kStubWireless1);
515 } 515 }
516 516
517 TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) { 517 TEST_F(NetworkPortalDetectorImplTest, NoResponseButBehindPortal) {
518 ASSERT_TRUE(is_state_idle()); 518 ASSERT_TRUE(is_state_idle());
519 set_min_time_between_attempts(base::TimeDelta()); 519 set_min_time_between_attempts(base::TimeDelta());
520 520
521 SetBehindPortal(kStubWireless1); 521 SetBehindPortal(kStubWireless1);
522 ASSERT_TRUE(is_state_checking_for_portal()); 522 ASSERT_TRUE(is_state_checking_for_portal());
523 523
524 CompleteURLFetch(net::ERR_CONNECTION_CLOSED, 524 CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
525 net::URLFetcher::RESPONSE_CODE_INVALID, 525 net::URLFetcher::RESPONSE_CODE_INVALID,
526 NULL); 526 NULL);
527 ASSERT_EQ(1, attempt_count()); 527 ASSERT_EQ(1, attempt_count());
528 ASSERT_TRUE(is_state_portal_detection_pending()); 528 ASSERT_TRUE(is_state_portal_detection_pending());
529 529
530 // To run CaptivePortalDetector::DetectCaptivePortal(). 530 // To run CaptivePortalDetector::DetectCaptivePortal().
531 MessageLoop::current()->RunUntilIdle(); 531 base::MessageLoop::current()->RunUntilIdle();
532 532
533 CompleteURLFetch(net::ERR_CONNECTION_CLOSED, 533 CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
534 net::URLFetcher::RESPONSE_CODE_INVALID, 534 net::URLFetcher::RESPONSE_CODE_INVALID,
535 NULL); 535 NULL);
536 ASSERT_EQ(2, attempt_count()); 536 ASSERT_EQ(2, attempt_count());
537 ASSERT_TRUE(is_state_portal_detection_pending()); 537 ASSERT_TRUE(is_state_portal_detection_pending());
538 538
539 // To run CaptivePortalDetector::DetectCaptivePortal(). 539 // To run CaptivePortalDetector::DetectCaptivePortal().
540 MessageLoop::current()->RunUntilIdle(); 540 base::MessageLoop::current()->RunUntilIdle();
541 541
542 CompleteURLFetch(net::ERR_CONNECTION_CLOSED, 542 CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
543 net::URLFetcher::RESPONSE_CODE_INVALID, 543 net::URLFetcher::RESPONSE_CODE_INVALID,
544 NULL); 544 NULL);
545 ASSERT_EQ(3, attempt_count()); 545 ASSERT_EQ(3, attempt_count());
546 ASSERT_TRUE(is_state_idle()); 546 ASSERT_TRUE(is_state_idle());
547 547
548 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 548 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL,
549 net::URLFetcher::RESPONSE_CODE_INVALID, 549 net::URLFetcher::RESPONSE_CODE_INVALID,
550 kStubWireless1); 550 kStubWireless1);
551 } 551 }
552 552
553 TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) { 553 TEST_F(NetworkPortalDetectorImplTest, LazyDetectionForOnlineNetwork) {
554 ASSERT_TRUE(is_state_idle()); 554 ASSERT_TRUE(is_state_idle());
555 set_min_time_between_attempts(base::TimeDelta()); 555 set_min_time_between_attempts(base::TimeDelta());
556 set_lazy_check_interval(base::TimeDelta()); 556 set_lazy_check_interval(base::TimeDelta());
557 557
558 SetConnected(kStubWireless1); 558 SetConnected(kStubWireless1);
559 enable_lazy_detection(); 559 enable_lazy_detection();
560 CompleteURLFetch(net::OK, 204, NULL); 560 CompleteURLFetch(net::OK, 204, NULL);
561 561
562 ASSERT_EQ(1, attempt_count()); 562 ASSERT_EQ(1, attempt_count());
563 ASSERT_TRUE(is_state_portal_detection_pending()); 563 ASSERT_TRUE(is_state_portal_detection_pending());
564 CheckPortalState( 564 CheckPortalState(
565 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, 565 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204,
566 kStubWireless1); 566 kStubWireless1);
567 567
568 // To run CaptivePortalDetector::DetectCaptivePortal(). 568 // To run CaptivePortalDetector::DetectCaptivePortal().
569 MessageLoop::current()->RunUntilIdle(); 569 base::MessageLoop::current()->RunUntilIdle();
570 570
571 CompleteURLFetch(net::OK, 204, NULL); 571 CompleteURLFetch(net::OK, 204, NULL);
572 572
573 ASSERT_EQ(2, attempt_count()); 573 ASSERT_EQ(2, attempt_count());
574 ASSERT_TRUE(is_state_portal_detection_pending()); 574 ASSERT_TRUE(is_state_portal_detection_pending());
575 CheckPortalState( 575 CheckPortalState(
576 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, 576 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204,
577 kStubWireless1); 577 kStubWireless1);
578 578
579 // To run CaptivePortalDetector::DetectCaptivePortal(). 579 // To run CaptivePortalDetector::DetectCaptivePortal().
580 MessageLoop::current()->RunUntilIdle(); 580 base::MessageLoop::current()->RunUntilIdle();
581 581
582 disable_lazy_detection(); 582 disable_lazy_detection();
583 583
584 // One more detection result, because DizableLazyDetection() doesn't 584 // One more detection result, because DizableLazyDetection() doesn't
585 // cancel last detection request. 585 // cancel last detection request.
586 CompleteURLFetch(net::OK, 204, NULL); 586 CompleteURLFetch(net::OK, 204, NULL);
587 ASSERT_EQ(3, attempt_count()); 587 ASSERT_EQ(3, attempt_count());
588 ASSERT_TRUE(is_state_idle()); 588 ASSERT_TRUE(is_state_idle());
589 CheckPortalState( 589 CheckPortalState(
590 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, 590 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204,
(...skipping 10 matching lines...) Expand all
601 601
602 CompleteURLFetch(net::ERR_CONNECTION_CLOSED, 602 CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
603 net::URLFetcher::RESPONSE_CODE_INVALID, 603 net::URLFetcher::RESPONSE_CODE_INVALID,
604 NULL); 604 NULL);
605 ASSERT_EQ(1, attempt_count()); 605 ASSERT_EQ(1, attempt_count());
606 ASSERT_TRUE(is_state_portal_detection_pending()); 606 ASSERT_TRUE(is_state_portal_detection_pending());
607 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, 607 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1,
608 kStubWireless1); 608 kStubWireless1);
609 609
610 // To run CaptivePortalDetector::DetectCaptivePortal(). 610 // To run CaptivePortalDetector::DetectCaptivePortal().
611 MessageLoop::current()->RunUntilIdle(); 611 base::MessageLoop::current()->RunUntilIdle();
612 612
613 CompleteURLFetch(net::ERR_CONNECTION_CLOSED, 613 CompleteURLFetch(net::ERR_CONNECTION_CLOSED,
614 net::URLFetcher::RESPONSE_CODE_INVALID, 614 net::URLFetcher::RESPONSE_CODE_INVALID,
615 NULL); 615 NULL);
616 ASSERT_EQ(2, attempt_count()); 616 ASSERT_EQ(2, attempt_count());
617 ASSERT_TRUE(is_state_portal_detection_pending()); 617 ASSERT_TRUE(is_state_portal_detection_pending());
618 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1, 618 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN, -1,
619 kStubWireless1); 619 kStubWireless1);
620 620
621 // To run CaptivePortalDetector::DetectCaptivePortal(). 621 // To run CaptivePortalDetector::DetectCaptivePortal().
622 MessageLoop::current()->RunUntilIdle(); 622 base::MessageLoop::current()->RunUntilIdle();
623 623
624 CompleteURLFetch(net::OK, 200, NULL); 624 CompleteURLFetch(net::OK, 200, NULL);
625 ASSERT_EQ(3, attempt_count()); 625 ASSERT_EQ(3, attempt_count());
626 ASSERT_TRUE(is_state_portal_detection_pending()); 626 ASSERT_TRUE(is_state_portal_detection_pending());
627 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, 627 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200,
628 kStubWireless1); 628 kStubWireless1);
629 629
630 // To run CaptivePortalDetector::DetectCaptivePortal(). 630 // To run CaptivePortalDetector::DetectCaptivePortal().
631 MessageLoop::current()->RunUntilIdle(); 631 base::MessageLoop::current()->RunUntilIdle();
632 632
633 disable_lazy_detection(); 633 disable_lazy_detection();
634 634
635 // One more detection result, because DizableLazyDetection() doesn't 635 // One more detection result, because DizableLazyDetection() doesn't
636 // cancel last detection request. 636 // cancel last detection request.
637 CompleteURLFetch(net::OK, 200, NULL); 637 CompleteURLFetch(net::OK, 200, NULL);
638 ASSERT_EQ(3, attempt_count()); 638 ASSERT_EQ(3, attempt_count());
639 ASSERT_TRUE(is_state_idle()); 639 ASSERT_TRUE(is_state_idle());
640 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, 640 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200,
641 kStubWireless1); 641 kStubWireless1);
(...skipping 29 matching lines...) Expand all
671 671
672 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204, 672 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE, 204,
673 kStubWireless1); 673 kStubWireless1);
674 ASSERT_TRUE(is_state_idle()); 674 ASSERT_TRUE(is_state_idle());
675 675
676 // First portal detection attempts determines PORTAL state. 676 // First portal detection attempts determines PORTAL state.
677 ASSERT_TRUE(start_detection_if_idle()); 677 ASSERT_TRUE(start_detection_if_idle());
678 ASSERT_TRUE(is_state_portal_detection_pending()); 678 ASSERT_TRUE(is_state_portal_detection_pending());
679 ASSERT_FALSE(start_detection_if_idle()); 679 ASSERT_FALSE(start_detection_if_idle());
680 680
681 MessageLoop::current()->RunUntilIdle(); 681 base::MessageLoop::current()->RunUntilIdle();
682 ASSERT_TRUE(is_state_checking_for_portal()); 682 ASSERT_TRUE(is_state_checking_for_portal());
683 CompleteURLFetch(net::OK, 200, NULL); 683 CompleteURLFetch(net::OK, 200, NULL);
684 684
685 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, 685 CheckPortalState(NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200,
686 kStubWireless1); 686 kStubWireless1);
687 ASSERT_TRUE(is_state_idle()); 687 ASSERT_TRUE(is_state_idle());
688 } 688 }
689 689
690 TEST_F(NetworkPortalDetectorImplTest, RequestTimeouts) { 690 TEST_F(NetworkPortalDetectorImplTest, RequestTimeouts) {
691 ASSERT_TRUE(is_state_idle()); 691 ASSERT_TRUE(is_state_idle());
692 set_min_time_between_attempts(base::TimeDelta()); 692 set_min_time_between_attempts(base::TimeDelta());
693 set_lazy_check_interval(base::TimeDelta()); 693 set_lazy_check_interval(base::TimeDelta());
694 694
695 SetNetworkDeviceEnabled(flimflam::kTypeWifi, false); 695 SetNetworkDeviceEnabled(flimflam::kTypeWifi, false);
696 SetConnected(kStubCellular); 696 SetConnected(kStubCellular);
697 697
698 // First portal detection attempt for cellular1 uses 5sec timeout. 698 // First portal detection attempt for cellular1 uses 5sec timeout.
699 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED, 699 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED,
700 net::URLFetcher::RESPONSE_CODE_INVALID); 700 net::URLFetcher::RESPONSE_CODE_INVALID);
701 701
702 // Second portal detection attempt for cellular1 uses 10sec timeout. 702 // Second portal detection attempt for cellular1 uses 10sec timeout.
703 ASSERT_TRUE(is_state_portal_detection_pending()); 703 ASSERT_TRUE(is_state_portal_detection_pending());
704 MessageLoop::current()->RunUntilIdle(); 704 base::MessageLoop::current()->RunUntilIdle();
705 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED, 705 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED,
706 net::URLFetcher::RESPONSE_CODE_INVALID); 706 net::URLFetcher::RESPONSE_CODE_INVALID);
707 707
708 // Third portal detection attempt for cellular1 uses 15sec timeout. 708 // Third portal detection attempt for cellular1 uses 15sec timeout.
709 ASSERT_TRUE(is_state_portal_detection_pending()); 709 ASSERT_TRUE(is_state_portal_detection_pending());
710 MessageLoop::current()->RunUntilIdle(); 710 base::MessageLoop::current()->RunUntilIdle();
711 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED, 711 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
712 net::URLFetcher::RESPONSE_CODE_INVALID); 712 net::URLFetcher::RESPONSE_CODE_INVALID);
713 713
714 ASSERT_TRUE(is_state_idle()); 714 ASSERT_TRUE(is_state_idle());
715 715
716 // Check that in lazy detection for cellular1 15sec timeout is used. 716 // Check that in lazy detection for cellular1 15sec timeout is used.
717 enable_lazy_detection(); 717 enable_lazy_detection();
718 ASSERT_TRUE(is_state_portal_detection_pending()); 718 ASSERT_TRUE(is_state_portal_detection_pending());
719 MessageLoop::current()->RunUntilIdle(); 719 base::MessageLoop::current()->RunUntilIdle();
720 disable_lazy_detection(); 720 disable_lazy_detection();
721 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED, 721 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
722 net::URLFetcher::RESPONSE_CODE_INVALID); 722 net::URLFetcher::RESPONSE_CODE_INVALID);
723 ASSERT_TRUE(is_state_idle()); 723 ASSERT_TRUE(is_state_idle());
724 724
725 SetNetworkDeviceEnabled(flimflam::kTypeWifi, true); 725 SetNetworkDeviceEnabled(flimflam::kTypeWifi, true);
726 SetConnected(kStubWireless1); 726 SetConnected(kStubWireless1);
727 727
728 // First portal detection attempt for wifi1 uses 5sec timeout. 728 // First portal detection attempt for wifi1 uses 5sec timeout.
729 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED, 729 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED,
730 net::URLFetcher::RESPONSE_CODE_INVALID); 730 net::URLFetcher::RESPONSE_CODE_INVALID);
731 731
732 // Second portal detection attempt for wifi1 also uses 5sec timeout. 732 // Second portal detection attempt for wifi1 also uses 5sec timeout.
733 ASSERT_TRUE(is_state_portal_detection_pending()); 733 ASSERT_TRUE(is_state_portal_detection_pending());
734 MessageLoop::current()->RunUntilIdle(); 734 base::MessageLoop::current()->RunUntilIdle();
735 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::OK, 204); 735 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::OK, 204);
736 ASSERT_TRUE(is_state_idle()); 736 ASSERT_TRUE(is_state_idle());
737 737
738 // Check that in lazy detection for wifi1 5sec timeout is used. 738 // Check that in lazy detection for wifi1 5sec timeout is used.
739 enable_lazy_detection(); 739 enable_lazy_detection();
740 ASSERT_TRUE(is_state_portal_detection_pending()); 740 ASSERT_TRUE(is_state_portal_detection_pending());
741 MessageLoop::current()->RunUntilIdle(); 741 base::MessageLoop::current()->RunUntilIdle();
742 disable_lazy_detection(); 742 disable_lazy_detection();
743 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::OK, 204); 743 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::OK, 204);
744 ASSERT_TRUE(is_state_idle()); 744 ASSERT_TRUE(is_state_idle());
745 } 745 }
746 746
747 TEST_F(NetworkPortalDetectorImplTest, StartDetectionIfIdle) { 747 TEST_F(NetworkPortalDetectorImplTest, StartDetectionIfIdle) {
748 ASSERT_TRUE(is_state_idle()); 748 ASSERT_TRUE(is_state_idle());
749 set_min_time_between_attempts(base::TimeDelta()); 749 set_min_time_between_attempts(base::TimeDelta());
750 SetConnected(kStubWireless1); 750 SetConnected(kStubWireless1);
751 751
752 // First portal detection attempt for wifi1 uses 5sec timeout. 752 // First portal detection attempt for wifi1 uses 5sec timeout.
753 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED, 753 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::ERR_CONNECTION_CLOSED,
754 net::URLFetcher::RESPONSE_CODE_INVALID); 754 net::URLFetcher::RESPONSE_CODE_INVALID);
755 ASSERT_TRUE(is_state_portal_detection_pending()); 755 ASSERT_TRUE(is_state_portal_detection_pending());
756 MessageLoop::current()->RunUntilIdle(); 756 base::MessageLoop::current()->RunUntilIdle();
757 757
758 // Second portal detection attempt for wifi1 uses 10sec timeout. 758 // Second portal detection attempt for wifi1 uses 10sec timeout.
759 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED, 759 CheckRequestTimeoutAndCompleteAttempt(2, 10, net::ERR_CONNECTION_CLOSED,
760 net::URLFetcher::RESPONSE_CODE_INVALID); 760 net::URLFetcher::RESPONSE_CODE_INVALID);
761 ASSERT_TRUE(is_state_portal_detection_pending()); 761 ASSERT_TRUE(is_state_portal_detection_pending());
762 MessageLoop::current()->RunUntilIdle(); 762 base::MessageLoop::current()->RunUntilIdle();
763 763
764 // Second portal detection attempt for wifi1 uses 15sec timeout. 764 // Second portal detection attempt for wifi1 uses 15sec timeout.
765 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED, 765 CheckRequestTimeoutAndCompleteAttempt(3, 15, net::ERR_CONNECTION_CLOSED,
766 net::URLFetcher::RESPONSE_CODE_INVALID); 766 net::URLFetcher::RESPONSE_CODE_INVALID);
767 ASSERT_TRUE(is_state_idle()); 767 ASSERT_TRUE(is_state_idle());
768 start_detection_if_idle(); 768 start_detection_if_idle();
769 769
770 ASSERT_TRUE(is_state_portal_detection_pending()); 770 ASSERT_TRUE(is_state_portal_detection_pending());
771 771
772 // First portal detection attempt for wifi1 uses 5sec timeout. 772 // First portal detection attempt for wifi1 uses 5sec timeout.
773 MessageLoop::current()->RunUntilIdle(); 773 base::MessageLoop::current()->RunUntilIdle();
774 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::OK, 204); 774 CheckRequestTimeoutAndCompleteAttempt(1, 5, net::OK, 204);
775 ASSERT_TRUE(is_state_idle()); 775 ASSERT_TRUE(is_state_idle());
776 } 776 }
777 777
778 } // namespace chromeos 778 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698