Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; } | |
|
Wez
2016/06/10 23:40:35
nit: As per Chromium-style guide, simple setters a
CJ
2016/06/13 23:45:20
Done.
| |
| 71 | |
| 72 LocationProvider* OverrideSystemLocationProvider() override { | |
|
Wez
2016/06/10 23:40:35
Note that in general we do not allow virtual funct
CJ
2016/06/13 23:45:20
Acknowledged.
| |
| 73 provider_ = new MockLocationProvider; | |
| 74 return provider_; | |
| 75 } | |
| 76 | |
| 77 bool UseNetworkLocationProviders() override { return use_network_; } | |
| 78 | |
| 79 MockLocationProvider* provider_ = nullptr; | |
|
Wez
2016/06/10 23:40:34
Please add a comment here to clarify that this poi
CJ
2016/06/13 23:45:20
Done.
| |
| 80 | |
| 81 private: | |
| 82 bool use_network_ = true; | |
| 83 }; | |
|
Wez
2016/06/10 23:40:35
nit: DISALLOW_COPY_AND_ASSIGN
CJ
2016/06/13 23:45:20
Done.
| |
| 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). |
| 119 | |
| 120 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and | |
| 121 // |gps_| to |system_location_provider_| | |
| 100 MockLocationProvider* cell_; | 122 MockLocationProvider* cell_; |
| 101 MockLocationProvider* gps_; | 123 MockLocationProvider* gps_; |
| 102 scoped_refptr<AccessTokenStore> access_token_store_; | 124 scoped_refptr<AccessTokenStore> access_token_store_; |
| 103 }; | 125 }; |
| 104 | 126 |
| 105 } // namespace | 127 } // namespace |
| 106 | 128 |
| 107 class GeolocationLocationArbitratorTest : public testing::Test { | 129 class GeolocationLocationArbitratorTest : public testing::Test { |
| 108 protected: | 130 protected: |
| 109 // testing::Test | 131 // testing::Test |
| 110 void SetUp() override { | 132 void SetUp() override { |
| 111 access_token_store_ = new NiceMock<FakeAccessTokenStore>; | 133 access_token_store_ = new NiceMock<FakeAccessTokenStore>; |
| 112 observer_.reset(new MockLocationObserver); | 134 observer_.reset(new MockLocationObserver); |
| 113 LocationArbitratorImpl::LocationUpdateCallback callback = | 135 LocationArbitratorImpl::LocationUpdateCallback callback = |
| 114 base::Bind(&MockLocationObserver::OnLocationUpdate, | 136 base::Bind(&MockLocationObserver::OnLocationUpdate, |
| 115 base::Unretained(observer_.get())); | 137 base::Unretained(observer_.get())); |
| 116 arbitrator_.reset(new TestingLocationArbitrator( | 138 arbitrator_.reset(new TestingLocationArbitrator( |
| 117 callback, access_token_store_.get())); | 139 callback, access_token_store_.get())); |
| 140 override_content_browser_client_.reset( | |
| 141 new GeolocationContentBrowserClient()); | |
| 118 } | 142 } |
| 119 | 143 |
| 120 // testing::Test | 144 // testing::Test |
| 121 void TearDown() override {} | 145 void TearDown() override {} |
| 122 | 146 |
| 123 void CheckLastPositionInfo(double latitude, | 147 void CheckLastPositionInfo(double latitude, |
| 124 double longitude, | 148 double longitude, |
| 125 double accuracy) { | 149 double accuracy) { |
| 126 Geoposition geoposition = observer_->last_position_; | 150 Geoposition geoposition = observer_->last_position_; |
| 127 EXPECT_TRUE(geoposition.Validate()); | 151 EXPECT_TRUE(geoposition.Validate()); |
| 128 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); | 152 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); |
| 129 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 153 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
| 130 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 154 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
| 131 } | 155 } |
| 132 | 156 |
| 133 base::TimeDelta SwitchOnFreshnessCliff() { | 157 base::TimeDelta SwitchOnFreshnessCliff() { |
| 134 // Add 1, to ensure it meets any greater-than test. | 158 // Add 1, to ensure it meets any greater-than test. |
| 135 return base::TimeDelta::FromMilliseconds( | 159 return base::TimeDelta::FromMilliseconds( |
| 136 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 160 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); |
| 137 } | 161 } |
| 138 | 162 |
| 139 MockLocationProvider* cell() { | 163 MockLocationProvider* cell() { |
| 140 return arbitrator_->cell_; | 164 return arbitrator_->cell_; |
| 141 } | 165 } |
| 142 | 166 |
| 143 MockLocationProvider* gps() { | 167 MockLocationProvider* gps() { |
| 144 return arbitrator_->gps_; | 168 return arbitrator_->gps_; |
| 145 } | 169 } |
| 146 | 170 |
| 171 MockLocationProvider* GetSystemLocationProviderOverride() { | |
| 172 return override_content_browser_client_->provider_; | |
| 173 } | |
| 174 | |
| 147 scoped_refptr<FakeAccessTokenStore> access_token_store_; | 175 scoped_refptr<FakeAccessTokenStore> access_token_store_; |
| 148 std::unique_ptr<MockLocationObserver> observer_; | 176 std::unique_ptr<MockLocationObserver> observer_; |
| 149 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 177 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
| 150 base::MessageLoop loop_; | 178 base::MessageLoop loop_; |
| 179 std::unique_ptr<GeolocationContentBrowserClient> | |
| 180 override_content_browser_client_; | |
| 151 }; | 181 }; |
| 152 | 182 |
| 153 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 183 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
| 154 EXPECT_TRUE(access_token_store_.get()); | 184 EXPECT_TRUE(access_token_store_.get()); |
| 155 EXPECT_TRUE(arbitrator_ != NULL); | 185 EXPECT_TRUE(arbitrator_); |
| 156 arbitrator_.reset(); | 186 arbitrator_.reset(); |
| 157 SUCCEED(); | 187 SUCCEED(); |
| 158 } | 188 } |
| 159 | 189 |
| 160 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { | 190 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { |
| 161 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 191 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 162 arbitrator_->OnPermissionGranted(); | 192 arbitrator_->OnPermissionGranted(); |
| 163 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 193 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 164 // Can't check the provider has been notified without going through the | 194 // Can't check the provider has been notified without going through the |
| 165 // motions to create the provider (see next test). | 195 // motions to create the provider (see next test). |
| 166 EXPECT_FALSE(cell()); | 196 EXPECT_FALSE(cell()); |
| 167 EXPECT_FALSE(gps()); | 197 EXPECT_FALSE(gps()); |
| 198 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 168 } | 199 } |
| 169 | 200 |
| 170 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { | 201 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { |
| 171 ASSERT_TRUE(access_token_store_.get()); | 202 ASSERT_TRUE(access_token_store_.get()); |
| 172 ASSERT_TRUE(arbitrator_ != NULL); | 203 ASSERT_TRUE(arbitrator_); |
| 173 | 204 |
| 174 EXPECT_FALSE(cell()); | 205 EXPECT_FALSE(cell()); |
| 175 EXPECT_FALSE(gps()); | 206 EXPECT_FALSE(gps()); |
| 207 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 176 arbitrator_->StartProviders(false); | 208 arbitrator_->StartProviders(false); |
| 177 | 209 |
| 178 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 210 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 179 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | |
| 180 | 211 |
| 181 access_token_store_->NotifyDelegateTokensLoaded(); | 212 access_token_store_->NotifyDelegateTokensLoaded(); |
| 182 ASSERT_TRUE(cell()); | 213 ASSERT_TRUE(cell()); |
| 183 EXPECT_TRUE(gps()); | 214 EXPECT_TRUE(gps()); |
| 215 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 184 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 216 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 185 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 217 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 186 EXPECT_FALSE(observer_->last_position_.Validate()); | 218 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 187 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, | 219 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, |
| 188 observer_->last_position_.error_code); | 220 observer_->last_position_.error_code); |
| 189 | 221 |
| 190 SetReferencePosition(cell()); | 222 SetReferencePosition(cell()); |
| 191 | 223 |
| 192 EXPECT_TRUE(observer_->last_position_.Validate() || | 224 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 193 observer_->last_position_.error_code != | 225 observer_->last_position_.error_code != |
| 194 Geoposition::ERROR_CODE_NONE); | 226 Geoposition::ERROR_CODE_NONE); |
| 195 EXPECT_EQ(cell()->position_.latitude, | 227 EXPECT_EQ(cell()->position_.latitude, |
| 196 observer_->last_position_.latitude); | 228 observer_->last_position_.latitude); |
| 197 | 229 |
| 198 EXPECT_FALSE(cell()->is_permission_granted_); | 230 EXPECT_FALSE(cell()->is_permission_granted_); |
| 199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 231 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 200 arbitrator_->OnPermissionGranted(); | 232 arbitrator_->OnPermissionGranted(); |
| 201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 233 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 202 EXPECT_TRUE(cell()->is_permission_granted_); | 234 EXPECT_TRUE(cell()->is_permission_granted_); |
| 203 } | 235 } |
| 204 | 236 |
| 237 TEST_F(GeolocationLocationArbitratorTest, OverrideNoNetworkUsage) { | |
|
Wez
2016/06/10 23:40:35
nit: Suggest calling this case CustomSystemProvide
CJ
2016/06/13 23:45:20
Done.
| |
| 238 override_content_browser_client_->SetUseNetwork(false); | |
| 239 SetBrowserClientForTesting(override_content_browser_client_.get()); | |
| 240 ASSERT_TRUE(arbitrator_); | |
| 241 | |
| 242 EXPECT_FALSE(cell()); | |
| 243 EXPECT_FALSE(gps()); | |
| 244 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 245 arbitrator_->StartProviders(false); | |
| 246 | |
| 247 ASSERT_FALSE(cell()); | |
| 248 EXPECT_FALSE(gps()); | |
| 249 EXPECT_TRUE(GetSystemLocationProviderOverride()); | |
| 250 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | |
| 251 GetSystemLocationProviderOverride()->state_); | |
| 252 EXPECT_FALSE(observer_->last_position_.Validate()); | |
| 253 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | |
| 254 | |
| 255 SetReferencePosition(GetSystemLocationProviderOverride()); | |
| 256 | |
| 257 EXPECT_TRUE(observer_->last_position_.Validate() || | |
| 258 observer_->last_position_.error_code != | |
| 259 Geoposition::ERROR_CODE_NONE); | |
| 260 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude, | |
| 261 observer_->last_position_.latitude); | |
| 262 | |
| 263 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_); | |
| 264 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | |
| 265 arbitrator_->OnPermissionGranted(); | |
| 266 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | |
| 267 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_); | |
| 268 } | |
| 269 | |
| 270 TEST_F(GeolocationLocationArbitratorTest, OverrideAndNetworkUsage) { | |
|
Wez
2016/06/10 23:40:35
nit: Suggest CustomSystemAndDefaultNetworkProvider
CJ
2016/06/13 23:45:20
Done.
| |
| 271 override_content_browser_client_->SetUseNetwork(true); | |
| 272 content::SetBrowserClientForTesting(override_content_browser_client_.get()); | |
| 273 ASSERT_TRUE(arbitrator_); | |
| 274 | |
| 275 EXPECT_FALSE(cell()); | |
| 276 EXPECT_FALSE(gps()); | |
| 277 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 278 arbitrator_->StartProviders(false); | |
| 279 | |
| 280 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | |
| 281 | |
| 282 access_token_store_->NotifyDelegateTokensLoaded(); | |
| 283 | |
| 284 ASSERT_TRUE(cell()); | |
| 285 EXPECT_FALSE(gps()); | |
| 286 EXPECT_TRUE(GetSystemLocationProviderOverride()); | |
| 287 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, | |
| 288 GetSystemLocationProviderOverride()->state_); | |
| 289 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | |
| 290 EXPECT_FALSE(observer_->last_position_.Validate()); | |
| 291 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); | |
| 292 | |
| 293 SetReferencePosition(cell()); | |
| 294 | |
| 295 EXPECT_TRUE(observer_->last_position_.Validate() || | |
| 296 observer_->last_position_.error_code != | |
| 297 Geoposition::ERROR_CODE_NONE); | |
| 298 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); | |
| 299 | |
| 300 EXPECT_FALSE(cell()->is_permission_granted_); | |
| 301 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | |
| 302 arbitrator_->OnPermissionGranted(); | |
| 303 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | |
| 304 EXPECT_TRUE(cell()->is_permission_granted_); | |
| 305 } | |
| 306 | |
| 205 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 307 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
| 206 arbitrator_->StartProviders(false); | 308 arbitrator_->StartProviders(false); |
| 207 access_token_store_->NotifyDelegateTokensLoaded(); | 309 access_token_store_->NotifyDelegateTokensLoaded(); |
| 208 ASSERT_TRUE(cell()); | 310 ASSERT_TRUE(cell()); |
| 209 ASSERT_TRUE(gps()); | 311 ASSERT_TRUE(gps()); |
| 312 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 210 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 313 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 211 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 314 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 212 SetReferencePosition(cell()); | 315 SetReferencePosition(cell()); |
| 213 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 316 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 214 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 317 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 215 arbitrator_->StartProviders(true); | 318 arbitrator_->StartProviders(true); |
| 216 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); | 319 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); |
| 217 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); | 320 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); |
| 321 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 218 } | 322 } |
| 219 | 323 |
| 220 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { | 324 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { |
| 221 arbitrator_->StartProviders(false); | 325 arbitrator_->StartProviders(false); |
| 222 access_token_store_->NotifyDelegateTokensLoaded(); | 326 access_token_store_->NotifyDelegateTokensLoaded(); |
| 223 ASSERT_TRUE(cell()); | 327 ASSERT_TRUE(cell()); |
| 224 ASSERT_TRUE(gps()); | 328 ASSERT_TRUE(gps()); |
| 329 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 225 | 330 |
| 226 SetPositionFix(cell(), 1, 2, 150); | 331 SetPositionFix(cell(), 1, 2, 150); |
| 227 | 332 |
| 228 // First position available | 333 // First position available |
| 229 EXPECT_TRUE(observer_->last_position_.Validate()); | 334 EXPECT_TRUE(observer_->last_position_.Validate()); |
| 230 CheckLastPositionInfo(1, 2, 150); | 335 CheckLastPositionInfo(1, 2, 150); |
| 231 | 336 |
| 232 SetPositionFix(gps(), 3, 4, 50); | 337 SetPositionFix(gps(), 3, 4, 50); |
| 233 | 338 |
| 234 // More accurate fix available | 339 // More accurate fix available |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. | 396 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. |
| 292 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); | 397 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); |
| 293 CheckLastPositionInfo(3.5658700, 139.069979, 1000); | 398 CheckLastPositionInfo(3.5658700, 139.069979, 1000); |
| 294 } | 399 } |
| 295 | 400 |
| 296 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { | 401 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { |
| 297 arbitrator_->StartProviders(false); | 402 arbitrator_->StartProviders(false); |
| 298 access_token_store_->NotifyDelegateTokensLoaded(); | 403 access_token_store_->NotifyDelegateTokensLoaded(); |
| 299 ASSERT_TRUE(cell()); | 404 ASSERT_TRUE(cell()); |
| 300 ASSERT_TRUE(gps()); | 405 ASSERT_TRUE(gps()); |
| 406 EXPECT_FALSE(GetSystemLocationProviderOverride()); | |
| 301 | 407 |
| 302 // Set the initial position. | 408 // Set the initial position. |
| 303 SetPositionFix(cell(), 3, 139, 100); | 409 SetPositionFix(cell(), 3, 139, 100); |
| 304 CheckLastPositionInfo(3, 139, 100); | 410 CheckLastPositionInfo(3, 139, 100); |
| 305 | 411 |
| 306 // Restart providers to simulate a one-shot request. | 412 // Restart providers to simulate a one-shot request. |
| 307 arbitrator_->StopProviders(); | 413 arbitrator_->StopProviders(); |
| 308 | 414 |
| 309 // To test 240956, perform a throwaway alloc. | 415 // To test 240956, perform a throwaway alloc. |
| 310 // This convinces the allocator to put the providers in a new memory location. | 416 // This convinces the allocator to put the providers in a new memory location. |
| 311 MockLocationProvider* fakeMockProvider = NULL; | 417 std::unique_ptr<MockLocationProvider> fakeMockProvider( |
|
Wez
2016/06/10 23:40:35
nit: Follow unix_hacker_style naming for variables
CJ
2016/06/13 23:45:20
Done.
| |
| 312 LocationProvider* fakeProvider = | 418 new MockLocationProvider); |
| 313 new MockLocationProvider(&fakeMockProvider); | |
| 314 | 419 |
| 315 arbitrator_->StartProviders(false); | 420 arbitrator_->StartProviders(false); |
| 316 access_token_store_->NotifyDelegateTokensLoaded(); | 421 access_token_store_->NotifyDelegateTokensLoaded(); |
| 317 | 422 |
| 318 // Advance the time a short while to simulate successive calls. | 423 // Advance the time a short while to simulate successive calls. |
| 319 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 424 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
| 320 | 425 |
| 321 // Update with a less accurate position to verify 240956. | 426 // Update with a less accurate position to verify 240956. |
| 322 SetPositionFix(cell(), 3, 139, 150); | 427 SetPositionFix(cell(), 3, 139, 150); |
| 323 CheckLastPositionInfo(3, 139, 150); | 428 CheckLastPositionInfo(3, 139, 150); |
| 324 | |
| 325 // No delete required for fakeMockProvider. It points to fakeProvider. | |
| 326 delete fakeProvider; | |
| 327 } | 429 } |
| 328 | 430 |
| 329 } // namespace content | 431 } // namespace content |
| OLD | NEW |