| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "device/geolocation/fake_access_token_store.h" | 12 #include "device/geolocation/fake_access_token_store.h" |
| 13 #include "device/geolocation/fake_location_provider.h" |
| 13 #include "device/geolocation/geolocation_delegate.h" | 14 #include "device/geolocation/geolocation_delegate.h" |
| 14 #include "device/geolocation/geoposition.h" | 15 #include "device/geolocation/geoposition.h" |
| 15 #include "device/geolocation/mock_location_provider.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using ::testing::NiceMock; | 19 using ::testing::NiceMock; |
| 20 | 20 |
| 21 namespace device { | 21 namespace device { |
| 22 | 22 |
| 23 class MockLocationObserver { | 23 class MockLocationObserver { |
| 24 public: | 24 public: |
| 25 // Need a vtable for GMock. | 25 // Need a vtable for GMock. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 double g_fake_time_now_secs = 1; | 40 double g_fake_time_now_secs = 1; |
| 41 | 41 |
| 42 base::Time GetTimeNowForTest() { | 42 base::Time GetTimeNowForTest() { |
| 43 return base::Time::FromDoubleT(g_fake_time_now_secs); | 43 return base::Time::FromDoubleT(g_fake_time_now_secs); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void AdvanceTimeNow(const base::TimeDelta& delta) { | 46 void AdvanceTimeNow(const base::TimeDelta& delta) { |
| 47 g_fake_time_now_secs += delta.InSecondsF(); | 47 g_fake_time_now_secs += delta.InSecondsF(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void SetPositionFix(MockLocationProvider* provider, | 50 void SetPositionFix(FakeLocationProvider* provider, |
| 51 double latitude, | 51 double latitude, |
| 52 double longitude, | 52 double longitude, |
| 53 double accuracy) { | 53 double accuracy) { |
| 54 Geoposition position; | 54 Geoposition position; |
| 55 position.error_code = Geoposition::ERROR_CODE_NONE; | 55 position.error_code = Geoposition::ERROR_CODE_NONE; |
| 56 position.latitude = latitude; | 56 position.latitude = latitude; |
| 57 position.longitude = longitude; | 57 position.longitude = longitude; |
| 58 position.accuracy = accuracy; | 58 position.accuracy = accuracy; |
| 59 position.timestamp = GetTimeNowForTest(); | 59 position.timestamp = GetTimeNowForTest(); |
| 60 ASSERT_TRUE(position.Validate()); | 60 ASSERT_TRUE(position.Validate()); |
| 61 provider->HandlePositionChanged(position); | 61 provider->HandlePositionChanged(position); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void SetReferencePosition(MockLocationProvider* provider) { | 64 // TODO(lethalantidote): Populate a Geoposition in the class from kConstants |
| 65 // and then just copy that with "=" versus using a helper function. |
| 66 void SetReferencePosition(FakeLocationProvider* provider) { |
| 65 SetPositionFix(provider, 51.0, -0.1, 400); | 67 SetPositionFix(provider, 51.0, -0.1, 400); |
| 66 } | 68 } |
| 67 | 69 |
| 68 namespace { | 70 namespace { |
| 69 | 71 |
| 70 class FakeGeolocationDelegate : public GeolocationDelegate { | 72 class FakeGeolocationDelegate : public GeolocationDelegate { |
| 71 public: | 73 public: |
| 72 FakeGeolocationDelegate() = default; | 74 FakeGeolocationDelegate() = default; |
| 73 | 75 |
| 74 bool UseNetworkLocationProviders() override { return use_network_; } | 76 bool UseNetworkLocationProviders() override { return use_network_; } |
| 75 void set_use_network(bool use_network) { use_network_ = use_network; } | 77 void set_use_network(bool use_network) { use_network_ = use_network; } |
| 76 | 78 |
| 77 std::unique_ptr<LocationProvider> OverrideSystemLocationProvider() override { | 79 std::unique_ptr<LocationProvider> OverrideSystemLocationProvider() override { |
| 78 DCHECK(!mock_location_provider_); | 80 DCHECK(!mock_location_provider_); |
| 79 mock_location_provider_ = new MockLocationProvider; | 81 mock_location_provider_ = new FakeLocationProvider; |
| 80 return base::WrapUnique(mock_location_provider_); | 82 return base::WrapUnique(mock_location_provider_); |
| 81 } | 83 } |
| 82 | 84 |
| 83 MockLocationProvider* mock_location_provider() const { | 85 FakeLocationProvider* mock_location_provider() const { |
| 84 return mock_location_provider_; | 86 return mock_location_provider_; |
| 85 } | 87 } |
| 86 | 88 |
| 87 private: | 89 private: |
| 88 bool use_network_ = true; | 90 bool use_network_ = true; |
| 89 MockLocationProvider* mock_location_provider_ = nullptr; | 91 FakeLocationProvider* mock_location_provider_ = nullptr; |
| 90 | 92 |
| 91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); | 93 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 } // namespace | 96 } // namespace |
| 95 | 97 |
| 96 class TestingLocationArbitrator : public LocationArbitratorImpl { | 98 class TestingLocationArbitrator : public LocationArbitratorImpl { |
| 97 public: | 99 public: |
| 98 TestingLocationArbitrator( | 100 TestingLocationArbitrator( |
| 99 const LocationProviderUpdateCallback& callback, | 101 const LocationProviderUpdateCallback& callback, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 | 112 |
| 111 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { | 113 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { |
| 112 return access_token_store_; | 114 return access_token_store_; |
| 113 } | 115 } |
| 114 | 116 |
| 115 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( | 117 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
| 116 const scoped_refptr<AccessTokenStore>& access_token_store, | 118 const scoped_refptr<AccessTokenStore>& access_token_store, |
| 117 const scoped_refptr<net::URLRequestContextGetter>& context, | 119 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 118 const GURL& url, | 120 const GURL& url, |
| 119 const base::string16& access_token) override { | 121 const base::string16& access_token) override { |
| 120 cell_ = new MockLocationProvider; | 122 cell_ = new FakeLocationProvider; |
| 121 return base::WrapUnique(cell_); | 123 return base::WrapUnique(cell_); |
| 122 } | 124 } |
| 123 | 125 |
| 124 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { | 126 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { |
| 125 gps_ = new MockLocationProvider; | 127 gps_ = new FakeLocationProvider; |
| 126 return base::WrapUnique(gps_); | 128 return base::WrapUnique(gps_); |
| 127 } | 129 } |
| 128 | 130 |
| 129 // Two location providers, with nice short names to make the tests more | 131 // Two location providers, with nice short names to make the tests more |
| 130 // readable. Note |gps_| will only be set when there is a high accuracy | 132 // readable. Note |gps_| will only be set when there is a high accuracy |
| 131 // observer registered (and |cell_| when there's at least one observer of any | 133 // observer registered (and |cell_| when there's at least one observer of any |
| 132 // type). | 134 // type). |
| 133 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and | 135 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and |
| 134 // |gps_| to |gps_location_provider_| | 136 // |gps_| to |gps_location_provider_| |
| 135 MockLocationProvider* cell_; | 137 FakeLocationProvider* cell_; |
| 136 MockLocationProvider* gps_; | 138 FakeLocationProvider* gps_; |
| 137 const scoped_refptr<AccessTokenStore> access_token_store_; | 139 const scoped_refptr<AccessTokenStore> access_token_store_; |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 class GeolocationLocationArbitratorTest : public testing::Test { | 142 class GeolocationLocationArbitratorTest : public testing::Test { |
| 141 protected: | 143 protected: |
| 142 GeolocationLocationArbitratorTest() | 144 GeolocationLocationArbitratorTest() |
| 143 : access_token_store_(new NiceMock<FakeAccessTokenStore>), | 145 : access_token_store_(new NiceMock<FakeAccessTokenStore>), |
| 144 observer_(new MockLocationObserver), | 146 observer_(new MockLocationObserver), |
| 145 delegate_(new GeolocationDelegate) {} | 147 delegate_(new GeolocationDelegate) {} |
| 146 | 148 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 168 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 170 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
| 169 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 171 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
| 170 } | 172 } |
| 171 | 173 |
| 172 base::TimeDelta SwitchOnFreshnessCliff() { | 174 base::TimeDelta SwitchOnFreshnessCliff() { |
| 173 // Add 1, to ensure it meets any greater-than test. | 175 // Add 1, to ensure it meets any greater-than test. |
| 174 return base::TimeDelta::FromMilliseconds( | 176 return base::TimeDelta::FromMilliseconds( |
| 175 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 177 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); |
| 176 } | 178 } |
| 177 | 179 |
| 178 MockLocationProvider* cell() { return arbitrator_->cell_; } | 180 FakeLocationProvider* cell() { return arbitrator_->cell_; } |
| 179 | 181 |
| 180 MockLocationProvider* gps() { return arbitrator_->gps_; } | 182 FakeLocationProvider* gps() { return arbitrator_->gps_; } |
| 181 | 183 |
| 182 const scoped_refptr<FakeAccessTokenStore> access_token_store_; | 184 const scoped_refptr<FakeAccessTokenStore> access_token_store_; |
| 183 const std::unique_ptr<MockLocationObserver> observer_; | 185 const std::unique_ptr<MockLocationObserver> observer_; |
| 184 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 186 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
| 185 std::unique_ptr<GeolocationDelegate> delegate_; | 187 std::unique_ptr<GeolocationDelegate> delegate_; |
| 186 const base::MessageLoop loop_; | 188 const base::MessageLoop loop_; |
| 187 }; | 189 }; |
| 188 | 190 |
| 189 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 191 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
| 190 EXPECT_TRUE(access_token_store_.get()); | 192 EXPECT_TRUE(access_token_store_.get()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 212 | 214 |
| 213 EXPECT_FALSE(cell()); | 215 EXPECT_FALSE(cell()); |
| 214 EXPECT_FALSE(gps()); | 216 EXPECT_FALSE(gps()); |
| 215 arbitrator_->StartProvider(false); | 217 arbitrator_->StartProvider(false); |
| 216 | 218 |
| 217 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 219 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 218 | 220 |
| 219 access_token_store_->NotifyDelegateTokensLoaded(); | 221 access_token_store_->NotifyDelegateTokensLoaded(); |
| 220 ASSERT_TRUE(cell()); | 222 ASSERT_TRUE(cell()); |
| 221 EXPECT_TRUE(gps()); | 223 EXPECT_TRUE(gps()); |
| 222 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 224 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
| 223 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 225 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
| 224 EXPECT_FALSE(observer_->last_position_.Validate()); | 226 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 225 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 227 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 226 | 228 |
| 227 SetReferencePosition(cell()); | 229 SetReferencePosition(cell()); |
| 228 | 230 |
| 229 EXPECT_TRUE(observer_->last_position_.Validate() || | 231 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 230 observer_->last_position_.error_code != | 232 observer_->last_position_.error_code != |
| 231 Geoposition::ERROR_CODE_NONE); | 233 Geoposition::ERROR_CODE_NONE); |
| 232 EXPECT_EQ(cell()->position().latitude, observer_->last_position_.latitude); | 234 EXPECT_EQ(cell()->GetPosition().latitude, observer_->last_position_.latitude); |
| 233 | 235 |
| 234 EXPECT_FALSE(cell()->is_permission_granted()); | 236 EXPECT_FALSE(cell()->is_permission_granted()); |
| 235 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 237 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 236 arbitrator_->OnPermissionGranted(); | 238 arbitrator_->OnPermissionGranted(); |
| 237 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 239 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 238 EXPECT_TRUE(cell()->is_permission_granted()); | 240 EXPECT_TRUE(cell()->is_permission_granted()); |
| 239 } | 241 } |
| 240 | 242 |
| 241 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { | 243 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { |
| 242 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 244 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
| 243 fake_delegate->set_use_network(false); | 245 fake_delegate->set_use_network(false); |
| 244 | 246 |
| 245 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); | 247 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); |
| 246 InitializeArbitrator(std::move(delegate)); | 248 InitializeArbitrator(std::move(delegate)); |
| 247 ASSERT_TRUE(arbitrator_); | 249 ASSERT_TRUE(arbitrator_); |
| 248 | 250 |
| 249 EXPECT_FALSE(cell()); | 251 EXPECT_FALSE(cell()); |
| 250 EXPECT_FALSE(gps()); | 252 EXPECT_FALSE(gps()); |
| 251 arbitrator_->StartProvider(false); | 253 arbitrator_->StartProvider(false); |
| 252 | 254 |
| 253 ASSERT_FALSE(cell()); | 255 ASSERT_FALSE(cell()); |
| 254 EXPECT_FALSE(gps()); | 256 EXPECT_FALSE(gps()); |
| 255 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 257 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
| 256 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 258 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, |
| 257 fake_delegate->mock_location_provider()->state_); | 259 fake_delegate->mock_location_provider()->state_); |
| 258 EXPECT_FALSE(observer_->last_position_.Validate()); | 260 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 259 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 261 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 260 | 262 |
| 261 SetReferencePosition(fake_delegate->mock_location_provider()); | 263 SetReferencePosition(fake_delegate->mock_location_provider()); |
| 262 | 264 |
| 263 EXPECT_TRUE(observer_->last_position_.Validate() || | 265 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 264 observer_->last_position_.error_code != | 266 observer_->last_position_.error_code != |
| 265 Geoposition::ERROR_CODE_NONE); | 267 Geoposition::ERROR_CODE_NONE); |
| 266 EXPECT_EQ(fake_delegate->mock_location_provider()->position().latitude, | 268 EXPECT_EQ(fake_delegate->mock_location_provider()->GetPosition().latitude, |
| 267 observer_->last_position_.latitude); | 269 observer_->last_position_.latitude); |
| 268 | 270 |
| 269 EXPECT_FALSE( | 271 EXPECT_FALSE( |
| 270 fake_delegate->mock_location_provider()->is_permission_granted()); | 272 fake_delegate->mock_location_provider()->is_permission_granted()); |
| 271 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 273 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 272 arbitrator_->OnPermissionGranted(); | 274 arbitrator_->OnPermissionGranted(); |
| 273 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 275 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 274 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted()); | 276 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted()); |
| 275 } | 277 } |
| 276 | 278 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 287 EXPECT_FALSE(gps()); | 289 EXPECT_FALSE(gps()); |
| 288 arbitrator_->StartProvider(false); | 290 arbitrator_->StartProvider(false); |
| 289 | 291 |
| 290 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 292 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 291 | 293 |
| 292 access_token_store_->NotifyDelegateTokensLoaded(); | 294 access_token_store_->NotifyDelegateTokensLoaded(); |
| 293 | 295 |
| 294 ASSERT_TRUE(cell()); | 296 ASSERT_TRUE(cell()); |
| 295 EXPECT_FALSE(gps()); | 297 EXPECT_FALSE(gps()); |
| 296 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 298 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
| 297 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 299 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, |
| 298 fake_delegate->mock_location_provider()->state_); | 300 fake_delegate->mock_location_provider()->state_); |
| 299 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 301 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
| 300 EXPECT_FALSE(observer_->last_position_.Validate()); | 302 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 301 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 303 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 302 | 304 |
| 303 SetReferencePosition(cell()); | 305 SetReferencePosition(cell()); |
| 304 | 306 |
| 305 EXPECT_TRUE(observer_->last_position_.Validate() || | 307 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 306 observer_->last_position_.error_code != | 308 observer_->last_position_.error_code != |
| 307 Geoposition::ERROR_CODE_NONE); | 309 Geoposition::ERROR_CODE_NONE); |
| 308 EXPECT_EQ(cell()->position().latitude, observer_->last_position_.latitude); | 310 EXPECT_EQ(cell()->GetPosition().latitude, observer_->last_position_.latitude); |
| 309 | 311 |
| 310 EXPECT_FALSE(cell()->is_permission_granted()); | 312 EXPECT_FALSE(cell()->is_permission_granted()); |
| 311 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 313 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 312 arbitrator_->OnPermissionGranted(); | 314 arbitrator_->OnPermissionGranted(); |
| 313 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 315 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
| 314 EXPECT_TRUE(cell()->is_permission_granted()); | 316 EXPECT_TRUE(cell()->is_permission_granted()); |
| 315 } | 317 } |
| 316 | 318 |
| 317 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 319 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
| 318 InitializeArbitrator(nullptr); | 320 InitializeArbitrator(nullptr); |
| 319 arbitrator_->StartProvider(false); | 321 arbitrator_->StartProvider(false); |
| 320 access_token_store_->NotifyDelegateTokensLoaded(); | 322 access_token_store_->NotifyDelegateTokensLoaded(); |
| 321 ASSERT_TRUE(cell()); | 323 ASSERT_TRUE(cell()); |
| 322 ASSERT_TRUE(gps()); | 324 ASSERT_TRUE(gps()); |
| 323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 325 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
| 324 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 326 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
| 325 SetReferencePosition(cell()); | 327 SetReferencePosition(cell()); |
| 326 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 328 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
| 327 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 329 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
| 328 arbitrator_->StartProvider(true); | 330 arbitrator_->StartProvider(true); |
| 329 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); | 331 EXPECT_EQ(FakeLocationProvider::HIGH_ACCURACY, cell()->state_); |
| 330 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); | 332 EXPECT_EQ(FakeLocationProvider::HIGH_ACCURACY, gps()->state_); |
| 331 } | 333 } |
| 332 | 334 |
| 333 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { | 335 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { |
| 334 InitializeArbitrator(nullptr); | 336 InitializeArbitrator(nullptr); |
| 335 arbitrator_->StartProvider(false); | 337 arbitrator_->StartProvider(false); |
| 336 access_token_store_->NotifyDelegateTokensLoaded(); | 338 access_token_store_->NotifyDelegateTokensLoaded(); |
| 337 ASSERT_TRUE(cell()); | 339 ASSERT_TRUE(cell()); |
| 338 ASSERT_TRUE(gps()); | 340 ASSERT_TRUE(gps()); |
| 339 | 341 |
| 340 SetPositionFix(cell(), 1, 2, 150); | 342 SetPositionFix(cell(), 1, 2, 150); |
| 341 | 343 |
| 342 // First position available | 344 // First position available |
| 343 EXPECT_TRUE(observer_->last_position_.Validate()); | 345 EXPECT_TRUE(observer_->last_position_.Validate()); |
| 344 CheckLastPositionInfo(1, 2, 150); | 346 CheckLastPositionInfo(1, 2, 150); |
| 345 | 347 |
| 346 SetPositionFix(gps(), 3, 4, 50); | 348 SetPositionFix(gps(), 3, 4, 50); |
| 347 | 349 |
| 348 // More accurate fix available | 350 // More accurate fix available |
| 349 CheckLastPositionInfo(3, 4, 50); | 351 CheckLastPositionInfo(3, 4, 50); |
| 350 | 352 |
| 351 SetPositionFix(cell(), 5, 6, 150); | 353 SetPositionFix(cell(), 5, 6, 150); |
| 352 | 354 |
| 353 // New fix is available but it's less accurate, older fix should be kept. | 355 // New fix is available but it's less accurate, older fix should be kept. |
| 354 CheckLastPositionInfo(3, 4, 50); | 356 CheckLastPositionInfo(3, 4, 50); |
| 355 | 357 |
| 356 // Advance time, and notify once again | 358 // Advance time, and notify once again |
| 357 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 359 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
| 358 cell()->HandlePositionChanged(cell()->position()); | 360 cell()->HandlePositionChanged(cell()->GetPosition()); |
| 359 | 361 |
| 360 // New fix is available, less accurate but fresher | 362 // New fix is available, less accurate but fresher |
| 361 CheckLastPositionInfo(5, 6, 150); | 363 CheckLastPositionInfo(5, 6, 150); |
| 362 | 364 |
| 363 // Advance time, and set a low accuracy position | 365 // Advance time, and set a low accuracy position |
| 364 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 366 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
| 365 SetPositionFix(cell(), 5.676731, 139.629385, 1000); | 367 SetPositionFix(cell(), 5.676731, 139.629385, 1000); |
| 366 CheckLastPositionInfo(5.676731, 139.629385, 1000); | 368 CheckLastPositionInfo(5.676731, 139.629385, 1000); |
| 367 | 369 |
| 368 // 15 secs later, step outside. Switches to gps signal. | 370 // 15 secs later, step outside. Switches to gps signal. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 418 |
| 417 // Set the initial position. | 419 // Set the initial position. |
| 418 SetPositionFix(cell(), 3, 139, 100); | 420 SetPositionFix(cell(), 3, 139, 100); |
| 419 CheckLastPositionInfo(3, 139, 100); | 421 CheckLastPositionInfo(3, 139, 100); |
| 420 | 422 |
| 421 // Restart providers to simulate a one-shot request. | 423 // Restart providers to simulate a one-shot request. |
| 422 arbitrator_->StopProvider(); | 424 arbitrator_->StopProvider(); |
| 423 | 425 |
| 424 // To test 240956, perform a throwaway alloc. | 426 // To test 240956, perform a throwaway alloc. |
| 425 // This convinces the allocator to put the providers in a new memory location. | 427 // This convinces the allocator to put the providers in a new memory location. |
| 426 std::unique_ptr<MockLocationProvider> dummy_provider( | 428 std::unique_ptr<FakeLocationProvider> dummy_provider( |
| 427 new MockLocationProvider); | 429 new FakeLocationProvider); |
| 428 | 430 |
| 429 arbitrator_->StartProvider(false); | 431 arbitrator_->StartProvider(false); |
| 430 access_token_store_->NotifyDelegateTokensLoaded(); | 432 access_token_store_->NotifyDelegateTokensLoaded(); |
| 431 | 433 |
| 432 // Advance the time a short while to simulate successive calls. | 434 // Advance the time a short while to simulate successive calls. |
| 433 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 435 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
| 434 | 436 |
| 435 // Update with a less accurate position to verify 240956. | 437 // Update with a less accurate position to verify 240956. |
| 436 SetPositionFix(cell(), 3, 139, 150); | 438 SetPositionFix(cell(), 3, 139, 150); |
| 437 CheckLastPositionInfo(3, 139, 150); | 439 CheckLastPositionInfo(3, 139, 150); |
| 438 } | 440 } |
| 439 | 441 |
| 440 } // namespace device | 442 } // namespace device |
| OLD | NEW |