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.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/fake_location_provider.h" |
14 #include "device/geolocation/geolocation_delegate.h" | 14 #include "device/geolocation/geolocation_delegate.h" |
15 #include "device/geolocation/geoposition.h" | 15 #include "device/geolocation/geoposition.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. |
26 virtual ~MockLocationObserver() {} | 26 virtual ~MockLocationObserver() {} |
27 void InvalidateLastPosition() { | 27 void InvalidateLastPosition() { |
28 last_position_.latitude = 100; | 28 last_position_.latitude = 100; |
29 last_position_.error_code = Geoposition::ERROR_CODE_NONE; | 29 last_position_.error_code = Geoposition::ERROR_CODE_NONE; |
30 ASSERT_FALSE(last_position_.Validate()); | 30 ASSERT_FALSE(last_position_.Validate()); |
31 } | 31 } |
32 // Delegate | 32 // Delegate |
33 void OnLocationUpdate(const LocationProvider*, const Geoposition& position) { | 33 void OnLocationUpdate(const LocationProvider* provider, |
| 34 const Geoposition& position) { |
34 last_position_ = position; | 35 last_position_ = position; |
35 } | 36 } |
36 | 37 |
37 Geoposition last_position_; | 38 Geoposition last_position_; |
38 }; | 39 }; |
39 | 40 |
40 double g_fake_time_now_secs = 1; | 41 double g_fake_time_now_secs = 1; |
41 | 42 |
42 base::Time GetTimeNowForTest() { | 43 base::Time GetTimeNowForTest() { |
43 return base::Time::FromDoubleT(g_fake_time_now_secs); | 44 return base::Time::FromDoubleT(g_fake_time_now_secs); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 private: | 90 private: |
90 bool use_network_ = true; | 91 bool use_network_ = true; |
91 FakeLocationProvider* mock_location_provider_ = nullptr; | 92 FakeLocationProvider* mock_location_provider_ = nullptr; |
92 | 93 |
93 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); | 94 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); |
94 }; | 95 }; |
95 | 96 |
96 } // namespace | 97 } // namespace |
97 | 98 |
98 class TestingLocationArbitrator : public LocationArbitratorImpl { | 99 class TestingLocationArbitrator : public LocationArbitrator { |
99 public: | 100 public: |
100 TestingLocationArbitrator( | 101 TestingLocationArbitrator( |
101 const LocationProviderUpdateCallback& callback, | 102 const LocationProviderUpdateCallback& callback, |
102 const scoped_refptr<AccessTokenStore>& access_token_store, | 103 const scoped_refptr<AccessTokenStore>& access_token_store, |
103 GeolocationDelegate* delegate) | 104 GeolocationDelegate* delegate) |
104 : LocationArbitratorImpl(delegate), | 105 : LocationArbitrator(delegate), |
105 cell_(nullptr), | 106 cell_(nullptr), |
106 gps_(nullptr), | 107 gps_(nullptr), |
107 access_token_store_(access_token_store) { | 108 access_token_store_(access_token_store) { |
108 SetUpdateCallback(callback); | 109 SetUpdateCallback(callback); |
109 } | 110 } |
110 | 111 |
111 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } | 112 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } |
112 | 113 |
113 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { | 114 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { |
114 return access_token_store_; | 115 return access_token_store_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 Geoposition geoposition = observer_->last_position_; | 168 Geoposition geoposition = observer_->last_position_; |
168 EXPECT_TRUE(geoposition.Validate()); | 169 EXPECT_TRUE(geoposition.Validate()); |
169 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); | 170 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); |
170 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 171 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
171 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 172 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
172 } | 173 } |
173 | 174 |
174 base::TimeDelta SwitchOnFreshnessCliff() { | 175 base::TimeDelta SwitchOnFreshnessCliff() { |
175 // Add 1, to ensure it meets any greater-than test. | 176 // Add 1, to ensure it meets any greater-than test. |
176 return base::TimeDelta::FromMilliseconds( | 177 return base::TimeDelta::FromMilliseconds( |
177 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 178 LocationArbitrator::kFixStaleTimeoutMilliseconds + 1); |
178 } | 179 } |
179 | 180 |
180 FakeLocationProvider* cell() { return arbitrator_->cell_; } | 181 FakeLocationProvider* cell() { return arbitrator_->cell_; } |
181 | 182 |
182 FakeLocationProvider* gps() { return arbitrator_->gps_; } | 183 FakeLocationProvider* gps() { return arbitrator_->gps_; } |
183 | 184 |
184 const scoped_refptr<FakeAccessTokenStore> access_token_store_; | 185 const scoped_refptr<FakeAccessTokenStore> access_token_store_; |
185 const std::unique_ptr<MockLocationObserver> observer_; | 186 const std::unique_ptr<MockLocationObserver> observer_; |
186 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 187 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
187 std::unique_ptr<GeolocationDelegate> delegate_; | 188 std::unique_ptr<GeolocationDelegate> delegate_; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 434 |
434 // Advance the time a short while to simulate successive calls. | 435 // Advance the time a short while to simulate successive calls. |
435 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 436 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
436 | 437 |
437 // Update with a less accurate position to verify 240956. | 438 // Update with a less accurate position to verify 240956. |
438 SetPositionFix(cell(), 3, 139, 150); | 439 SetPositionFix(cell(), 3, 139, 150); |
439 CheckLastPositionInfo(3, 139, 150); | 440 CheckLastPositionInfo(3, 139, 150); |
440 } | 441 } |
441 | 442 |
442 } // namespace device | 443 } // namespace device |
OLD | NEW |