Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: content/browser/geolocation/location_arbitrator_impl_unittest.cc

Issue 2126893003: Geolocation cleanup: make GeolocationDelegate::OverrideSystemLocationProvider return unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
Wez 2016/07/07 18:51:39 nit: See below - do you actually need this bare-po
mcasas 2016/07/07 19:07:09 Acknowledged.
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 24 matching lines...) Expand all
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_);
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();
Wez 2016/07/07 18:51:39 Why do you need this special-case for |is_fake_del
mcasas 2016/07/07 19:07:09 OverrideSystemLocationProvider() will always creat
Wez 2016/07/07 21:47:10 My point is that the GetLocationProvider() impleme
mcasas 2016/07/07 23:58:41 Ok, took your suggestion and deepened the cleanup
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698