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

Side by Side Diff: device/geolocation/location_arbitrator_impl_unittest.cc

Issue 2226143002: Gets rid of the LocationArbitrator interface, in preference for LocationProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removes LocationArbitrator.h Created 4 years, 4 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
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 EXPECT_FALSE(gps()); 202 EXPECT_FALSE(gps());
203 } 203 }
204 204
205 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { 205 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
206 InitializeArbitrator(nullptr); 206 InitializeArbitrator(nullptr);
207 ASSERT_TRUE(access_token_store_.get()); 207 ASSERT_TRUE(access_token_store_.get());
208 ASSERT_TRUE(arbitrator_); 208 ASSERT_TRUE(arbitrator_);
209 209
210 EXPECT_FALSE(cell()); 210 EXPECT_FALSE(cell());
211 EXPECT_FALSE(gps()); 211 EXPECT_FALSE(gps());
212 arbitrator_->StartProviders(false); 212 arbitrator_->StartProvider(false);
213 213
214 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 214 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
215 215
216 access_token_store_->NotifyDelegateTokensLoaded(); 216 access_token_store_->NotifyDelegateTokensLoaded();
217 ASSERT_TRUE(cell()); 217 ASSERT_TRUE(cell());
218 EXPECT_TRUE(gps()); 218 EXPECT_TRUE(gps());
219 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 219 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
220 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 220 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
221 EXPECT_FALSE(observer_->last_position_.Validate()); 221 EXPECT_FALSE(observer_->last_position_.Validate());
222 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 222 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
(...skipping 15 matching lines...) Expand all
238 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { 238 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) {
239 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; 239 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate;
240 fake_delegate->set_use_network(false); 240 fake_delegate->set_use_network(false);
241 241
242 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); 242 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate);
243 InitializeArbitrator(std::move(delegate)); 243 InitializeArbitrator(std::move(delegate));
244 ASSERT_TRUE(arbitrator_); 244 ASSERT_TRUE(arbitrator_);
245 245
246 EXPECT_FALSE(cell()); 246 EXPECT_FALSE(cell());
247 EXPECT_FALSE(gps()); 247 EXPECT_FALSE(gps());
248 arbitrator_->StartProviders(false); 248 arbitrator_->StartProvider(false);
249 249
250 ASSERT_FALSE(cell()); 250 ASSERT_FALSE(cell());
251 EXPECT_FALSE(gps()); 251 EXPECT_FALSE(gps());
252 ASSERT_TRUE(fake_delegate->mock_location_provider()); 252 ASSERT_TRUE(fake_delegate->mock_location_provider());
253 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 253 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
254 fake_delegate->mock_location_provider()->state_); 254 fake_delegate->mock_location_provider()->state_);
255 EXPECT_FALSE(observer_->last_position_.Validate()); 255 EXPECT_FALSE(observer_->last_position_.Validate());
256 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 256 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
257 257
258 SetReferencePosition(fake_delegate->mock_location_provider()); 258 SetReferencePosition(fake_delegate->mock_location_provider());
(...skipping 15 matching lines...) Expand all
274 CustomSystemAndDefaultNetworkProviders) { 274 CustomSystemAndDefaultNetworkProviders) {
275 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; 275 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate;
276 fake_delegate->set_use_network(true); 276 fake_delegate->set_use_network(true);
277 277
278 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); 278 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate);
279 InitializeArbitrator(std::move(delegate)); 279 InitializeArbitrator(std::move(delegate));
280 ASSERT_TRUE(arbitrator_); 280 ASSERT_TRUE(arbitrator_);
281 281
282 EXPECT_FALSE(cell()); 282 EXPECT_FALSE(cell());
283 EXPECT_FALSE(gps()); 283 EXPECT_FALSE(gps());
284 arbitrator_->StartProviders(false); 284 arbitrator_->StartProvider(false);
285 285
286 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 286 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
287 287
288 access_token_store_->NotifyDelegateTokensLoaded(); 288 access_token_store_->NotifyDelegateTokensLoaded();
289 289
290 ASSERT_TRUE(cell()); 290 ASSERT_TRUE(cell());
291 EXPECT_FALSE(gps()); 291 EXPECT_FALSE(gps());
292 ASSERT_TRUE(fake_delegate->mock_location_provider()); 292 ASSERT_TRUE(fake_delegate->mock_location_provider());
293 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 293 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
294 fake_delegate->mock_location_provider()->state_); 294 fake_delegate->mock_location_provider()->state_);
(...skipping 10 matching lines...) Expand all
305 305
306 EXPECT_FALSE(cell()->is_permission_granted_); 306 EXPECT_FALSE(cell()->is_permission_granted_);
307 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 307 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
308 arbitrator_->OnPermissionGranted(); 308 arbitrator_->OnPermissionGranted();
309 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 309 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
310 EXPECT_TRUE(cell()->is_permission_granted_); 310 EXPECT_TRUE(cell()->is_permission_granted_);
311 } 311 }
312 312
313 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { 313 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
314 InitializeArbitrator(nullptr); 314 InitializeArbitrator(nullptr);
315 arbitrator_->StartProviders(false); 315 arbitrator_->StartProvider(false);
316 access_token_store_->NotifyDelegateTokensLoaded(); 316 access_token_store_->NotifyDelegateTokensLoaded();
317 ASSERT_TRUE(cell()); 317 ASSERT_TRUE(cell());
318 ASSERT_TRUE(gps()); 318 ASSERT_TRUE(gps());
319 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 319 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
321 SetReferencePosition(cell()); 321 SetReferencePosition(cell());
322 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 322 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
324 arbitrator_->StartProviders(true); 324 arbitrator_->StartProvider(true);
325 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); 325 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_);
326 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); 326 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_);
327 } 327 }
328 328
329 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 329 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
330 InitializeArbitrator(nullptr); 330 InitializeArbitrator(nullptr);
331 arbitrator_->StartProviders(false); 331 arbitrator_->StartProvider(false);
332 access_token_store_->NotifyDelegateTokensLoaded(); 332 access_token_store_->NotifyDelegateTokensLoaded();
333 ASSERT_TRUE(cell()); 333 ASSERT_TRUE(cell());
334 ASSERT_TRUE(gps()); 334 ASSERT_TRUE(gps());
335 335
336 SetPositionFix(cell(), 1, 2, 150); 336 SetPositionFix(cell(), 1, 2, 150);
337 337
338 // First position available 338 // First position available
339 EXPECT_TRUE(observer_->last_position_.Validate()); 339 EXPECT_TRUE(observer_->last_position_.Validate());
340 CheckLastPositionInfo(1, 2, 150); 340 CheckLastPositionInfo(1, 2, 150);
341 341
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 398
399 // 2 minutes later 399 // 2 minutes later
400 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); 400 AdvanceTimeNow(base::TimeDelta::FromMinutes(2));
401 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 401 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
402 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 402 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
403 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 403 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
404 } 404 }
405 405
406 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { 406 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
407 InitializeArbitrator(nullptr); 407 InitializeArbitrator(nullptr);
408 arbitrator_->StartProviders(false); 408 arbitrator_->StartProvider(false);
409 access_token_store_->NotifyDelegateTokensLoaded(); 409 access_token_store_->NotifyDelegateTokensLoaded();
410 ASSERT_TRUE(cell()); 410 ASSERT_TRUE(cell());
411 ASSERT_TRUE(gps()); 411 ASSERT_TRUE(gps());
412 412
413 // Set the initial position. 413 // Set the initial position.
414 SetPositionFix(cell(), 3, 139, 100); 414 SetPositionFix(cell(), 3, 139, 100);
415 CheckLastPositionInfo(3, 139, 100); 415 CheckLastPositionInfo(3, 139, 100);
416 416
417 // Restart providers to simulate a one-shot request. 417 // Restart providers to simulate a one-shot request.
418 arbitrator_->StopProviders(); 418 arbitrator_->StopProvider();
419 419
420 // To test 240956, perform a throwaway alloc. 420 // To test 240956, perform a throwaway alloc.
421 // This convinces the allocator to put the providers in a new memory location. 421 // This convinces the allocator to put the providers in a new memory location.
422 std::unique_ptr<MockLocationProvider> dummy_provider( 422 std::unique_ptr<MockLocationProvider> dummy_provider(
423 new MockLocationProvider); 423 new MockLocationProvider);
424 424
425 arbitrator_->StartProviders(false); 425 arbitrator_->StartProvider(false);
426 access_token_store_->NotifyDelegateTokensLoaded(); 426 access_token_store_->NotifyDelegateTokensLoaded();
427 427
428 // Advance the time a short while to simulate successive calls. 428 // Advance the time a short while to simulate successive calls.
429 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 429 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
430 430
431 // Update with a less accurate position to verify 240956. 431 // Update with a less accurate position to verify 240956.
432 SetPositionFix(cell(), 3, 139, 150); 432 SetPositionFix(cell(), 3, 139, 150);
433 CheckLastPositionInfo(3, 139, 150); 433 CheckLastPositionInfo(3, 139, 150);
434 } 434 }
435 435
436 } // namespace device 436 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698