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 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "device/geolocation/fake_access_token_store.h" | 12 #include "device/geolocation/fake_access_token_store.h" |
12 #include "device/geolocation/geolocation_delegate.h" | 13 #include "device/geolocation/geolocation_delegate.h" |
13 #include "device/geolocation/geoposition.h" | 14 #include "device/geolocation/geoposition.h" |
14 #include "device/geolocation/mock_location_provider.h" | 15 #include "device/geolocation/mock_location_provider.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using ::testing::NiceMock; | 19 using ::testing::NiceMock; |
19 | 20 |
20 namespace device { | 21 namespace device { |
21 | 22 |
22 class MockLocationObserver { | 23 class MockLocationObserver { |
23 public: | 24 public: |
24 // Need a vtable for GMock. | 25 // Need a vtable for GMock. |
25 virtual ~MockLocationObserver() {} | 26 virtual ~MockLocationObserver() {} |
26 void InvalidateLastPosition() { | 27 void InvalidateLastPosition() { |
27 last_position_.latitude = 100; | 28 last_position_.latitude = 100; |
28 last_position_.error_code = Geoposition::ERROR_CODE_NONE; | 29 last_position_.error_code = Geoposition::ERROR_CODE_NONE; |
29 ASSERT_FALSE(last_position_.Validate()); | 30 ASSERT_FALSE(last_position_.Validate()); |
30 } | 31 } |
31 // Delegate | 32 // Delegate |
32 void OnLocationUpdate(const Geoposition& position) { | 33 void OnLocationUpdate(const LocationProvider*, const Geoposition& position) { |
33 last_position_ = position; | 34 last_position_ = position; |
34 } | 35 } |
35 | 36 |
36 Geoposition last_position_; | 37 Geoposition last_position_; |
37 }; | 38 }; |
38 | 39 |
39 double g_fake_time_now_secs = 1; | 40 double g_fake_time_now_secs = 1; |
40 | 41 |
41 base::Time GetTimeNowForTest() { | 42 base::Time GetTimeNowForTest() { |
42 return base::Time::FromDoubleT(g_fake_time_now_secs); | 43 return base::Time::FromDoubleT(g_fake_time_now_secs); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 MockLocationProvider* mock_location_provider_ = nullptr; | 89 MockLocationProvider* mock_location_provider_ = nullptr; |
89 | 90 |
90 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); |
91 }; | 92 }; |
92 | 93 |
93 } // namespace | 94 } // namespace |
94 | 95 |
95 class TestingLocationArbitrator : public LocationArbitratorImpl { | 96 class TestingLocationArbitrator : public LocationArbitratorImpl { |
96 public: | 97 public: |
97 TestingLocationArbitrator( | 98 TestingLocationArbitrator( |
98 const LocationArbitratorImpl::LocationUpdateCallback& callback, | 99 const LocationProviderUpdateCallback& callback, |
99 const scoped_refptr<AccessTokenStore>& access_token_store, | 100 const scoped_refptr<AccessTokenStore>& access_token_store, |
100 GeolocationDelegate* delegate) | 101 GeolocationDelegate* delegate) |
101 : LocationArbitratorImpl(callback, delegate), | 102 : LocationArbitratorImpl(delegate), |
102 cell_(nullptr), | 103 cell_(nullptr), |
103 gps_(nullptr), | 104 gps_(nullptr), |
104 access_token_store_(access_token_store) {} | 105 access_token_store_(access_token_store) { |
| 106 SetUpdateCallback(callback); |
| 107 } |
105 | 108 |
106 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } | 109 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } |
107 | 110 |
108 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { | 111 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { |
109 return access_token_store_; | 112 return access_token_store_; |
110 } | 113 } |
111 | 114 |
112 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( | 115 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
113 const scoped_refptr<AccessTokenStore>& access_token_store, | 116 const scoped_refptr<AccessTokenStore>& access_token_store, |
114 const scoped_refptr<net::URLRequestContextGetter>& context, | 117 const scoped_refptr<net::URLRequestContextGetter>& context, |
(...skipping 24 matching lines...) Expand all Loading... |
139 GeolocationLocationArbitratorTest() | 142 GeolocationLocationArbitratorTest() |
140 : access_token_store_(new NiceMock<FakeAccessTokenStore>), | 143 : access_token_store_(new NiceMock<FakeAccessTokenStore>), |
141 observer_(new MockLocationObserver), | 144 observer_(new MockLocationObserver), |
142 delegate_(new GeolocationDelegate) {} | 145 delegate_(new GeolocationDelegate) {} |
143 | 146 |
144 // Initializes |arbitrator_|, with the possibility of injecting a specific | 147 // Initializes |arbitrator_|, with the possibility of injecting a specific |
145 // |delegate|, otherwise a default, no-op GeolocationDelegate is used. | 148 // |delegate|, otherwise a default, no-op GeolocationDelegate is used. |
146 void InitializeArbitrator(std::unique_ptr<GeolocationDelegate> delegate) { | 149 void InitializeArbitrator(std::unique_ptr<GeolocationDelegate> delegate) { |
147 if (delegate) | 150 if (delegate) |
148 delegate_ = std::move(delegate); | 151 delegate_ = std::move(delegate); |
149 const LocationArbitratorImpl::LocationUpdateCallback callback = | 152 const LocationProvider::LocationProviderUpdateCallback callback = |
150 base::Bind(&MockLocationObserver::OnLocationUpdate, | 153 base::Bind(&MockLocationObserver::OnLocationUpdate, |
151 base::Unretained(observer_.get())); | 154 base::Unretained(observer_.get())); |
152 arbitrator_.reset(new TestingLocationArbitrator( | 155 arbitrator_.reset(new TestingLocationArbitrator( |
153 callback, access_token_store_, delegate_.get())); | 156 callback, access_token_store_, delegate_.get())); |
154 } | 157 } |
155 | 158 |
156 // testing::Test | 159 // testing::Test |
157 void TearDown() override {} | 160 void TearDown() override {} |
158 | 161 |
159 void CheckLastPositionInfo(double latitude, | 162 void CheckLastPositionInfo(double latitude, |
(...skipping 26 matching lines...) Expand all Loading... |
186 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 189 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
187 EXPECT_TRUE(access_token_store_.get()); | 190 EXPECT_TRUE(access_token_store_.get()); |
188 InitializeArbitrator(nullptr); | 191 InitializeArbitrator(nullptr); |
189 EXPECT_TRUE(arbitrator_); | 192 EXPECT_TRUE(arbitrator_); |
190 arbitrator_.reset(); | 193 arbitrator_.reset(); |
191 SUCCEED(); | 194 SUCCEED(); |
192 } | 195 } |
193 | 196 |
194 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { | 197 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { |
195 InitializeArbitrator(nullptr); | 198 InitializeArbitrator(nullptr); |
196 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
197 arbitrator_->OnPermissionGranted(); | 200 arbitrator_->OnPermissionGranted(); |
198 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
199 // Can't check the provider has been notified without going through the | 202 // Can't check the provider has been notified without going through the |
200 // motions to create the provider (see next test). | 203 // motions to create the provider (see next test). |
201 EXPECT_FALSE(cell()); | 204 EXPECT_FALSE(cell()); |
202 EXPECT_FALSE(gps()); | 205 EXPECT_FALSE(gps()); |
203 } | 206 } |
204 | 207 |
205 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { | 208 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { |
206 InitializeArbitrator(nullptr); | 209 InitializeArbitrator(nullptr); |
207 ASSERT_TRUE(access_token_store_.get()); | 210 ASSERT_TRUE(access_token_store_.get()); |
208 ASSERT_TRUE(arbitrator_); | 211 ASSERT_TRUE(arbitrator_); |
209 | 212 |
210 EXPECT_FALSE(cell()); | 213 EXPECT_FALSE(cell()); |
211 EXPECT_FALSE(gps()); | 214 EXPECT_FALSE(gps()); |
212 arbitrator_->StartProviders(false); | 215 arbitrator_->StartProvider(false); |
213 | 216 |
214 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 217 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
215 | 218 |
216 access_token_store_->NotifyDelegateTokensLoaded(); | 219 access_token_store_->NotifyDelegateTokensLoaded(); |
217 ASSERT_TRUE(cell()); | 220 ASSERT_TRUE(cell()); |
218 EXPECT_TRUE(gps()); | 221 EXPECT_TRUE(gps()); |
219 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 222 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
220 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 223 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
221 EXPECT_FALSE(observer_->last_position_.Validate()); | 224 EXPECT_FALSE(observer_->last_position_.Validate()); |
222 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 225 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
223 | 226 |
224 SetReferencePosition(cell()); | 227 SetReferencePosition(cell()); |
225 | 228 |
226 EXPECT_TRUE(observer_->last_position_.Validate() || | 229 EXPECT_TRUE(observer_->last_position_.Validate() || |
227 observer_->last_position_.error_code != | 230 observer_->last_position_.error_code != |
228 Geoposition::ERROR_CODE_NONE); | 231 Geoposition::ERROR_CODE_NONE); |
229 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); | 232 EXPECT_EQ(cell()->position().latitude, observer_->last_position_.latitude); |
230 | 233 |
231 EXPECT_FALSE(cell()->is_permission_granted_); | 234 EXPECT_FALSE(cell()->is_permission_granted()); |
232 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 235 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
233 arbitrator_->OnPermissionGranted(); | 236 arbitrator_->OnPermissionGranted(); |
234 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 237 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
235 EXPECT_TRUE(cell()->is_permission_granted_); | 238 EXPECT_TRUE(cell()->is_permission_granted()); |
236 } | 239 } |
237 | 240 |
238 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { | 241 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { |
239 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 242 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
240 fake_delegate->set_use_network(false); | 243 fake_delegate->set_use_network(false); |
241 | 244 |
242 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); | 245 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); |
243 InitializeArbitrator(std::move(delegate)); | 246 InitializeArbitrator(std::move(delegate)); |
244 ASSERT_TRUE(arbitrator_); | 247 ASSERT_TRUE(arbitrator_); |
245 | 248 |
246 EXPECT_FALSE(cell()); | 249 EXPECT_FALSE(cell()); |
247 EXPECT_FALSE(gps()); | 250 EXPECT_FALSE(gps()); |
248 arbitrator_->StartProviders(false); | 251 arbitrator_->StartProvider(false); |
249 | 252 |
250 ASSERT_FALSE(cell()); | 253 ASSERT_FALSE(cell()); |
251 EXPECT_FALSE(gps()); | 254 EXPECT_FALSE(gps()); |
252 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 255 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
253 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 256 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, |
254 fake_delegate->mock_location_provider()->state_); | 257 fake_delegate->mock_location_provider()->state_); |
255 EXPECT_FALSE(observer_->last_position_.Validate()); | 258 EXPECT_FALSE(observer_->last_position_.Validate()); |
256 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 259 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
257 | 260 |
258 SetReferencePosition(fake_delegate->mock_location_provider()); | 261 SetReferencePosition(fake_delegate->mock_location_provider()); |
259 | 262 |
260 EXPECT_TRUE(observer_->last_position_.Validate() || | 263 EXPECT_TRUE(observer_->last_position_.Validate() || |
261 observer_->last_position_.error_code != | 264 observer_->last_position_.error_code != |
262 Geoposition::ERROR_CODE_NONE); | 265 Geoposition::ERROR_CODE_NONE); |
263 EXPECT_EQ(fake_delegate->mock_location_provider()->position_.latitude, | 266 EXPECT_EQ(fake_delegate->mock_location_provider()->position().latitude, |
264 observer_->last_position_.latitude); | 267 observer_->last_position_.latitude); |
265 | 268 |
266 EXPECT_FALSE(fake_delegate->mock_location_provider()->is_permission_granted_); | 269 EXPECT_FALSE( |
267 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 270 fake_delegate->mock_location_provider()->is_permission_granted()); |
| 271 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
268 arbitrator_->OnPermissionGranted(); | 272 arbitrator_->OnPermissionGranted(); |
269 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 273 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
270 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted_); | 274 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted()); |
271 } | 275 } |
272 | 276 |
273 TEST_F(GeolocationLocationArbitratorTest, | 277 TEST_F(GeolocationLocationArbitratorTest, |
274 CustomSystemAndDefaultNetworkProviders) { | 278 CustomSystemAndDefaultNetworkProviders) { |
275 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 279 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
276 fake_delegate->set_use_network(true); | 280 fake_delegate->set_use_network(true); |
277 | 281 |
278 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); | 282 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); |
279 InitializeArbitrator(std::move(delegate)); | 283 InitializeArbitrator(std::move(delegate)); |
280 ASSERT_TRUE(arbitrator_); | 284 ASSERT_TRUE(arbitrator_); |
281 | 285 |
282 EXPECT_FALSE(cell()); | 286 EXPECT_FALSE(cell()); |
283 EXPECT_FALSE(gps()); | 287 EXPECT_FALSE(gps()); |
284 arbitrator_->StartProviders(false); | 288 arbitrator_->StartProvider(false); |
285 | 289 |
286 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 290 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
287 | 291 |
288 access_token_store_->NotifyDelegateTokensLoaded(); | 292 access_token_store_->NotifyDelegateTokensLoaded(); |
289 | 293 |
290 ASSERT_TRUE(cell()); | 294 ASSERT_TRUE(cell()); |
291 EXPECT_FALSE(gps()); | 295 EXPECT_FALSE(gps()); |
292 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 296 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
293 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 297 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, |
294 fake_delegate->mock_location_provider()->state_); | 298 fake_delegate->mock_location_provider()->state_); |
295 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 299 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
296 EXPECT_FALSE(observer_->last_position_.Validate()); | 300 EXPECT_FALSE(observer_->last_position_.Validate()); |
297 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 301 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
298 | 302 |
299 SetReferencePosition(cell()); | 303 SetReferencePosition(cell()); |
300 | 304 |
301 EXPECT_TRUE(observer_->last_position_.Validate() || | 305 EXPECT_TRUE(observer_->last_position_.Validate() || |
302 observer_->last_position_.error_code != | 306 observer_->last_position_.error_code != |
303 Geoposition::ERROR_CODE_NONE); | 307 Geoposition::ERROR_CODE_NONE); |
304 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); | 308 EXPECT_EQ(cell()->position().latitude, observer_->last_position_.latitude); |
305 | 309 |
306 EXPECT_FALSE(cell()->is_permission_granted_); | 310 EXPECT_FALSE(cell()->is_permission_granted()); |
307 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 311 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
308 arbitrator_->OnPermissionGranted(); | 312 arbitrator_->OnPermissionGranted(); |
309 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 313 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
310 EXPECT_TRUE(cell()->is_permission_granted_); | 314 EXPECT_TRUE(cell()->is_permission_granted()); |
311 } | 315 } |
312 | 316 |
313 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 317 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
314 InitializeArbitrator(nullptr); | 318 InitializeArbitrator(nullptr); |
315 arbitrator_->StartProviders(false); | 319 arbitrator_->StartProvider(false); |
316 access_token_store_->NotifyDelegateTokensLoaded(); | 320 access_token_store_->NotifyDelegateTokensLoaded(); |
317 ASSERT_TRUE(cell()); | 321 ASSERT_TRUE(cell()); |
318 ASSERT_TRUE(gps()); | 322 ASSERT_TRUE(gps()); |
319 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 324 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
321 SetReferencePosition(cell()); | 325 SetReferencePosition(cell()); |
322 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 326 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 327 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
324 arbitrator_->StartProviders(true); | 328 arbitrator_->StartProvider(true); |
325 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); | 329 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); |
326 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); | 330 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); |
327 } | 331 } |
328 | 332 |
329 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { | 333 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { |
330 InitializeArbitrator(nullptr); | 334 InitializeArbitrator(nullptr); |
331 arbitrator_->StartProviders(false); | 335 arbitrator_->StartProvider(false); |
332 access_token_store_->NotifyDelegateTokensLoaded(); | 336 access_token_store_->NotifyDelegateTokensLoaded(); |
333 ASSERT_TRUE(cell()); | 337 ASSERT_TRUE(cell()); |
334 ASSERT_TRUE(gps()); | 338 ASSERT_TRUE(gps()); |
335 | 339 |
336 SetPositionFix(cell(), 1, 2, 150); | 340 SetPositionFix(cell(), 1, 2, 150); |
337 | 341 |
338 // First position available | 342 // First position available |
339 EXPECT_TRUE(observer_->last_position_.Validate()); | 343 EXPECT_TRUE(observer_->last_position_.Validate()); |
340 CheckLastPositionInfo(1, 2, 150); | 344 CheckLastPositionInfo(1, 2, 150); |
341 | 345 |
342 SetPositionFix(gps(), 3, 4, 50); | 346 SetPositionFix(gps(), 3, 4, 50); |
343 | 347 |
344 // More accurate fix available | 348 // More accurate fix available |
345 CheckLastPositionInfo(3, 4, 50); | 349 CheckLastPositionInfo(3, 4, 50); |
346 | 350 |
347 SetPositionFix(cell(), 5, 6, 150); | 351 SetPositionFix(cell(), 5, 6, 150); |
348 | 352 |
349 // New fix is available but it's less accurate, older fix should be kept. | 353 // New fix is available but it's less accurate, older fix should be kept. |
350 CheckLastPositionInfo(3, 4, 50); | 354 CheckLastPositionInfo(3, 4, 50); |
351 | 355 |
352 // Advance time, and notify once again | 356 // Advance time, and notify once again |
353 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 357 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
354 cell()->HandlePositionChanged(cell()->position_); | 358 cell()->HandlePositionChanged(cell()->position()); |
355 | 359 |
356 // New fix is available, less accurate but fresher | 360 // New fix is available, less accurate but fresher |
357 CheckLastPositionInfo(5, 6, 150); | 361 CheckLastPositionInfo(5, 6, 150); |
358 | 362 |
359 // Advance time, and set a low accuracy position | 363 // Advance time, and set a low accuracy position |
360 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 364 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
361 SetPositionFix(cell(), 5.676731, 139.629385, 1000); | 365 SetPositionFix(cell(), 5.676731, 139.629385, 1000); |
362 CheckLastPositionInfo(5.676731, 139.629385, 1000); | 366 CheckLastPositionInfo(5.676731, 139.629385, 1000); |
363 | 367 |
364 // 15 secs later, step outside. Switches to gps signal. | 368 // 15 secs later, step outside. Switches to gps signal. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 402 |
399 // 2 minutes later | 403 // 2 minutes later |
400 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); | 404 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); |
401 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. | 405 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. |
402 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); | 406 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); |
403 CheckLastPositionInfo(3.5658700, 139.069979, 1000); | 407 CheckLastPositionInfo(3.5658700, 139.069979, 1000); |
404 } | 408 } |
405 | 409 |
406 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { | 410 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { |
407 InitializeArbitrator(nullptr); | 411 InitializeArbitrator(nullptr); |
408 arbitrator_->StartProviders(false); | 412 arbitrator_->StartProvider(false); |
409 access_token_store_->NotifyDelegateTokensLoaded(); | 413 access_token_store_->NotifyDelegateTokensLoaded(); |
410 ASSERT_TRUE(cell()); | 414 ASSERT_TRUE(cell()); |
411 ASSERT_TRUE(gps()); | 415 ASSERT_TRUE(gps()); |
412 | 416 |
413 // Set the initial position. | 417 // Set the initial position. |
414 SetPositionFix(cell(), 3, 139, 100); | 418 SetPositionFix(cell(), 3, 139, 100); |
415 CheckLastPositionInfo(3, 139, 100); | 419 CheckLastPositionInfo(3, 139, 100); |
416 | 420 |
417 // Restart providers to simulate a one-shot request. | 421 // Restart providers to simulate a one-shot request. |
418 arbitrator_->StopProviders(); | 422 arbitrator_->StopProvider(); |
419 | 423 |
420 // To test 240956, perform a throwaway alloc. | 424 // To test 240956, perform a throwaway alloc. |
421 // This convinces the allocator to put the providers in a new memory location. | 425 // This convinces the allocator to put the providers in a new memory location. |
422 std::unique_ptr<MockLocationProvider> dummy_provider( | 426 std::unique_ptr<MockLocationProvider> dummy_provider( |
423 new MockLocationProvider); | 427 new MockLocationProvider); |
424 | 428 |
425 arbitrator_->StartProviders(false); | 429 arbitrator_->StartProvider(false); |
426 access_token_store_->NotifyDelegateTokensLoaded(); | 430 access_token_store_->NotifyDelegateTokensLoaded(); |
427 | 431 |
428 // Advance the time a short while to simulate successive calls. | 432 // Advance the time a short while to simulate successive calls. |
429 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 433 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
430 | 434 |
431 // Update with a less accurate position to verify 240956. | 435 // Update with a less accurate position to verify 240956. |
432 SetPositionFix(cell(), 3, 139, 150); | 436 SetPositionFix(cell(), 3, 139, 150); |
433 CheckLastPositionInfo(3, 139, 150); | 437 CheckLastPositionInfo(3, 139, 150); |
434 } | 438 } |
435 | 439 |
436 } // namespace device | 440 } // namespace device |
OLD | NEW |