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 #include "device/gamepad/gamepad_test_helpers.h" | 5 #include "device/gamepad/gamepad_test_helpers.h" |
6 | 6 |
7 namespace device { | 7 namespace device { |
8 | 8 |
9 MockGamepadDataFetcher::MockGamepadDataFetcher( | 9 MockGamepadDataFetcher::MockGamepadDataFetcher( |
10 const blink::WebGamepads& test_data) | 10 const blink::WebGamepads& test_data) |
11 : test_data_(test_data), | 11 : test_data_(test_data), |
12 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 12 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
13 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 13 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
14 | 14 |
15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} | 15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} |
16 | 16 |
17 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, | 17 GamepadSource MockGamepadDataFetcher::source() { |
18 bool devices_changed_hint) { | 18 return GAMEPAD_SOURCE_TEST; |
| 19 } |
| 20 |
| 21 void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) { |
19 { | 22 { |
20 base::AutoLock lock(lock_); | 23 base::AutoLock lock(lock_); |
21 *pads = test_data_; | 24 |
| 25 for (unsigned int i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) { |
| 26 if (test_data_.items[i].connected) { |
| 27 PadState* pad = provider()->GetPadState(GAMEPAD_SOURCE_TEST, i); |
| 28 if (pad) |
| 29 memcpy(&pad->data, &test_data_.items[i], sizeof(blink::WebGamepad)); |
| 30 } |
| 31 } |
22 } | 32 } |
23 read_data_.Signal(); | 33 read_data_.Signal(); |
24 } | 34 } |
25 | 35 |
26 void MockGamepadDataFetcher::WaitForDataRead() { | 36 void MockGamepadDataFetcher::WaitForDataRead() { |
27 return read_data_.Wait(); | 37 return read_data_.Wait(); |
28 } | 38 } |
29 | 39 |
30 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { | 40 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { |
31 // The provider will read the data on the background thread (setting the | 41 // The provider will read the data on the background thread (setting the |
(...skipping 29 matching lines...) Expand all Loading... |
61 | 71 |
62 void MockGamepadSharedBuffer::WriteBegin() {} | 72 void MockGamepadSharedBuffer::WriteBegin() {} |
63 | 73 |
64 void MockGamepadSharedBuffer::WriteEnd() {} | 74 void MockGamepadSharedBuffer::WriteEnd() {} |
65 | 75 |
66 GamepadTestHelper::GamepadTestHelper() {} | 76 GamepadTestHelper::GamepadTestHelper() {} |
67 | 77 |
68 GamepadTestHelper::~GamepadTestHelper() {} | 78 GamepadTestHelper::~GamepadTestHelper() {} |
69 | 79 |
70 } // namespace device | 80 } // namespace device |
OLD | NEW |