| 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 "content/browser/gamepad/gamepad_test_helpers.h" | 5 #include "device/gamepad/gamepad_test_helpers.h" | 
| 6 | 6 | 
| 7 #include "content/browser/gamepad/gamepad_service.h" | 7 namespace device { | 
| 8 |  | 
| 9 namespace content { |  | 
| 10 | 8 | 
| 11 MockGamepadDataFetcher::MockGamepadDataFetcher( | 9 MockGamepadDataFetcher::MockGamepadDataFetcher( | 
| 12     const blink::WebGamepads& test_data) | 10     const blink::WebGamepads& test_data) | 
| 13     : test_data_(test_data), | 11     : test_data_(test_data), | 
| 14       read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 12       read_data_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 
| 15                  base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 13                  base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 
| 16 | 14 | 
| 17 MockGamepadDataFetcher::~MockGamepadDataFetcher() { | 15 MockGamepadDataFetcher::~MockGamepadDataFetcher() {} | 
| 18 } |  | 
| 19 | 16 | 
| 20 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, | 17 void MockGamepadDataFetcher::GetGamepadData(blink::WebGamepads* pads, | 
| 21                                             bool devices_changed_hint) { | 18                                             bool devices_changed_hint) { | 
| 22   { | 19   { | 
| 23     base::AutoLock lock(lock_); | 20     base::AutoLock lock(lock_); | 
| 24     *pads = test_data_; | 21     *pads = test_data_; | 
| 25   } | 22   } | 
| 26   read_data_.Signal(); | 23   read_data_.Signal(); | 
| 27 } | 24 } | 
| 28 | 25 | 
| 29 void MockGamepadDataFetcher::WaitForDataRead() { | 26 void MockGamepadDataFetcher::WaitForDataRead() { | 
| 30   return read_data_.Wait(); | 27   return read_data_.Wait(); | 
| 31 } | 28 } | 
| 32 | 29 | 
| 33 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { | 30 void MockGamepadDataFetcher::WaitForDataReadAndCallbacksIssued() { | 
| 34   // The provider will read the data on the background thread (setting the | 31   // 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 | 32   // 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 | 33   // 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). | 34   // callbacks for the first read (if it issued one). | 
| 38   WaitForDataRead(); | 35   WaitForDataRead(); | 
| 39   WaitForDataRead(); | 36   WaitForDataRead(); | 
| 40 } | 37 } | 
| 41 | 38 | 
| 42 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { | 39 void MockGamepadDataFetcher::SetTestData(const blink::WebGamepads& new_data) { | 
| 43   base::AutoLock lock(lock_); | 40   base::AutoLock lock(lock_); | 
| 44   test_data_ = new_data; | 41   test_data_ = new_data; | 
| 45 } | 42 } | 
| 46 | 43 | 
| 47 GamepadTestHelper::GamepadTestHelper() { | 44 MockGamepadSharedBuffer::MockGamepadSharedBuffer() { | 
|  | 45   size_t data_size = sizeof(blink::WebGamepads); | 
|  | 46   bool res = shared_memory_.CreateAndMapAnonymous(data_size); | 
|  | 47   CHECK(res); | 
|  | 48   blink::WebGamepads* buf = buffer(); | 
|  | 49   memset(buf, 0, sizeof(blink::WebGamepads)); | 
| 48 } | 50 } | 
| 49 | 51 | 
| 50 GamepadTestHelper::~GamepadTestHelper() { | 52 base::SharedMemory* MockGamepadSharedBuffer::shared_memory() { | 
|  | 53   return &shared_memory_; | 
| 51 } | 54 } | 
| 52 | 55 | 
| 53 GamepadServiceTestConstructor::GamepadServiceTestConstructor( | 56 blink::WebGamepads* MockGamepadSharedBuffer::buffer() { | 
| 54     const blink::WebGamepads& test_data) { | 57   void* mem = shared_memory_.memory(); | 
| 55   data_fetcher_ = new MockGamepadDataFetcher(test_data); | 58   CHECK(mem); | 
| 56   gamepad_service_ = | 59   return static_cast<blink::WebGamepads*>(mem); | 
| 57       new GamepadService(std::unique_ptr<GamepadDataFetcher>(data_fetcher_)); |  | 
| 58 } | 60 } | 
| 59 | 61 | 
| 60 GamepadServiceTestConstructor::~GamepadServiceTestConstructor() { | 62 void MockGamepadSharedBuffer::WriteBegin() {} | 
| 61   delete gamepad_service_; |  | 
| 62 } |  | 
| 63 | 63 | 
| 64 }  // namespace content | 64 void MockGamepadSharedBuffer::WriteEnd() {} | 
|  | 65 | 
|  | 66 GamepadTestHelper::GamepadTestHelper() {} | 
|  | 67 | 
|  | 68 GamepadTestHelper::~GamepadTestHelper() {} | 
|  | 69 | 
|  | 70 }  // namespace device | 
| OLD | NEW | 
|---|