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

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

Issue 2082343002: Remove calls to deprecated MessageLoop methods in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/geolocation_provider_impl.h" 5 #include "content/browser/geolocation/geolocation_provider_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/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "content/browser/geolocation/mock_location_arbitrator.h" 19 #include "content/browser/geolocation/mock_location_arbitrator.h"
19 #include "content/public/browser/access_token_store.h" 20 #include "content/public/browser/access_token_store.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 145
145 146
146 bool GeolocationProviderTest::ProvidersStarted() { 147 bool GeolocationProviderTest::ProvidersStarted() {
147 DCHECK(provider_->IsRunning()); 148 DCHECK(provider_->IsRunning());
148 DCHECK(base::MessageLoop::current() == &message_loop_); 149 DCHECK(base::MessageLoop::current() == &message_loop_);
149 bool started; 150 bool started;
150 provider_->task_runner()->PostTaskAndReply( 151 provider_->task_runner()->PostTaskAndReply(
151 FROM_HERE, base::Bind(&GeolocationProviderTest::GetProvidersStarted, 152 FROM_HERE, base::Bind(&GeolocationProviderTest::GetProvidersStarted,
152 base::Unretained(this), &started), 153 base::Unretained(this), &started),
153 base::MessageLoop::QuitWhenIdleClosure()); 154 base::MessageLoop::QuitWhenIdleClosure());
154 message_loop_.Run(); 155 base::RunLoop().Run();
155 return started; 156 return started;
156 } 157 }
157 158
158 void GeolocationProviderTest::GetProvidersStarted(bool* started) { 159 void GeolocationProviderTest::GetProvidersStarted(bool* started) {
159 DCHECK(base::MessageLoop::current() == provider_->message_loop()); 160 DCHECK(base::MessageLoop::current() == provider_->message_loop());
160 *started = provider_->mock_arbitrator()->providers_started(); 161 *started = provider_->mock_arbitrator()->providers_started();
161 } 162 }
162 163
163 void GeolocationProviderTest::SendMockLocation(const Geoposition& position) { 164 void GeolocationProviderTest::SendMockLocation(const Geoposition& position) {
164 DCHECK(provider_->IsRunning()); 165 DCHECK(provider_->IsRunning());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 first_position.timestamp = base::Time::Now(); 202 first_position.timestamp = base::Time::Now();
202 203
203 AsyncMockGeolocationObserver first_observer; 204 AsyncMockGeolocationObserver first_observer;
204 GeolocationProviderImpl::LocationUpdateCallback first_callback = base::Bind( 205 GeolocationProviderImpl::LocationUpdateCallback first_callback = base::Bind(
205 &MockGeolocationObserver::OnLocationUpdate, 206 &MockGeolocationObserver::OnLocationUpdate,
206 base::Unretained(&first_observer)); 207 base::Unretained(&first_observer));
207 EXPECT_CALL(first_observer, OnLocationUpdate(GeopositionEq(first_position))); 208 EXPECT_CALL(first_observer, OnLocationUpdate(GeopositionEq(first_position)));
208 std::unique_ptr<content::GeolocationProvider::Subscription> subscription = 209 std::unique_ptr<content::GeolocationProvider::Subscription> subscription =
209 provider()->AddLocationUpdateCallback(first_callback, false); 210 provider()->AddLocationUpdateCallback(first_callback, false);
210 SendMockLocation(first_position); 211 SendMockLocation(first_position);
211 base::MessageLoop::current()->Run(); 212 base::RunLoop().Run();
212 213
213 subscription.reset(); 214 subscription.reset();
214 215
215 Geoposition second_position; 216 Geoposition second_position;
216 second_position.latitude = 13; 217 second_position.latitude = 13;
217 second_position.longitude = 34; 218 second_position.longitude = 34;
218 second_position.accuracy = 56; 219 second_position.accuracy = 56;
219 second_position.timestamp = base::Time::Now(); 220 second_position.timestamp = base::Time::Now();
220 221
221 AsyncMockGeolocationObserver second_observer; 222 AsyncMockGeolocationObserver second_observer;
222 223
223 // After adding a second observer, check that no unexpected position update 224 // After adding a second observer, check that no unexpected position update
224 // is sent. 225 // is sent.
225 EXPECT_CALL(second_observer, OnLocationUpdate(testing::_)).Times(0); 226 EXPECT_CALL(second_observer, OnLocationUpdate(testing::_)).Times(0);
226 GeolocationProviderImpl::LocationUpdateCallback second_callback = base::Bind( 227 GeolocationProviderImpl::LocationUpdateCallback second_callback = base::Bind(
227 &MockGeolocationObserver::OnLocationUpdate, 228 &MockGeolocationObserver::OnLocationUpdate,
228 base::Unretained(&second_observer)); 229 base::Unretained(&second_observer));
229 std::unique_ptr<content::GeolocationProvider::Subscription> subscription2 = 230 std::unique_ptr<content::GeolocationProvider::Subscription> subscription2 =
230 provider()->AddLocationUpdateCallback(second_callback, false); 231 provider()->AddLocationUpdateCallback(second_callback, false);
231 base::MessageLoop::current()->RunUntilIdle(); 232 base::RunLoop().RunUntilIdle();
232 233
233 // The second observer should receive the new position now. 234 // The second observer should receive the new position now.
234 EXPECT_CALL(second_observer, 235 EXPECT_CALL(second_observer,
235 OnLocationUpdate(GeopositionEq(second_position))); 236 OnLocationUpdate(GeopositionEq(second_position)));
236 SendMockLocation(second_position); 237 SendMockLocation(second_position);
237 base::MessageLoop::current()->Run(); 238 base::RunLoop().Run();
238 239
239 subscription2.reset(); 240 subscription2.reset();
240 EXPECT_FALSE(ProvidersStarted()); 241 EXPECT_FALSE(ProvidersStarted());
241 } 242 }
242 243
243 TEST_F(GeolocationProviderTest, OverrideLocationForTesting) { 244 TEST_F(GeolocationProviderTest, OverrideLocationForTesting) {
244 Geoposition position; 245 Geoposition position;
245 position.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; 246 position.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
246 provider()->OverrideLocationForTesting(position); 247 provider()->OverrideLocationForTesting(position);
247 // Adding an observer when the location is overridden should synchronously 248 // Adding an observer when the location is overridden should synchronously
248 // update the observer with our overridden position. 249 // update the observer with our overridden position.
249 MockGeolocationObserver mock_observer; 250 MockGeolocationObserver mock_observer;
250 EXPECT_CALL(mock_observer, OnLocationUpdate(GeopositionEq(position))); 251 EXPECT_CALL(mock_observer, OnLocationUpdate(GeopositionEq(position)));
251 GeolocationProviderImpl::LocationUpdateCallback callback = base::Bind( 252 GeolocationProviderImpl::LocationUpdateCallback callback = base::Bind(
252 &MockGeolocationObserver::OnLocationUpdate, 253 &MockGeolocationObserver::OnLocationUpdate,
253 base::Unretained(&mock_observer)); 254 base::Unretained(&mock_observer));
254 std::unique_ptr<content::GeolocationProvider::Subscription> subscription = 255 std::unique_ptr<content::GeolocationProvider::Subscription> subscription =
255 provider()->AddLocationUpdateCallback(callback, false); 256 provider()->AddLocationUpdateCallback(callback, false);
256 subscription.reset(); 257 subscription.reset();
257 // Wait for the providers to be stopped now that all clients are gone. 258 // Wait for the providers to be stopped now that all clients are gone.
258 EXPECT_FALSE(ProvidersStarted()); 259 EXPECT_FALSE(ProvidersStarted());
259 } 260 }
260 261
261 } // namespace content 262 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698