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

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

Issue 2098553002: Geolocation: extract ContentBrowserClient methods specific to Geolocation into a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Minor touch in LocationArbitratorImplTest to restate previous behaviour. 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 ASSERT_TRUE(position.Validate()); 59 ASSERT_TRUE(position.Validate());
60 provider->HandlePositionChanged(position); 60 provider->HandlePositionChanged(position);
61 } 61 }
62 62
63 void SetReferencePosition(MockLocationProvider* provider) { 63 void SetReferencePosition(MockLocationProvider* provider) {
64 SetPositionFix(provider, 51.0, -0.1, 400); 64 SetPositionFix(provider, 51.0, -0.1, 400);
65 } 65 }
66 66
67 namespace { 67 namespace {
68 68
69 class GeolocationContentBrowserClient : public TestContentBrowserClient { 69 class FakeDelegate : public GeolocationProvider::Delegate {
70 public: 70 public:
71 GeolocationContentBrowserClient() {} 71 FakeDelegate() = default;
72 72
73 bool UseNetworkLocationProviders() override { return use_network_; }
73 void set_use_network(bool use_network) { use_network_ = use_network; } 74 void set_use_network(bool use_network) { use_network_ = use_network; }
74 75
75 LocationProvider* OverrideSystemLocationProvider() override { 76 LocationProvider* OverrideSystemLocationProvider() override {
76 provider_ = new MockLocationProvider; 77 if (!location_provider_)
77 return provider_; 78 location_provider_ = base::WrapUnique(new MockLocationProvider);
79 return location_provider_.get();
78 } 80 }
79 81 LocationProvider* location_provider() const {
Michael van Ouwerkerk 2016/06/28 11:17:07 nit: blank line above this one
mcasas 2016/06/28 16:51:25 Done.
80 bool UseNetworkLocationProviders() override { return use_network_; } 82 return location_provider_.get();
81 83 }
82 // This provider does not own the object. It is returned by
83 // GeolocationLocationAribtratorTest::GetSystemLocationProviderOverride().
84 // The caller takes ownership. This is just a reference we can use for
85 // mocking purposes.
86 MockLocationProvider* provider_ = nullptr;
87 84
88 private: 85 private:
89 bool use_network_ = true; 86 bool use_network_ = true;
87 std::unique_ptr<LocationProvider> location_provider_;
Michael van Ouwerkerk 2016/06/28 11:17:08 nit: consider renaming to system_location_provider
mcasas 2016/06/28 16:51:25 Done.
90 88
91 DISALLOW_COPY_AND_ASSIGN(GeolocationContentBrowserClient); 89 DISALLOW_COPY_AND_ASSIGN(FakeDelegate);
92 }; 90 };
93 91
94 class TestingLocationArbitrator : public LocationArbitratorImpl { 92 class TestingLocationArbitrator : public LocationArbitratorImpl {
95 public: 93 public:
96 TestingLocationArbitrator( 94 TestingLocationArbitrator(
97 const LocationArbitratorImpl::LocationUpdateCallback& callback, 95 const LocationArbitratorImpl::LocationUpdateCallback& callback,
98 AccessTokenStore* access_token_store) 96 AccessTokenStore* access_token_store,
99 : LocationArbitratorImpl(callback), 97 GeolocationProvider::Delegate* delegate,
98 bool is_fake_delegate)
99 : LocationArbitratorImpl(callback, delegate),
100 is_fake_delegate_(is_fake_delegate),
100 cell_(nullptr), 101 cell_(nullptr),
101 gps_(nullptr), 102 gps_(nullptr),
102 access_token_store_(access_token_store) {} 103 access_token_store_(access_token_store) {}
103 104
104 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } 105 base::Time GetTimeNow() const override { return GetTimeNowForTest(); }
105 106
106 AccessTokenStore* NewAccessTokenStore() override { 107 AccessTokenStore* NewAccessTokenStore() override {
107 return access_token_store_.get(); 108 return access_token_store_.get();
108 } 109 }
109 110
110 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( 111 std::unique_ptr<LocationProvider> NewNetworkLocationProvider(
111 AccessTokenStore* access_token_store, 112 AccessTokenStore* access_token_store,
112 net::URLRequestContextGetter* context, 113 net::URLRequestContextGetter* context,
113 const GURL& url, 114 const GURL& url,
114 const base::string16& access_token) override { 115 const base::string16& access_token) override {
115 cell_ = new MockLocationProvider; 116 cell_ = new MockLocationProvider;
116 return base::WrapUnique(cell_); 117 return base::WrapUnique(cell_);
117 } 118 }
118 119
119 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { 120 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override {
120 gps_ = new MockLocationProvider; 121 gps_ = new MockLocationProvider;
121 return base::WrapUnique(gps_); 122 return base::WrapUnique(gps_);
122 } 123 }
123 124
125 FakeDelegate* GetFakeDelegate() {
126 DCHECK(is_fake_delegate_);
127 return static_cast<FakeDelegate*>(GetDelegateForTesting());
128 }
129
130 LocationProvider* GetLocationProvider() {
131 if (is_fake_delegate_)
132 return GetFakeDelegate()->location_provider();
133 return GetDelegateForTesting()->OverrideSystemLocationProvider();
134 }
135
136 const bool is_fake_delegate_;
Michael van Ouwerkerk 2016/06/28 11:17:07 nit: blank line below this one
mcasas 2016/06/28 16:51:25 Done.
124 // Two location providers, with nice short names to make the tests more 137 // Two location providers, with nice short names to make the tests more
125 // readable. Note |gps_| will only be set when there is a high accuracy 138 // readable. Note |gps_| will only be set when there is a high accuracy
126 // observer registered (and |cell_| when there's at least one observer of any 139 // observer registered (and |cell_| when there's at least one observer of any
127 // type). 140 // type).
128 141
129 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and 142 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and
130 // |gps_| to |system_location_provider_| 143 // |gps_| to |system_location_provider_|
131 MockLocationProvider* cell_; 144 MockLocationProvider* cell_;
132 MockLocationProvider* gps_; 145 MockLocationProvider* gps_;
133 scoped_refptr<AccessTokenStore> access_token_store_; 146 scoped_refptr<AccessTokenStore> access_token_store_;
134 }; 147 };
135 148
136 } // namespace 149 } // namespace
137 150
138 class GeolocationLocationArbitratorTest : public testing::Test { 151 class GeolocationLocationArbitratorTest : public testing::Test {
139 protected: 152 protected:
140 // testing::Test 153 // testing::Test
141 void SetUp() override { 154 void SetUp() override {
142 access_token_store_ = new NiceMock<FakeAccessTokenStore>; 155 access_token_store_ = new NiceMock<FakeAccessTokenStore>;
143 observer_.reset(new MockLocationObserver); 156 observer_.reset(new MockLocationObserver);
144 LocationArbitratorImpl::LocationUpdateCallback callback = 157 }
158
159 // There are two types of test cases: those using FakeDelegate and the ones
160 // exercising whatever the embedder provides. Test cases call this method to
161 // choose the appropriate one.
162 void InitializeArbitrator(bool use_fake_delegate) {
163 delegate_.reset(use_fake_delegate ? new FakeDelegate()
164 : new GeolocationProvider::Delegate);
165 const LocationArbitratorImpl::LocationUpdateCallback callback =
145 base::Bind(&MockLocationObserver::OnLocationUpdate, 166 base::Bind(&MockLocationObserver::OnLocationUpdate,
146 base::Unretained(observer_.get())); 167 base::Unretained(observer_.get()));
147 arbitrator_.reset(new TestingLocationArbitrator( 168 arbitrator_.reset(
148 callback, access_token_store_.get())); 169 new TestingLocationArbitrator(callback, access_token_store_.get(),
149 override_content_browser_client_.reset(new GeolocationContentBrowserClient); 170 delegate_.get(), use_fake_delegate));
150 } 171 }
151 172
152 // testing::Test 173 // testing::Test
153 void TearDown() override {} 174 void TearDown() override {}
154 175
155 void CheckLastPositionInfo(double latitude, 176 void CheckLastPositionInfo(double latitude,
156 double longitude, 177 double longitude,
157 double accuracy) { 178 double accuracy) {
158 Geoposition geoposition = observer_->last_position_; 179 Geoposition geoposition = observer_->last_position_;
159 EXPECT_TRUE(geoposition.Validate()); 180 EXPECT_TRUE(geoposition.Validate());
(...skipping 10 matching lines...) Expand all
170 191
171 MockLocationProvider* cell() { 192 MockLocationProvider* cell() {
172 return arbitrator_->cell_; 193 return arbitrator_->cell_;
173 } 194 }
174 195
175 MockLocationProvider* gps() { 196 MockLocationProvider* gps() {
176 return arbitrator_->gps_; 197 return arbitrator_->gps_;
177 } 198 }
178 199
179 MockLocationProvider* GetSystemLocationProviderOverride() { 200 MockLocationProvider* GetSystemLocationProviderOverride() {
180 return override_content_browser_client_->provider_; 201 return static_cast<MockLocationProvider*>(
202 arbitrator_->GetLocationProvider());
181 } 203 }
182 204
183 scoped_refptr<FakeAccessTokenStore> access_token_store_; 205 scoped_refptr<FakeAccessTokenStore> access_token_store_;
184 std::unique_ptr<MockLocationObserver> observer_; 206 std::unique_ptr<MockLocationObserver> observer_;
185 std::unique_ptr<TestingLocationArbitrator> arbitrator_; 207 std::unique_ptr<TestingLocationArbitrator> arbitrator_;
208 std::unique_ptr<GeolocationProvider::Delegate> delegate_;
186 base::MessageLoop loop_; 209 base::MessageLoop loop_;
187 std::unique_ptr<GeolocationContentBrowserClient>
188 override_content_browser_client_;
189 }; 210 };
190 211
191 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { 212 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
192 EXPECT_TRUE(access_token_store_.get()); 213 EXPECT_TRUE(access_token_store_.get());
214 InitializeArbitrator(true /* use_fake_delegate */);
193 EXPECT_TRUE(arbitrator_); 215 EXPECT_TRUE(arbitrator_);
194 arbitrator_.reset(); 216 arbitrator_.reset();
195 SUCCEED(); 217 SUCCEED();
196 } 218 }
197 219
198 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { 220 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
221 InitializeArbitrator(false /* use_fake_delegate */);
199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 222 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
200 arbitrator_->OnPermissionGranted(); 223 arbitrator_->OnPermissionGranted();
201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 224 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
202 // Can't check the provider has been notified without going through the 225 // Can't check the provider has been notified without going through the
203 // motions to create the provider (see next test). 226 // motions to create the provider (see next test).
204 EXPECT_FALSE(cell()); 227 EXPECT_FALSE(cell());
205 EXPECT_FALSE(gps()); 228 EXPECT_FALSE(gps());
206 EXPECT_FALSE(GetSystemLocationProviderOverride()); 229 EXPECT_FALSE(GetSystemLocationProviderOverride());
207 } 230 }
208 231
209 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { 232 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
233 InitializeArbitrator(false /* use_fake_delegate */);
210 ASSERT_TRUE(access_token_store_.get()); 234 ASSERT_TRUE(access_token_store_.get());
211 ASSERT_TRUE(arbitrator_); 235 ASSERT_TRUE(arbitrator_);
212 236
213 EXPECT_FALSE(cell()); 237 EXPECT_FALSE(cell());
214 EXPECT_FALSE(gps()); 238 EXPECT_FALSE(gps());
215 EXPECT_FALSE(GetSystemLocationProviderOverride()); 239 EXPECT_FALSE(GetSystemLocationProviderOverride());
216 arbitrator_->StartProviders(false); 240 arbitrator_->StartProviders(false);
217 241
218 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 242 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
219 243
(...skipping 16 matching lines...) Expand all
236 observer_->last_position_.latitude); 260 observer_->last_position_.latitude);
237 261
238 EXPECT_FALSE(cell()->is_permission_granted_); 262 EXPECT_FALSE(cell()->is_permission_granted_);
239 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 263 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
240 arbitrator_->OnPermissionGranted(); 264 arbitrator_->OnPermissionGranted();
241 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 265 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
242 EXPECT_TRUE(cell()->is_permission_granted_); 266 EXPECT_TRUE(cell()->is_permission_granted_);
243 } 267 }
244 268
245 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { 269 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) {
246 override_content_browser_client_->set_use_network(false); 270 InitializeArbitrator(true /* use_fake_delegate */);
247 SetBrowserClientForTesting(override_content_browser_client_.get()); 271 arbitrator_->GetFakeDelegate()->set_use_network(false);
248 ASSERT_TRUE(arbitrator_); 272 ASSERT_TRUE(arbitrator_);
249 273
250 EXPECT_FALSE(cell()); 274 EXPECT_FALSE(cell());
251 EXPECT_FALSE(gps()); 275 EXPECT_FALSE(gps());
252 EXPECT_FALSE(GetSystemLocationProviderOverride());
253 arbitrator_->StartProviders(false); 276 arbitrator_->StartProviders(false);
254 277
255 ASSERT_FALSE(cell()); 278 ASSERT_FALSE(cell());
256 EXPECT_FALSE(gps()); 279 EXPECT_FALSE(gps());
257 EXPECT_TRUE(GetSystemLocationProviderOverride()); 280 ASSERT_TRUE(GetSystemLocationProviderOverride());
258 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 281 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
259 GetSystemLocationProviderOverride()->state_); 282 GetSystemLocationProviderOverride()->state_);
260 EXPECT_FALSE(observer_->last_position_.Validate()); 283 EXPECT_FALSE(observer_->last_position_.Validate());
261 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 284 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
262 285
263 SetReferencePosition(GetSystemLocationProviderOverride()); 286 SetReferencePosition(GetSystemLocationProviderOverride());
264 287
265 EXPECT_TRUE(observer_->last_position_.Validate() || 288 EXPECT_TRUE(observer_->last_position_.Validate() ||
266 observer_->last_position_.error_code != 289 observer_->last_position_.error_code !=
267 Geoposition::ERROR_CODE_NONE); 290 Geoposition::ERROR_CODE_NONE);
268 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude, 291 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude,
269 observer_->last_position_.latitude); 292 observer_->last_position_.latitude);
270 293
271 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_); 294 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_);
272 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 295 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
273 arbitrator_->OnPermissionGranted(); 296 arbitrator_->OnPermissionGranted();
274 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 297 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
275 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_); 298 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_);
276 } 299 }
277 300
278 TEST_F(GeolocationLocationArbitratorTest, 301 TEST_F(GeolocationLocationArbitratorTest,
279 CustomSystemAndDefaultNetworkProviders) { 302 CustomSystemAndDefaultNetworkProviders) {
280 override_content_browser_client_->set_use_network(true); 303 InitializeArbitrator(true /* use_fake_delegate */);
281 content::SetBrowserClientForTesting(override_content_browser_client_.get()); 304 arbitrator_->GetFakeDelegate()->set_use_network(true);
282 ASSERT_TRUE(arbitrator_); 305 ASSERT_TRUE(arbitrator_);
283 306
284 EXPECT_FALSE(cell()); 307 EXPECT_FALSE(cell());
285 EXPECT_FALSE(gps()); 308 EXPECT_FALSE(gps());
286 EXPECT_FALSE(GetSystemLocationProviderOverride());
287 arbitrator_->StartProviders(false); 309 arbitrator_->StartProviders(false);
288 310
289 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 311 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
290 312
291 access_token_store_->NotifyDelegateTokensLoaded(); 313 access_token_store_->NotifyDelegateTokensLoaded();
292 314
293 ASSERT_TRUE(cell()); 315 ASSERT_TRUE(cell());
294 EXPECT_FALSE(gps()); 316 EXPECT_FALSE(gps());
295 EXPECT_TRUE(GetSystemLocationProviderOverride()); 317 ASSERT_TRUE(GetSystemLocationProviderOverride());
296 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, 318 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
297 GetSystemLocationProviderOverride()->state_); 319 GetSystemLocationProviderOverride()->state_);
298 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
299 EXPECT_FALSE(observer_->last_position_.Validate()); 321 EXPECT_FALSE(observer_->last_position_.Validate());
300 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); 322 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
301 323
302 SetReferencePosition(cell()); 324 SetReferencePosition(cell());
303 325
304 EXPECT_TRUE(observer_->last_position_.Validate() || 326 EXPECT_TRUE(observer_->last_position_.Validate() ||
305 observer_->last_position_.error_code != 327 observer_->last_position_.error_code !=
306 Geoposition::ERROR_CODE_NONE); 328 Geoposition::ERROR_CODE_NONE);
307 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); 329 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude);
308 330
309 EXPECT_FALSE(cell()->is_permission_granted_); 331 EXPECT_FALSE(cell()->is_permission_granted_);
310 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 332 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
311 arbitrator_->OnPermissionGranted(); 333 arbitrator_->OnPermissionGranted();
312 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 334 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
313 EXPECT_TRUE(cell()->is_permission_granted_); 335 EXPECT_TRUE(cell()->is_permission_granted_);
314 } 336 }
315 337
316 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { 338 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
339 InitializeArbitrator(false /* use_fake_delegate */);
317 arbitrator_->StartProviders(false); 340 arbitrator_->StartProviders(false);
318 access_token_store_->NotifyDelegateTokensLoaded(); 341 access_token_store_->NotifyDelegateTokensLoaded();
319 ASSERT_TRUE(cell()); 342 ASSERT_TRUE(cell());
320 ASSERT_TRUE(gps()); 343 ASSERT_TRUE(gps());
321 EXPECT_FALSE(GetSystemLocationProviderOverride()); 344 EXPECT_FALSE(GetSystemLocationProviderOverride());
322 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 345 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 346 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
324 SetReferencePosition(cell()); 347 SetReferencePosition(cell());
325 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 348 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
326 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 349 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
327 arbitrator_->StartProviders(true); 350 arbitrator_->StartProviders(true);
328 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); 351 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_);
329 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); 352 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_);
330 EXPECT_FALSE(GetSystemLocationProviderOverride()); 353 EXPECT_FALSE(GetSystemLocationProviderOverride());
331 } 354 }
332 355
333 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 356 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
357 InitializeArbitrator(false /* use_fake_delegate */);
334 arbitrator_->StartProviders(false); 358 arbitrator_->StartProviders(false);
335 access_token_store_->NotifyDelegateTokensLoaded(); 359 access_token_store_->NotifyDelegateTokensLoaded();
336 ASSERT_TRUE(cell()); 360 ASSERT_TRUE(cell());
337 ASSERT_TRUE(gps()); 361 ASSERT_TRUE(gps());
338 EXPECT_FALSE(GetSystemLocationProviderOverride()); 362 EXPECT_FALSE(GetSystemLocationProviderOverride());
339 363
340 SetPositionFix(cell(), 1, 2, 150); 364 SetPositionFix(cell(), 1, 2, 150);
341 365
342 // First position available 366 // First position available
343 EXPECT_TRUE(observer_->last_position_.Validate()); 367 EXPECT_TRUE(observer_->last_position_.Validate());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 CheckLastPositionInfo(3.5657104, 139.690341, 300); 425 CheckLastPositionInfo(3.5657104, 139.690341, 300);
402 426
403 // 2 minutes later 427 // 2 minutes later
404 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); 428 AdvanceTimeNow(base::TimeDelta::FromMinutes(2));
405 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 429 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
406 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 430 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
407 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 431 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
408 } 432 }
409 433
410 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { 434 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
435 InitializeArbitrator(false /* use_fake_delegate */);
411 arbitrator_->StartProviders(false); 436 arbitrator_->StartProviders(false);
412 access_token_store_->NotifyDelegateTokensLoaded(); 437 access_token_store_->NotifyDelegateTokensLoaded();
413 ASSERT_TRUE(cell()); 438 ASSERT_TRUE(cell());
414 ASSERT_TRUE(gps()); 439 ASSERT_TRUE(gps());
415 EXPECT_FALSE(GetSystemLocationProviderOverride()); 440 EXPECT_FALSE(GetSystemLocationProviderOverride());
416 441
417 // Set the initial position. 442 // Set the initial position.
418 SetPositionFix(cell(), 3, 139, 100); 443 SetPositionFix(cell(), 3, 139, 100);
419 CheckLastPositionInfo(3, 139, 100); 444 CheckLastPositionInfo(3, 139, 100);
420 445
(...skipping 10 matching lines...) Expand all
431 456
432 // Advance the time a short while to simulate successive calls. 457 // Advance the time a short while to simulate successive calls.
433 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 458 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
434 459
435 // Update with a less accurate position to verify 240956. 460 // Update with a less accurate position to verify 240956.
436 SetPositionFix(cell(), 3, 139, 150); 461 SetPositionFix(cell(), 3, 139, 150);
437 CheckLastPositionInfo(3, 139, 150); 462 CheckLastPositionInfo(3, 139, 150);
438 } 463 }
439 464
440 } // namespace content 465 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698