Chromium Code Reviews| Index: content/browser/gamepad/gamepad_provider_unittest.cc |
| =================================================================== |
| --- content/browser/gamepad/gamepad_provider_unittest.cc (revision 113580) |
| +++ content/browser/gamepad/gamepad_provider_unittest.cc (working copy) |
| @@ -6,6 +6,7 @@ |
| #include "base/process_util.h" |
| #include "base/synchronization/waitable_event.h" |
| #include "base/system_monitor/system_monitor.h" |
| +#include "base/threading/platform_thread.h" |
| #include "content/browser/gamepad/gamepad_provider.h" |
| #include "content/common/gamepad_messages.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -18,19 +19,15 @@ |
| class MockDataFetcher : public GamepadDataFetcher { |
| public: |
| - MockDataFetcher(WebGamepads& test_data) : read_data_(false, false) { |
| + explicit MockDataFetcher(WebGamepads const& test_data) { |
|
darin (slow to review)
2011/12/08 22:10:48
nit: please stick with the more canonical "const F
dvyukov
2011/12/13 13:46:20
Done.
|
| test_data_ = test_data; |
| } |
| virtual void GetGamepadData(WebGamepads* pads, |
| bool devices_changed_hint) OVERRIDE { |
| *pads = test_data_; |
| - read_data_.Signal(); |
| } |
| - void WaitForDataRead() { return read_data_.Wait(); } |
| - |
| WebGamepads test_data_; |
| - base::WaitableEvent read_data_; |
| }; |
| // Main test fixture |
| @@ -72,8 +69,6 @@ |
| main_message_loop_.RunAllPending(); |
| - mock_data_fetcher_->WaitForDataRead(); |
| - |
| // Renderer-side, pull data out of poll buffer. |
| base::SharedMemoryHandle handle = |
| provider->GetRendererSharedMemoryHandle(base::GetCurrentProcessHandle()); |
| @@ -83,15 +78,14 @@ |
| void* mem = shared_memory->memory(); |
| GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem); |
| - // See gamepad_hardware_buffer.h for details on the read discipline. |
| WebGamepads output; |
| - |
| - base::subtle::Atomic32 version; |
| - do { |
| - version = hwbuf->sequence.ReadBegin(); |
| - memcpy(&output, &hwbuf->buffer, sizeof(output)); |
| - } while (hwbuf->sequence.ReadRetry(version)); |
| - |
| + output.length = 0; |
| + for (;;) { |
| + hwbuf->gamepads.ReadTo(&output); |
| + if (output.length == 1) |
| + break; |
| + base::PlatformThread::YieldCurrentThread(); |
| + } |
| EXPECT_EQ(1u, output.length); |
| EXPECT_EQ(1u, output.items[0].buttonsLength); |
| EXPECT_EQ(1.f, output.items[0].buttons[0]); |