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

Side by Side Diff: ppapi/tests/test_input_event.cc

Issue 10873074: ppapi: Make sure the touch-event interface is detected correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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
« no previous file with comments | « ppapi/tests/test_input_event.h ('k') | ppapi/thunk/interfaces_ppb_public_stable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/tests/test_input_event.h" 5 #include "ppapi/tests/test_input_event.h"
6 6
7 #include "ppapi/c/dev/ppb_testing_dev.h" 7 #include "ppapi/c/dev/ppb_testing_dev.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_input_event.h" 9 #include "ppapi/c/ppb_input_event.h"
10 #include "ppapi/cpp/input_event.h" 10 #include "ppapi/cpp/input_event.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 #undef RUN_TEST_EXACT_MATCH 48 #undef RUN_TEST_EXACT_MATCH
49 } 49 }
50 50
51 TestInputEvent::TestInputEvent(TestingInstance* instance) 51 TestInputEvent::TestInputEvent(TestingInstance* instance)
52 : TestCase(instance), 52 : TestCase(instance),
53 input_event_interface_(NULL), 53 input_event_interface_(NULL),
54 mouse_input_event_interface_(NULL), 54 mouse_input_event_interface_(NULL),
55 wheel_input_event_interface_(NULL), 55 wheel_input_event_interface_(NULL),
56 keyboard_input_event_interface_(NULL), 56 keyboard_input_event_interface_(NULL),
57 touch_input_event_interface_(NULL),
57 view_rect_(), 58 view_rect_(),
58 expected_input_event_(0), 59 expected_input_event_(0),
59 received_expected_event_(false), 60 received_expected_event_(false),
60 received_finish_message_(false) { 61 received_finish_message_(false) {
61 } 62 }
62 63
63 TestInputEvent::~TestInputEvent() { 64 TestInputEvent::~TestInputEvent() {
64 // Remove the special listener that only responds to a 65 // Remove the special listener that only responds to a
65 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added. 66 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added.
66 std::string js_code; 67 std::string js_code;
67 js_code += "var plugin = document.getElementById('plugin');" 68 js_code += "var plugin = document.getElementById('plugin');"
68 "plugin.removeEventListener('message'," 69 "plugin.removeEventListener('message',"
69 " plugin.wait_for_messages_handler);" 70 " plugin.wait_for_messages_handler);"
70 "delete plugin.wait_for_messages_handler;"; 71 "delete plugin.wait_for_messages_handler;";
71 instance_->EvalScript(js_code); 72 instance_->EvalScript(js_code);
72 } 73 }
73 74
74 bool TestInputEvent::Init() { 75 bool TestInputEvent::Init() {
75 input_event_interface_ = static_cast<const PPB_InputEvent*>( 76 input_event_interface_ = static_cast<const PPB_InputEvent*>(
76 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); 77 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE));
77 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>( 78 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>(
78 pp::Module::Get()->GetBrowserInterface( 79 pp::Module::Get()->GetBrowserInterface(
79 PPB_MOUSE_INPUT_EVENT_INTERFACE)); 80 PPB_MOUSE_INPUT_EVENT_INTERFACE));
80 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>( 81 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>(
81 pp::Module::Get()->GetBrowserInterface( 82 pp::Module::Get()->GetBrowserInterface(
82 PPB_WHEEL_INPUT_EVENT_INTERFACE)); 83 PPB_WHEEL_INPUT_EVENT_INTERFACE));
83 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>( 84 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>(
84 pp::Module::Get()->GetBrowserInterface( 85 pp::Module::Get()->GetBrowserInterface(
85 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); 86 PPB_KEYBOARD_INPUT_EVENT_INTERFACE));
87 touch_input_event_interface_ = static_cast<const PPB_TouchInputEvent*>(
88 pp::Module::Get()->GetBrowserInterface(
89 PPB_TOUCH_INPUT_EVENT_INTERFACE));
86 90
87 bool success = 91 bool success =
88 input_event_interface_ && 92 input_event_interface_ &&
89 mouse_input_event_interface_ && 93 mouse_input_event_interface_ &&
90 wheel_input_event_interface_ && 94 wheel_input_event_interface_ &&
91 keyboard_input_event_interface_ && 95 keyboard_input_event_interface_ &&
96 touch_input_event_interface_ &&
92 CheckTestingInterface(); 97 CheckTestingInterface();
93 98
94 // Set up a listener for our message that signals that all input events have 99 // Set up a listener for our message that signals that all input events have
95 // been received. 100 // been received.
96 std::string js_code; 101 std::string js_code;
97 // Note the following code is dependent on some features of test_case.html. 102 // Note the following code is dependent on some features of test_case.html.
98 // E.g., it is assumed that the DOM element where the plugin is embedded has 103 // E.g., it is assumed that the DOM element where the plugin is embedded has
99 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows 104 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows
100 // us to ignore the messages that are intended for use by the testing 105 // us to ignore the messages that are intended for use by the testing
101 // framework itself. 106 // framework itself.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 pp::InputEvent TestInputEvent::CreateCharEvent(const std::string& text) { 157 pp::InputEvent TestInputEvent::CreateCharEvent(const std::string& text) {
153 return pp::KeyboardInputEvent( 158 return pp::KeyboardInputEvent(
154 instance_, 159 instance_,
155 PP_INPUTEVENT_TYPE_CHAR, 160 PP_INPUTEVENT_TYPE_CHAR,
156 100, // time_stamp 161 100, // time_stamp
157 0, // modifiers 162 0, // modifiers
158 0, // keycode 163 0, // keycode
159 pp::Var(text)); 164 pp::Var(text));
160 } 165 }
161 166
167 pp::InputEvent TestInputEvent::CreateTouchEvent(PP_InputEvent_Type type,
168 const pp::FloatPoint& point) {
169 PP_TouchPoint touch_point;
170 touch_point.position = point;
171
172 pp::TouchInputEvent touch_event(instance_, type, 100, 0);
173 touch_event.AddTouchPoint(PP_TOUCHLIST_TYPE_TOUCHES, touch_point);
174 touch_event.AddTouchPoint(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, touch_point);
175 touch_event.AddTouchPoint(PP_TOUCHLIST_TYPE_TARGETTOUCHES, touch_point);
176
177 return touch_event;
178 }
179
162 // Simulates the input event and calls PostMessage to let us know when 180 // Simulates the input event and calls PostMessage to let us know when
163 // we have received all resulting events from the browser. 181 // we have received all resulting events from the browser.
164 bool TestInputEvent::SimulateInputEvent( 182 bool TestInputEvent::SimulateInputEvent(
165 const pp::InputEvent& input_event) { 183 const pp::InputEvent& input_event) {
166 expected_input_event_ = pp::InputEvent(input_event.pp_resource()); 184 expected_input_event_ = pp::InputEvent(input_event.pp_resource());
167 received_expected_event_ = false; 185 received_expected_event_ = false;
168 received_finish_message_ = false; 186 received_finish_message_ = false;
169 testing_interface_->SimulateInputEvent(instance_->pp_instance(), 187 testing_interface_->SimulateInputEvent(instance_->pp_instance(),
170 input_event.pp_resource()); 188 input_event.pp_resource());
171 instance_->PostMessage(pp::Var(FINISHED_WAITING_MESSAGE)); 189 instance_->PostMessage(pp::Var(FINISHED_WAITING_MESSAGE));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 243
226 case PP_INPUTEVENT_TYPE_CHAR: 244 case PP_INPUTEVENT_TYPE_CHAR:
227 return 245 return
228 keyboard_input_event_interface_->GetKeyCode(received) == 246 keyboard_input_event_interface_->GetKeyCode(received) ==
229 keyboard_input_event_interface_->GetKeyCode(expected) && 247 keyboard_input_event_interface_->GetKeyCode(expected) &&
230 pp::Var(pp::PASS_REF, 248 pp::Var(pp::PASS_REF,
231 keyboard_input_event_interface_->GetCharacterText(received)) == 249 keyboard_input_event_interface_->GetCharacterText(received)) ==
232 pp::Var(pp::PASS_REF, 250 pp::Var(pp::PASS_REF,
233 keyboard_input_event_interface_->GetCharacterText(expected)); 251 keyboard_input_event_interface_->GetCharacterText(expected));
234 252
253 case PP_INPUTEVENT_TYPE_TOUCHSTART:
254 case PP_INPUTEVENT_TYPE_TOUCHMOVE:
255 case PP_INPUTEVENT_TYPE_TOUCHEND:
256 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: {
257 if (!touch_input_event_interface_->IsTouchInputEvent(received) ||
258 !touch_input_event_interface_->IsTouchInputEvent(expected))
259 return false;
260
261 uint32_t touch_count = touch_input_event_interface_->GetTouchCount(
262 received, PP_TOUCHLIST_TYPE_TOUCHES);
263 if (touch_count <= 0 ||
264 touch_count != touch_input_event_interface_->GetTouchCount(expected,
265 PP_TOUCHLIST_TYPE_TOUCHES))
266 return false;
267
268 for (uint32_t i = 0; i < touch_count; ++i) {
269 PP_TouchPoint expected_point = touch_input_event_interface_->
270 GetTouchByIndex(expected, PP_TOUCHLIST_TYPE_TOUCHES, i);
271 PP_TouchPoint received_point = touch_input_event_interface_->
272 GetTouchByIndex(received, PP_TOUCHLIST_TYPE_TOUCHES, i);
273
274 if (expected_point.id != received_point.id ||
275 expected_point.radius != received_point.radius ||
276 expected_point.rotation_angle != received_point.rotation_angle ||
277 expected_point.pressure != received_point.pressure)
278 return false;
279
280 // The expected position is in the page coordinate system, and the
281 // received event is in the plugins coordinate system.
282 if (expected_point.position.x != received_point.position.x +
283 view_rect_.x() ||
284 expected_point.position.y != received_point.position.y +
285 view_rect_.y())
286 return false;
287 }
288 return true;
289 }
290
235 default: 291 default:
236 break; 292 break;
237 } 293 }
238 294
239 return false; 295 return false;
240 } 296 }
241 297
242 bool TestInputEvent::HandleInputEvent(const pp::InputEvent& input_event) { 298 bool TestInputEvent::HandleInputEvent(const pp::InputEvent& input_event) {
243 // Some events may cause extra events to be generated, so look for the 299 // Some events may cause extra events to be generated, so look for the
244 // first one that matches. 300 // first one that matches.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN, 346 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN,
291 PP_INPUTEVENT_MOUSEBUTTON_LEFT))); 347 PP_INPUTEVENT_MOUSEBUTTON_LEFT)));
292 ASSERT_FALSE( 348 ASSERT_FALSE(
293 SimulateInputEvent(CreateWheelEvent())); 349 SimulateInputEvent(CreateWheelEvent()));
294 ASSERT_FALSE( 350 ASSERT_FALSE(
295 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN, 351 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN,
296 kSpaceChar))); 352 kSpaceChar)));
297 ASSERT_FALSE( 353 ASSERT_FALSE(
298 SimulateInputEvent(CreateCharEvent(kSpaceString))); 354 SimulateInputEvent(CreateCharEvent(kSpaceString)));
299 355
356 #if !defined(PPAPI_OS_WIN)
sadrul 2012/08/28 19:18:40 The test passes on debug builds, but fails on rele
357 // This fails on windows. See http://crbug.com/145236
358 // Request touch events.
359 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
360 PP_INPUTEVENT_CLASS_TOUCH);
361 ASSERT_TRUE(SimulateInputEvent(CreateTouchEvent(PP_INPUTEVENT_TYPE_TOUCHSTART,
362 pp::FloatPoint(12, 23))));
363 #endif
300 PASS(); 364 PASS();
301 } 365 }
302 366
303 std::string TestInputEvent::TestAcceptTouchEvent_1() { 367 std::string TestInputEvent::TestAcceptTouchEvent_1() {
304 // The browser normally sends touch-events to the renderer only if the page 368 // The browser normally sends touch-events to the renderer only if the page
305 // has touch-event handlers. Since test-case.html does not have any 369 // has touch-event handlers. Since test-case.html does not have any
306 // touch-event handler, it would normally not receive any touch events from 370 // touch-event handler, it would normally not receive any touch events from
307 // the browser. However, if a plugin in the page does accept touch events, 371 // the browser. However, if a plugin in the page does accept touch events,
308 // then the browser should start sending touch-events to the page. In this 372 // then the browser should start sending touch-events to the page. In this
309 // test, the plugin simply registers for touch-events. The real test is to 373 // test, the plugin simply registers for touch-events. The real test is to
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 instance_->set_remove_plugin(false); 415 instance_->set_remove_plugin(false);
352 input_event_interface_->RequestInputEvents(instance_->pp_instance(), 416 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
353 PP_INPUTEVENT_CLASS_MOUSE | 417 PP_INPUTEVENT_CLASS_MOUSE |
354 PP_INPUTEVENT_CLASS_WHEEL | 418 PP_INPUTEVENT_CLASS_WHEEL |
355 PP_INPUTEVENT_CLASS_KEYBOARD); 419 PP_INPUTEVENT_CLASS_KEYBOARD);
356 input_event_interface_->RequestInputEvents(instance_->pp_instance(), 420 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
357 PP_INPUTEVENT_CLASS_TOUCH); 421 PP_INPUTEVENT_CLASS_TOUCH);
358 PASS(); 422 PASS();
359 } 423 }
360 424
OLDNEW
« no previous file with comments | « ppapi/tests/test_input_event.h ('k') | ppapi/thunk/interfaces_ppb_public_stable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698