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

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 = PP_MakeTouchPoint();
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 16 matching lines...) Expand all
261 317
262 void TestInputEvent::DidChangeView(const pp::View& view) { 318 void TestInputEvent::DidChangeView(const pp::View& view) {
263 view_rect_ = view.GetRect(); 319 view_rect_ = view.GetRect();
264 } 320 }
265 321
266 std::string TestInputEvent::TestEvents() { 322 std::string TestInputEvent::TestEvents() {
267 // Request all input event classes. 323 // Request all input event classes.
268 input_event_interface_->RequestInputEvents(instance_->pp_instance(), 324 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
269 PP_INPUTEVENT_CLASS_MOUSE | 325 PP_INPUTEVENT_CLASS_MOUSE |
270 PP_INPUTEVENT_CLASS_WHEEL | 326 PP_INPUTEVENT_CLASS_WHEEL |
271 PP_INPUTEVENT_CLASS_KEYBOARD); 327 PP_INPUTEVENT_CLASS_KEYBOARD |
328 PP_INPUTEVENT_CLASS_TOUCH);
272 // Send the events and check that we received them. 329 // Send the events and check that we received them.
273 ASSERT_TRUE( 330 ASSERT_TRUE(
274 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN, 331 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN,
275 PP_INPUTEVENT_MOUSEBUTTON_LEFT))); 332 PP_INPUTEVENT_MOUSEBUTTON_LEFT)));
276 ASSERT_TRUE( 333 ASSERT_TRUE(
277 SimulateInputEvent(CreateWheelEvent())); 334 SimulateInputEvent(CreateWheelEvent()));
278 ASSERT_TRUE( 335 ASSERT_TRUE(
279 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN, 336 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN,
280 kSpaceChar))); 337 kSpaceChar)));
281 ASSERT_TRUE( 338 ASSERT_TRUE(
282 SimulateInputEvent(CreateCharEvent(kSpaceString))); 339 SimulateInputEvent(CreateCharEvent(kSpaceString)));
283 340 ASSERT_TRUE(SimulateInputEvent(CreateTouchEvent(PP_INPUTEVENT_TYPE_TOUCHSTART,
341 pp::FloatPoint(12, 23))));
284 // Request only mouse events. 342 // Request only mouse events.
285 input_event_interface_->ClearInputEventRequest(instance_->pp_instance(), 343 input_event_interface_->ClearInputEventRequest(instance_->pp_instance(),
286 PP_INPUTEVENT_CLASS_WHEEL | 344 PP_INPUTEVENT_CLASS_WHEEL |
287 PP_INPUTEVENT_CLASS_KEYBOARD); 345 PP_INPUTEVENT_CLASS_KEYBOARD);
288 // Check that we only receive mouse events. 346 // Check that we only receive mouse events.
289 ASSERT_TRUE( 347 ASSERT_TRUE(
290 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN, 348 SimulateInputEvent(CreateMouseEvent(PP_INPUTEVENT_TYPE_MOUSEDOWN,
291 PP_INPUTEVENT_MOUSEBUTTON_LEFT))); 349 PP_INPUTEVENT_MOUSEBUTTON_LEFT)));
292 ASSERT_FALSE( 350 ASSERT_FALSE(
293 SimulateInputEvent(CreateWheelEvent())); 351 SimulateInputEvent(CreateWheelEvent()));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 instance_->set_remove_plugin(false); 409 instance_->set_remove_plugin(false);
352 input_event_interface_->RequestInputEvents(instance_->pp_instance(), 410 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
353 PP_INPUTEVENT_CLASS_MOUSE | 411 PP_INPUTEVENT_CLASS_MOUSE |
354 PP_INPUTEVENT_CLASS_WHEEL | 412 PP_INPUTEVENT_CLASS_WHEEL |
355 PP_INPUTEVENT_CLASS_KEYBOARD); 413 PP_INPUTEVENT_CLASS_KEYBOARD);
356 input_event_interface_->RequestInputEvents(instance_->pp_instance(), 414 input_event_interface_->RequestInputEvents(instance_->pp_instance(),
357 PP_INPUTEVENT_CLASS_TOUCH); 415 PP_INPUTEVENT_CLASS_TOUCH);
358 PASS(); 416 PASS();
359 } 417 }
360 418
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