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