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

Side by Side Diff: content/browser/geolocation/location_arbitrator_impl_unittest.cc

Issue 2126893003: Geolocation cleanup: make GeolocationDelegate::OverrideSystemLocationProvider return unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez@ comments (InitializeArbitrator(), removed hacks) Created 4 years, 5 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 "content/browser/geolocation/location_arbitrator_impl.h" 5 #include "content/browser/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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 namespace { 68 namespace {
69 69
70 class FakeGeolocationDelegate : public GeolocationDelegate { 70 class FakeGeolocationDelegate : public GeolocationDelegate {
71 public: 71 public:
72 FakeGeolocationDelegate() = default; 72 FakeGeolocationDelegate() = default;
73 73
74 bool UseNetworkLocationProviders() override { return use_network_; } 74 bool UseNetworkLocationProviders() override { return use_network_; }
75 void set_use_network(bool use_network) { use_network_ = use_network; } 75 void set_use_network(bool use_network) { use_network_ = use_network; }
76 76
77 LocationProvider* OverrideSystemLocationProvider() override { 77 std::unique_ptr<LocationProvider> OverrideSystemLocationProvider() override {
78 if (!system_location_provider_) 78 mock_location_provider_ = new MockLocationProvider;
Wez 2016/07/11 17:10:10 Looks like you want to ASSERT/DCHECK(!mock_locatio
mcasas 2016/07/11 17:18:19 Done.
79 system_location_provider_ = base::WrapUnique(new MockLocationProvider); 79 return base::WrapUnique(mock_location_provider_);
80 return system_location_provider_.get();
81 } 80 }
82 81
83 LocationProvider* system_location_provider() const { 82 MockLocationProvider* mock_location_provider() const {
84 return system_location_provider_.get(); 83 return mock_location_provider_;
85 } 84 }
86 85
87 private: 86 private:
88 bool use_network_ = true; 87 bool use_network_ = true;
89 std::unique_ptr<LocationProvider> system_location_provider_; 88 MockLocationProvider* mock_location_provider_ = nullptr;
90 89
91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); 90 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate);
92 }; 91 };
93 92
93 } // namespace
94
94 class TestingLocationArbitrator : public LocationArbitratorImpl { 95 class TestingLocationArbitrator : public LocationArbitratorImpl {
95 public: 96 public:
96 TestingLocationArbitrator( 97 TestingLocationArbitrator(
97 const LocationArbitratorImpl::LocationUpdateCallback& callback, 98 const LocationArbitratorImpl::LocationUpdateCallback& callback,
98 AccessTokenStore* access_token_store, 99 AccessTokenStore* access_token_store,
99 GeolocationDelegate* delegate, 100 GeolocationDelegate* delegate)
100 bool is_fake_delegate)
101 : LocationArbitratorImpl(callback, delegate), 101 : LocationArbitratorImpl(callback, delegate),
102 is_fake_delegate_(is_fake_delegate),
103 cell_(nullptr), 102 cell_(nullptr),
104 gps_(nullptr), 103 gps_(nullptr),
105 access_token_store_(access_token_store) {} 104 access_token_store_(access_token_store) {}
106 105
107 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } 106 base::Time GetTimeNow() const override { return GetTimeNowForTest(); }
108 107
109 AccessTokenStore* NewAccessTokenStore() override { 108 AccessTokenStore* NewAccessTokenStore() override {
110 return access_token_store_.get(); 109 return access_token_store_.get();
111 } 110 }
112 111
113 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( 112 std::unique_ptr<LocationProvider> NewNetworkLocationProvider(
114 AccessTokenStore* access_token_store, 113 AccessTokenStore* access_token_store,
115 net::URLRequestContextGetter* context, 114 net::URLRequestContextGetter* context,
116 const GURL& url, 115 const GURL& url,
117 const base::string16& access_token) override { 116 const base::string16& access_token) override {
118 cell_ = new MockLocationProvider; 117 cell_ = new MockLocationProvider;
119 return base::WrapUnique(cell_); 118 return base::WrapUnique(cell_);
120 } 119 }
121 120
122 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { 121 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override {
123 gps_ = new MockLocationProvider; 122 gps_ = new MockLocationProvider;
124 return base::WrapUnique(gps_); 123 return base::WrapUnique(gps_);
125 } 124 }
126 125
127 FakeGeolocationDelegate* GetFakeGeolocationDelegate() {
128 DCHECK(is_fake_delegate_);
129 return static_cast<FakeGeolocationDelegate*>(GetDelegateForTesting());
130 }
131
132 LocationProvider* GetLocationProvider() {
133 if (is_fake_delegate_)
134 return GetFakeGeolocationDelegate()->system_location_provider();
135 return GetDelegateForTesting()->OverrideSystemLocationProvider();
136 }
137
138 const bool is_fake_delegate_;
139
140 // Two location providers, with nice short names to make the tests more 126 // Two location providers, with nice short names to make the tests more
141 // readable. Note |gps_| will only be set when there is a high accuracy 127 // readable. Note |gps_| will only be set when there is a high accuracy
142 // observer registered (and |cell_| when there's at least one observer of any 128 // observer registered (and |cell_| when there's at least one observer of any
143 // type). 129 // type).
144
145 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and 130 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and
146 // |gps_| to |system_location_provider_| 131 // |gps_| to |gps_location_provider_|
147 MockLocationProvider* cell_; 132 MockLocationProvider* cell_;
148 MockLocationProvider* gps_; 133 MockLocationProvider* gps_;
134 std::unique_ptr<LocationProvider> system_location_provider_;
149 scoped_refptr<AccessTokenStore> access_token_store_; 135 scoped_refptr<AccessTokenStore> access_token_store_;
150 }; 136 };
151 137
152 } // namespace
153
154 class GeolocationLocationArbitratorTest : public testing::Test { 138 class GeolocationLocationArbitratorTest : public testing::Test {
155 protected: 139 protected:
156 // testing::Test 140 // testing::Test
157 void SetUp() override { 141 void SetUp() override {
158 access_token_store_ = new NiceMock<FakeAccessTokenStore>; 142 access_token_store_ = new NiceMock<FakeAccessTokenStore>;
159 observer_.reset(new MockLocationObserver); 143 observer_.reset(new MockLocationObserver);
144 delegate_.reset(new GeolocationDelegate);
160 } 145 }
161 146
162 // There are two types of test cases: those using FakeGeolocationDelegate and 147 // Initializes |arbitrator_|, with the possibility of injecting a specific
163 // the ones exercising whatever the embedder provides. Test cases call this 148 // |delegate|, otherwise a default, no-op GeolocationDelegate is used.
164 // method to choose the appropriate one. 149 void InitializeArbitrator(std::unique_ptr<GeolocationDelegate> delegate) {
165 void InitializeArbitrator(bool use_fake_delegate) { 150 if (delegate)
166 delegate_.reset(use_fake_delegate ? new FakeGeolocationDelegate() 151 delegate_ = std::move(delegate);
167 : new GeolocationDelegate);
168 const LocationArbitratorImpl::LocationUpdateCallback callback = 152 const LocationArbitratorImpl::LocationUpdateCallback callback =
169 base::Bind(&MockLocationObserver::OnLocationUpdate, 153 base::Bind(&MockLocationObserver::OnLocationUpdate,
170 base::Unretained(observer_.get())); 154 base::Unretained(observer_.get()));
171 arbitrator_.reset( 155 arbitrator_.reset(new TestingLocationArbitrator(
172 new TestingLocationArbitrator(callback, access_token_store_.get(), 156 callback, access_token_store_.get(), delegate_.get()));
173 delegate_.get(), use_fake_delegate));
174 } 157 }
175 158
176 // testing::Test 159 // testing::Test
177 void TearDown() override {} 160 void TearDown() override {}
178 161
179 void CheckLastPositionInfo(double latitude, 162 void CheckLastPositionInfo(double latitude,
180 double longitude, 163 double longitude,
181 double accuracy) { 164 double accuracy) {
182 Geoposition geoposition = observer_->last_position_; 165 Geoposition geoposition = observer_->last_position_;
183 EXPECT_TRUE(geoposition.Validate()); 166 EXPECT_TRUE(geoposition.Validate());
184 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); 167 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude);
185 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); 168 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude);
186 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); 169 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy);
187 } 170 }
188 171
189 base::TimeDelta SwitchOnFreshnessCliff() { 172 base::TimeDelta SwitchOnFreshnessCliff() {
190 // Add 1, to ensure it meets any greater-than test. 173 // Add 1, to ensure it meets any greater-than test.
191 return base::TimeDelta::FromMilliseconds( 174 return base::TimeDelta::FromMilliseconds(
192 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); 175 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1);
193 } 176 }
194 177
195 MockLocationProvider* cell() { 178 MockLocationProvider* cell() {
196 return arbitrator_->cell_; 179 return arbitrator_->cell_;
197 } 180 }
198 181
199 MockLocationProvider* gps() { 182 MockLocationProvider* gps() {
200 return arbitrator_->gps_; 183 return arbitrator_->gps_;
201 } 184 }
202 185
203 MockLocationProvider* GetSystemLocationProviderOverride() {
204 return static_cast<MockLocationProvider*>(
205 arbitrator_->GetLocationProvider());
206 }
207
208 scoped_refptr<FakeAccessTokenStore> access_token_store_; 186 scoped_refptr<FakeAccessTokenStore> access_token_store_;
209 std::unique_ptr<MockLocationObserver> observer_; 187 std::unique_ptr<MockLocationObserver> observer_;
210 std::unique_ptr<TestingLocationArbitrator> arbitrator_; 188 std::unique_ptr<TestingLocationArbitrator> arbitrator_;
211 std::unique_ptr<GeolocationDelegate> delegate_; 189 std::unique_ptr<GeolocationDelegate> delegate_;
212 base::MessageLoop loop_; 190 base::MessageLoop loop_;
213 }; 191 };
214 192
215 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { 193 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
216 EXPECT_TRUE(access_token_store_.get()); 194 EXPECT_TRUE(access_token_store_.get());
217 InitializeArbitrator(true /* use_fake_delegate */); 195 InitializeArbitrator(nullptr);
218 EXPECT_TRUE(arbitrator_); 196 EXPECT_TRUE(arbitrator_);
219 arbitrator_.reset(); 197 arbitrator_.reset();
220 SUCCEED(); 198 SUCCEED();
221 } 199 }
222 200
223 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { 201 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
224 InitializeArbitrator(false /* use_fake_delegate */); 202 InitializeArbitrator(nullptr);
225 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 203 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
226 arbitrator_->OnPermissionGranted(); 204 arbitrator_->OnPermissionGranted();
227 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 205 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
228 // Can't check the provider has been notified without going through the 206 // Can't check the provider has been notified without going through the
229 // motions to create the provider (see next test). 207 // motions to create the provider (see next test).
230 EXPECT_FALSE(cell()); 208 EXPECT_FALSE(cell());
231 EXPECT_FALSE(gps()); 209 EXPECT_FALSE(gps());
232 EXPECT_FALSE(GetSystemLocationProviderOverride());
233 } 210 }
234 211
235 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { 212 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
236 InitializeArbitrator(false /* use_fake_delegate */); 213 InitializeArbitrator(nullptr);
237 ASSERT_TRUE(access_token_store_.get()); 214 ASSERT_TRUE(access_token_store_.get());
238 ASSERT_TRUE(arbitrator_); 215 ASSERT_TRUE(arbitrator_);
239 216
240 EXPECT_FALSE(cell()); 217 EXPECT_FALSE(cell());
241 EXPECT_FALSE(gps()); 218 EXPECT_FALSE(gps());
242 EXPECT_FALSE(GetSystemLocationProviderOverride());
243 arbitrator_->StartProviders(false); 219 arbitrator_->StartProviders(false);
244 220
245 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 221 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
246 222
247 access_token_store_->NotifyDelegateTokensLoaded(); 223 access_token_store_->NotifyDelegateTokensLoaded();
248 ASSERT_TRUE(cell()); 224 ASSERT_TRUE(cell());
249 EXPECT_TRUE(gps()); 225 EXPECT_TRUE(gps());
250 EXPECT_FALSE(GetSystemLocationProviderOverride());
251 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 226 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
252 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 227 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
253 EXPECT_FALSE(observer_->last_position_.Validate()); 228 EXPECT_FALSE(observer_->last_position_.Validate());
254 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, 229 EXPECT_EQ(Geoposition::ERROR_CODE_NONE,
255 observer_->last_position_.error_code); 230 observer_->last_position_.error_code);
256 231
257 SetReferencePosition(cell()); 232 SetReferencePosition(cell());
258 233
259 EXPECT_TRUE(observer_->last_position_.Validate() || 234 EXPECT_TRUE(observer_->last_position_.Validate() ||
260 observer_->last_position_.error_code != 235 observer_->last_position_.error_code !=
261 Geoposition::ERROR_CODE_NONE); 236 Geoposition::ERROR_CODE_NONE);
262 EXPECT_EQ(cell()->position_.latitude, 237 EXPECT_EQ(cell()->position_.latitude,
263 observer_->last_position_.latitude); 238 observer_->last_position_.latitude);
264 239
265 EXPECT_FALSE(cell()->is_permission_granted_); 240 EXPECT_FALSE(cell()->is_permission_granted_);
266 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 241 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
267 arbitrator_->OnPermissionGranted(); 242 arbitrator_->OnPermissionGranted();
268 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 243 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
269 EXPECT_TRUE(cell()->is_permission_granted_); 244 EXPECT_TRUE(cell()->is_permission_granted_);
270 } 245 }
271 246
272 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { 247 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) {
273 InitializeArbitrator(true /* use_fake_delegate */); 248 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate;
274 arbitrator_->GetFakeGeolocationDelegate()->set_use_network(false); 249 fake_delegate->set_use_network(false);
250
251 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate);
252 InitializeArbitrator(std::move(delegate));
275 ASSERT_TRUE(arbitrator_); 253 ASSERT_TRUE(arbitrator_);
276 254
277 EXPECT_FALSE(cell()); 255 EXPECT_FALSE(cell());
278 EXPECT_FALSE(gps()); 256 EXPECT_FALSE(gps());
279 arbitrator_->StartProviders(false); 257 arbitrator_->StartProviders(false);
280 258
281 ASSERT_FALSE(cell()); 259 ASSERT_FALSE(cell());
282 EXPECT_FALSE(gps()); 260 EXPECT_FALSE(gps());
283 ASSERT_TRUE(GetSystemLocationProviderOverride()); 261 ASSERT_TRUE(fake_delegate->mock_location_provider());
284 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 262 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
285 GetSystemLocationProviderOverride()->state_); 263 fake_delegate->mock_location_provider()->state_);
286 EXPECT_FALSE(observer_->last_position_.Validate()); 264 EXPECT_FALSE(observer_->last_position_.Validate());
287 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 265 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
288 266
289 SetReferencePosition(GetSystemLocationProviderOverride()); 267 SetReferencePosition(fake_delegate->mock_location_provider());
290 268
291 EXPECT_TRUE(observer_->last_position_.Validate() || 269 EXPECT_TRUE(observer_->last_position_.Validate() ||
292 observer_->last_position_.error_code != 270 observer_->last_position_.error_code !=
293 Geoposition::ERROR_CODE_NONE); 271 Geoposition::ERROR_CODE_NONE);
294 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude, 272 EXPECT_EQ(fake_delegate->mock_location_provider()->position_.latitude,
295 observer_->last_position_.latitude); 273 observer_->last_position_.latitude);
296 274
297 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_); 275 EXPECT_FALSE(fake_delegate->mock_location_provider()->is_permission_granted_);
298 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 276 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
299 arbitrator_->OnPermissionGranted(); 277 arbitrator_->OnPermissionGranted();
300 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 278 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
301 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_); 279 EXPECT_TRUE(fake_delegate->mock_location_provider()->is_permission_granted_);
302 } 280 }
303 281
304 TEST_F(GeolocationLocationArbitratorTest, 282 TEST_F(GeolocationLocationArbitratorTest,
305 CustomSystemAndDefaultNetworkProviders) { 283 CustomSystemAndDefaultNetworkProviders) {
306 InitializeArbitrator(true /* use_fake_delegate */); 284 FakeGeolocationDelegate* fake_delegate = new FakeGeolocationDelegate;
307 arbitrator_->GetFakeGeolocationDelegate()->set_use_network(true); 285 fake_delegate->set_use_network(true);
286
287 std::unique_ptr<GeolocationDelegate> delegate(fake_delegate);
288 InitializeArbitrator(std::move(delegate));
308 ASSERT_TRUE(arbitrator_); 289 ASSERT_TRUE(arbitrator_);
309 290
310 EXPECT_FALSE(cell()); 291 EXPECT_FALSE(cell());
311 EXPECT_FALSE(gps()); 292 EXPECT_FALSE(gps());
312 arbitrator_->StartProviders(false); 293 arbitrator_->StartProviders(false);
313 294
314 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 295 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
315 296
316 access_token_store_->NotifyDelegateTokensLoaded(); 297 access_token_store_->NotifyDelegateTokensLoaded();
317 298
318 ASSERT_TRUE(cell()); 299 ASSERT_TRUE(cell());
319 EXPECT_FALSE(gps()); 300 EXPECT_FALSE(gps());
320 ASSERT_TRUE(GetSystemLocationProviderOverride()); 301 ASSERT_TRUE(fake_delegate->mock_location_provider());
321 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 302 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
322 GetSystemLocationProviderOverride()->state_); 303 fake_delegate->mock_location_provider()->state_);
323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 304 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
324 EXPECT_FALSE(observer_->last_position_.Validate()); 305 EXPECT_FALSE(observer_->last_position_.Validate());
325 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 306 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
326 307
327 SetReferencePosition(cell()); 308 SetReferencePosition(cell());
328 309
329 EXPECT_TRUE(observer_->last_position_.Validate() || 310 EXPECT_TRUE(observer_->last_position_.Validate() ||
330 observer_->last_position_.error_code != 311 observer_->last_position_.error_code !=
331 Geoposition::ERROR_CODE_NONE); 312 Geoposition::ERROR_CODE_NONE);
332 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); 313 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude);
333 314
334 EXPECT_FALSE(cell()->is_permission_granted_); 315 EXPECT_FALSE(cell()->is_permission_granted_);
335 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 316 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
336 arbitrator_->OnPermissionGranted(); 317 arbitrator_->OnPermissionGranted();
337 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 318 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
338 EXPECT_TRUE(cell()->is_permission_granted_); 319 EXPECT_TRUE(cell()->is_permission_granted_);
339 } 320 }
340 321
341 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { 322 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
342 InitializeArbitrator(false /* use_fake_delegate */); 323 InitializeArbitrator(nullptr);
343 arbitrator_->StartProviders(false); 324 arbitrator_->StartProviders(false);
344 access_token_store_->NotifyDelegateTokensLoaded(); 325 access_token_store_->NotifyDelegateTokensLoaded();
345 ASSERT_TRUE(cell()); 326 ASSERT_TRUE(cell());
346 ASSERT_TRUE(gps()); 327 ASSERT_TRUE(gps());
347 EXPECT_FALSE(GetSystemLocationProviderOverride());
348 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 328 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
349 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 329 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
350 SetReferencePosition(cell()); 330 SetReferencePosition(cell());
351 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 331 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
352 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 332 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
353 arbitrator_->StartProviders(true); 333 arbitrator_->StartProviders(true);
354 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); 334 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_);
355 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); 335 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_);
356 EXPECT_FALSE(GetSystemLocationProviderOverride());
357 } 336 }
358 337
359 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 338 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
360 InitializeArbitrator(false /* use_fake_delegate */); 339 InitializeArbitrator(nullptr);
361 arbitrator_->StartProviders(false); 340 arbitrator_->StartProviders(false);
362 access_token_store_->NotifyDelegateTokensLoaded(); 341 access_token_store_->NotifyDelegateTokensLoaded();
363 ASSERT_TRUE(cell()); 342 ASSERT_TRUE(cell());
364 ASSERT_TRUE(gps()); 343 ASSERT_TRUE(gps());
365 EXPECT_FALSE(GetSystemLocationProviderOverride());
366 344
367 SetPositionFix(cell(), 1, 2, 150); 345 SetPositionFix(cell(), 1, 2, 150);
368 346
369 // First position available 347 // First position available
370 EXPECT_TRUE(observer_->last_position_.Validate()); 348 EXPECT_TRUE(observer_->last_position_.Validate());
371 CheckLastPositionInfo(1, 2, 150); 349 CheckLastPositionInfo(1, 2, 150);
372 350
373 SetPositionFix(gps(), 3, 4, 50); 351 SetPositionFix(gps(), 3, 4, 50);
374 352
375 // More accurate fix available 353 // More accurate fix available
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 CheckLastPositionInfo(3.5657104, 139.690341, 300); 406 CheckLastPositionInfo(3.5657104, 139.690341, 300);
429 407
430 // 2 minutes later 408 // 2 minutes later
431 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); 409 AdvanceTimeNow(base::TimeDelta::FromMinutes(2));
432 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 410 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
433 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 411 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
434 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 412 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
435 } 413 }
436 414
437 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { 415 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
438 InitializeArbitrator(false /* use_fake_delegate */); 416 InitializeArbitrator(nullptr);
439 arbitrator_->StartProviders(false); 417 arbitrator_->StartProviders(false);
440 access_token_store_->NotifyDelegateTokensLoaded(); 418 access_token_store_->NotifyDelegateTokensLoaded();
441 ASSERT_TRUE(cell()); 419 ASSERT_TRUE(cell());
442 ASSERT_TRUE(gps()); 420 ASSERT_TRUE(gps());
443 EXPECT_FALSE(GetSystemLocationProviderOverride());
444 421
445 // Set the initial position. 422 // Set the initial position.
446 SetPositionFix(cell(), 3, 139, 100); 423 SetPositionFix(cell(), 3, 139, 100);
447 CheckLastPositionInfo(3, 139, 100); 424 CheckLastPositionInfo(3, 139, 100);
448 425
449 // Restart providers to simulate a one-shot request. 426 // Restart providers to simulate a one-shot request.
450 arbitrator_->StopProviders(); 427 arbitrator_->StopProviders();
451 428
452 // To test 240956, perform a throwaway alloc. 429 // To test 240956, perform a throwaway alloc.
453 // This convinces the allocator to put the providers in a new memory location. 430 // This convinces the allocator to put the providers in a new memory location.
454 std::unique_ptr<MockLocationProvider> dummy_provider( 431 std::unique_ptr<MockLocationProvider> dummy_provider(
455 new MockLocationProvider); 432 new MockLocationProvider);
456 433
457 arbitrator_->StartProviders(false); 434 arbitrator_->StartProviders(false);
458 access_token_store_->NotifyDelegateTokensLoaded(); 435 access_token_store_->NotifyDelegateTokensLoaded();
459 436
460 // Advance the time a short while to simulate successive calls. 437 // Advance the time a short while to simulate successive calls.
461 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 438 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
462 439
463 // Update with a less accurate position to verify 240956. 440 // Update with a less accurate position to verify 240956.
464 SetPositionFix(cell(), 3, 139, 150); 441 SetPositionFix(cell(), 3, 139, 150);
465 CheckLastPositionInfo(3, 139, 150); 442 CheckLastPositionInfo(3, 139, 150);
466 } 443 }
467 444
468 } // namespace content 445 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_arbitrator_impl.cc ('k') | content/public/browser/geolocation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698