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_provider.h" | 5 #include "content/browser/gamepad/gamepad_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/run_loop.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 #include "content/browser/gamepad/gamepad_data_fetcher.h" | 13 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
13 #include "content/browser/gamepad/gamepad_test_helpers.h" | 14 #include "content/browser/gamepad/gamepad_test_helpers.h" |
14 #include "content/common/gamepad_hardware_buffer.h" | 15 #include "content/common/gamepad_hardware_buffer.h" |
15 #include "content/common/gamepad_messages.h" | 16 #include "content/common/gamepad_messages.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 test_data.items[0].buttonsLength = 1; | 83 test_data.items[0].buttonsLength = 1; |
83 test_data.items[0].axesLength = 2; | 84 test_data.items[0].axesLength = 2; |
84 test_data.items[0].buttons[0].value = 1.f; | 85 test_data.items[0].buttons[0].value = 1.f; |
85 test_data.items[0].buttons[0].pressed = true; | 86 test_data.items[0].buttons[0].pressed = true; |
86 test_data.items[0].axes[0] = -1.f; | 87 test_data.items[0].axes[0] = -1.f; |
87 test_data.items[0].axes[1] = .5f; | 88 test_data.items[0].axes[1] = .5f; |
88 | 89 |
89 GamepadProvider* provider = CreateProvider(test_data); | 90 GamepadProvider* provider = CreateProvider(test_data); |
90 provider->Resume(); | 91 provider->Resume(); |
91 | 92 |
92 message_loop().RunUntilIdle(); | 93 base::RunLoop().RunUntilIdle(); |
93 | 94 |
94 mock_data_fetcher_->WaitForDataRead(); | 95 mock_data_fetcher_->WaitForDataRead(); |
95 | 96 |
96 // Renderer-side, pull data out of poll buffer. | 97 // Renderer-side, pull data out of poll buffer. |
97 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( | 98 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( |
98 base::GetCurrentProcessHandle()); | 99 base::GetCurrentProcessHandle()); |
99 std::unique_ptr<base::SharedMemory> shared_memory( | 100 std::unique_ptr<base::SharedMemory> shared_memory( |
100 new base::SharedMemory(handle, true)); | 101 new base::SharedMemory(handle, true)); |
101 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 102 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
102 void* mem = shared_memory->memory(); | 103 void* mem = shared_memory->memory(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 button_down_data.items[0].buttons[0].pressed = true; | 139 button_down_data.items[0].buttons[0].pressed = true; |
139 | 140 |
140 UserGestureListener listener; | 141 UserGestureListener listener; |
141 GamepadProvider* provider = CreateProvider(no_button_data); | 142 GamepadProvider* provider = CreateProvider(no_button_data); |
142 provider->Resume(); | 143 provider->Resume(); |
143 | 144 |
144 provider->RegisterForUserGesture(listener.GetClosure()); | 145 provider->RegisterForUserGesture(listener.GetClosure()); |
145 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); | 146 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); |
146 | 147 |
147 // It should not have issued our callback. | 148 // It should not have issued our callback. |
148 message_loop().RunUntilIdle(); | 149 base::RunLoop().RunUntilIdle(); |
149 EXPECT_FALSE(listener.has_user_gesture()); | 150 EXPECT_FALSE(listener.has_user_gesture()); |
150 | 151 |
151 // Set a button down and wait for it to be read twice. | 152 // Set a button down and wait for it to be read twice. |
152 mock_data_fetcher_->SetTestData(button_down_data); | 153 mock_data_fetcher_->SetTestData(button_down_data); |
153 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); | 154 mock_data_fetcher_->WaitForDataReadAndCallbacksIssued(); |
154 | 155 |
155 // It should have issued our callback. | 156 // It should have issued our callback. |
156 message_loop().RunUntilIdle(); | 157 base::RunLoop().RunUntilIdle(); |
157 EXPECT_TRUE(listener.has_user_gesture()); | 158 EXPECT_TRUE(listener.has_user_gesture()); |
158 } | 159 } |
159 | 160 |
160 } // namespace | 161 } // namespace |
161 | 162 |
162 } // namespace content | 163 } // namespace content |
OLD | NEW |