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

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

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. Created 5 years, 6 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/location.h"
7 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "content/browser/geolocation/geolocation_provider_impl.h" 13 #include "content/browser/geolocation/geolocation_provider_impl.h"
13 #include "content/browser/geolocation/mock_location_arbitrator.h" 14 #include "content/browser/geolocation/mock_location_arbitrator.h"
14 #include "content/public/browser/access_token_store.h" 15 #include "content/public/browser/access_token_store.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 base::MessageLoop message_loop_; 134 base::MessageLoop message_loop_;
134 TestBrowserThread ui_thread_; 135 TestBrowserThread ui_thread_;
135 scoped_ptr<LocationProviderForTestArbitrator> provider_; 136 scoped_ptr<LocationProviderForTestArbitrator> provider_;
136 }; 137 };
137 138
138 139
139 bool GeolocationProviderTest::ProvidersStarted() { 140 bool GeolocationProviderTest::ProvidersStarted() {
140 DCHECK(provider_->IsRunning()); 141 DCHECK(provider_->IsRunning());
141 DCHECK(base::MessageLoop::current() == &message_loop_); 142 DCHECK(base::MessageLoop::current() == &message_loop_);
142 bool started; 143 bool started;
143 provider_->message_loop_proxy()->PostTaskAndReply( 144 provider_->task_runner()->PostTaskAndReply(
144 FROM_HERE, 145 FROM_HERE, base::Bind(&GeolocationProviderTest::GetProvidersStarted,
145 base::Bind(&GeolocationProviderTest::GetProvidersStarted, 146 base::Unretained(this), &started),
146 base::Unretained(this),
147 &started),
148 base::MessageLoop::QuitClosure()); 147 base::MessageLoop::QuitClosure());
149 message_loop_.Run(); 148 message_loop_.Run();
150 return started; 149 return started;
151 } 150 }
152 151
153 void GeolocationProviderTest::GetProvidersStarted(bool* started) { 152 void GeolocationProviderTest::GetProvidersStarted(bool* started) {
154 DCHECK(base::MessageLoop::current() == provider_->message_loop()); 153 DCHECK(base::MessageLoop::current() == provider_->message_loop());
155 *started = provider_->mock_arbitrator()->providers_started(); 154 *started = provider_->mock_arbitrator()->providers_started();
156 } 155 }
157 156
158 void GeolocationProviderTest::SendMockLocation(const Geoposition& position) { 157 void GeolocationProviderTest::SendMockLocation(const Geoposition& position) {
159 DCHECK(provider_->IsRunning()); 158 DCHECK(provider_->IsRunning());
160 DCHECK(base::MessageLoop::current() == &message_loop_); 159 DCHECK(base::MessageLoop::current() == &message_loop_);
161 provider_->message_loop() 160 provider_->task_runner()->PostTask(
162 ->PostTask(FROM_HERE, 161 FROM_HERE, base::Bind(&GeolocationProviderImpl::OnLocationUpdate,
163 base::Bind(&GeolocationProviderImpl::OnLocationUpdate, 162 base::Unretained(provider_.get()), position));
164 base::Unretained(provider_.get()),
165 position));
166 } 163 }
167 164
168 // Regression test for http://crbug.com/59377 165 // Regression test for http://crbug.com/59377
169 TEST_F(GeolocationProviderTest, OnPermissionGrantedWithoutObservers) { 166 TEST_F(GeolocationProviderTest, OnPermissionGrantedWithoutObservers) {
170 EXPECT_FALSE(provider()->user_did_opt_into_location_services_for_testing()); 167 EXPECT_FALSE(provider()->user_did_opt_into_location_services_for_testing());
171 provider()->UserDidOptIntoLocationServices(); 168 provider()->UserDidOptIntoLocationServices();
172 EXPECT_TRUE(provider()->user_did_opt_into_location_services_for_testing()); 169 EXPECT_TRUE(provider()->user_did_opt_into_location_services_for_testing());
173 } 170 }
174 171
175 void DummyFunction(const Geoposition& position) { 172 void DummyFunction(const Geoposition& position) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 &MockGeolocationObserver::OnLocationUpdate, 246 &MockGeolocationObserver::OnLocationUpdate,
250 base::Unretained(&mock_observer)); 247 base::Unretained(&mock_observer));
251 scoped_ptr<content::GeolocationProvider::Subscription> subscription = 248 scoped_ptr<content::GeolocationProvider::Subscription> subscription =
252 provider()->AddLocationUpdateCallback(callback, false); 249 provider()->AddLocationUpdateCallback(callback, false);
253 subscription.reset(); 250 subscription.reset();
254 // Wait for the providers to be stopped now that all clients are gone. 251 // Wait for the providers to be stopped now that all clients are gone.
255 EXPECT_FALSE(ProvidersStarted()); 252 EXPECT_FALSE(ProvidersStarted());
256 } 253 }
257 254
258 } // namespace content 255 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_provider_impl.cc ('k') | content/browser/geolocation/location_api_adapter_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698