| 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/renderer_host/pepper/pepper_gamepad_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 EXPECT_EQ(AddressDiff(&content_buf.data, &content_buf), | 69 EXPECT_EQ(AddressDiff(&content_buf.data, &content_buf), |
| 70 AddressDiff(&ppapi_buf.buffer, &ppapi_buf)); | 70 AddressDiff(&ppapi_buf.buffer, &ppapi_buf)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) { | 73 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) { |
| 74 // Gamepads. | 74 // Gamepads. |
| 75 static_assert(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads), | 75 static_assert(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads), |
| 76 "gamepads data must match"); | 76 "gamepads data must match"); |
| 77 ppapi::WebKitGamepads ppapi_gamepads; | 77 ppapi::WebKitGamepads ppapi_gamepads; |
| 78 blink::WebGamepads web_gamepads; | 78 blink::WebGamepads web_gamepads; |
| 79 EXPECT_EQ(AddressDiff(&web_gamepads.length, &web_gamepads), | |
| 80 AddressDiff(&ppapi_gamepads.length, &ppapi_gamepads)); | |
| 81 | 79 |
| 82 // See comment below on storage & the EXPECT macro. | 80 // See comment below on storage & the EXPECT macro. |
| 83 size_t webkit_items_length_cap = blink::WebGamepads::itemsLengthCap; | 81 size_t webkit_items_length_cap = blink::WebGamepads::itemsLengthCap; |
| 84 size_t ppapi_items_length_cap = ppapi::WebKitGamepads::kItemsLengthCap; | 82 size_t ppapi_items_length_cap = ppapi::WebKitGamepads::kItemsLengthCap; |
| 85 EXPECT_EQ(webkit_items_length_cap, ppapi_items_length_cap); | 83 EXPECT_EQ(webkit_items_length_cap, ppapi_items_length_cap); |
| 86 | 84 |
| 87 for (size_t i = 0; i < web_gamepads.itemsLengthCap; i++) { | 85 for (size_t i = 0; i < web_gamepads.itemsLengthCap; i++) { |
| 88 EXPECT_EQ(AddressDiff(&web_gamepads.items[0], &web_gamepads), | 86 EXPECT_EQ(AddressDiff(&web_gamepads.items[0], &web_gamepads), |
| 89 AddressDiff(&ppapi_gamepads.items[0], &ppapi_gamepads)); | 87 AddressDiff(&ppapi_gamepads.items[0], &ppapi_gamepads)); |
| 90 } | 88 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 128 |
| 131 // crbug.com/147549 | 129 // crbug.com/147549 |
| 132 #if defined(OS_ANDROID) | 130 #if defined(OS_ANDROID) |
| 133 #define MAYBE_WaitForReply DISABLED_WaitForReply | 131 #define MAYBE_WaitForReply DISABLED_WaitForReply |
| 134 #else | 132 #else |
| 135 #define MAYBE_WaitForReply WaitForReply | 133 #define MAYBE_WaitForReply WaitForReply |
| 136 #endif | 134 #endif |
| 137 TEST_F(PepperGamepadHostTest, MAYBE_WaitForReply) { | 135 TEST_F(PepperGamepadHostTest, MAYBE_WaitForReply) { |
| 138 blink::WebGamepads default_data; | 136 blink::WebGamepads default_data; |
| 139 memset(&default_data, 0, sizeof(blink::WebGamepads)); | 137 memset(&default_data, 0, sizeof(blink::WebGamepads)); |
| 140 default_data.length = 1; | |
| 141 default_data.items[0].connected = true; | 138 default_data.items[0].connected = true; |
| 142 default_data.items[0].buttonsLength = 1; | 139 default_data.items[0].buttonsLength = 1; |
| 143 ConstructService(default_data); | 140 ConstructService(default_data); |
| 144 | 141 |
| 145 PP_Instance pp_instance = 12345; | 142 PP_Instance pp_instance = 12345; |
| 146 PP_Resource pp_resource = 67890; | 143 PP_Resource pp_resource = 67890; |
| 147 PepperGamepadHost gamepad_host( | 144 PepperGamepadHost gamepad_host( |
| 148 gamepad_service(), GetBrowserPpapiHost(), pp_instance, pp_resource); | 145 gamepad_service(), GetBrowserPpapiHost(), pp_instance, pp_resource); |
| 149 | 146 |
| 150 // Synthesize a request for gamepad data. | 147 // Synthesize a request for gamepad data. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 178 // Extract the shared memory handle. | 175 // Extract the shared memory handle. |
| 179 base::SharedMemoryHandle reply_handle; | 176 base::SharedMemoryHandle reply_handle; |
| 180 EXPECT_TRUE(reply_params.TakeSharedMemoryHandleAtIndex(0, &reply_handle)); | 177 EXPECT_TRUE(reply_params.TakeSharedMemoryHandleAtIndex(0, &reply_handle)); |
| 181 | 178 |
| 182 // Validate the shared memory. | 179 // Validate the shared memory. |
| 183 base::SharedMemory shared_memory(reply_handle, true); | 180 base::SharedMemory shared_memory(reply_handle, true); |
| 184 EXPECT_TRUE(shared_memory.Map(sizeof(ppapi::ContentGamepadHardwareBuffer))); | 181 EXPECT_TRUE(shared_memory.Map(sizeof(ppapi::ContentGamepadHardwareBuffer))); |
| 185 const ppapi::ContentGamepadHardwareBuffer* buffer = | 182 const ppapi::ContentGamepadHardwareBuffer* buffer = |
| 186 static_cast<const ppapi::ContentGamepadHardwareBuffer*>( | 183 static_cast<const ppapi::ContentGamepadHardwareBuffer*>( |
| 187 shared_memory.memory()); | 184 shared_memory.memory()); |
| 188 EXPECT_EQ(button_down_data.length, buffer->buffer.length); | |
| 189 EXPECT_EQ(button_down_data.items[0].buttonsLength, | 185 EXPECT_EQ(button_down_data.items[0].buttonsLength, |
| 190 buffer->buffer.items[0].buttons_length); | 186 buffer->buffer.items[0].buttons_length); |
| 191 for (size_t i = 0; i < ppapi::WebKitGamepad::kButtonsLengthCap; i++) { | 187 for (size_t i = 0; i < ppapi::WebKitGamepad::kButtonsLengthCap; i++) { |
| 192 EXPECT_EQ(button_down_data.items[0].buttons[i].value, | 188 EXPECT_EQ(button_down_data.items[0].buttons[i].value, |
| 193 buffer->buffer.items[0].buttons[i].value); | 189 buffer->buffer.items[0].buttons[i].value); |
| 194 EXPECT_EQ(button_down_data.items[0].buttons[i].pressed, | 190 EXPECT_EQ(button_down_data.items[0].buttons[i].pressed, |
| 195 buffer->buffer.items[0].buttons[i].pressed); | 191 buffer->buffer.items[0].buttons[i].pressed); |
| 196 } | 192 } |
| 197 | 193 |
| 198 // Duplicate requests should be denied. | 194 // Duplicate requests should be denied. |
| 199 EXPECT_EQ(PP_ERROR_FAILED, | 195 EXPECT_EQ(PP_ERROR_FAILED, |
| 200 gamepad_host.OnResourceMessageReceived( | 196 gamepad_host.OnResourceMessageReceived( |
| 201 PpapiHostMsg_Gamepad_RequestMemory(), &context)); | 197 PpapiHostMsg_Gamepad_RequestMemory(), &context)); |
| 202 } | 198 } |
| 203 | 199 |
| 204 } // namespace content | 200 } // namespace content |
| OLD | NEW |