| 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 "base/memory/ptr_util.h" |
| 10 #include "content/browser/geolocation/fake_access_token_store.h" | 11 #include "content/browser/geolocation/fake_access_token_store.h" |
| 11 #include "content/browser/geolocation/mock_location_provider.h" | 12 #include "content/browser/geolocation/mock_location_provider.h" |
| 12 #include "content/public/common/geoposition.h" | 13 #include "content/public/common/geoposition.h" |
| 14 #include "content/test/test_content_browser_client.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 using ::testing::NiceMock; | 18 using ::testing::NiceMock; |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 20 class MockLocationObserver { | 22 class MockLocationObserver { |
| 21 public: | 23 public: |
| 22 // Need a vtable for GMock. | 24 // Need a vtable for GMock. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ASSERT_TRUE(position.Validate()); | 59 ASSERT_TRUE(position.Validate()); |
| 58 provider->HandlePositionChanged(position); | 60 provider->HandlePositionChanged(position); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SetReferencePosition(MockLocationProvider* provider) { | 63 void SetReferencePosition(MockLocationProvider* provider) { |
| 62 SetPositionFix(provider, 51.0, -0.1, 400); | 64 SetPositionFix(provider, 51.0, -0.1, 400); |
| 63 } | 65 } |
| 64 | 66 |
| 65 namespace { | 67 namespace { |
| 66 | 68 |
| 69 class GeolocationContentBrowserClient : public TestContentBrowserClient { |
| 70 public: |
| 71 GeolocationContentBrowserClient() {} |
| 72 |
| 73 void set_use_network(bool use_network) { use_network_ = use_network; } |
| 74 |
| 75 LocationProvider* OverrideSystemLocationProvider() override { |
| 76 provider_ = new MockLocationProvider; |
| 77 return provider_; |
| 78 } |
| 79 |
| 80 bool UseNetworkLocationProviders() override { return use_network_; } |
| 81 |
| 82 // This provider does not own the object. It is returned by |
| 83 // GeolocationLocationAribtratorTest::GetSystemLocationProviderOverride(). |
| 84 // The caller takes ownership. This is just a reference we can use for |
| 85 // mocking purposes. |
| 86 MockLocationProvider* provider_ = nullptr; |
| 87 |
| 88 private: |
| 89 bool use_network_ = true; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(GeolocationContentBrowserClient); |
| 92 }; |
| 93 |
| 67 class TestingLocationArbitrator : public LocationArbitratorImpl { | 94 class TestingLocationArbitrator : public LocationArbitratorImpl { |
| 68 public: | 95 public: |
| 69 TestingLocationArbitrator( | 96 TestingLocationArbitrator( |
| 70 const LocationArbitratorImpl::LocationUpdateCallback& callback, | 97 const LocationArbitratorImpl::LocationUpdateCallback& callback, |
| 71 AccessTokenStore* access_token_store) | 98 AccessTokenStore* access_token_store) |
| 72 : LocationArbitratorImpl(callback), | 99 : LocationArbitratorImpl(callback), |
| 73 cell_(NULL), | 100 cell_(nullptr), |
| 74 gps_(NULL), | 101 gps_(nullptr), |
| 75 access_token_store_(access_token_store) { | 102 access_token_store_(access_token_store) {} |
| 76 } | |
| 77 | 103 |
| 78 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } | 104 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } |
| 79 | 105 |
| 80 AccessTokenStore* NewAccessTokenStore() override { | 106 AccessTokenStore* NewAccessTokenStore() override { |
| 81 return access_token_store_.get(); | 107 return access_token_store_.get(); |
| 82 } | 108 } |
| 83 | 109 |
| 84 LocationProvider* NewNetworkLocationProvider( | 110 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( |
| 85 AccessTokenStore* access_token_store, | 111 AccessTokenStore* access_token_store, |
| 86 net::URLRequestContextGetter* context, | 112 net::URLRequestContextGetter* context, |
| 87 const GURL& url, | 113 const GURL& url, |
| 88 const base::string16& access_token) override { | 114 const base::string16& access_token) override { |
| 89 return new MockLocationProvider(&cell_); | 115 cell_ = new MockLocationProvider; |
| 116 return base::WrapUnique(cell_); |
| 90 } | 117 } |
| 91 | 118 |
| 92 LocationProvider* NewSystemLocationProvider() override { | 119 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { |
| 93 return new MockLocationProvider(&gps_); | 120 gps_ = new MockLocationProvider; |
| 121 return base::WrapUnique(gps_); |
| 94 } | 122 } |
| 95 | 123 |
| 96 // Two location providers, with nice short names to make the tests more | 124 // 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 | 125 // 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 | 126 // observer registered (and |cell_| when there's at least one observer of any |
| 99 // type). | 127 // type). |
| 128 |
| 129 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and |
| 130 // |gps_| to |system_location_provider_| |
| 100 MockLocationProvider* cell_; | 131 MockLocationProvider* cell_; |
| 101 MockLocationProvider* gps_; | 132 MockLocationProvider* gps_; |
| 102 scoped_refptr<AccessTokenStore> access_token_store_; | 133 scoped_refptr<AccessTokenStore> access_token_store_; |
| 103 }; | 134 }; |
| 104 | 135 |
| 105 } // namespace | 136 } // namespace |
| 106 | 137 |
| 107 class GeolocationLocationArbitratorTest : public testing::Test { | 138 class GeolocationLocationArbitratorTest : public testing::Test { |
| 108 protected: | 139 protected: |
| 109 // testing::Test | 140 // testing::Test |
| 110 void SetUp() override { | 141 void SetUp() override { |
| 111 access_token_store_ = new NiceMock<FakeAccessTokenStore>; | 142 access_token_store_ = new NiceMock<FakeAccessTokenStore>; |
| 112 observer_.reset(new MockLocationObserver); | 143 observer_.reset(new MockLocationObserver); |
| 113 LocationArbitratorImpl::LocationUpdateCallback callback = | 144 LocationArbitratorImpl::LocationUpdateCallback callback = |
| 114 base::Bind(&MockLocationObserver::OnLocationUpdate, | 145 base::Bind(&MockLocationObserver::OnLocationUpdate, |
| 115 base::Unretained(observer_.get())); | 146 base::Unretained(observer_.get())); |
| 116 arbitrator_.reset(new TestingLocationArbitrator( | 147 arbitrator_.reset(new TestingLocationArbitrator( |
| 117 callback, access_token_store_.get())); | 148 callback, access_token_store_.get())); |
| 149 override_content_browser_client_.reset(new GeolocationContentBrowserClient); |
| 118 } | 150 } |
| 119 | 151 |
| 120 // testing::Test | 152 // testing::Test |
| 121 void TearDown() override {} | 153 void TearDown() override {} |
| 122 | 154 |
| 123 void CheckLastPositionInfo(double latitude, | 155 void CheckLastPositionInfo(double latitude, |
| 124 double longitude, | 156 double longitude, |
| 125 double accuracy) { | 157 double accuracy) { |
| 126 Geoposition geoposition = observer_->last_position_; | 158 Geoposition geoposition = observer_->last_position_; |
| 127 EXPECT_TRUE(geoposition.Validate()); | 159 EXPECT_TRUE(geoposition.Validate()); |
| 128 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); | 160 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); |
| 129 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); | 161 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); |
| 130 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); | 162 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); |
| 131 } | 163 } |
| 132 | 164 |
| 133 base::TimeDelta SwitchOnFreshnessCliff() { | 165 base::TimeDelta SwitchOnFreshnessCliff() { |
| 134 // Add 1, to ensure it meets any greater-than test. | 166 // Add 1, to ensure it meets any greater-than test. |
| 135 return base::TimeDelta::FromMilliseconds( | 167 return base::TimeDelta::FromMilliseconds( |
| 136 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); | 168 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); |
| 137 } | 169 } |
| 138 | 170 |
| 139 MockLocationProvider* cell() { | 171 MockLocationProvider* cell() { |
| 140 return arbitrator_->cell_; | 172 return arbitrator_->cell_; |
| 141 } | 173 } |
| 142 | 174 |
| 143 MockLocationProvider* gps() { | 175 MockLocationProvider* gps() { |
| 144 return arbitrator_->gps_; | 176 return arbitrator_->gps_; |
| 145 } | 177 } |
| 146 | 178 |
| 179 MockLocationProvider* GetSystemLocationProviderOverride() { |
| 180 return override_content_browser_client_->provider_; |
| 181 } |
| 182 |
| 147 scoped_refptr<FakeAccessTokenStore> access_token_store_; | 183 scoped_refptr<FakeAccessTokenStore> access_token_store_; |
| 148 std::unique_ptr<MockLocationObserver> observer_; | 184 std::unique_ptr<MockLocationObserver> observer_; |
| 149 std::unique_ptr<TestingLocationArbitrator> arbitrator_; | 185 std::unique_ptr<TestingLocationArbitrator> arbitrator_; |
| 150 base::MessageLoop loop_; | 186 base::MessageLoop loop_; |
| 187 std::unique_ptr<GeolocationContentBrowserClient> |
| 188 override_content_browser_client_; |
| 151 }; | 189 }; |
| 152 | 190 |
| 153 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 191 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
| 154 EXPECT_TRUE(access_token_store_.get()); | 192 EXPECT_TRUE(access_token_store_.get()); |
| 155 EXPECT_TRUE(arbitrator_ != NULL); | 193 EXPECT_TRUE(arbitrator_); |
| 156 arbitrator_.reset(); | 194 arbitrator_.reset(); |
| 157 SUCCEED(); | 195 SUCCEED(); |
| 158 } | 196 } |
| 159 | 197 |
| 160 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { | 198 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { |
| 161 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 162 arbitrator_->OnPermissionGranted(); | 200 arbitrator_->OnPermissionGranted(); |
| 163 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 164 // Can't check the provider has been notified without going through the | 202 // Can't check the provider has been notified without going through the |
| 165 // motions to create the provider (see next test). | 203 // motions to create the provider (see next test). |
| 166 EXPECT_FALSE(cell()); | 204 EXPECT_FALSE(cell()); |
| 167 EXPECT_FALSE(gps()); | 205 EXPECT_FALSE(gps()); |
| 206 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 168 } | 207 } |
| 169 | 208 |
| 170 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { | 209 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { |
| 171 ASSERT_TRUE(access_token_store_.get()); | 210 ASSERT_TRUE(access_token_store_.get()); |
| 172 ASSERT_TRUE(arbitrator_ != NULL); | 211 ASSERT_TRUE(arbitrator_); |
| 173 | 212 |
| 174 EXPECT_FALSE(cell()); | 213 EXPECT_FALSE(cell()); |
| 175 EXPECT_FALSE(gps()); | 214 EXPECT_FALSE(gps()); |
| 215 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 176 arbitrator_->StartProviders(false); | 216 arbitrator_->StartProviders(false); |
| 177 | 217 |
| 178 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | 218 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 179 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); | |
| 180 | 219 |
| 181 access_token_store_->NotifyDelegateTokensLoaded(); | 220 access_token_store_->NotifyDelegateTokensLoaded(); |
| 182 ASSERT_TRUE(cell()); | 221 ASSERT_TRUE(cell()); |
| 183 EXPECT_TRUE(gps()); | 222 EXPECT_TRUE(gps()); |
| 223 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 184 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 224 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 185 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 225 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 186 EXPECT_FALSE(observer_->last_position_.Validate()); | 226 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 187 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, | 227 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, |
| 188 observer_->last_position_.error_code); | 228 observer_->last_position_.error_code); |
| 189 | 229 |
| 190 SetReferencePosition(cell()); | 230 SetReferencePosition(cell()); |
| 191 | 231 |
| 192 EXPECT_TRUE(observer_->last_position_.Validate() || | 232 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 193 observer_->last_position_.error_code != | 233 observer_->last_position_.error_code != |
| 194 Geoposition::ERROR_CODE_NONE); | 234 Geoposition::ERROR_CODE_NONE); |
| 195 EXPECT_EQ(cell()->position_.latitude, | 235 EXPECT_EQ(cell()->position_.latitude, |
| 196 observer_->last_position_.latitude); | 236 observer_->last_position_.latitude); |
| 197 | 237 |
| 198 EXPECT_FALSE(cell()->is_permission_granted_); | 238 EXPECT_FALSE(cell()->is_permission_granted_); |
| 199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 239 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 200 arbitrator_->OnPermissionGranted(); | 240 arbitrator_->OnPermissionGranted(); |
| 201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 241 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 202 EXPECT_TRUE(cell()->is_permission_granted_); | 242 EXPECT_TRUE(cell()->is_permission_granted_); |
| 203 } | 243 } |
| 204 | 244 |
| 245 TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) { |
| 246 override_content_browser_client_->set_use_network(false); |
| 247 SetBrowserClientForTesting(override_content_browser_client_.get()); |
| 248 ASSERT_TRUE(arbitrator_); |
| 249 |
| 250 EXPECT_FALSE(cell()); |
| 251 EXPECT_FALSE(gps()); |
| 252 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 253 arbitrator_->StartProviders(false); |
| 254 |
| 255 ASSERT_FALSE(cell()); |
| 256 EXPECT_FALSE(gps()); |
| 257 EXPECT_TRUE(GetSystemLocationProviderOverride()); |
| 258 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, |
| 259 GetSystemLocationProviderOverride()->state_); |
| 260 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 261 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 262 |
| 263 SetReferencePosition(GetSystemLocationProviderOverride()); |
| 264 |
| 265 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 266 observer_->last_position_.error_code != |
| 267 Geoposition::ERROR_CODE_NONE); |
| 268 EXPECT_EQ(GetSystemLocationProviderOverride()->position_.latitude, |
| 269 observer_->last_position_.latitude); |
| 270 |
| 271 EXPECT_FALSE(GetSystemLocationProviderOverride()->is_permission_granted_); |
| 272 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 273 arbitrator_->OnPermissionGranted(); |
| 274 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 275 EXPECT_TRUE(GetSystemLocationProviderOverride()->is_permission_granted_); |
| 276 } |
| 277 |
| 278 TEST_F(GeolocationLocationArbitratorTest, |
| 279 CustomSystemAndDefaultNetworkProviders) { |
| 280 override_content_browser_client_->set_use_network(true); |
| 281 content::SetBrowserClientForTesting(override_content_browser_client_.get()); |
| 282 ASSERT_TRUE(arbitrator_); |
| 283 |
| 284 EXPECT_FALSE(cell()); |
| 285 EXPECT_FALSE(gps()); |
| 286 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 287 arbitrator_->StartProviders(false); |
| 288 |
| 289 EXPECT_TRUE(access_token_store_->access_token_map_.empty()); |
| 290 |
| 291 access_token_store_->NotifyDelegateTokensLoaded(); |
| 292 |
| 293 ASSERT_TRUE(cell()); |
| 294 EXPECT_FALSE(gps()); |
| 295 EXPECT_TRUE(GetSystemLocationProviderOverride()); |
| 296 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, |
| 297 GetSystemLocationProviderOverride()->state_); |
| 298 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 299 EXPECT_FALSE(observer_->last_position_.Validate()); |
| 300 EXPECT_EQ(Geoposition::ERROR_CODE_NONE, observer_->last_position_.error_code); |
| 301 |
| 302 SetReferencePosition(cell()); |
| 303 |
| 304 EXPECT_TRUE(observer_->last_position_.Validate() || |
| 305 observer_->last_position_.error_code != |
| 306 Geoposition::ERROR_CODE_NONE); |
| 307 EXPECT_EQ(cell()->position_.latitude, observer_->last_position_.latitude); |
| 308 |
| 309 EXPECT_FALSE(cell()->is_permission_granted_); |
| 310 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 311 arbitrator_->OnPermissionGranted(); |
| 312 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 313 EXPECT_TRUE(cell()->is_permission_granted_); |
| 314 } |
| 315 |
| 205 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 316 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
| 206 arbitrator_->StartProviders(false); | 317 arbitrator_->StartProviders(false); |
| 207 access_token_store_->NotifyDelegateTokensLoaded(); | 318 access_token_store_->NotifyDelegateTokensLoaded(); |
| 208 ASSERT_TRUE(cell()); | 319 ASSERT_TRUE(cell()); |
| 209 ASSERT_TRUE(gps()); | 320 ASSERT_TRUE(gps()); |
| 321 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 210 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 322 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 211 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 323 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 212 SetReferencePosition(cell()); | 324 SetReferencePosition(cell()); |
| 213 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 325 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 214 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 326 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 215 arbitrator_->StartProviders(true); | 327 arbitrator_->StartProviders(true); |
| 216 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); | 328 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, cell()->state_); |
| 217 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); | 329 EXPECT_EQ(MockLocationProvider::HIGH_ACCURACY, gps()->state_); |
| 330 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 218 } | 331 } |
| 219 | 332 |
| 220 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { | 333 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { |
| 221 arbitrator_->StartProviders(false); | 334 arbitrator_->StartProviders(false); |
| 222 access_token_store_->NotifyDelegateTokensLoaded(); | 335 access_token_store_->NotifyDelegateTokensLoaded(); |
| 223 ASSERT_TRUE(cell()); | 336 ASSERT_TRUE(cell()); |
| 224 ASSERT_TRUE(gps()); | 337 ASSERT_TRUE(gps()); |
| 338 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 225 | 339 |
| 226 SetPositionFix(cell(), 1, 2, 150); | 340 SetPositionFix(cell(), 1, 2, 150); |
| 227 | 341 |
| 228 // First position available | 342 // First position available |
| 229 EXPECT_TRUE(observer_->last_position_.Validate()); | 343 EXPECT_TRUE(observer_->last_position_.Validate()); |
| 230 CheckLastPositionInfo(1, 2, 150); | 344 CheckLastPositionInfo(1, 2, 150); |
| 231 | 345 |
| 232 SetPositionFix(gps(), 3, 4, 50); | 346 SetPositionFix(gps(), 3, 4, 50); |
| 233 | 347 |
| 234 // More accurate fix available | 348 // 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. | 405 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. |
| 292 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); | 406 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); |
| 293 CheckLastPositionInfo(3.5658700, 139.069979, 1000); | 407 CheckLastPositionInfo(3.5658700, 139.069979, 1000); |
| 294 } | 408 } |
| 295 | 409 |
| 296 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { | 410 TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) { |
| 297 arbitrator_->StartProviders(false); | 411 arbitrator_->StartProviders(false); |
| 298 access_token_store_->NotifyDelegateTokensLoaded(); | 412 access_token_store_->NotifyDelegateTokensLoaded(); |
| 299 ASSERT_TRUE(cell()); | 413 ASSERT_TRUE(cell()); |
| 300 ASSERT_TRUE(gps()); | 414 ASSERT_TRUE(gps()); |
| 415 EXPECT_FALSE(GetSystemLocationProviderOverride()); |
| 301 | 416 |
| 302 // Set the initial position. | 417 // Set the initial position. |
| 303 SetPositionFix(cell(), 3, 139, 100); | 418 SetPositionFix(cell(), 3, 139, 100); |
| 304 CheckLastPositionInfo(3, 139, 100); | 419 CheckLastPositionInfo(3, 139, 100); |
| 305 | 420 |
| 306 // Restart providers to simulate a one-shot request. | 421 // Restart providers to simulate a one-shot request. |
| 307 arbitrator_->StopProviders(); | 422 arbitrator_->StopProviders(); |
| 308 | 423 |
| 309 // To test 240956, perform a throwaway alloc. | 424 // To test 240956, perform a throwaway alloc. |
| 310 // This convinces the allocator to put the providers in a new memory location. | 425 // This convinces the allocator to put the providers in a new memory location. |
| 311 MockLocationProvider* fakeMockProvider = NULL; | 426 std::unique_ptr<MockLocationProvider> dummy_provider( |
| 312 LocationProvider* fakeProvider = | 427 new MockLocationProvider); |
| 313 new MockLocationProvider(&fakeMockProvider); | |
| 314 | 428 |
| 315 arbitrator_->StartProviders(false); | 429 arbitrator_->StartProviders(false); |
| 316 access_token_store_->NotifyDelegateTokensLoaded(); | 430 access_token_store_->NotifyDelegateTokensLoaded(); |
| 317 | 431 |
| 318 // Advance the time a short while to simulate successive calls. | 432 // Advance the time a short while to simulate successive calls. |
| 319 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 433 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
| 320 | 434 |
| 321 // Update with a less accurate position to verify 240956. | 435 // Update with a less accurate position to verify 240956. |
| 322 SetPositionFix(cell(), 3, 139, 150); | 436 SetPositionFix(cell(), 3, 139, 150); |
| 323 CheckLastPositionInfo(3, 139, 150); | 437 CheckLastPositionInfo(3, 139, 150); |
| 324 | |
| 325 // No delete required for fakeMockProvider. It points to fakeProvider. | |
| 326 delete fakeProvider; | |
| 327 } | 438 } |
| 328 | 439 |
| 329 } // namespace content | 440 } // namespace content |
| OLD | NEW |