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 LocationArbitratorImpl::LocationUpdateCallback& callback, | 101 const LocationArbitratorImpl::LocationUpdateCallback& callback, |
100 const scoped_refptr<AccessTokenStore>& access_token_store, | 102 const scoped_refptr<AccessTokenStore>& access_token_store, |
101 GeolocationDelegate* delegate) | 103 GeolocationDelegate* delegate) |
102 : LocationArbitratorImpl(callback, delegate), | 104 : LocationArbitratorImpl(callback, delegate), |
103 cell_(nullptr), | 105 cell_(nullptr), |
104 gps_(nullptr), | 106 gps_(nullptr), |
105 access_token_store_(access_token_store) {} | 107 access_token_store_(access_token_store) {} |
106 | 108 |
107 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } | 109 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } |
108 | 110 |
109 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { | 111 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override { |
110 return access_token_store_; | 112 return access_token_store_; |
111 } | 113 } |
112 | 114 |
113 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( | 115 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
114 const scoped_refptr<AccessTokenStore>& access_token_store, | 116 const scoped_refptr<AccessTokenStore>& access_token_store, |
115 const scoped_refptr<net::URLRequestContextGetter>& context, | 117 const scoped_refptr<net::URLRequestContextGetter>& context, |
116 const GURL& url, | 118 const GURL& url, |
117 const base::string16& access_token) override { | 119 const base::string16& access_token) override { |
118 cell_ = new MockLocationProvider; | 120 cell_ = new FakeLocationProvider; |
119 return base::WrapUnique(cell_); | 121 return base::WrapUnique(cell_); |
120 } | 122 } |
121 | 123 |
122 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { | 124 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { |
123 gps_ = new MockLocationProvider; | 125 gps_ = new FakeLocationProvider; |
124 return base::WrapUnique(gps_); | 126 return base::WrapUnique(gps_); |
125 } | 127 } |
126 | 128 |
127 // Two location providers, with nice short names to make the tests more | 129 // Two location providers, with nice short names to make the tests more |
128 // readable. Note |gps_| will only be set when there is a high accuracy | 130 // readable. Note |gps_| will only be set when there is a high accuracy |
129 // observer registered (and |cell_| when there's at least one observer of any | 131 // observer registered (and |cell_| when there's at least one observer of any |
130 // type). | 132 // type). |
131 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and | 133 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and |
132 // |gps_| to |gps_location_provider_| | 134 // |gps_| to |gps_location_provider_| |
133 MockLocationProvider* cell_; | 135 FakeLocationProvider* cell_; |
134 MockLocationProvider* gps_; | 136 FakeLocationProvider* gps_; |
135 const scoped_refptr<AccessTokenStore> access_token_store_; | 137 const scoped_refptr<AccessTokenStore> access_token_store_; |
136 }; | 138 }; |
137 | 139 |
138 class GeolocationLocationArbitratorTest : public testing::Test { | 140 class GeolocationLocationArbitratorTest : public testing::Test { |
139 protected: | 141 protected: |
140 GeolocationLocationArbitratorTest() | 142 GeolocationLocationArbitratorTest() |
141 : access_token_store_(new NiceMock<FakeAccessTokenStore>), | 143 : access_token_store_(new NiceMock<FakeAccessTokenStore>), |
142 observer_(new MockLocationObserver), | 144 observer_(new MockLocationObserver), |
143 delegate_(new GeolocationDelegate) {} | 145 delegate_(new GeolocationDelegate) {} |
144 | 146 |
(...skipping 21 matching lines...) Expand all Loading... |
166 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 168 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
167 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 169 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
168 } | 170 } |
169 | 171 |
170 base::TimeDelta SwitchOnFreshnessCliff() { | 172 base::TimeDelta SwitchOnFreshnessCliff() { |
171 // Add 1, to ensure it meets any greater-than test. | 173 // Add 1, to ensure it meets any greater-than test. |
172 return base::TimeDelta::FromMilliseconds( | 174 return base::TimeDelta::FromMilliseconds( |
173 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 175 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); |
174 } | 176 } |
175 | 177 |
176 MockLocationProvider* cell() { return arbitrator_->cell_; } | 178 FakeLocationProvider* cell() { return arbitrator_->cell_; } |
177 | 179 |
178 MockLocationProvider* gps() { return arbitrator_->gps_; } | 180 FakeLocationProvider* gps() { return arbitrator_->gps_; } |
179 | 181 |
180 const scoped_refptr<FakeAccessTokenStore> access_token_store_; | 182 const scoped_refptr<FakeAccessTokenStore> access_token_store_; |
181 const std::unique_ptr<MockLocationObserver> observer_; | 183 const std::unique_ptr<MockLocationObserver> observer_; |
182 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 184 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
183 std::unique_ptr<GeolocationDelegate> delegate_; | 185 std::unique_ptr<GeolocationDelegate> delegate_; |
184 const base::MessageLoop loop_; | 186 const base::MessageLoop loop_; |
185 }; | 187 }; |
186 | 188 |
187 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 189 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
188 EXPECT_TRUE(access_token_store_.get()); | 190 EXPECT_TRUE(access_token_store_.get()); |
(...skipping 21 matching lines...) Expand all Loading... |
210 | 212 |
211 EXPECT_FALSE(cell()); | 213 EXPECT_FALSE(cell()); |
212 EXPECT_FALSE(gps()); | 214 EXPECT_FALSE(gps()); |
213 arbitrator_->StartProvider(false); | 215 arbitrator_->StartProvider(false); |
214 | 216 |
215 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 217 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
216 | 218 |
217 access_token_store_->NotifyDelegateTokensLoaded(); | 219 access_token_store_->NotifyDelegateTokensLoaded(); |
218 ASSERT_TRUE(cell()); | 220 ASSERT_TRUE(cell()); |
219 EXPECT_TRUE(gps()); | 221 EXPECT_TRUE(gps()); |
220 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 222 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
221 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 223 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
222 EXPECT_FALSE(observer_->last_position_.Validate()); | 224 EXPECT_FALSE(observer_->last_position_.Validate()); |
223 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 225 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
224 | 226 |
225 SetReferencePosition(cell()); | 227 SetReferencePosition(cell()); |
226 | 228 |
227 EXPECT_TRUE(observer_->last_position_.Validate() || | 229 EXPECT_TRUE(observer_->last_position_.Validate() || |
228 observer_->last_position_.error_code != | 230 observer_->last_position_.error_code != |
229 Geoposition::ERROR_CODE_NONE); | 231 Geoposition::ERROR_CODE_NONE); |
230 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); | 232 EXPECT_EQ(cell()->get_position().latitude, |
| 233 observer_->last_position_.latitude); |
231 | 234 |
232 EXPECT_FALSE(cell()->is_permission_granted_); | 235 EXPECT_FALSE(cell()->get_is_permission_granted()); |
233 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 236 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
234 arbitrator_->OnPermissionGranted(); | 237 arbitrator_->OnPermissionGranted(); |
235 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 238 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
236 EXPECT_TRUE(cell()->is_permission_granted_); | 239 EXPECT_TRUE(cell()->get_is_permission_granted()); |
237 } | 240 } |
238 | 241 |
239 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { | 242 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { |
240 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 243 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
241 fake_delegate->set_use_network(false); | 244 fake_delegate->set_use_network(false); |
242 | 245 |
243 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); | 246 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); |
244 InitializeArbitrator(std::move(delegate)); | 247 InitializeArbitrator(std::move(delegate)); |
245 ASSERT_TRUE(arbitrator_); | 248 ASSERT_TRUE(arbitrator_); |
246 | 249 |
247 EXPECT_FALSE(cell()); | 250 EXPECT_FALSE(cell()); |
248 EXPECT_FALSE(gps()); | 251 EXPECT_FALSE(gps()); |
249 arbitrator_->StartProvider(false); | 252 arbitrator_->StartProvider(false); |
250 | 253 |
251 ASSERT_FALSE(cell()); | 254 ASSERT_FALSE(cell()); |
252 EXPECT_FALSE(gps()); | 255 EXPECT_FALSE(gps()); |
253 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 256 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
254 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 257 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, |
255 fake_delegate->mock_location_provider()->state_); | 258 fake_delegate->mock_location_provider()->state_); |
256 EXPECT_FALSE(observer_->last_position_.Validate()); | 259 EXPECT_FALSE(observer_->last_position_.Validate()); |
257 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 260 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
258 | 261 |
259 SetReferencePosition(fake_delegate->mock_location_provider()); | 262 SetReferencePosition(fake_delegate->mock_location_provider()); |
260 | 263 |
261 EXPECT_TRUE(observer_->last_position_.Validate() || | 264 EXPECT_TRUE(observer_->last_position_.Validate() || |
262 observer_->last_position_.error_code != | 265 observer_->last_position_.error_code != |
263 Geoposition::ERROR_CODE_NONE); | 266 Geoposition::ERROR_CODE_NONE); |
264 EXPECT_EQ(fake_delegate->mock_location_provider()->position_.latitude, | 267 EXPECT_EQ(fake_delegate->mock_location_provider()->get_position().latitude, |
265 observer_->last_position_.latitude); | 268 observer_->last_position_.latitude); |
266 | 269 |
267 EXPECT_FALSE(fake_delegate->mock_location_provider()->is_permission_granted_); | 270 EXPECT_FALSE( |
| 271 fake_delegate->mock_location_provider()->get_is_permission_granted()); |
268 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 272 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
269 arbitrator_->OnPermissionGranted(); | 273 arbitrator_->OnPermissionGranted(); |
270 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 274 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
271 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted_); | 275 EXPECT_TRUE( |
| 276 fake_delegate->mock_location_provider()->get_is_permission_granted()); |
272 } | 277 } |
273 | 278 |
274 TEST_F(GeolocationLocationArbitratorTest, | 279 TEST_F(GeolocationLocationArbitratorTest, |
275 CustomSystemAndDefaultNetworkProviders) { | 280 CustomSystemAndDefaultNetworkProviders) { |
276 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; | 281 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate; |
277 fake_delegate->set_use_network(true); | 282 fake_delegate->set_use_network(true); |
278 | 283 |
279 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); | 284 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate); |
280 InitializeArbitrator(std::move(delegate)); | 285 InitializeArbitrator(std::move(delegate)); |
281 ASSERT_TRUE(arbitrator_); | 286 ASSERT_TRUE(arbitrator_); |
282 | 287 |
283 EXPECT_FALSE(cell()); | 288 EXPECT_FALSE(cell()); |
284 EXPECT_FALSE(gps()); | 289 EXPECT_FALSE(gps()); |
285 arbitrator_->StartProvider(false); | 290 arbitrator_->StartProvider(false); |
286 | 291 |
287 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 292 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
288 | 293 |
289 access_token_store_->NotifyDelegateTokensLoaded(); | 294 access_token_store_->NotifyDelegateTokensLoaded(); |
290 | 295 |
291 ASSERT_TRUE(cell()); | 296 ASSERT_TRUE(cell()); |
292 EXPECT_FALSE(gps()); | 297 EXPECT_FALSE(gps()); |
293 ASSERT_TRUE(fake_delegate->mock_location_provider()); | 298 ASSERT_TRUE(fake_delegate->mock_location_provider()); |
294 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | 299 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, |
295 fake_delegate->mock_location_provider()->state_); | 300 fake_delegate->mock_location_provider()->state_); |
296 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 301 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
297 EXPECT_FALSE(observer_->last_position_.Validate()); | 302 EXPECT_FALSE(observer_->last_position_.Validate()); |
298 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | 303 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
299 | 304 |
300 SetReferencePosition(cell()); | 305 SetReferencePosition(cell()); |
301 | 306 |
302 EXPECT_TRUE(observer_->last_position_.Validate() || | 307 EXPECT_TRUE(observer_->last_position_.Validate() || |
303 observer_->last_position_.error_code != | 308 observer_->last_position_.error_code != |
304 Geoposition::ERROR_CODE_NONE); | 309 Geoposition::ERROR_CODE_NONE); |
305 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); | 310 EXPECT_EQ(cell()->get_position().latitude, |
| 311 observer_->last_position_.latitude); |
306 | 312 |
307 EXPECT_FALSE(cell()->is_permission_granted_); | 313 EXPECT_FALSE(cell()->get_is_permission_granted()); |
308 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); | 314 EXPECT_FALSE(arbitrator_->HasPermissionBeenGrantedForTest()); |
309 arbitrator_->OnPermissionGranted(); | 315 arbitrator_->OnPermissionGranted(); |
310 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); | 316 EXPECT_TRUE(arbitrator_->HasPermissionBeenGrantedForTest()); |
311 EXPECT_TRUE(cell()->is_permission_granted_); | 317 EXPECT_TRUE(cell()->get_is_permission_granted()); |
312 } | 318 } |
313 | 319 |
314 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 320 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
315 InitializeArbitrator(nullptr); | 321 InitializeArbitrator(nullptr); |
316 arbitrator_->StartProvider(false); | 322 arbitrator_->StartProvider(false); |
317 access_token_store_->NotifyDelegateTokensLoaded(); | 323 access_token_store_->NotifyDelegateTokensLoaded(); |
318 ASSERT_TRUE(cell()); | 324 ASSERT_TRUE(cell()); |
319 ASSERT_TRUE(gps()); | 325 ASSERT_TRUE(gps()); |
320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 326 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
321 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 327 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
322 SetReferencePosition(cell()); | 328 SetReferencePosition(cell()); |
323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 329 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, cell()->state_); |
324 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 330 EXPECT_EQ(FakeLocationProvider::LOW_ACCURACY, gps()->state_); |
325 arbitrator_->StartProvider(true); | 331 arbitrator_->StartProvider(true); |
326 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); | 332 EXPECT_EQ(FakeLocationProvider::HIGH_ACCURACY, cell()->state_); |
327 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); | 333 EXPECT_EQ(FakeLocationProvider::HIGH_ACCURACY, gps()->state_); |
328 } | 334 } |
329 | 335 |
330 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { | 336 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { |
331 InitializeArbitrator(nullptr); | 337 InitializeArbitrator(nullptr); |
332 arbitrator_->StartProvider(false); | 338 arbitrator_->StartProvider(false); |
333 access_token_store_->NotifyDelegateTokensLoaded(); | 339 access_token_store_->NotifyDelegateTokensLoaded(); |
334 ASSERT_TRUE(cell()); | 340 ASSERT_TRUE(cell()); |
335 ASSERT_TRUE(gps()); | 341 ASSERT_TRUE(gps()); |
336 | 342 |
337 SetPositionFix(cell(), 1, 2, 150); | 343 SetPositionFix(cell(), 1, 2, 150); |
338 | 344 |
339 // First position available | 345 // First position available |
340 EXPECT_TRUE(observer_->last_position_.Validate()); | 346 EXPECT_TRUE(observer_->last_position_.Validate()); |
341 CheckLastPositionInfo(1, 2, 150); | 347 CheckLastPositionInfo(1, 2, 150); |
342 | 348 |
343 SetPositionFix(gps(), 3, 4, 50); | 349 SetPositionFix(gps(), 3, 4, 50); |
344 | 350 |
345 // More accurate fix available | 351 // More accurate fix available |
346 CheckLastPositionInfo(3, 4, 50); | 352 CheckLastPositionInfo(3, 4, 50); |
347 | 353 |
348 SetPositionFix(cell(), 5, 6, 150); | 354 SetPositionFix(cell(), 5, 6, 150); |
349 | 355 |
350 // New fix is available but it's less accurate, older fix should be kept. | 356 // New fix is available but it's less accurate, older fix should be kept. |
351 CheckLastPositionInfo(3, 4, 50); | 357 CheckLastPositionInfo(3, 4, 50); |
352 | 358 |
353 // Advance time, and notify once again | 359 // Advance time, and notify once again |
354 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 360 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
355 cell()->HandlePositionChanged(cell()->position_); | 361 cell()->HandlePositionChanged(cell()->get_position()); |
356 | 362 |
357 // New fix is available, less accurate but fresher | 363 // New fix is available, less accurate but fresher |
358 CheckLastPositionInfo(5, 6, 150); | 364 CheckLastPositionInfo(5, 6, 150); |
359 | 365 |
360 // Advance time, and set a low accuracy position | 366 // Advance time, and set a low accuracy position |
361 AdvanceTimeNow(SwitchOnFreshnessCliff()); | 367 AdvanceTimeNow(SwitchOnFreshnessCliff()); |
362 SetPositionFix(cell(), 5.676731, 139.629385, 1000); | 368 SetPositionFix(cell(), 5.676731, 139.629385, 1000); |
363 CheckLastPositionInfo(5.676731, 139.629385, 1000); | 369 CheckLastPositionInfo(5.676731, 139.629385, 1000); |
364 | 370 |
365 // 15 secs later, step outside. Switches to gps signal. | 371 // 15 secs later, step outside. Switches to gps signal. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 419 |
414 // Set the initial position. | 420 // Set the initial position. |
415 SetPositionFix(cell(), 3, 139, 100); | 421 SetPositionFix(cell(), 3, 139, 100); |
416 CheckLastPositionInfo(3, 139, 100); | 422 CheckLastPositionInfo(3, 139, 100); |
417 | 423 |
418 // Restart providers to simulate a one-shot request. | 424 // Restart providers to simulate a one-shot request. |
419 arbitrator_->StopProvider(); | 425 arbitrator_->StopProvider(); |
420 | 426 |
421 // To test 240956, perform a throwaway alloc. | 427 // To test 240956, perform a throwaway alloc. |
422 // This convinces the allocator to put the providers in a new memory location. | 428 // This convinces the allocator to put the providers in a new memory location. |
423 std::unique_ptr<MockLocationProvider> dummy_provider( | 429 std::unique_ptr<FakeLocationProvider> dummy_provider( |
424 new MockLocationProvider); | 430 new FakeLocationProvider); |
425 | 431 |
426 arbitrator_->StartProvider(false); | 432 arbitrator_->StartProvider(false); |
427 access_token_store_->NotifyDelegateTokensLoaded(); | 433 access_token_store_->NotifyDelegateTokensLoaded(); |
428 | 434 |
429 // Advance the time a short while to simulate successive calls. | 435 // Advance the time a short while to simulate successive calls. |
430 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 436 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
431 | 437 |
432 // Update with a less accurate position to verify 240956. | 438 // Update with a less accurate position to verify 240956. |
433 SetPositionFix(cell(), 3, 139, 150); | 439 SetPositionFix(cell(), 3, 139, 150); |
434 CheckLastPositionInfo(3, 139, 150); | 440 CheckLastPositionInfo(3, 139, 150); |
435 } | 441 } |
436 | 442 |
437 } // namespace device | 443 } // namespace device |
OLD | NEW |