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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "content/browser/gamepad/gamepad_test_helpers.h" | 9 #include "content/browser/gamepad/gamepad_test_helpers.h" |
10 #include "content/browser/renderer_host/pepper/browser_ppapi_host_test.h" | 10 #include "content/browser/renderer_host/pepper/browser_ppapi_host_test.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 EXPECT_EQ(0u, sink().message_count()); | 157 EXPECT_EQ(0u, sink().message_count()); |
158 | 158 |
159 // Set a button down and wait for it to be read twice. | 159 // Set a button down and wait for it to be read twice. |
160 // | 160 // |
161 // We wait for two reads before calling RunAllPending because the provider | 161 // We wait for two reads before calling RunAllPending because the provider |
162 // will read the data on the background thread (setting the event) and *then* | 162 // will read the data on the background thread (setting the event) and *then* |
163 // will issue the callback on our thread. Waiting for it to read twice | 163 // will issue the callback on our thread. Waiting for it to read twice |
164 // ensures that it was able to issue callbacks for the first read (if it | 164 // ensures that it was able to issue callbacks for the first read (if it |
165 // issued one) before we try to check for it. | 165 // issued one) before we try to check for it. |
166 blink::WebGamepads button_down_data = default_data; | 166 blink::WebGamepads button_down_data = default_data; |
167 button_down_data.items[0].buttons[0] = 1.f; | 167 button_down_data.items[0].buttons[0].value = 1.f; |
| 168 button_down_data.items[0].buttons[0].pressed = true; |
168 fetcher->SetTestData(button_down_data); | 169 fetcher->SetTestData(button_down_data); |
169 fetcher->WaitForDataRead(); | 170 fetcher->WaitForDataRead(); |
170 fetcher->WaitForDataRead(); | 171 fetcher->WaitForDataRead(); |
171 | 172 |
172 // It should have sent a callback. | 173 // It should have sent a callback. |
173 service_->message_loop().RunUntilIdle(); | 174 service_->message_loop().RunUntilIdle(); |
174 ppapi::proxy::ResourceMessageReplyParams reply_params; | 175 ppapi::proxy::ResourceMessageReplyParams reply_params; |
175 IPC::Message reply_msg; | 176 IPC::Message reply_msg; |
176 ASSERT_TRUE(sink().GetFirstResourceReplyMatching( | 177 ASSERT_TRUE(sink().GetFirstResourceReplyMatching( |
177 PpapiPluginMsg_Gamepad_SendMemory::ID, &reply_params, &reply_msg)); | 178 PpapiPluginMsg_Gamepad_SendMemory::ID, &reply_params, &reply_msg)); |
178 | 179 |
179 // Extract the shared memory handle. | 180 // Extract the shared memory handle. |
180 base::SharedMemoryHandle reply_handle; | 181 base::SharedMemoryHandle reply_handle; |
181 EXPECT_TRUE(reply_params.TakeSharedMemoryHandleAtIndex(0, &reply_handle)); | 182 EXPECT_TRUE(reply_params.TakeSharedMemoryHandleAtIndex(0, &reply_handle)); |
182 | 183 |
183 // Validate the shared memory. | 184 // Validate the shared memory. |
184 base::SharedMemory shared_memory(reply_handle, true); | 185 base::SharedMemory shared_memory(reply_handle, true); |
185 EXPECT_TRUE(shared_memory.Map(sizeof(ppapi::ContentGamepadHardwareBuffer))); | 186 EXPECT_TRUE(shared_memory.Map(sizeof(ppapi::ContentGamepadHardwareBuffer))); |
186 const ppapi::ContentGamepadHardwareBuffer* buffer = | 187 const ppapi::ContentGamepadHardwareBuffer* buffer = |
187 static_cast<const ppapi::ContentGamepadHardwareBuffer*>( | 188 static_cast<const ppapi::ContentGamepadHardwareBuffer*>( |
188 shared_memory.memory()); | 189 shared_memory.memory()); |
189 EXPECT_EQ(button_down_data.length, buffer->buffer.length); | 190 EXPECT_EQ(button_down_data.length, buffer->buffer.length); |
190 EXPECT_EQ(button_down_data.items[0].buttonsLength, | 191 EXPECT_EQ(button_down_data.items[0].buttonsLength, |
191 buffer->buffer.items[0].buttons_length); | 192 buffer->buffer.items[0].buttons_length); |
192 for (size_t i = 0; i < ppapi::WebKitGamepad::kButtonsLengthCap; i++) { | 193 for (size_t i = 0; i < ppapi::WebKitGamepad::kButtonsLengthCap; i++) { |
193 EXPECT_EQ(button_down_data.items[0].buttons[i], | 194 EXPECT_EQ(button_down_data.items[0].buttons[i].value, |
194 buffer->buffer.items[0].buttons[i]); | 195 buffer->buffer.items[0].buttons[i].value); |
| 196 EXPECT_EQ(button_down_data.items[0].buttons[i].pressed, |
| 197 buffer->buffer.items[0].buttons[i].pressed); |
195 } | 198 } |
196 | 199 |
197 // Duplicate requests should be denied. | 200 // Duplicate requests should be denied. |
198 EXPECT_EQ(PP_ERROR_FAILED, | 201 EXPECT_EQ(PP_ERROR_FAILED, |
199 gamepad_host.OnResourceMessageReceived( | 202 gamepad_host.OnResourceMessageReceived( |
200 PpapiHostMsg_Gamepad_RequestMemory(), | 203 PpapiHostMsg_Gamepad_RequestMemory(), |
201 &context)); | 204 &context)); |
202 } | 205 } |
203 | 206 |
204 } // namespace content | 207 } // namespace content |
OLD | NEW |