| 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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/browser/geolocation/geolocation_provider_impl.h" | 12 #include "content/browser/geolocation/geolocation_provider_impl.h" |
| 13 #include "content/browser/geolocation/mock_location_arbitrator.h" | 13 #include "content/browser/geolocation/mock_location_arbitrator.h" |
| 14 #include "content/public/browser/access_token_store.h" | 14 #include "content/public/browser/access_token_store.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using testing::MakeMatcher; | 20 using testing::MakeMatcher; |
| 21 using testing::Matcher; | 21 using testing::Matcher; |
| 22 using testing::MatcherInterface; | 22 using testing::MatcherInterface; |
| 23 using testing::MatchResultListener; | 23 using testing::MatchResultListener; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 class LocationProviderForTestArbitrator : public GeolocationProviderImpl { | 27 class LocationProviderForTestArbitrator : public GeolocationProviderImpl { |
| 28 public: | 28 public: |
| 29 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} | 29 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} |
| 30 virtual ~LocationProviderForTestArbitrator() {} | 30 ~LocationProviderForTestArbitrator() override {} |
| 31 | 31 |
| 32 // Only valid for use on the geolocation thread. | 32 // Only valid for use on the geolocation thread. |
| 33 MockLocationArbitrator* mock_arbitrator() const { | 33 MockLocationArbitrator* mock_arbitrator() const { |
| 34 return mock_arbitrator_; | 34 return mock_arbitrator_; |
| 35 } | 35 } |
| 36 | 36 |
| 37 protected: | 37 protected: |
| 38 // GeolocationProviderImpl implementation: | 38 // GeolocationProviderImpl implementation: |
| 39 virtual LocationArbitrator* CreateArbitrator() override; | 39 LocationArbitrator* CreateArbitrator() override; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 MockLocationArbitrator* mock_arbitrator_; | 42 MockLocationArbitrator* mock_arbitrator_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 LocationArbitrator* LocationProviderForTestArbitrator::CreateArbitrator() { | 45 LocationArbitrator* LocationProviderForTestArbitrator::CreateArbitrator() { |
| 46 DCHECK(mock_arbitrator_ == NULL); | 46 DCHECK(mock_arbitrator_ == NULL); |
| 47 mock_arbitrator_ = new MockLocationArbitrator; | 47 mock_arbitrator_ = new MockLocationArbitrator; |
| 48 return mock_arbitrator_; | 48 return mock_arbitrator_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 class GeolocationObserver { | 51 class GeolocationObserver { |
| 52 public: | 52 public: |
| 53 virtual ~GeolocationObserver() {} | 53 virtual ~GeolocationObserver() {} |
| 54 virtual void OnLocationUpdate(const Geoposition& position) = 0; | 54 virtual void OnLocationUpdate(const Geoposition& position) = 0; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class MockGeolocationObserver : public GeolocationObserver { | 57 class MockGeolocationObserver : public GeolocationObserver { |
| 58 public: | 58 public: |
| 59 MOCK_METHOD1(OnLocationUpdate, void(const Geoposition& position)); | 59 MOCK_METHOD1(OnLocationUpdate, void(const Geoposition& position)); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class AsyncMockGeolocationObserver : public MockGeolocationObserver { | 62 class AsyncMockGeolocationObserver : public MockGeolocationObserver { |
| 63 public: | 63 public: |
| 64 virtual void OnLocationUpdate(const Geoposition& position) override { | 64 void OnLocationUpdate(const Geoposition& position) override { |
| 65 MockGeolocationObserver::OnLocationUpdate(position); | 65 MockGeolocationObserver::OnLocationUpdate(position); |
| 66 base::MessageLoop::current()->Quit(); | 66 base::MessageLoop::current()->Quit(); |
| 67 } | 67 } |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class MockGeolocationCallbackWrapper { | 70 class MockGeolocationCallbackWrapper { |
| 71 public: | 71 public: |
| 72 MOCK_METHOD1(Callback, void(const Geoposition& position)); | 72 MOCK_METHOD1(Callback, void(const Geoposition& position)); |
| 73 }; | 73 }; |
| 74 | 74 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 &MockGeolocationObserver::OnLocationUpdate, | 249 &MockGeolocationObserver::OnLocationUpdate, |
| 250 base::Unretained(&mock_observer)); | 250 base::Unretained(&mock_observer)); |
| 251 scoped_ptr<content::GeolocationProvider::Subscription> subscription = | 251 scoped_ptr<content::GeolocationProvider::Subscription> subscription = |
| 252 provider()->AddLocationUpdateCallback(callback, false); | 252 provider()->AddLocationUpdateCallback(callback, false); |
| 253 subscription.reset(); | 253 subscription.reset(); |
| 254 // 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. |
| 255 EXPECT_FALSE(ProvidersStarted()); | 255 EXPECT_FALSE(ProvidersStarted()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 } // namespace content | 258 } // namespace content |
| OLD | NEW |