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

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

Issue 2129313002: Geolocation cleanup: corrects uses of content::AccessTokenStore* and net::URLRequestContextGetter* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed StartTestStepFromClientThread() 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate); 91 DISALLOW_COPY_AND_ASSIGN(FakeGeolocationDelegate);
92 }; 92 };
93 93
94 } // namespace 94 } // namespace
95 95
96 class TestingLocationArbitrator : public LocationArbitratorImpl { 96 class TestingLocationArbitrator : public LocationArbitratorImpl {
97 public: 97 public:
98 TestingLocationArbitrator( 98 TestingLocationArbitrator(
99 const LocationArbitratorImpl::LocationUpdateCallback& callback, 99 const LocationArbitratorImpl::LocationUpdateCallback& callback,
100 AccessTokenStore* access_token_store, 100 const scoped_refptr<AccessTokenStore>& access_token_store,
101 GeolocationDelegate* delegate) 101 GeolocationDelegate* delegate)
102 : LocationArbitratorImpl(callback, delegate), 102 : LocationArbitratorImpl(callback, delegate),
103 cell_(nullptr), 103 cell_(nullptr),
104 gps_(nullptr), 104 gps_(nullptr),
105 access_token_store_(access_token_store) {} 105 access_token_store_(access_token_store) {}
106 106
107 base::Time GetTimeNow() const override { return GetTimeNowForTest(); } 107 base::Time GetTimeNow() const override { return GetTimeNowForTest(); }
108 108
109 AccessTokenStore* NewAccessTokenStore() override { 109 scoped_refptr<AccessTokenStore> NewAccessTokenStore() override {
110 return access_token_store_.get(); 110 return access_token_store_;
111 } 111 }
112 112
113 std::unique_ptr<LocationProvider> NewNetworkLocationProvider( 113 std::unique_ptr<LocationProvider> NewNetworkLocationProvider(
114 AccessTokenStore* access_token_store, 114 const scoped_refptr<AccessTokenStore>& access_token_store,
115 net::URLRequestContextGetter* context, 115 const scoped_refptr<net::URLRequestContextGetter>& context,
116 const GURL& url, 116 const GURL& url,
117 const base::string16& access_token) override { 117 const base::string16& access_token) override {
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 // Two location providers, with nice short names to make the tests more 127 // Two location providers, with nice short names to make the tests more
128 // readable. Note |gps_| will only be set when there is a high accuracy 128 // readable. Note |gps_| will only be set when there is a high accuracy
129 // observer registered (and |cell_| when there's at least one observer of any 129 // observer registered (and |cell_| when there's at least one observer of any
130 // type). 130 // type).
131 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and 131 // TODO(mvanouwerkerk): rename |cell_| to |network_location_provider_| and
132 // |gps_| to |gps_location_provider_| 132 // |gps_| to |gps_location_provider_|
133 MockLocationProvider* cell_; 133 MockLocationProvider* cell_;
134 MockLocationProvider* gps_; 134 MockLocationProvider* gps_;
135 std::unique_ptr<LocationProvider> system_location_provider_; 135 const scoped_refptr<AccessTokenStore> access_token_store_;
136 scoped_refptr<AccessTokenStore> access_token_store_;
137 }; 136 };
138 137
139 class GeolocationLocationArbitratorTest : public testing::Test { 138 class GeolocationLocationArbitratorTest : public testing::Test {
140 protected: 139 protected:
141 // testing::Test 140 GeolocationLocationArbitratorTest()
142 void SetUp() override { 141 : access_token_store_(new NiceMock<FakeAccessTokenStore>),
143 access_token_store_ = new NiceMock<FakeAccessTokenStore>; 142 observer_(new MockLocationObserver),
144 observer_.reset(new MockLocationObserver); 143 delegate_(new GeolocationDelegate) {}
145 delegate_.reset(new GeolocationDelegate);
146 }
147 144
148 // Initializes |arbitrator_|, with the possibility of injecting a specific 145 // Initializes |arbitrator_|, with the possibility of injecting a specific
149 // |delegate|, otherwise a default, no-op GeolocationDelegate is used. 146 // |delegate|, otherwise a default, no-op GeolocationDelegate is used.
150 void InitializeArbitrator(std::unique_ptr<GeolocationDelegate> delegate) { 147 void InitializeArbitrator(std::unique_ptr<GeolocationDelegate> delegate) {
151 if (delegate) 148 if (delegate)
152 delegate_ = std::move(delegate); 149 delegate_ = std::move(delegate);
153 const LocationArbitratorImpl::LocationUpdateCallback callback = 150 const LocationArbitratorImpl::LocationUpdateCallback callback =
154 base::Bind(&MockLocationObserver::OnLocationUpdate, 151 base::Bind(&MockLocationObserver::OnLocationUpdate,
155 base::Unretained(observer_.get())); 152 base::Unretained(observer_.get()));
156 arbitrator_.reset(new TestingLocationArbitrator( 153 arbitrator_.reset(new TestingLocationArbitrator(
157 callback, access_token_store_.get(), delegate_.get())); 154 callback, access_token_store_, delegate_.get()));
158 } 155 }
159 156
160 // testing::Test 157 // testing::Test
161 void TearDown() override {} 158 void TearDown() override {}
162 159
163 void CheckLastPositionInfo(double latitude, 160 void CheckLastPositionInfo(double latitude,
164 double longitude, 161 double longitude,
165 double accuracy) { 162 double accuracy) {
166 Geoposition geoposition = observer_->last_position_; 163 Geoposition geoposition = observer_->last_position_;
167 EXPECT_TRUE(geoposition.Validate()); 164 EXPECT_TRUE(geoposition.Validate());
168 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); 165 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude);
169 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); 166 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude);
170 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); 167 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy);
171 } 168 }
172 169
173 base::TimeDelta SwitchOnFreshnessCliff() { 170 base::TimeDelta SwitchOnFreshnessCliff() {
174 // Add 1, to ensure it meets any greater-than test. 171 // Add 1, to ensure it meets any greater-than test.
175 return base::TimeDelta::FromMilliseconds( 172 return base::TimeDelta::FromMilliseconds(
176 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1); 173 LocationArbitratorImpl::kFixStaleTimeoutMilliseconds + 1);
177 } 174 }
178 175
179 MockLocationProvider* cell() { 176 MockLocationProvider* cell() {
180 return arbitrator_->cell_; 177 return arbitrator_->cell_;
181 } 178 }
182 179
183 MockLocationProvider* gps() { 180 MockLocationProvider* gps() {
184 return arbitrator_->gps_; 181 return arbitrator_->gps_;
185 } 182 }
186 183
187 scoped_refptr<FakeAccessTokenStore> access_token_store_; 184 const scoped_refptr<FakeAccessTokenStore> access_token_store_;
188 std::unique_ptr<MockLocationObserver> observer_; 185 const std::unique_ptr<MockLocationObserver> observer_;
189 std::unique_ptr<TestingLocationArbitrator> arbitrator_; 186 std::unique_ptr<TestingLocationArbitrator> arbitrator_;
190 std::unique_ptr<GeolocationDelegate> delegate_; 187 std::unique_ptr<GeolocationDelegate> delegate_;
191 base::MessageLoop loop_; 188 const base::MessageLoop loop_;
192 }; 189 };
193 190
194 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { 191 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
195 EXPECT_TRUE(access_token_store_.get()); 192 EXPECT_TRUE(access_token_store_.get());
196 InitializeArbitrator(nullptr); 193 InitializeArbitrator(nullptr);
197 EXPECT_TRUE(arbitrator_); 194 EXPECT_TRUE(arbitrator_);
198 arbitrator_.reset(); 195 arbitrator_.reset();
199 SUCCEED(); 196 SUCCEED();
200 } 197 }
201 198
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 434
438 // Advance the time a short while to simulate successive calls. 435 // Advance the time a short while to simulate successive calls.
439 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5)); 436 AdvanceTimeNow(base::TimeDelta::FromMilliseconds(5));
440 437
441 // Update with a less accurate position to verify 240956. 438 // Update with a less accurate position to verify 240956.
442 SetPositionFix(cell(), 3, 139, 150); 439 SetPositionFix(cell(), 3, 139, 150);
443 CheckLastPositionInfo(3, 139, 150); 440 CheckLastPositionInfo(3, 139, 150);
444 } 441 }
445 442
446 } // namespace content 443 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_arbitrator_impl.cc ('k') | content/browser/geolocation/location_provider_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698