OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 5 #ifndef DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
6 #define DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 6 #define DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/single_thread_task_runner.h" | |
12 #include "base/threading/thread.h" | |
13 #include "device/geolocation/geoposition.h" | 8 #include "device/geolocation/geoposition.h" |
14 #include "device/geolocation/location_provider_base.h" | 9 #include "device/geolocation/location_provider.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
15 | 11 |
16 namespace device { | 12 namespace device { |
17 | 13 |
18 // Mock implementation of a location provider for testing. | 14 class MockLocationProvider : public device::LocationProvider { |
19 class MockLocationProvider : public LocationProviderBase { | |
20 public: | 15 public: |
21 enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; | |
22 | |
23 MockLocationProvider(); | 16 MockLocationProvider(); |
24 ~MockLocationProvider() override; | 17 ~MockLocationProvider() override; |
25 | 18 |
26 bool is_started() const { return state_ != STOPPED; } | 19 MOCK_METHOD1(SetUpdateCallback, |
27 bool is_permission_granted() { return is_permission_granted_; } | 20 void(const LocationProviderUpdateCallback& callback)); |
28 const Geoposition& position() { return position_; } | 21 MOCK_METHOD1(StartProvider, bool(bool high_accuracy)); |
29 | 22 MOCK_METHOD0(StopProvider, void()); |
30 // Updates listeners with the new position. | 23 MOCK_METHOD0(GetPosition, const device::Geoposition&()); |
31 void HandlePositionChanged(const Geoposition& position); | 24 MOCK_METHOD0(OnPermissionGranted, void()); |
32 | |
33 // LocationProvider implementation. | |
34 bool StartProvider(bool high_accuracy) override; | |
35 void StopProvider() override; | |
36 const Geoposition& GetPosition() override; | |
37 void OnPermissionGranted() override; | |
38 | 25 |
39 private: | 26 private: |
40 bool is_permission_granted_; | |
41 Geoposition position_; | |
42 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); | 27 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); |
45 }; | 28 }; |
46 | 29 |
47 } // namespace device | 30 } // namespace device |
48 | 31 |
49 #endif // DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | 32 #endif // DEVICE_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ |
OLD | NEW |