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