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(const Gamepads& test_data) |
10 const blink::WebGamepads& test_data) | |
11 : test_data_(test_data), | 10 : test_data_(test_data), |
12 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 11 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
13 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 12 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
14 | 13 |
15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} | 14 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} |
16 | 15 |
17 GamepadSource MockGamepadDataFetcher::source() { | 16 GamepadSource MockGamepadDataFetcher::source() { |
18 return GAMEPAD_SOURCE_TEST; | 17 return GAMEPAD_SOURCE_TEST; |
19 } | 18 } |
20 | 19 |
21 void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) { | 20 void MockGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) { |
22 { | 21 { |
23 base::AutoLock lock(lock_); | 22 base::AutoLock lock(lock_); |
24 | 23 |
25 for (unsigned int i = 0; i < blink::WebGamepads::kItemsLengthCap; ++i) { | 24 for (unsigned int i = 0; i < Gamepads::kItemsLengthCap; ++i) { |
26 if (test_data_.items[i].connected) { | 25 if (test_data_.items[i].connected) { |
27 PadState* pad = GetPadState(i); | 26 PadState* pad = GetPadState(i); |
28 if (pad) | 27 if (pad) |
29 memcpy(&pad->data, &test_data_.items[i], sizeof(blink::WebGamepad)); | 28 memcpy(&pad->data, &test_data_.items[i], sizeof(Gamepad)); |
30 } | 29 } |
31 } | 30 } |
32 } | 31 } |
33 read_data_.Signal(); | 32 read_data_.Signal(); |
34 } | 33 } |
35 | 34 |
36 void MockGamepadDataFetcher::WaitForDataRead() { | 35 void MockGamepadDataFetcher::WaitForDataRead() { |
37 return read_data_.Wait(); | 36 return read_data_.Wait(); |
38 } | 37 } |
39 | 38 |
40 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { | 39 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { |
41 // The provider will read the data on the background thread (setting the | 40 // The provider will read the data on the background thread (setting the |
42 // event) and *then* will issue the callback on the client thread. Waiting for | 41 // event) and *then* will issue the callback on the client thread. Waiting for |
43 // it to read twice is a simple way to ensure that it was able to issue | 42 // it to read twice is a simple way to ensure that it was able to issue |
44 // callbacks for the first read (if it issued one). | 43 // callbacks for the first read (if it issued one). |
45 WaitForDataRead(); | 44 WaitForDataRead(); |
46 WaitForDataRead(); | 45 WaitForDataRead(); |
47 } | 46 } |
48 | 47 |
49 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { | 48 void MockGamepadDataFetcher::SetTestData(const Gamepads& new_data) { |
50 base::AutoLock lock(lock_); | 49 base::AutoLock lock(lock_); |
51 test_data_ = new_data; | 50 test_data_ = new_data; |
52 } | 51 } |
53 | 52 |
54 GamepadTestHelper::GamepadTestHelper() {} | 53 GamepadTestHelper::GamepadTestHelper() {} |
55 | 54 |
56 GamepadTestHelper::~GamepadTestHelper() {} | 55 GamepadTestHelper::~GamepadTestHelper() {} |
57 | 56 |
58 GamepadServiceTestConstructor::GamepadServiceTestConstructor( | 57 GamepadServiceTestConstructor::GamepadServiceTestConstructor( |
59 const blink::WebGamepads& test_data) { | 58 const Gamepads& test_data) { |
60 data_fetcher_ = new MockGamepadDataFetcher(test_data); | 59 data_fetcher_ = new MockGamepadDataFetcher(test_data); |
61 gamepad_service_ = | 60 gamepad_service_ = |
62 new GamepadService(std::unique_ptr<GamepadDataFetcher>(data_fetcher_)); | 61 new GamepadService(std::unique_ptr<GamepadDataFetcher>(data_fetcher_)); |
63 } | 62 } |
64 | 63 |
65 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { | 64 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { |
66 delete gamepad_service_; | 65 delete gamepad_service_; |
67 } | 66 } |
68 | 67 |
69 } // namespace device | 68 } // namespace device |
OLD | NEW |