| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} | 29 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} |
| 30 virtual ~LocationProviderForTestArbitrator() {} | 30 virtual ~LocationProviderForTestArbitrator() {} |
| 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 virtual 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 virtual 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 |
| 75 class GeopositionEqMatcher | 75 class GeopositionEqMatcher |
| 76 : public MatcherInterface<const Geoposition&> { | 76 : public MatcherInterface<const Geoposition&> { |
| 77 public: | 77 public: |
| 78 explicit GeopositionEqMatcher(const Geoposition& expected) | 78 explicit GeopositionEqMatcher(const Geoposition& expected) |
| 79 : expected_(expected) {} | 79 : expected_(expected) {} |
| 80 | 80 |
| 81 virtual bool MatchAndExplain(const Geoposition& actual, | 81 virtual bool MatchAndExplain(const Geoposition& actual, |
| 82 MatchResultListener* listener) const OVERRIDE { | 82 MatchResultListener* listener) const override { |
| 83 return actual.latitude == expected_.latitude && | 83 return actual.latitude == expected_.latitude && |
| 84 actual.longitude == expected_.longitude && | 84 actual.longitude == expected_.longitude && |
| 85 actual.altitude == expected_.altitude && | 85 actual.altitude == expected_.altitude && |
| 86 actual.accuracy == expected_.accuracy && | 86 actual.accuracy == expected_.accuracy && |
| 87 actual.altitude_accuracy == expected_.altitude_accuracy && | 87 actual.altitude_accuracy == expected_.altitude_accuracy && |
| 88 actual.heading == expected_.heading && | 88 actual.heading == expected_.heading && |
| 89 actual.speed == expected_.speed && | 89 actual.speed == expected_.speed && |
| 90 actual.timestamp == expected_.timestamp && | 90 actual.timestamp == expected_.timestamp && |
| 91 actual.error_code == expected_.error_code && | 91 actual.error_code == expected_.error_code && |
| 92 actual.error_message == expected_.error_message; | 92 actual.error_message == expected_.error_message; |
| 93 } | 93 } |
| 94 | 94 |
| 95 virtual void DescribeTo(::std::ostream* os) const OVERRIDE { | 95 virtual void DescribeTo(::std::ostream* os) const override { |
| 96 *os << "which matches the expected position"; | 96 *os << "which matches the expected position"; |
| 97 } | 97 } |
| 98 | 98 |
| 99 virtual void DescribeNegationTo(::std::ostream* os) const OVERRIDE { | 99 virtual void DescribeNegationTo(::std::ostream* os) const override { |
| 100 *os << "which does not match the expected position"; | 100 *os << "which does not match the expected position"; |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 Geoposition expected_; | 104 Geoposition expected_; |
| 105 | 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(GeopositionEqMatcher); | 106 DISALLOW_COPY_AND_ASSIGN(GeopositionEqMatcher); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 Matcher<const Geoposition&> GeopositionEq(const Geoposition& expected) { | 109 Matcher<const Geoposition&> GeopositionEq(const Geoposition& expected) { |
| (...skipping 139 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 |