Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: content/browser/renderer_host/pepper/pepper_gamepad_host_unittest.cc

Issue 2563483006: Move gamepad_service out of content/ and into device/ (Closed)
Patch Set: addressed Blundell's review comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/browser/gamepad/gamepad_service_test_helpers.h"
17 #include "content/browser/renderer_host/pepper/browser_ppapi_host_test.h" 16 #include "content/browser/renderer_host/pepper/browser_ppapi_host_test.h"
18 #include "content/common/gamepad_hardware_buffer.h" 17 #include "device/gamepad/gamepad_shared_buffer.h"
19 #include "device/gamepad/gamepad_test_helpers.h" 18 #include "device/gamepad/gamepad_test_helpers.h"
20 #include "ppapi/c/pp_errors.h" 19 #include "ppapi/c/pp_errors.h"
21 #include "ppapi/host/host_message_context.h" 20 #include "ppapi/host/host_message_context.h"
22 #include "ppapi/proxy/gamepad_resource.h" 21 #include "ppapi/proxy/gamepad_resource.h"
23 #include "ppapi/proxy/ppapi_messages.h" 22 #include "ppapi/proxy/ppapi_messages.h"
24 #include "ppapi/proxy/resource_message_params.h" 23 #include "ppapi/proxy/resource_message_params.h"
25 #include "ppapi/shared_impl/ppb_gamepad_shared.h" 24 #include "ppapi/shared_impl/ppb_gamepad_shared.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 26
28 namespace content { 27 namespace content {
29 28
30 namespace { 29 namespace {
31 30
32 class PepperGamepadHostTest : public testing::Test, 31 class PepperGamepadHostTest : public testing::Test,
33 public BrowserPpapiHostTest { 32 public BrowserPpapiHostTest {
34 public: 33 public:
35 PepperGamepadHostTest() {} 34 PepperGamepadHostTest() {}
36 ~PepperGamepadHostTest() override {} 35 ~PepperGamepadHostTest() override {}
37 36
38 void ConstructService(const blink::WebGamepads& test_data) { 37 void ConstructService(const blink::WebGamepads& test_data) {
39 service_.reset(new GamepadServiceTestConstructor(test_data)); 38 service_.reset(new device::GamepadServiceTestConstructor(test_data));
40 } 39 }
41 40
42 GamepadService* gamepad_service() { return service_->gamepad_service(); } 41 device::GamepadService* gamepad_service() {
42 return service_->gamepad_service();
43 }
43 44
44 protected: 45 protected:
45 std::unique_ptr<GamepadServiceTestConstructor> service_; 46 std::unique_ptr<device::GamepadServiceTestConstructor> service_;
46 47
47 DISALLOW_COPY_AND_ASSIGN(PepperGamepadHostTest); 48 DISALLOW_COPY_AND_ASSIGN(PepperGamepadHostTest);
48 }; 49 };
49 50
50 inline ptrdiff_t AddressDiff(const void* a, const void* b) { 51 inline ptrdiff_t AddressDiff(const void* a, const void* b) {
51 return static_cast<const char*>(a) - static_cast<const char*>(b); 52 return static_cast<const char*>(a) - static_cast<const char*>(b);
52 } 53 }
53 54
54 } // namespace 55 } // namespace
55 56
56 // Validate the memory layout of the Pepper proxy struct matches the content 57 // Validate the memory layout of the Pepper proxy struct matches the content
57 // one. The proxy can't depend on content so has a duplicate definition. This 58 // one. The proxy can't depend on content so has a duplicate definition. This
58 // code can see both definitions so we do the validation here. 59 // code can see both definitions so we do the validation here.
59 TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) { 60 TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) {
60 // Hardware buffer. 61 // Hardware buffer.
61 static_assert(sizeof(ppapi::ContentGamepadHardwareBuffer) == 62 static_assert(sizeof(ppapi::ContentGamepadHardwareBuffer) ==
62 sizeof(GamepadHardwareBuffer), 63 sizeof(device::GamepadHardwareBuffer),
63 "gamepad hardware buffers must match"); 64 "gamepad hardware buffers must match");
64 ppapi::ContentGamepadHardwareBuffer ppapi_buf; 65 ppapi::ContentGamepadHardwareBuffer ppapi_buf;
65 GamepadHardwareBuffer content_buf; 66 device::GamepadHardwareBuffer content_buf;
66 EXPECT_EQ(AddressDiff(&content_buf.sequence, &content_buf), 67 EXPECT_EQ(AddressDiff(&content_buf.seqlock, &content_buf),
67 AddressDiff(&ppapi_buf.sequence, &ppapi_buf)); 68 AddressDiff(&ppapi_buf.sequence, &ppapi_buf));
68 EXPECT_EQ(AddressDiff(&content_buf.buffer, &content_buf), 69 EXPECT_EQ(AddressDiff(&content_buf.data, &content_buf),
69 AddressDiff(&ppapi_buf.buffer, &ppapi_buf)); 70 AddressDiff(&ppapi_buf.buffer, &ppapi_buf));
70 } 71 }
71 72
72 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) { 73 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) {
73 // Gamepads. 74 // Gamepads.
74 static_assert(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads), 75 static_assert(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads),
75 "gamepads data must match"); 76 "gamepads data must match");
76 ppapi::WebKitGamepads ppapi_gamepads; 77 ppapi::WebKitGamepads ppapi_gamepads;
77 blink::WebGamepads web_gamepads; 78 blink::WebGamepads web_gamepads;
78 EXPECT_EQ(AddressDiff(&web_gamepads.length, &web_gamepads), 79 EXPECT_EQ(AddressDiff(&web_gamepads.length, &web_gamepads),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 buffer->buffer.items[0].buttons[i].pressed); 195 buffer->buffer.items[0].buttons[i].pressed);
195 } 196 }
196 197
197 // Duplicate requests should be denied. 198 // Duplicate requests should be denied.
198 EXPECT_EQ(PP_ERROR_FAILED, 199 EXPECT_EQ(PP_ERROR_FAILED,
199 gamepad_host.OnResourceMessageReceived( 200 gamepad_host.OnResourceMessageReceived(
200 PpapiHostMsg_Gamepad_RequestMemory(), &context)); 201 PpapiHostMsg_Gamepad_RequestMemory(), &context));
201 } 202 }
202 203
203 } // namespace content 204 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_gamepad_host.cc ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698