| 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) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // callbacks for the first read (if it issued one). | 44 // callbacks for the first read (if it issued one). |
| 45 WaitForDataRead(); | 45 WaitForDataRead(); |
| 46 WaitForDataRead(); | 46 WaitForDataRead(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { | 49 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { |
| 50 base::AutoLock lock(lock_); | 50 base::AutoLock lock(lock_); |
| 51 test_data_ = new_data; | 51 test_data_ = new_data; |
| 52 } | 52 } |
| 53 | 53 |
| 54 MockGamepadSharedBuffer::MockGamepadSharedBuffer() { | |
| 55 size_t data_size = sizeof(blink::WebGamepads); | |
| 56 bool res = shared_memory_.CreateAndMapAnonymous(data_size); | |
| 57 CHECK(res); | |
| 58 blink::WebGamepads* buf = buffer(); | |
| 59 memset(buf, 0, sizeof(blink::WebGamepads)); | |
| 60 } | |
| 61 | |
| 62 base::SharedMemory* MockGamepadSharedBuffer::shared_memory() { | |
| 63 return &shared_memory_; | |
| 64 } | |
| 65 | |
| 66 blink::WebGamepads* MockGamepadSharedBuffer::buffer() { | |
| 67 void* mem = shared_memory_.memory(); | |
| 68 CHECK(mem); | |
| 69 return static_cast<blink::WebGamepads*>(mem); | |
| 70 } | |
| 71 | |
| 72 void MockGamepadSharedBuffer::WriteBegin() {} | |
| 73 | |
| 74 void MockGamepadSharedBuffer::WriteEnd() {} | |
| 75 | |
| 76 GamepadTestHelper::GamepadTestHelper() {} | 54 GamepadTestHelper::GamepadTestHelper() {} |
| 77 | 55 |
| 78 GamepadTestHelper::~GamepadTestHelper() {} | 56 GamepadTestHelper::~GamepadTestHelper() {} |
| 79 | 57 |
| 58 GamepadServiceTestConstructor::GamepadServiceTestConstructor( |
| 59 const blink::WebGamepads& test_data) { |
| 60 data_fetcher_ = new MockGamepadDataFetcher(test_data); |
| 61 gamepad_service_ = |
| 62 new GamepadService(std::unique_ptr<GamepadDataFetcher>(data_fetcher_)); |
| 63 } |
| 64 |
| 65 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { |
| 66 delete gamepad_service_; |
| 67 } |
| 68 |
| 80 } // namespace device | 69 } // namespace device |
| OLD | NEW |