| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "content/browser/geolocation/location_provider_base.h" | 14 #include "content/browser/geolocation/location_provider_base.h" |
| 15 #include "content/public/common/geoposition.h" | 15 #include "content/public/common/geoposition.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 // Mock implementation of a location provider for testing. | 19 // Mock implementation of a location provider for testing. |
| 20 class MockLocationProvider : public LocationProviderBase { | 20 class MockLocationProvider : public LocationProviderBase { |
| 21 public: | 21 public: |
| 22 // Will update |*self_ref| to point to |this| on construction, and to NULL | 22 enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; |
| 23 // on destruction. | 23 |
| 24 explicit MockLocationProvider(MockLocationProvider** self_ref); | 24 MockLocationProvider(); |
| 25 ~MockLocationProvider() override; | 25 ~MockLocationProvider() override; |
| 26 | 26 |
| 27 // Updates listeners with the new position. | 27 // Updates listeners with the new position. |
| 28 void HandlePositionChanged(const Geoposition& position); | 28 void HandlePositionChanged(const Geoposition& position); |
| 29 | 29 |
| 30 // LocationProvider implementation. | 30 // LocationProvider implementation. |
| 31 bool StartProvider(bool high_accuracy) override; | 31 bool StartProvider(bool high_accuracy) override; |
| 32 void StopProvider() override; | 32 void StopProvider() override; |
| 33 void GetPosition(Geoposition* position) override; | 33 void GetPosition(Geoposition* position) override; |
| 34 void OnPermissionGranted() override; | 34 void OnPermissionGranted() override; |
| 35 | 35 |
| 36 bool is_permission_granted_; |
| 36 Geoposition position_; | 37 Geoposition position_; |
| 37 enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; | |
| 38 bool is_permission_granted_; | |
| 39 MockLocationProvider** self_ref_; | |
| 40 | |
| 41 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; | 38 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; |
| 42 | 39 |
| 43 // Set when an instance of the mock is created via a factory function. | 40 private: |
| 44 static MockLocationProvider* instance_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); | 41 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); |
| 47 }; | 42 }; |
| 48 | 43 |
| 49 // Factory functions for the various sorts of mock location providers, | 44 // Factory functions for the various sorts of mock location providers, |
| 50 // for use with LocationArbitrator::SetProviderFactoryForTest (i.e. | 45 // for use with LocationArbitrator::SetProviderFactoryForTest (i.e. |
| 51 // not intended for test code to use to get access to the mock, you can use | 46 // not intended for test code to use to get access to the mock, you can use |
| 52 // MockLocationProvider::instance_ for this, or make a custom factory method). | 47 // MockLocationProvider::instance_ for this, or make a custom factory method). |
| 53 | 48 |
| 54 // Creates a mock location provider with no default behavior. | 49 // Creates a mock location provider with no default behavior. |
| 55 LocationProvider* NewMockLocationProvider(); | 50 LocationProvider* NewMockLocationProvider(); |
| 56 // Creates a mock location provider that automatically notifies its | 51 // Creates a mock location provider that automatically notifies its |
| 57 // listeners with a valid location when StartProvider is called. | 52 // listeners with a valid location when StartProvider is called. |
| 58 LocationProvider* NewAutoSuccessMockLocationProvider(); | 53 LocationProvider* NewAutoSuccessMockLocationProvider(); |
| 59 // Creates a mock location provider that automatically notifies its | 54 // Creates a mock location provider that automatically notifies its |
| 60 // listeners with an error when StartProvider is called. | 55 // listeners with an error when StartProvider is called. |
| 61 LocationProvider* NewAutoFailMockLocationProvider(); | 56 LocationProvider* NewAutoFailMockLocationProvider(); |
| 62 // Similar to NewAutoSuccessMockLocationProvider but mimicks the behavior of | 57 // Similar to NewAutoSuccessMockLocationProvider but mimicks the behavior of |
| 63 // the Network Location provider, in deferring making location updates until | 58 // the Network Location provider, in deferring making location updates until |
| 64 // a permission request has been confirmed. | 59 // a permission request has been confirmed. |
| 65 LocationProvider* NewAutoSuccessMockNetworkLocationProvider(); | 60 LocationProvider* NewAutoSuccessMockNetworkLocationProvider(); |
| 66 | 61 |
| 67 } // namespace content | 62 } // namespace content |
| 68 | 63 |
| 69 #endif // CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 64 #endif // CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
| OLD | NEW |