OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "content/browser/geofencing/geofencing_manager.h" | 7 #include "content/browser/geofencing/geofencing_manager.h" |
8 #include "content/browser/geofencing/geofencing_service.h" | 8 #include "content/browser/geofencing/geofencing_service.h" |
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 test_region_, | 404 test_region_, |
405 GEOFENCING_STATUS_OK, | 405 GEOFENCING_STATUS_OK, |
406 kTestGeofencingRegistrationId)); | 406 kTestGeofencingRegistrationId)); |
407 | 407 |
408 EXPECT_CALL(*service_, UnregisterRegion(kTestGeofencingRegistrationId)) | 408 EXPECT_CALL(*service_, UnregisterRegion(kTestGeofencingRegistrationId)) |
409 .WillOnce(QuitRunner(runner)); | 409 .WillOnce(QuitRunner(runner)); |
410 manager_->Shutdown(); | 410 manager_->Shutdown(); |
411 runner->Run(); | 411 runner->Run(); |
412 } | 412 } |
413 | 413 |
| 414 TEST_F(GeofencingManagerTest, RegisterRegion_MockedNoService) { |
| 415 manager_->SetMockProvider(kTestServiceWorkerRegistrationId, |
| 416 GeofencingMockState::SERVICE_UNAVAILABLE); |
| 417 // Make sure real service doesn't get called. |
| 418 EXPECT_CALL(*service_, IsServiceAvailable()).Times(0); |
| 419 |
| 420 EXPECT_EQ(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE, |
| 421 RegisterRegionSync(kTestServiceWorkerRegistrationId, kTestRegionId, |
| 422 test_region_)); |
| 423 } |
| 424 |
| 425 TEST_F(GeofencingManagerTest, UnregisterRegion_MockedNoService) { |
| 426 manager_->SetMockProvider(kTestServiceWorkerRegistrationId, |
| 427 GeofencingMockState::SERVICE_UNAVAILABLE); |
| 428 // Make sure real service doesn't get called. |
| 429 EXPECT_CALL(*service_, IsServiceAvailable()).Times(0); |
| 430 |
| 431 EXPECT_EQ(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE, |
| 432 UnregisterRegionSync(kTestServiceWorkerRegistrationId, |
| 433 kTestRegionId, false)); |
| 434 } |
| 435 |
| 436 TEST_F(GeofencingManagerTest, GetRegisteredRegions_MockedNoService) { |
| 437 manager_->SetMockProvider(kTestServiceWorkerRegistrationId, |
| 438 GeofencingMockState::SERVICE_UNAVAILABLE); |
| 439 // Make sure real service doesn't get called. |
| 440 EXPECT_CALL(*service_, IsServiceAvailable()).Times(0); |
| 441 |
| 442 RegionMap regions; |
| 443 EXPECT_EQ(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE, |
| 444 manager_->GetRegisteredRegions(kTestServiceWorkerRegistrationId, |
| 445 ®ions)); |
| 446 EXPECT_TRUE(regions.empty()); |
| 447 } |
| 448 |
| 449 TEST_F(GeofencingManagerTest, RegisterRegion_MockedService) { |
| 450 manager_->SetMockProvider(kTestServiceWorkerRegistrationId, |
| 451 GeofencingMockState::SERVICE_AVAILABLE); |
| 452 |
| 453 EXPECT_EQ(GEOFENCING_STATUS_OK, |
| 454 RegisterRegionSync(kTestServiceWorkerRegistrationId, kTestRegionId, |
| 455 test_region_)); |
| 456 VerifyRegions(kTestServiceWorkerRegistrationId, expected_regions_); |
| 457 } |
| 458 |
| 459 TEST_F(GeofencingManagerTest, SetMockProviderClearsRegistrations) { |
| 460 SetHasProviderForTests(); |
| 461 EXPECT_EQ(GEOFENCING_STATUS_OK, |
| 462 RegisterRegionSyncWithServiceResult( |
| 463 kTestServiceWorkerRegistrationId, kTestRegionId, test_region_, |
| 464 GEOFENCING_STATUS_OK, kTestGeofencingRegistrationId)); |
| 465 VerifyRegions(kTestServiceWorkerRegistrationId, expected_regions_); |
| 466 |
| 467 EXPECT_CALL(*service_, UnregisterRegion(kTestGeofencingRegistrationId)); |
| 468 |
| 469 manager_->SetMockProvider(kTestServiceWorkerRegistrationId, |
| 470 GeofencingMockState::SERVICE_AVAILABLE); |
| 471 VerifyRegions(kTestServiceWorkerRegistrationId, RegionMap()); |
| 472 } |
| 473 |
414 } // namespace content | 474 } // namespace content |
OLD | NEW |