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

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 and mvanouwerkerk's comments + code clean up 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 OverrideContentBrowserClient : public TestContentBrowserClient {
Michael van Ouwerkerk 2016/06/09 13:03:11 The name of this class trips me up a bit, as I rea
CJ 2016/06/09 20:31:50 Done.
69 public:
70 void SetUseNetwork(bool use_network) {
71 use_network_ = use_network;
72 }
73
74 LocationProvider* OverrideSystemLocationProvider() override {
75 provider_ = new MockLocationProvider;
76 return provider_;
77 }
78
79 bool UseNetworkLocationProviders() override {
80 return use_network_;
81 }
82
83 MockLocationProvider* provider_ = nullptr;
84 private:
Michael van Ouwerkerk 2016/06/09 13:03:10 nit: I would expect to see a blank line before "pr
CJ 2016/06/09 20:31:50 Done.
85 bool use_network_ = true;
86 };
87
67 class TestingLocationArbitrator : public LocationArbitratorImpl { 88 class TestingLocationArbitrator : public LocationArbitratorImpl {
68 public: 89 public:
69 TestingLocationArbitrator( 90 TestingLocationArbitrator(
70 const LocationArbitratorImpl::LocationUpdateCallback& callback, 91 const LocationArbitratorImpl::LocationUpdateCallback& callback,
71 AccessTokenStore* access_token_store) 92 AccessTokenStore* access_token_store)
72 : LocationArbitratorImpl(callback), 93 : LocationArbitratorImpl(callback),
73 cell_(NULL),
74 gps_(NULL),
75 access_token_store_(access_token_store) { 94 access_token_store_(access_token_store) {
95 cell_ = nullptr;
Michael van Ouwerkerk 2016/06/09 13:03:10 Why move these inside the constructor body? Genera
CJ 2016/06/09 20:31:50 Done.
96 gps_ = nullptr;
76 } 97 }
77 98
78 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } 99 base::Time GetTimeNow() const override { return GetTimeNowForTest(); }
79 100
80 AccessTokenStore* NewAccessTokenStore() override { 101 AccessTokenStore* NewAccessTokenStore() override {
81 return access_token_store_.get(); 102 return access_token_store_.get();
82 } 103 }
83 104
84 LocationProvider* NewNetworkLocationProvider( 105 LocationProvider* NewNetworkLocationProvider(
85 AccessTokenStore* access_token_store, 106 AccessTokenStore* access_token_store,
86 net::URLRequestContextGetter* context, 107 net::URLRequestContextGetter* context,
87 const GURL& url, 108 const GURL& url,
88 const base::string16& access_token) override { 109 const base::string16& access_token) override {
89 return new MockLocationProvider(&cell_); 110 cell_ = new MockLocationProvider;
111 return cell_;
90 } 112 }
91 113
92 LocationProvider* NewSystemLocationProvider() override { 114 LocationProvider* NewSystemLocationProvider() override {
93 return new MockLocationProvider(&gps_); 115 gps_ = new MockLocationProvider;
116 return gps_;
94 } 117 }
95 118
96 // Two location providers, with nice short names to make the tests more 119 // Three location providers, with nice short names to make the tests more
Michael van Ouwerkerk 2016/06/09 13:03:11 Just two again.
CJ 2016/06/09 20:31:50 Done.
97 // readable. Note |gps_| will only be set when there is a high accuracy 120 // 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 121 // observer registered (and |cell_| when there's at least one observer of any
99 // type). 122 // type). |override_| will be included only if the ContentBrowser specifies
Michael van Ouwerkerk 2016/06/09 13:03:10 |override_| is gone again
CJ 2016/06/09 20:31:50 Done.
123 // for it.
100 MockLocationProvider* cell_; 124 MockLocationProvider* cell_;
101 MockLocationProvider* gps_; 125 MockLocationProvider* gps_;
102 scoped_refptr<AccessTokenStore> access_token_store_; 126 scoped_refptr<AccessTokenStore> access_token_store_;
103 }; 127 };
104 128
105 } // namespace 129 } // namespace
106 130
107 class GeolocationLocationArbitratorTest : public testing::Test { 131 class GeolocationLocationArbitratorTest : public testing::Test {
108 protected: 132 protected:
109 // testing::Test 133 // testing::Test
110 void SetUp() override { 134 void SetUp() override {
111 access_token_store_ = new NiceMock<FakeAccessTokenStore>; 135 access_token_store_ = new NiceMock<FakeAccessTokenStore>;
112 observer_.reset(new MockLocationObserver); 136 observer_.reset(new MockLocationObserver);
113 LocationArbitratorImpl::LocationUpdateCallback callback = 137 LocationArbitratorImpl::LocationUpdateCallback callback =
114 base::Bind(&MockLocationObserver::OnLocationUpdate, 138 base::Bind(&MockLocationObserver::OnLocationUpdate,
115 base::Unretained(observer_.get())); 139 base::Unretained(observer_.get()));
116 arbitrator_.reset(new TestingLocationArbitrator( 140 arbitrator_.reset(new TestingLocationArbitrator(
117 callback, access_token_store_.get())); 141 callback, access_token_store_.get()));
142 override_content_browser_client_.reset(new OverrideContentBrowserClient());
118 } 143 }
119 144
120 // testing::Test 145 // testing::Test
121 void TearDown() override {} 146 void TearDown() override {}
122 147
123 void CheckLastPositionInfo(double latitude, 148 void CheckLastPositionInfo(double latitude,
124 double longitude, 149 double longitude,
125 double accuracy) { 150 double accuracy) {
126 Geoposition geoposition = observer_->last_position_; 151 Geoposition geoposition = observer_->last_position_;
127 EXPECT_TRUE(geoposition.Validate()); 152 EXPECT_TRUE(geoposition.Validate());
128 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); 153 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude);
129 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); 154 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude);
130 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); 155 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy);
131 } 156 }
132 157
133 base::TimeDelta SwitchOnFreshnessCliff() { 158 base::TimeDelta SwitchOnFreshnessCliff() {
134 // Add 1, to ensure it meets any greater-than test. 159 // Add 1, to ensure it meets any greater-than test.
135 return base::TimeDelta::FromMilliseconds( 160 return base::TimeDelta::FromMilliseconds(
136 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); 161 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1);
137 } 162 }
138 163
139 MockLocationProvider* cell() { 164 MockLocationProvider* cell() {
140 return arbitrator_->cell_; 165 return arbitrator_->cell_;
141 } 166 }
142 167
143 MockLocationProvider* gps() { 168 MockLocationProvider* gps() {
144 return arbitrator_->gps_; 169 return arbitrator_->gps_;
145 } 170 }
146 171
172 MockLocationProvider* overrider() {
Michael van Ouwerkerk 2016/06/09 13:03:11 Two things here: 1) This is not a simple member ge
CJ 2016/06/09 20:31:50 Done.
173 return override_content_browser_client_->provider_;
174 }
175
147 scoped_refptr<FakeAccessTokenStore> access_token_store_; 176 scoped_refptr<FakeAccessTokenStore> access_token_store_;
148 std::unique_ptr<MockLocationObserver> observer_; 177 std::unique_ptr<MockLocationObserver> observer_;
149 std::unique_ptr<TestingLocationArbitrator> arbitrator_; 178 std::unique_ptr<TestingLocationArbitrator> arbitrator_;
150 base::MessageLoop loop_; 179 base::MessageLoop loop_;
180 std::unique_ptr<OverrideContentBrowserClient>
181 override_content_browser_client_;
151 }; 182 };
152 183
153 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { 184 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
154 EXPECT_TRUE(access_token_store_.get()); 185 EXPECT_TRUE(access_token_store_.get());
155 EXPECT_TRUE(arbitrator_ != NULL); 186 EXPECT_TRUE(arbitrator_ != NULL);
156 arbitrator_.reset(); 187 arbitrator_.reset();
157 SUCCEED(); 188 SUCCEED();
158 } 189 }
159 190
160 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { 191 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
161 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 192 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
162 arbitrator_->OnPermissionGranted(); 193 arbitrator_->OnPermissionGranted();
163 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 194 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
164 // Can't check the provider has been notified without going through the 195 // Can't check the provider has been notified without going through the
165 // motions to create the provider (see next test). 196 // motions to create the provider (see next test).
166 EXPECT_FALSE(cell()); 197 EXPECT_FALSE(cell());
167 EXPECT_FALSE(gps()); 198 EXPECT_FALSE(gps());
199 EXPECT_FALSE(overrider());
168 } 200 }
169 201
170 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { 202 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
171 ASSERT_TRUE(access_token_store_.get()); 203 ASSERT_TRUE(access_token_store_.get());
172 ASSERT_TRUE(arbitrator_ != NULL); 204 ASSERT_TRUE(arbitrator_ != NULL);
173 205
174 EXPECT_FALSE(cell()); 206 EXPECT_FALSE(cell());
175 EXPECT_FALSE(gps()); 207 EXPECT_FALSE(gps());
208 EXPECT_FALSE(overrider());
176 arbitrator_->StartProviders(false); 209 arbitrator_->StartProviders(false);
177 210
178 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 211 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
179 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); 212 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
180 213
181 access_token_store_->NotifyDelegateTokensLoaded(); 214 access_token_store_->NotifyDelegateTokensLoaded();
182 ASSERT_TRUE(cell()); 215 ASSERT_TRUE(cell());
183 EXPECT_TRUE(gps()); 216 EXPECT_TRUE(gps());
217 EXPECT_FALSE(overrider());
184 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 218 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
185 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 219 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
186 EXPECT_FALSE(observer_->last_position_.Validate()); 220 EXPECT_FALSE(observer_->last_position_.Validate());
187 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, 221 EXPECT_EQ(Geoposition::ERROR_CODE_NONE,
188 observer_->last_position_.error_code); 222 observer_->last_position_.error_code);
189 223
190 SetReferencePosition(cell()); 224 SetReferencePosition(cell());
191 225
192 EXPECT_TRUE(observer_->last_position_.Validate() || 226 EXPECT_TRUE(observer_->last_position_.Validate() ||
193 observer_->last_position_.error_code != 227 observer_->last_position_.error_code !=
194 Geoposition::ERROR_CODE_NONE); 228 Geoposition::ERROR_CODE_NONE);
195 EXPECT_EQ(cell()->position_.latitude, 229 EXPECT_EQ(cell()->position_.latitude,
196 observer_->last_position_.latitude); 230 observer_->last_position_.latitude);
197 231
198 EXPECT_FALSE(cell()->is_permission_granted_); 232 EXPECT_FALSE(cell()->is_permission_granted_);
199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 233 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
200 arbitrator_->OnPermissionGranted(); 234 arbitrator_->OnPermissionGranted();
201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 235 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
202 EXPECT_TRUE(cell()->is_permission_granted_); 236 EXPECT_TRUE(cell()->is_permission_granted_);
203 } 237 }
204 238
239 TEST_F(GeolocationLocationArbitratorTest, OverrideNoNetworkUsage) {
240 override_content_browser_client_->SetUseNetwork(false);
241 content::SetBrowserClientForTesting(override_content_browser_client_.get());
Michael van Ouwerkerk 2016/06/09 13:03:11 nit: I think there's no need for "content::" as we
CJ 2016/06/09 20:31:50 Done.
242 ASSERT_TRUE(arbitrator_ != NULL);
Michael van Ouwerkerk 2016/06/09 13:03:11 nit: use nullptr in new code, but even simpler to
CJ 2016/06/09 20:31:50 Done.
243
244 EXPECT_FALSE(cell());
245 EXPECT_FALSE(gps());
246 EXPECT_FALSE(overrider());
247 arbitrator_->StartProviders(false);
248
249 ASSERT_FALSE(cell());
250 EXPECT_FALSE(gps());
251 EXPECT_TRUE(overrider());
252 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, overrider()->state_);
253 EXPECT_FALSE(observer_->last_position_.Validate());
254 EXPECT_EQ(Geoposition::ERROR_CODE_NONE,
255 observer_->last_position_.error_code);
256
257 SetReferencePosition(overrider());
258
259 EXPECT_TRUE(observer_->last_position_.Validate() ||
260 observer_->last_position_.error_code !=
261 Geoposition::ERROR_CODE_NONE);
262 EXPECT_EQ(overrider()->position_.latitude,
263 observer_->last_position_.latitude);
264
265 EXPECT_FALSE(overrider()->is_permission_granted_);
266 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
267 arbitrator_->OnPermissionGranted();
268 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
269 EXPECT_TRUE(overrider()->is_permission_granted_);
270 }
271
272 TEST_F(GeolocationLocationArbitratorTest, OverrideAndNetworkUsage) {
273 override_content_browser_client_->SetUseNetwork(true);
274 content::SetBrowserClientForTesting(override_content_browser_client_.get());
Michael van Ouwerkerk 2016/06/09 13:03:11 nit: I think there's no need for "content::" as we
CJ 2016/06/09 20:31:50 Done.
275 ASSERT_TRUE(arbitrator_ != NULL);
Michael van Ouwerkerk 2016/06/09 13:03:10 nit: use nullptr in new code, but even simpler to
CJ 2016/06/09 20:31:50 Done.
276
277 EXPECT_FALSE(cell());
278 EXPECT_FALSE(gps());
279 EXPECT_FALSE(overrider());
280 arbitrator_->StartProviders(false);
281
282 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
283 EXPECT_TRUE(access_token_store_->access_token_map_.empty());
Michael van Ouwerkerk 2016/06/09 13:03:11 delete this duplicate line
CJ 2016/06/09 20:31:50 Was wondering about it since it was in the origina
284
285 access_token_store_->NotifyDelegateTokensLoaded();
286
287 ASSERT_TRUE(cell());
288 EXPECT_FALSE(gps());
289 EXPECT_TRUE(overrider());
290 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, overrider()->state_);
291 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
292 EXPECT_FALSE(observer_->last_position_.Validate());
293 EXPECT_EQ(Geoposition::ERROR_CODE_NONE,
294 observer_->last_position_.error_code);
295
296 SetReferencePosition(cell());
297
298 EXPECT_TRUE(observer_->last_position_.Validate() ||
299 observer_->last_position_.error_code !=
300 Geoposition::ERROR_CODE_NONE);
301 EXPECT_EQ(cell()->position_.latitude,
302 observer_->last_position_.latitude);
303
304 EXPECT_FALSE(cell()->is_permission_granted_);
305 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
306 arbitrator_->OnPermissionGranted();
307 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
308 EXPECT_TRUE(cell()->is_permission_granted_);
309 }
310
205 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { 311 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
206 arbitrator_->StartProviders(false); 312 arbitrator_->StartProviders(false);
207 access_token_store_->NotifyDelegateTokensLoaded(); 313 access_token_store_->NotifyDelegateTokensLoaded();
208 ASSERT_TRUE(cell()); 314 ASSERT_TRUE(cell());
209 ASSERT_TRUE(gps()); 315 ASSERT_TRUE(gps());
316 EXPECT_FALSE(overrider());
210 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 317 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
211 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 318 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
212 SetReferencePosition(cell()); 319 SetReferencePosition(cell());
213 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 320 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
214 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 321 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
215 arbitrator_->StartProviders(true); 322 arbitrator_->StartProviders(true);
216 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); 323 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_);
217 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); 324 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_);
325 EXPECT_FALSE(overrider());
218 } 326 }
219 327
220 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 328 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
221 arbitrator_->StartProviders(false); 329 arbitrator_->StartProviders(false);
222 access_token_store_->NotifyDelegateTokensLoaded(); 330 access_token_store_->NotifyDelegateTokensLoaded();
223 ASSERT_TRUE(cell()); 331 ASSERT_TRUE(cell());
224 ASSERT_TRUE(gps()); 332 ASSERT_TRUE(gps());
333 EXPECT_FALSE(overrider());
225 334
226 SetPositionFix(cell(), 1, 2, 150); 335 SetPositionFix(cell(), 1, 2, 150);
227 336
228 // First position available 337 // First position available
229 EXPECT_TRUE(observer_->last_position_.Validate()); 338 EXPECT_TRUE(observer_->last_position_.Validate());
230 CheckLastPositionInfo(1, 2, 150); 339 CheckLastPositionInfo(1, 2, 150);
231 340
232 SetPositionFix(gps(), 3, 4, 50); 341 SetPositionFix(gps(), 3, 4, 50);
233 342
234 // More accurate fix available 343 // More accurate fix available
(...skipping 24 matching lines...) Expand all
259 // 5 mins later switch cells while walking. Stay on gps. 368 // 5 mins later switch cells while walking. Stay on gps.
260 AdvanceTimeNow(base::TimeDelta::FromMinutes(5)); 369 AdvanceTimeNow(base::TimeDelta::FromMinutes(5));
261 SetPositionFix(cell(), 3.567832, 139.634648, 300); 370 SetPositionFix(cell(), 3.567832, 139.634648, 300);
262 SetPositionFix(gps(), 3.5677675, 139.632314, 50); 371 SetPositionFix(gps(), 3.5677675, 139.632314, 50);
263 CheckLastPositionInfo(3.5677675, 139.632314, 50); 372 CheckLastPositionInfo(3.5677675, 139.632314, 50);
264 373
265 // Ride train and gps signal degrades slightly. Stay on fresher gps 374 // Ride train and gps signal degrades slightly. Stay on fresher gps
266 AdvanceTimeNow(base::TimeDelta::FromMinutes(5)); 375 AdvanceTimeNow(base::TimeDelta::FromMinutes(5));
267 SetPositionFix(gps(), 3.5679026, 139.634777, 300); 376 SetPositionFix(gps(), 3.5679026, 139.634777, 300);
268 CheckLastPositionInfo(3.5679026, 139.634777, 300); 377 CheckLastPositionInfo(3.5679026, 139.634777, 300);
269 378 // 14 minutes later AdvanceTimeNow(base::TimeDelta::FromMinutes(14));
Michael van Ouwerkerk 2016/06/09 13:03:10 Did you intend to comment out this line?
CJ 2016/06/09 20:31:50 Done.
270 // 14 minutes later
271 AdvanceTimeNow(base::TimeDelta::FromMinutes(14));
272 379
273 // GPS reading misses a beat, but don't switch to cell yet to avoid 380 // GPS reading misses a beat, but don't switch to cell yet to avoid
274 // oscillating. 381 // oscillating.
275 SetPositionFix(gps(), 3.5659005, 139.682579, 300); 382 SetPositionFix(gps(), 3.5659005, 139.682579, 300);
276 383
277 AdvanceTimeNow(base::TimeDelta::FromSeconds(7)); 384 AdvanceTimeNow(base::TimeDelta::FromSeconds(7));
278 SetPositionFix(cell(), 3.5689579, 139.691420, 1000); 385 SetPositionFix(cell(), 3.5689579, 139.691420, 1000);
279 CheckLastPositionInfo(3.5659005, 139.682579, 300); 386 CheckLastPositionInfo(3.5659005, 139.682579, 300);
280 387
281 // 1 minute later 388 // 1 minute later
282 AdvanceTimeNow(base::TimeDelta::FromMinutes(1)); 389 AdvanceTimeNow(base::TimeDelta::FromMinutes(1));
283 390
284 // Enter tunnel. Stay on fresher gps for a moment. 391 // Enter tunnel. Stay on fresher gps for a moment.
285 SetPositionFix(cell(), 3.5657078, 139.68922, 300); 392 SetPositionFix(cell(), 3.5657078, 139.68922, 300);
286 SetPositionFix(gps(), 3.5657104, 139.690341, 300); 393 SetPositionFix(gps(), 3.5657104, 139.690341, 300);
287 CheckLastPositionInfo(3.5657104, 139.690341, 300); 394 CheckLastPositionInfo(3.5657104, 139.690341, 300);
288 395
289 // 2 minutes later 396 // 2 minutes later
290 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); 397 AdvanceTimeNow(base::TimeDelta::FromMinutes(2));
291 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 398 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
292 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 399 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
293 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 400 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
294 } 401 }
295 402
296 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { 403 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
297 arbitrator_->StartProviders(false); 404 arbitrator_->StartProviders(false);
298 access_token_store_->NotifyDelegateTokensLoaded(); 405 access_token_store_->NotifyDelegateTokensLoaded();
299 ASSERT_TRUE(cell()); 406 ASSERT_TRUE(cell());
300 ASSERT_TRUE(gps()); 407 ASSERT_TRUE(gps());
408 EXPECT_FALSE(overrider());
301 409
302 // Set the initial position. 410 // Set the initial position.
303 SetPositionFix(cell(), 3, 139, 100); 411 SetPositionFix(cell(), 3, 139, 100);
304 CheckLastPositionInfo(3, 139, 100); 412 CheckLastPositionInfo(3, 139, 100);
305 413
306 // Restart providers to simulate a one-shot request. 414 // Restart providers to simulate a one-shot request.
307 arbitrator_->StopProviders(); 415 arbitrator_->StopProviders();
308 416
309 // To test 240956, perform a throwaway alloc. 417 // To test 240956, perform a throwaway alloc.
310 // This convinces the allocator to put the providers in a new memory location. 418 // This convinces the allocator to put the providers in a new memory location.
311 MockLocationProvider* fakeMockProvider = NULL; 419 std::unique_ptr<MockLocationProvider> fakeMockProvider(
312 LocationProvider* fakeProvider = 420 new MockLocationProvider);
313 new MockLocationProvider(&fakeMockProvider);
314 421
315 arbitrator_->StartProviders(false); 422 arbitrator_->StartProviders(false);
316 access_token_store_->NotifyDelegateTokensLoaded(); 423 access_token_store_->NotifyDelegateTokensLoaded();
317 424
318 // Advance the time a short while to simulate successive calls. 425 // Advance the time a short while to simulate successive calls.
319 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 426 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
320 427
321 // Update with a less accurate position to verify 240956. 428 // Update with a less accurate position to verify 240956.
322 SetPositionFix(cell(), 3, 139, 150); 429 SetPositionFix(cell(), 3, 139, 150);
323 CheckLastPositionInfo(3, 139, 150); 430 CheckLastPositionInfo(3, 139, 150);
324
325 // No delete required for fakeMockProvider. It points to fakeProvider.
326 delete fakeProvider;
327 } 431 }
328 432
329 } // namespace content 433 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698