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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return static_cast<const char*>(a) - static_cast<const char*>(b); | 44 return static_cast<const char*>(a) - static_cast<const char*>(b); |
45 } | 45 } |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 // Validate the memory layout of the Pepper proxy struct matches the content | 49 // Validate the memory layout of the Pepper proxy struct matches the content |
50 // one. The proxy can't depend on content so has a duplicate definition. This | 50 // one. The proxy can't depend on content so has a duplicate definition. This |
51 // code can see both definitions so we do the validation here. | 51 // code can see both definitions so we do the validation here. |
52 TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) { | 52 TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) { |
53 // Hardware buffer. | 53 // Hardware buffer. |
54 COMPILE_ASSERT(sizeof(ppapi::ContentGamepadHardwareBuffer) == | 54 static_assert(sizeof(ppapi::ContentGamepadHardwareBuffer) == |
55 sizeof(GamepadHardwareBuffer), | 55 sizeof(GamepadHardwareBuffer), |
56 gamepad_hardware_buffers_must_match); | 56 "gamepad hardware buffers must match"); |
57 ppapi::ContentGamepadHardwareBuffer ppapi_buf; | 57 ppapi::ContentGamepadHardwareBuffer ppapi_buf; |
58 GamepadHardwareBuffer content_buf; | 58 GamepadHardwareBuffer content_buf; |
59 EXPECT_EQ(AddressDiff(&content_buf.sequence, &content_buf), | 59 EXPECT_EQ(AddressDiff(&content_buf.sequence, &content_buf), |
60 AddressDiff(&ppapi_buf.sequence, &ppapi_buf)); | 60 AddressDiff(&ppapi_buf.sequence, &ppapi_buf)); |
61 EXPECT_EQ(AddressDiff(&content_buf.buffer, &content_buf), | 61 EXPECT_EQ(AddressDiff(&content_buf.buffer, &content_buf), |
62 AddressDiff(&ppapi_buf.buffer, &ppapi_buf)); | 62 AddressDiff(&ppapi_buf.buffer, &ppapi_buf)); |
63 } | 63 } |
64 | 64 |
65 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) { | 65 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) { |
66 // Gamepads. | 66 // Gamepads. |
67 COMPILE_ASSERT(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads), | 67 static_assert(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads), |
68 gamepads_data_must_match); | 68 "gamepads data must match"); |
69 ppapi::WebKitGamepads ppapi_gamepads; | 69 ppapi::WebKitGamepads ppapi_gamepads; |
70 blink::WebGamepads web_gamepads; | 70 blink::WebGamepads web_gamepads; |
71 EXPECT_EQ(AddressDiff(&web_gamepads.length, &web_gamepads), | 71 EXPECT_EQ(AddressDiff(&web_gamepads.length, &web_gamepads), |
72 AddressDiff(&ppapi_gamepads.length, &ppapi_gamepads)); | 72 AddressDiff(&ppapi_gamepads.length, &ppapi_gamepads)); |
73 | 73 |
74 // See comment below on storage & the EXPECT macro. | 74 // See comment below on storage & the EXPECT macro. |
75 size_t webkit_items_length_cap = blink::WebGamepads::itemsLengthCap; | 75 size_t webkit_items_length_cap = blink::WebGamepads::itemsLengthCap; |
76 size_t ppapi_items_length_cap = ppapi::WebKitGamepads::kItemsLengthCap; | 76 size_t ppapi_items_length_cap = ppapi::WebKitGamepads::kItemsLengthCap; |
77 EXPECT_EQ(webkit_items_length_cap, ppapi_items_length_cap); | 77 EXPECT_EQ(webkit_items_length_cap, ppapi_items_length_cap); |
78 | 78 |
79 for (size_t i = 0; i < web_gamepads.itemsLengthCap; i++) { | 79 for (size_t i = 0; i < web_gamepads.itemsLengthCap; i++) { |
80 EXPECT_EQ(AddressDiff(&web_gamepads.items[0], &web_gamepads), | 80 EXPECT_EQ(AddressDiff(&web_gamepads.items[0], &web_gamepads), |
81 AddressDiff(&ppapi_gamepads.items[0], &ppapi_gamepads)); | 81 AddressDiff(&ppapi_gamepads.items[0], &ppapi_gamepads)); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 TEST_F(PepperGamepadHostTest, ValidateGamepadMatch) { | 85 TEST_F(PepperGamepadHostTest, ValidateGamepadMatch) { |
86 // Gamepad. | 86 // Gamepad. |
87 COMPILE_ASSERT(sizeof(ppapi::WebKitGamepad) == sizeof(blink::WebGamepad), | 87 static_assert(sizeof(ppapi::WebKitGamepad) == sizeof(blink::WebGamepad), |
88 gamepad_data_must_match); | 88 "gamepad data must match"); |
89 ppapi::WebKitGamepad ppapi_gamepad; | 89 ppapi::WebKitGamepad ppapi_gamepad; |
90 blink::WebGamepad web_gamepad; | 90 blink::WebGamepad web_gamepad; |
91 | 91 |
92 // Using EXPECT seems to force storage for the parameter, which the constants | 92 // Using EXPECT seems to force storage for the parameter, which the constants |
93 // in the WebKit/PPAPI headers don't have. So we have to use temporaries | 93 // in the WebKit/PPAPI headers don't have. So we have to use temporaries |
94 // before comparing them. | 94 // before comparing them. |
95 size_t webkit_id_length_cap = blink::WebGamepad::idLengthCap; | 95 size_t webkit_id_length_cap = blink::WebGamepad::idLengthCap; |
96 size_t ppapi_id_length_cap = ppapi::WebKitGamepad::kIdLengthCap; | 96 size_t ppapi_id_length_cap = ppapi::WebKitGamepad::kIdLengthCap; |
97 EXPECT_EQ(webkit_id_length_cap, ppapi_id_length_cap); | 97 EXPECT_EQ(webkit_id_length_cap, ppapi_id_length_cap); |
98 | 98 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 buffer->buffer.items[0].buttons[i].pressed); | 181 buffer->buffer.items[0].buttons[i].pressed); |
182 } | 182 } |
183 | 183 |
184 // Duplicate requests should be denied. | 184 // Duplicate requests should be denied. |
185 EXPECT_EQ(PP_ERROR_FAILED, | 185 EXPECT_EQ(PP_ERROR_FAILED, |
186 gamepad_host.OnResourceMessageReceived( | 186 gamepad_host.OnResourceMessageReceived( |
187 PpapiHostMsg_Gamepad_RequestMemory(), &context)); | 187 PpapiHostMsg_Gamepad_RequestMemory(), &context)); |
188 } | 188 } |
189 | 189 |
190 } // namespace content | 190 } // namespace content |
OLD | NEW |