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