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