| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/geolocation/location_arbitrator_impl.h" | 5 #include "device/geolocation/location_arbitrator_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 165 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
| 166 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 166 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
| 167 } | 167 } |
| 168 | 168 |
| 169 base::TimeDelta SwitchOnFreshnessCliff() { | 169 base::TimeDelta SwitchOnFreshnessCliff() { |
| 170 // Add 1, to ensure it meets any greater-than test. | 170 // Add 1, to ensure it meets any greater-than test. |
| 171 return base::TimeDelta::FromMilliseconds( | 171 return base::TimeDelta::FromMilliseconds( |
| 172 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 172 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); |
| 173 } | 173 } |
| 174 | 174 |
| 175 MockLocationProvider* cell() { | 175 MockLocationProvider* cell() { return arbitrator_->cell_; } |
| 176 return arbitrator_->cell_; | |
| 177 } | |
| 178 | 176 |
| 179 MockLocationProvider* gps() { | 177 MockLocationProvider* gps() { return arbitrator_->gps_; } |
| 180 return arbitrator_->gps_; | |
| 181 } | |
| 182 | 178 |
| 183 const scoped_refptr<FakeAccessTokenStore> access_token_store_; | 179 const scoped_refptr<FakeAccessTokenStore> access_token_store_; |
| 184 const std::unique_ptr<MockLocationObserver> observer_; | 180 const std::unique_ptr<MockLocationObserver> observer_; |
| 185 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 181 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
| 186 std::unique_ptr<GeolocationDelegate> delegate_; | 182 std::unique_ptr<GeolocationDelegate> delegate_; |
| 187 const base::MessageLoop loop_; | 183 const base::MessageLoop loop_; |
| 188 }; | 184 }; |
| 189 | 185 |
| 190 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 186 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
| 191 EXPECT_TRUE(access_token_store_.get()); | 187 EXPECT_TRUE(access_token_store_.get()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 216 arbitrator_->StartProviders(false); | 212 arbitrator_->StartProviders(false); |
| 217 | 213 |
| 218 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 214 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 219 | 215 |
| 220 access_token_store_->NotifyDelegateTokensLoaded(); | 216 access_token_store_->NotifyDelegateTokensLoaded(); |
| 221 ASSERT_TRUE(cell()); | 217 ASSERT_TRUE(cell()); |
| 222 EXPECT_TRUE(gps()); | 218 EXPECT_TRUE(gps()); |
| 223 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 219 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 224 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 220 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 225 EXPECT_FALSE(observer_->last_position_.Validate()); | 221 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 226 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, | 222 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 227 observer_->last_position_.error_code); | |
| 228 | 223 |
| 229 SetReferencePosition(cell()); | 224 SetReferencePosition(cell()); |
| 230 | 225 |
| 231 EXPECT_TRUE(observer_->last_position_.Validate() || | 226 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 232 observer_->last_position_.error_code != | 227 observer_->last_position_.error_code != |
| 233 Geoposition::ERROR_CODE_NONE); | 228 Geoposition::ERROR_CODE_NONE); |
| 234 EXPECT_EQ(cell()->position_.latitude, | 229 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); |
| 235 observer_->last_position_.latitude); | |
| 236 | 230 |
| 237 EXPECT_FALSE(cell()->is_permission_granted_); | 231 EXPECT_FALSE(cell()->is_permission_granted_); |
| 238 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 232 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 239 arbitrator_->OnPermissionGranted(); | 233 arbitrator_->OnPermissionGranted(); |
| 240 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 234 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 241 EXPECT_TRUE(cell()->is_permission_granted_); | 235 EXPECT_TRUE(cell()->is_permission_granted_); |
| 242 } | 236 } |
| 243 | 237 |
| 244 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { | 238 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { |
| 245 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 239 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 427 |
| 434 // Advance the time a short while to simulate successive calls. | 428 // Advance the time a short while to simulate successive calls. |
| 435 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 429 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
| 436 | 430 |
| 437 // Update with a less accurate position to verify 240956. | 431 // Update with a less accurate position to verify 240956. |
| 438 SetPositionFix(cell(), 3, 139, 150); | 432 SetPositionFix(cell(), 3, 139, 150); |
| 439 CheckLastPositionInfo(3, 139, 150); | 433 CheckLastPositionInfo(3, 139, 150); |
| 440 } | 434 } |
| 441 | 435 |
| 442 } // namespace device | 436 } // namespace device |
| OLD | NEW |