OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/gamepad/gamepad_test_helpers.h" | |
6 | |
7 #include "content/browser/gamepad/gamepad_service.h" | |
8 | |
9 namespace content { | |
10 | |
11 MockGamepadDataFetcher::MockGamepadDataFetcher( | |
12 const blink::WebGamepads& test_data) | |
13 : test_data_(test_data), | |
14 read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
15 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | |
16 | |
17 MockGamepadDataFetcher::~MockGamepadDataFetcher() { | |
18 } | |
19 | |
20 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, | |
21 bool devices_changed_hint) { | |
22 { | |
23 base::AutoLock lock(lock_); | |
24 *pads = test_data_; | |
25 } | |
26 read_data_.Signal(); | |
27 } | |
28 | |
29 void MockGamepadDataFetcher::WaitForDataRead() { | |
30 return read_data_.Wait(); | |
31 } | |
32 | |
33 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { | |
34 // The provider will read the data on the background thread (setting the | |
35 // event) and *then* will issue the callback on the client thread. Waiting for | |
36 // it to read twice is a simple way to ensure that it was able to issue | |
37 // callbacks for the first read (if it issued one). | |
38 WaitForDataRead(); | |
39 WaitForDataRead(); | |
40 } | |
41 | |
42 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { | |
43 base::AutoLock lock(lock_); | |
44 test_data_ = new_data; | |
45 } | |
46 | |
47 GamepadTestHelper::GamepadTestHelper() { | |
48 } | |
49 | |
50 GamepadTestHelper::~GamepadTestHelper() { | |
51 } | |
52 | |
53 GamepadServiceTestConstructor::GamepadServiceTestConstructor( | |
54 const blink::WebGamepads& test_data) { | |
55 data_fetcher_ = new MockGamepadDataFetcher(test_data); | |
56 gamepad_service_ = | |
57 new GamepadService(std::unique_ptr<GamepadDataFetcher>(data_fetcher_)); | |
58 } | |
59 | |
60 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { | |
61 delete gamepad_service_; | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |