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

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

Powered by Google App Engine
This is Rietveld 408576698