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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 | 69 |
| 70 class FakeGeolocationDelegate : public GeolocationDelegate { | 70 class FakeGeolocationDelegate : public GeolocationDelegate { |
| 71 public: | 71 public: |
| 72 FakeGeolocationDelegate() = default; | 72 FakeGeolocationDelegate() = default; |
| 73 | 73 |
| 74 bool UseNetworkLocationProviders() override { return use_network_; } | 74 bool UseNetworkLocationProviders() override { return use_network_; } |
| 75 void set_use_network(bool use_network) { use_network_ = use_network; } | 75 void set_use_network(bool use_network) { use_network_ = use_network; } |
| 76 | 76 |
| 77 LocationProvider* OverrideSystemLocationProvider() override { | 77 std::unique_ptr<LocationProvider> OverrideSystemLocationProvider() override { |
| 78 if (!system_location_provider_) | 78 std::unique_ptr<LocationProvider> provider(new MockLocationProvider); |
| 79 system_location_provider_ = base::WrapUnique(new MockLocationProvider); | 79 system_location_provider_ = provider.get(); |
| 80 return system_location_provider_.get(); | 80 return provider; |
| 81 } | 81 } |
| 82 | 82 |
| 83 LocationProvider* system_location_provider() const { | 83 LocationProvider* system_location_provider() const { |
| 84 return system_location_provider_.get(); | 84 return system_location_provider_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 bool use_network_ = true; | 88 bool use_network_ = true; |
| 89 std::unique_ptr<LocationProvider> system_location_provider_; | 89 LocationProvider* system_location_provider_ = nullptr; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class TestingLocationArbitrator : public LocationArbitratorImpl { | 94 class TestingLocationArbitrator : public LocationArbitratorImpl { |
| 95 public: | 95 public: |
| 96 TestingLocationArbitrator( | 96 TestingLocationArbitrator( |
| 97 const LocationArbitratorImpl::LocationUpdateCallback& callback, | 97 const LocationArbitratorImpl::LocationUpdateCallback& callback, |
| 98 AccessTokenStore* access_token_store, | 98 AccessTokenStore* access_token_store, |
| 99 GeolocationDelegate* delegate, | 99 GeolocationDelegate* delegate, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 118 cell_ = new MockLocationProvider; | 118 cell_ = new MockLocationProvider; |
| 119 return base::WrapUnique(cell_); | 119 return base::WrapUnique(cell_); |
| 120 } | 120 } |
| 121 | 121 |
| 122 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { | 122 std::unique_ptr<LocationProvider> NewSystemLocationProvider() override { |
| 123 gps_ = new MockLocationProvider; | 123 gps_ = new MockLocationProvider; |
| 124 return base::WrapUnique(gps_); | 124 return base::WrapUnique(gps_); |
| 125 } | 125 } |
| 126 | 126 |
| 127 FakeGeolocationDelegate* GetFakeGeolocationDelegate() { | 127 FakeGeolocationDelegate* GetFakeGeolocationDelegate() { |
| 128 DCHECK(is_fake_delegate_); | 128 DCHECK(is_fake_delegate_); |
|
Wez
2016/07/08 23:12:57
You don't want to remove this, otherwise someone w
| |
| 129 return static_cast<FakeGeolocationDelegate*>(GetDelegateForTesting()); | 129 return static_cast<FakeGeolocationDelegate*>(GetDelegateForTesting()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 LocationProvider* GetLocationProvider() { | 132 LocationProvider* GetLocationProvider() { |
| 133 if (is_fake_delegate_) | 133 if (is_fake_delegate_) |
| 134 return GetFakeGeolocationDelegate()->system_location_provider(); | 134 return GetFakeGeolocationDelegate()->system_location_provider(); |
| 135 return GetDelegateForTesting()->OverrideSystemLocationProvider(); | 135 system_location_provider_ = |
| 136 GetDelegateForTesting()->OverrideSystemLocationProvider(); | |
| 137 return system_location_provider_.get(); | |
| 136 } | 138 } |
| 137 | 139 |
| 138 const bool is_fake_delegate_; | 140 const bool is_fake_delegate_; |
| 139 | 141 |
| 140 // Two location providers, with nice short names to make the tests more | 142 // Two location providers, with nice short names to make the tests more |
| 141 // readable. Note |gps_| will only be set when there is a high accuracy | 143 // readable. Note |gps_| will only be set when there is a high accuracy |
| 142 // observer registered (and |cell_| when there's at least one observer of any | 144 // observer registered (and |cell_| when there's at least one observer of any |
| 143 // type). | 145 // type). |
| 144 | |
| 145 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and | 146 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and |
| 146 // |gps_| to |system_location_provider_| | 147 // |gps_| to |gps_location_provider_| |
| 147 MockLocationProvider* cell_; | 148 MockLocationProvider* cell_; |
| 148 MockLocationProvider* gps_; | 149 MockLocationProvider* gps_; |
| 150 std::unique_ptr<LocationProvider> system_location_provider_; | |
| 149 scoped_refptr<AccessTokenStore> access_token_store_; | 151 scoped_refptr<AccessTokenStore> access_token_store_; |
| 150 }; | 152 }; |
| 151 | 153 |
| 152 } // namespace | 154 } // namespace |
| 153 | 155 |
| 154 class GeolocationLocationArbitratorTest : public testing::Test { | 156 class GeolocationLocationArbitratorTest : public testing::Test { |
| 155 protected: | 157 protected: |
| 156 // testing::Test | 158 // testing::Test |
| 157 void SetUp() override { | 159 void SetUp() override { |
| 158 access_token_store_ = new NiceMock<FakeAccessTokenStore>; | 160 access_token_store_ = new NiceMock<FakeAccessTokenStore>; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 | 461 |
| 460 // Advance the time a short while to simulate successive calls. | 462 // Advance the time a short while to simulate successive calls. |
| 461 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); | 463 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); |
| 462 | 464 |
| 463 // Update with a less accurate position to verify 240956. | 465 // Update with a less accurate position to verify 240956. |
| 464 SetPositionFix(cell(), 3, 139, 150); | 466 SetPositionFix(cell(), 3, 139, 150); |
| 465 CheckLastPositionInfo(3, 139, 150); | 467 CheckLastPositionInfo(3, 139, 150); |
| 466 } | 468 } |
| 467 | 469 |
| 468 } // namespace content | 470 } // namespace content |
| OLD | NEW |