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