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

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

Issue 165983005: Updating Gamepad API to match latest spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed typo in GamepadProviderTest Created 6 years, 9 months 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 | Annotate | Revision Log
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 <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
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
OLDNEW
« no previous file with comments | « content/browser/gamepad/gamepad_standard_mappings_win.cc ('k') | content/common/gamepad_user_gesture.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698