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

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

Issue 2028823002: Refactor to make BlimpLocationProvider accessible to content layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses kmarshall's #63 comments Created 4 years, 6 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 "content/browser/geolocation/fake_access_token_store.h" 10 #include "content/browser/geolocation/fake_access_token_store.h"
11 #include "content/browser/geolocation/mock_location_provider.h" 11 #include "content/browser/geolocation/mock_location_provider.h"
12 #include "content/public/common/geoposition.h" 12 #include "content/public/common/geoposition.h"
13 #include "content/test/test_content_browser_client.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using ::testing::NiceMock; 17 using ::testing::NiceMock;
17 18
18 namespace content { 19 namespace content {
19 20
20 class MockLocationObserver { 21 class MockLocationObserver {
21 public: 22 public:
22 // Need a vtable for GMock. 23 // Need a vtable for GMock.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ASSERT_TRUE(position.Validate()); 58 ASSERT_TRUE(position.Validate());
58 provider->HandlePositionChanged(position); 59 provider->HandlePositionChanged(position);
59 } 60 }
60 61
61 void SetReferencePosition(MockLocationProvider* provider) { 62 void SetReferencePosition(MockLocationProvider* provider) {
62 SetPositionFix(provider, 51.0, -0.1, 400); 63 SetPositionFix(provider, 51.0, -0.1, 400);
63 } 64 }
64 65
65 namespace { 66 namespace {
66 67
68 class GeolocationContentBrowserClient : public TestContentBrowserClient {
69 public:
70 void SetUseNetwork(bool use_network) { use_network_ = use_network; }
71
72 LocationProvider* OverrideSystemLocationProvider() override {
73 provider_ = new MockLocationProvider;
74 return provider_;
75 }
76
77 bool UseNetworkLocationProviders() override { return use_network_; }
78
79 MockLocationProvider* provider_ = nullptr;
80
81 private:
82 bool use_network_ = true;
83 };
84
67 class TestingLocationArbitrator : public LocationArbitratorImpl { 85 class TestingLocationArbitrator : public LocationArbitratorImpl {
68 public: 86 public:
69 TestingLocationArbitrator( 87 TestingLocationArbitrator(
70 const LocationArbitratorImpl::LocationUpdateCallback& callback, 88 const LocationArbitratorImpl::LocationUpdateCallback& callback,
71 AccessTokenStore* access_token_store) 89 AccessTokenStore* access_token_store)
72 : LocationArbitratorImpl(callback), 90 : LocationArbitratorImpl(callback),
73 cell_(NULL), 91 cell_(nullptr),
74 gps_(NULL), 92 gps_(nullptr),
75 access_token_store_(access_token_store) { 93 access_token_store_(access_token_store) {}
76 }
77 94
78 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } 95 base::Time GetTimeNow() const override { return GetTimeNowForTest(); }
79 96
80 AccessTokenStore* NewAccessTokenStore() override { 97 AccessTokenStore* NewAccessTokenStore() override {
81 return access_token_store_.get(); 98 return access_token_store_.get();
82 } 99 }
83 100
84 LocationProvider* NewNetworkLocationProvider( 101 LocationProvider* NewNetworkLocationProvider(
85 AccessTokenStore* access_token_store, 102 AccessTokenStore* access_token_store,
86 net::URLRequestContextGetter* context, 103 net::URLRequestContextGetter* context,
87 const GURL& url, 104 const GURL& url,
88 const base::string16& access_token) override { 105 const base::string16& access_token) override {
89 return new MockLocationProvider(&cell_); 106 cell_ = new MockLocationProvider;
107 return cell_;
90 } 108 }
91 109
92 LocationProvider* NewSystemLocationProvider() override { 110 LocationProvider* NewSystemLocationProvider() override {
93 return new MockLocationProvider(&gps_); 111 gps_ = new MockLocationProvider;
112 return gps_;
94 } 113 }
95 114
96 // Two location providers, with nice short names to make the tests more 115 // Two location providers, with nice short names to make the tests more
97 // readable. Note |gps_| will only be set when there is a high accuracy 116 // readable. Note |gps_| will only be set when there is a high accuracy
98 // observer registered (and |cell_| when there's at least one observer of any 117 // observer registered (and |cell_| when there's at least one observer of any
99 // type). 118 // type).
100 MockLocationProvider* cell_; 119 MockLocationProvider* cell_;
Michael van Ouwerkerk 2016/06/10 12:46:52 nit: While these names (cell_ and gps_) may have b
CJ 2016/06/10 19:51:34 Done.
101 MockLocationProvider* gps_; 120 MockLocationProvider* gps_;
102 scoped_refptr<AccessTokenStore> access_token_store_; 121 scoped_refptr<AccessTokenStore> access_token_store_;
103 }; 122 };
104 123
105 } // namespace 124 } // namespace
106 125
107 class GeolocationLocationArbitratorTest : public testing::Test { 126 class GeolocationLocationArbitratorTest : public testing::Test {
108 protected: 127 protected:
109 // testing::Test 128 // testing::Test
110 void SetUp() override { 129 void SetUp() override {
111 access_token_store_ = new NiceMock<FakeAccessTokenStore>; 130 access_token_store_ = new NiceMock<FakeAccessTokenStore>;
112 observer_.reset(new MockLocationObserver); 131 observer_.reset(new MockLocationObserver);
113 LocationArbitratorImpl::LocationUpdateCallback callback = 132 LocationArbitratorImpl::LocationUpdateCallback callback =
114 base::Bind(&MockLocationObserver::OnLocationUpdate, 133 base::Bind(&MockLocationObserver::OnLocationUpdate,
115 base::Unretained(observer_.get())); 134 base::Unretained(observer_.get()));
116 arbitrator_.reset(new TestingLocationArbitrator( 135 arbitrator_.reset(new TestingLocationArbitrator(
117 callback, access_token_store_.get())); 136 callback, access_token_store_.get()));
137 override_content_browser_client_.reset(
138 new GeolocationContentBrowserClient());
118 } 139 }
119 140
120 // testing::Test 141 // testing::Test
121 void TearDown() override {} 142 void TearDown() override {}
122 143
123 void CheckLastPositionInfo(double latitude, 144 void CheckLastPositionInfo(double latitude,
124 double longitude, 145 double longitude,
125 double accuracy) { 146 double accuracy) {
126 Geoposition geoposition = observer_->last_position_; 147 Geoposition geoposition = observer_->last_position_;
127 EXPECT_TRUE(geoposition.Validate()); 148 EXPECT_TRUE(geoposition.Validate());
128 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); 149 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude);
129 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); 150 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude);
130 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); 151 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy);
131 } 152 }
132 153
133 base::TimeDelta SwitchOnFreshnessCliff() { 154 base::TimeDelta SwitchOnFreshnessCliff() {
134 // Add 1, to ensure it meets any greater-than test. 155 // Add 1, to ensure it meets any greater-than test.
135 return base::TimeDelta::FromMilliseconds( 156 return base::TimeDelta::FromMilliseconds(
136 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); 157 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1);
137 } 158 }
138 159
139 MockLocationProvider* cell() { 160 MockLocationProvider* cell() {
140 return arbitrator_->cell_; 161 return arbitrator_->cell_;
141 } 162 }
142 163
143 MockLocationProvider* gps() { 164 MockLocationProvider* gps() {
144 return arbitrator_->gps_; 165 return arbitrator_->gps_;
145 } 166 }
146 167
168 MockLocationProvider* GetSystemLocationProviderOverride() {
169 return override_content_browser_client_->provider_;
170 }
171
147 scoped_refptr<FakeAccessTokenStore> access_token_store_; 172 scoped_refptr<FakeAccessTokenStore> access_token_store_;
148 std::unique_ptr<MockLocationObserver> observer_; 173 std::unique_ptr<MockLocationObserver> observer_;
149 std::unique_ptr<TestingLocationArbitrator> arbitrator_; 174 std::unique_ptr<TestingLocationArbitrator> arbitrator_;
150 base::MessageLoop loop_; 175 base::MessageLoop loop_;
176 std::unique_ptr<GeolocationContentBrowserClient>
177 override_content_browser_client_;
151 }; 178 };
152 179
153 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { 180 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
154 EXPECT_TRUE(access_token_store_.get()); 181 EXPECT_TRUE(access_token_store_.get());
155 EXPECT_TRUE(arbitrator_ != NULL); 182 EXPECT_TRUE(arbitrator_);
156 arbitrator_.reset(); 183 arbitrator_.reset();
157 SUCCEED(); 184 SUCCEED();
158 } 185 }
159 186
160 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { 187 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
161 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 188 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
162 arbitrator_->OnPermissionGranted(); 189 arbitrator_->OnPermissionGranted();
163 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 190 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
164 // Can't check the provider has been notified without going through the 191 // Can't check the provider has been notified without going through the
165 // motions to create the provider (see next test). 192 // motions to create the provider (see next test).
166 EXPECT_FALSE(cell()); 193 EXPECT_FALSE(cell());
167 EXPECT_FALSE(gps()); 194 EXPECT_FALSE(gps());
195 EXPECT_FALSE(GetSystemLocationProviderOverride());
168 } 196 }
169 197
170 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { 198 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
171 ASSERT_TRUE(access_token_store_.get()); 199 ASSERT_TRUE(access_token_store_.get());
172 ASSERT_TRUE(arbitrator_ != NULL); 200 ASSERT_TRUE(arbitrator_);
173 201
174 EXPECT_FALSE(cell()); 202 EXPECT_FALSE(cell());
175 EXPECT_FALSE(gps()); 203 EXPECT_FALSE(gps());
204 EXPECT_FALSE(GetSystemLocationProviderOverride());
176 arbitrator_->StartProviders(false); 205 arbitrator_->StartProviders(false);
177 206
178 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 207 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
179 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
180 208
181 access_token_store_->NotifyDelegateTokensLoaded(); 209 access_token_store_->NotifyDelegateTokensLoaded();
182 ASSERT_TRUE(cell()); 210 ASSERT_TRUE(cell());
183 EXPECT_TRUE(gps()); 211 EXPECT_TRUE(gps());
212 EXPECT_FALSE(GetSystemLocationProviderOverride());
184 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 213 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
185 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 214 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
186 EXPECT_FALSE(observer_->last_position_.Validate()); 215 EXPECT_FALSE(observer_->last_position_.Validate());
187 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, 216 EXPECT_EQ(Geoposition::ERROR_CODE_NONE,
188 observer_->last_position_.error_code); 217 observer_->last_position_.error_code);
189 218
190 SetReferencePosition(cell()); 219 SetReferencePosition(cell());
191 220
192 EXPECT_TRUE(observer_->last_position_.Validate() || 221 EXPECT_TRUE(observer_->last_position_.Validate() ||
193 observer_->last_position_.error_code != 222 observer_->last_position_.error_code !=
194 Geoposition::ERROR_CODE_NONE); 223 Geoposition::ERROR_CODE_NONE);
195 EXPECT_EQ(cell()->position_.latitude, 224 EXPECT_EQ(cell()->position_.latitude,
196 observer_->last_position_.latitude); 225 observer_->last_position_.latitude);
197 226
198 EXPECT_FALSE(cell()->is_permission_granted_); 227 EXPECT_FALSE(cell()->is_permission_granted_);
199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 228 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
200 arbitrator_->OnPermissionGranted(); 229 arbitrator_->OnPermissionGranted();
201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 230 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
202 EXPECT_TRUE(cell()->is_permission_granted_); 231 EXPECT_TRUE(cell()->is_permission_granted_);
203 } 232 }
204 233
234 TEST_F(GeolocationLocationArbitratorTest, OverrideNoNetworkUsage) {
235 override_content_browser_client_->SetUseNetwork(false);
236 SetBrowserClientForTesting(override_content_browser_client_.get());
237 ASSERT_TRUE(arbitrator_);
238
239 EXPECT_FALSE(cell());
240 EXPECT_FALSE(gps());
241 EXPECT_FALSE(GetSystemLocationProviderOverride());
242 arbitrator_->StartProviders(false);
243
244 ASSERT_FALSE(cell());
245 EXPECT_FALSE(gps());
246 EXPECT_TRUE(GetSystemLocationProviderOverride());
247 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
248 GetSystemLocationProviderOverride()->state_);
249 EXPECT_FALSE(observer_->last_position_.Validate());
250 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
251
252 SetReferencePosition(GetSystemLocationProviderOverride());
253
254 EXPECT_TRUE(observer_->last_position_.Validate() ||
255 observer_->last_position_.error_code !=
256 Geoposition::ERROR_CODE_NONE);
257 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude,
258 observer_->last_position_.latitude);
259
260 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_);
261 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
262 arbitrator_->OnPermissionGranted();
263 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
264 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_);
265 }
266
267 TEST_F(GeolocationLocationArbitratorTest, OverrideAndNetworkUsage) {
268 override_content_browser_client_->SetUseNetwork(true);
269 content::SetBrowserClientForTesting(override_content_browser_client_.get());
270 ASSERT_TRUE(arbitrator_);
271
272 EXPECT_FALSE(cell());
273 EXPECT_FALSE(gps());
274 EXPECT_FALSE(GetSystemLocationProviderOverride());
275 arbitrator_->StartProviders(false);
276
277 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
278
279 access_token_store_->NotifyDelegateTokensLoaded();
280
281 ASSERT_TRUE(cell());
282 EXPECT_FALSE(gps());
283 EXPECT_TRUE(GetSystemLocationProviderOverride());
284 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
285 GetSystemLocationProviderOverride()->state_);
286 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
287 EXPECT_FALSE(observer_->last_position_.Validate());
288 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code);
289
290 SetReferencePosition(cell());
291
292 EXPECT_TRUE(observer_->last_position_.Validate() ||
293 observer_->last_position_.error_code !=
294 Geoposition::ERROR_CODE_NONE);
295 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude);
296
297 EXPECT_FALSE(cell()->is_permission_granted_);
298 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
299 arbitrator_->OnPermissionGranted();
300 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
301 EXPECT_TRUE(cell()->is_permission_granted_);
302 }
303
205 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { 304 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
206 arbitrator_->StartProviders(false); 305 arbitrator_->StartProviders(false);
207 access_token_store_->NotifyDelegateTokensLoaded(); 306 access_token_store_->NotifyDelegateTokensLoaded();
208 ASSERT_TRUE(cell()); 307 ASSERT_TRUE(cell());
209 ASSERT_TRUE(gps()); 308 ASSERT_TRUE(gps());
309 EXPECT_FALSE(GetSystemLocationProviderOverride());
210 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 310 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
211 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 311 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
212 SetReferencePosition(cell()); 312 SetReferencePosition(cell());
213 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 313 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
214 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 314 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
215 arbitrator_->StartProviders(true); 315 arbitrator_->StartProviders(true);
216 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); 316 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_);
217 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); 317 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_);
318 EXPECT_FALSE(GetSystemLocationProviderOverride());
218 } 319 }
219 320
220 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 321 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
221 arbitrator_->StartProviders(false); 322 arbitrator_->StartProviders(false);
222 access_token_store_->NotifyDelegateTokensLoaded(); 323 access_token_store_->NotifyDelegateTokensLoaded();
223 ASSERT_TRUE(cell()); 324 ASSERT_TRUE(cell());
224 ASSERT_TRUE(gps()); 325 ASSERT_TRUE(gps());
326 EXPECT_FALSE(GetSystemLocationProviderOverride());
225 327
226 SetPositionFix(cell(), 1, 2, 150); 328 SetPositionFix(cell(), 1, 2, 150);
227 329
228 // First position available 330 // First position available
229 EXPECT_TRUE(observer_->last_position_.Validate()); 331 EXPECT_TRUE(observer_->last_position_.Validate());
230 CheckLastPositionInfo(1, 2, 150); 332 CheckLastPositionInfo(1, 2, 150);
231 333
232 SetPositionFix(gps(), 3, 4, 50); 334 SetPositionFix(gps(), 3, 4, 50);
233 335
234 // More accurate fix available 336 // More accurate fix available
(...skipping 24 matching lines...) Expand all
259 // 5 mins later switch cells while walking. Stay on gps. 361 // 5 mins later switch cells while walking. Stay on gps.
260 AdvanceTimeNow(base::TimeDelta::FromMinutes(5)); 362 AdvanceTimeNow(base::TimeDelta::FromMinutes(5));
261 SetPositionFix(cell(), 3.567832, 139.634648, 300); 363 SetPositionFix(cell(), 3.567832, 139.634648, 300);
262 SetPositionFix(gps(), 3.5677675, 139.632314, 50); 364 SetPositionFix(gps(), 3.5677675, 139.632314, 50);
263 CheckLastPositionInfo(3.5677675, 139.632314, 50); 365 CheckLastPositionInfo(3.5677675, 139.632314, 50);
264 366
265 // Ride train and gps signal degrades slightly. Stay on fresher gps 367 // Ride train and gps signal degrades slightly. Stay on fresher gps
266 AdvanceTimeNow(base::TimeDelta::FromMinutes(5)); 368 AdvanceTimeNow(base::TimeDelta::FromMinutes(5));
267 SetPositionFix(gps(), 3.5679026, 139.634777, 300); 369 SetPositionFix(gps(), 3.5679026, 139.634777, 300);
268 CheckLastPositionInfo(3.5679026, 139.634777, 300); 370 CheckLastPositionInfo(3.5679026, 139.634777, 300);
269
Michael van Ouwerkerk 2016/06/10 12:46:52 nit: please leave this blank line as is
CJ 2016/06/10 19:51:34 Done.
270 // 14 minutes later 371 // 14 minutes later
271 AdvanceTimeNow(base::TimeDelta::FromMinutes(14)); 372 AdvanceTimeNow(base::TimeDelta::FromMinutes(14));
272 373
273 // GPS reading misses a beat, but don't switch to cell yet to avoid 374 // GPS reading misses a beat, but don't switch to cell yet to avoid
274 // oscillating. 375 // oscillating.
275 SetPositionFix(gps(), 3.5659005, 139.682579, 300); 376 SetPositionFix(gps(), 3.5659005, 139.682579, 300);
276 377
277 AdvanceTimeNow(base::TimeDelta::FromSeconds(7)); 378 AdvanceTimeNow(base::TimeDelta::FromSeconds(7));
278 SetPositionFix(cell(), 3.5689579, 139.691420, 1000); 379 SetPositionFix(cell(), 3.5689579, 139.691420, 1000);
279 CheckLastPositionInfo(3.5659005, 139.682579, 300); 380 CheckLastPositionInfo(3.5659005, 139.682579, 300);
(...skipping 11 matching lines...) Expand all
291 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 392 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
292 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 393 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
293 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 394 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
294 } 395 }
295 396
296 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { 397 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
297 arbitrator_->StartProviders(false); 398 arbitrator_->StartProviders(false);
298 access_token_store_->NotifyDelegateTokensLoaded(); 399 access_token_store_->NotifyDelegateTokensLoaded();
299 ASSERT_TRUE(cell()); 400 ASSERT_TRUE(cell());
300 ASSERT_TRUE(gps()); 401 ASSERT_TRUE(gps());
402 EXPECT_FALSE(GetSystemLocationProviderOverride());
301 403
302 // Set the initial position. 404 // Set the initial position.
303 SetPositionFix(cell(), 3, 139, 100); 405 SetPositionFix(cell(), 3, 139, 100);
304 CheckLastPositionInfo(3, 139, 100); 406 CheckLastPositionInfo(3, 139, 100);
305 407
306 // Restart providers to simulate a one-shot request. 408 // Restart providers to simulate a one-shot request.
307 arbitrator_->StopProviders(); 409 arbitrator_->StopProviders();
308 410
309 // To test 240956, perform a throwaway alloc. 411 // To test 240956, perform a throwaway alloc.
310 // This convinces the allocator to put the providers in a new memory location. 412 // This convinces the allocator to put the providers in a new memory location.
311 MockLocationProvider* fakeMockProvider = NULL; 413 std::unique_ptr<MockLocationProvider> fakeMockProvider(
312 LocationProvider* fakeProvider = 414 new MockLocationProvider);
313 new MockLocationProvider(&fakeMockProvider);
314 415
315 arbitrator_->StartProviders(false); 416 arbitrator_->StartProviders(false);
316 access_token_store_->NotifyDelegateTokensLoaded(); 417 access_token_store_->NotifyDelegateTokensLoaded();
317 418
318 // Advance the time a short while to simulate successive calls. 419 // Advance the time a short while to simulate successive calls.
319 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 420 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
320 421
321 // Update with a less accurate position to verify 240956. 422 // Update with a less accurate position to verify 240956.
322 SetPositionFix(cell(), 3, 139, 150); 423 SetPositionFix(cell(), 3, 139, 150);
323 CheckLastPositionInfo(3, 139, 150); 424 CheckLastPositionInfo(3, 139, 150);
324
325 // No delete required for fakeMockProvider. It points to fakeProvider.
326 delete fakeProvider;
327 } 425 }
328 426
329 } // namespace content 427 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698