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 DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ | 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ |
6 #define DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ | 6 #define DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "device/gamepad/gamepad_data_fetcher.h" | 14 #include "device/gamepad/gamepad_data_fetcher.h" |
| 15 #include "device/gamepad/gamepad_service.h" |
15 #include "device/gamepad/gamepad_shared_buffer.h" | 16 #include "device/gamepad/gamepad_shared_buffer.h" |
16 #include "third_party/WebKit/public/platform/WebGamepads.h" | 17 #include "third_party/WebKit/public/platform/WebGamepads.h" |
17 | 18 |
18 namespace device { | 19 namespace device { |
19 | 20 |
20 // Data fetcher that returns canned data for the gamepad provider. | 21 // Data fetcher that returns canned data for the gamepad provider. |
21 class MockGamepadDataFetcher : public GamepadDataFetcher { | 22 class MockGamepadDataFetcher : public GamepadDataFetcher { |
22 public: | 23 public: |
23 // Initializes the fetcher with the given gamepad data, which will be | 24 // Initializes the fetcher with the given gamepad data, which will be |
24 // returned when the provider queries us. | 25 // returned when the provider queries us. |
(...skipping 19 matching lines...) Expand all Loading... |
44 void SetTestData(const blink::WebGamepads& new_data); | 45 void SetTestData(const blink::WebGamepads& new_data); |
45 | 46 |
46 private: | 47 private: |
47 base::Lock lock_; | 48 base::Lock lock_; |
48 blink::WebGamepads test_data_; | 49 blink::WebGamepads test_data_; |
49 base::WaitableEvent read_data_; | 50 base::WaitableEvent read_data_; |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher); | 52 DISALLOW_COPY_AND_ASSIGN(MockGamepadDataFetcher); |
52 }; | 53 }; |
53 | 54 |
54 class MockGamepadSharedBuffer : public GamepadSharedBuffer { | |
55 public: | |
56 MockGamepadSharedBuffer(); | |
57 | |
58 base::SharedMemory* shared_memory() override; | |
59 blink::WebGamepads* buffer() override; | |
60 | |
61 void WriteBegin() override; | |
62 void WriteEnd() override; | |
63 | |
64 private: | |
65 base::SharedMemory shared_memory_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(MockGamepadSharedBuffer); | |
68 }; | |
69 | |
70 // Base class for the other test helpers. This just sets up the system monitor. | 55 // Base class for the other test helpers. This just sets up the system monitor. |
71 class GamepadTestHelper { | 56 class GamepadTestHelper { |
72 public: | 57 public: |
73 GamepadTestHelper(); | 58 GamepadTestHelper(); |
74 virtual ~GamepadTestHelper(); | 59 virtual ~GamepadTestHelper(); |
75 | 60 |
76 base::MessageLoop& message_loop() { return message_loop_; } | 61 base::MessageLoop& message_loop() { return message_loop_; } |
77 | 62 |
78 private: | 63 private: |
79 // This must be constructed before the system monitor. | 64 // This must be constructed before the system monitor. |
80 base::MessageLoop message_loop_; | 65 base::MessageLoop message_loop_; |
81 | 66 |
82 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper); | 67 DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper); |
83 }; | 68 }; |
84 | 69 |
| 70 // Constructs a GamepadService with a mock data source. This bypasses the |
| 71 // global singleton for the gamepad service. |
| 72 class GamepadServiceTestConstructor : public GamepadTestHelper { |
| 73 public: |
| 74 explicit GamepadServiceTestConstructor(const blink::WebGamepads& test_data); |
| 75 ~GamepadServiceTestConstructor() override; |
| 76 |
| 77 GamepadService* gamepad_service() { return gamepad_service_; } |
| 78 MockGamepadDataFetcher* data_fetcher() { return data_fetcher_; } |
| 79 |
| 80 private: |
| 81 // Owning pointer (can't be a scoped_ptr due to private destructor). |
| 82 GamepadService* gamepad_service_; |
| 83 |
| 84 // Pointer owned by the provider (which is owned by the gamepad service). |
| 85 MockGamepadDataFetcher* data_fetcher_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(GamepadServiceTestConstructor); |
| 88 }; |
| 89 |
85 } // namespace device | 90 } // namespace device |
86 | 91 |
87 #endif // DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ | 92 #endif // DEVICE_GAMEPAD_GAMEPAD_TEST_HELPERS_H_ |
OLD | NEW |