| 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 "ppapi/tests/test_input_event.h" | 5 #include "ppapi/tests/test_input_event.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_input_event.h" | 8 #include "ppapi/c/ppb_input_event.h" |
| 9 #include "ppapi/cpp/input_event.h" | 9 #include "ppapi/cpp/input_event.h" |
| 10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 pp::Point GetCenter(const pp::Rect& rect) { | 24 pp::Point GetCenter(const pp::Rect& rect) { |
| 25 return pp::Point( | 25 return pp::Point( |
| 26 rect.x() + rect.width() / 2, | 26 rect.x() + rect.width() / 2, |
| 27 rect.y() + rect.height() / 2); | 27 rect.y() + rect.height() / 2); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 void TestInputEvent::RunTests(const std::string& filter) { | 32 void TestInputEvent::RunTests(const std::string& filter) { |
| 33 RUN_TEST(Events, filter); | 33 RUN_TEST(Events, filter); |
| 34 RUN_TEST(EventsLatencyTracking, filter); |
| 34 | 35 |
| 35 // The AcceptTouchEvent_N tests should not be run when the filter is empty; | 36 // The AcceptTouchEvent_N tests should not be run when the filter is empty; |
| 36 // they can only be run one at a time. | 37 // they can only be run one at a time. |
| 37 // TODO(dmichael): Figure out a way to make these run in the same test fixture | 38 // TODO(dmichael): Figure out a way to make these run in the same test fixture |
| 38 // instance. | 39 // instance. |
| 39 if (!ShouldRunAllTests(filter)) { | 40 if (!ShouldRunAllTests(filter)) { |
| 40 RUN_TEST(AcceptTouchEvent_1, filter); | 41 RUN_TEST(AcceptTouchEvent_1, filter); |
| 41 RUN_TEST(AcceptTouchEvent_2, filter); | 42 RUN_TEST(AcceptTouchEvent_2, filter); |
| 42 RUN_TEST(AcceptTouchEvent_3, filter); | 43 RUN_TEST(AcceptTouchEvent_3, filter); |
| 43 RUN_TEST(AcceptTouchEvent_4, filter); | 44 RUN_TEST(AcceptTouchEvent_4, filter); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 TestInputEvent::TestInputEvent(TestingInstance* instance) | 48 TestInputEvent::TestInputEvent(TestingInstance* instance) |
| 48 : TestCase(instance), | 49 : TestCase(instance), |
| 49 input_event_interface_(NULL), | 50 input_event_interface_(NULL), |
| 50 mouse_input_event_interface_(NULL), | 51 mouse_input_event_interface_(NULL), |
| 51 wheel_input_event_interface_(NULL), | 52 wheel_input_event_interface_(NULL), |
| 52 keyboard_input_event_interface_(NULL), | 53 keyboard_input_event_interface_(NULL), |
| 53 touch_input_event_interface_(NULL), | 54 touch_input_event_interface_(NULL), |
| 54 nested_event_(instance->pp_instance()), | 55 nested_event_(instance->pp_instance()), |
| 55 view_rect_(), | 56 view_rect_(), |
| 56 expected_input_event_(0), | 57 expected_input_event_(0), |
| 57 received_expected_event_(false), | 58 received_expected_event_(false), |
| 58 received_finish_message_(false) { | 59 received_finish_message_(false), |
| 60 enable_latency_tracking_(false), |
| 61 last_latency_tracking_successful_(false) { |
| 59 } | 62 } |
| 60 | 63 |
| 61 TestInputEvent::~TestInputEvent() { | 64 TestInputEvent::~TestInputEvent() { |
| 62 // Remove the special listener that only responds to a | 65 // Remove the special listener that only responds to a |
| 63 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added. | 66 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added. |
| 64 std::string js_code; | 67 std::string js_code; |
| 65 js_code += "var plugin = document.getElementById('plugin');" | 68 js_code += "var plugin = document.getElementById('plugin');" |
| 66 "plugin.removeEventListener('message'," | 69 "plugin.removeEventListener('message'," |
| 67 " plugin.wait_for_messages_handler);" | 70 " plugin.wait_for_messages_handler);" |
| 68 "delete plugin.wait_for_messages_handler;"; | 71 "delete plugin.wait_for_messages_handler;"; |
| 69 instance_->EvalScript(js_code); | 72 instance_->EvalScript(js_code); |
| 70 } | 73 } |
| 71 | 74 |
| 72 bool TestInputEvent::Init() { | 75 bool TestInputEvent::Init() { |
| 73 input_event_interface_ = static_cast<const PPB_InputEvent*>( | 76 input_event_interface_ = static_cast<const PPB_InputEvent*>( |
| 74 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); | 77 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); |
| 78 input_event_private_interface_ = static_cast<const PPB_InputEvent_Private*>( |
| 79 pp::Module::Get()->GetBrowserInterface(PPB_INPUTEVENT_PRIVATE_INTERFACE)); |
| 75 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>( | 80 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>( |
| 76 pp::Module::Get()->GetBrowserInterface( | 81 pp::Module::Get()->GetBrowserInterface( |
| 77 PPB_MOUSE_INPUT_EVENT_INTERFACE)); | 82 PPB_MOUSE_INPUT_EVENT_INTERFACE)); |
| 78 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>( | 83 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>( |
| 79 pp::Module::Get()->GetBrowserInterface( | 84 pp::Module::Get()->GetBrowserInterface( |
| 80 PPB_WHEEL_INPUT_EVENT_INTERFACE)); | 85 PPB_WHEEL_INPUT_EVENT_INTERFACE)); |
| 81 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>( | 86 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>( |
| 82 pp::Module::Get()->GetBrowserInterface( | 87 pp::Module::Get()->GetBrowserInterface( |
| 83 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); | 88 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); |
| 84 touch_input_event_interface_ = static_cast<const PPB_TouchInputEvent*>( | 89 touch_input_event_interface_ = static_cast<const PPB_TouchInputEvent*>( |
| 85 pp::Module::Get()->GetBrowserInterface( | 90 pp::Module::Get()->GetBrowserInterface( |
| 86 PPB_TOUCH_INPUT_EVENT_INTERFACE)); | 91 PPB_TOUCH_INPUT_EVENT_INTERFACE)); |
| 87 | 92 |
| 88 bool success = | 93 bool success = |
| 89 input_event_interface_ && | 94 input_event_interface_ && |
| 95 input_event_private_interface_ && |
| 90 mouse_input_event_interface_ && | 96 mouse_input_event_interface_ && |
| 91 wheel_input_event_interface_ && | 97 wheel_input_event_interface_ && |
| 92 keyboard_input_event_interface_ && | 98 keyboard_input_event_interface_ && |
| 93 touch_input_event_interface_ && | 99 touch_input_event_interface_ && |
| 94 CheckTestingInterface(); | 100 CheckTestingInterface(); |
| 95 | 101 |
| 96 // Set up a listener for our message that signals that all input events have | 102 // Set up a listener for our message that signals that all input events have |
| 97 // been received. | 103 // been received. |
| 98 std::string js_code; | 104 std::string js_code; |
| 99 // Note the following code is dependent on some features of test_case.html. | 105 // Note the following code is dependent on some features of test_case.html. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 304 |
| 299 bool TestInputEvent::HandleInputEvent(const pp::InputEvent& input_event) { | 305 bool TestInputEvent::HandleInputEvent(const pp::InputEvent& input_event) { |
| 300 // Some events may cause extra events to be generated, so look for the | 306 // Some events may cause extra events to be generated, so look for the |
| 301 // first one that matches. | 307 // first one that matches. |
| 302 if (!received_expected_event_) { | 308 if (!received_expected_event_) { |
| 303 received_expected_event_ = AreEquivalentEvents( | 309 received_expected_event_ = AreEquivalentEvents( |
| 304 input_event.pp_resource(), | 310 input_event.pp_resource(), |
| 305 expected_input_event_.pp_resource()); | 311 expected_input_event_.pp_resource()); |
| 306 } | 312 } |
| 307 // Handle all input events. | 313 // Handle all input events. |
| 314 if (enable_latency_tracking_) { |
| 315 pp::InputEventPrivate private_event(input_event); |
| 316 last_latency_tracking_successful_ = private_event.TraceInputLatency(true); |
| 317 } |
| 308 return true; | 318 return true; |
| 309 } | 319 } |
| 310 | 320 |
| 311 void TestInputEvent::HandleMessage(const pp::Var& message_data) { | 321 void TestInputEvent::HandleMessage(const pp::Var& message_data) { |
| 312 if (message_data.is_string() && | 322 if (message_data.is_string() && |
| 313 (message_data.AsString() == FINISHED_WAITING_MESSAGE)) { | 323 (message_data.AsString() == FINISHED_WAITING_MESSAGE)) { |
| 314 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 324 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
| 315 received_finish_message_ = true; | 325 received_finish_message_ = true; |
| 316 nested_event_.Signal(); | 326 nested_event_.Signal(); |
| 317 } | 327 } |
| 318 } | 328 } |
| 319 | 329 |
| 320 void TestInputEvent::DidChangeView(const pp::View& view) { | 330 void TestInputEvent::DidChangeView(const pp::View& view) { |
| 321 view_rect_ = view.GetRect(); | 331 view_rect_ = view.GetRect(); |
| 322 } | 332 } |
| 323 | 333 |
| 334 std::string TestInputEvent::TestEventsLatencyTracking() { |
| 335 enable_latency_tracking_ = true; |
| 336 input_event_interface_->RequestInputEvents(instance_->pp_instance(), |
| 337 PP_INPUTEVENT_CLASS_TOUCH); |
| 338 PostMessageBarrier(); |
| 339 |
| 340 ASSERT_TRUE(SimulateInputEvent(CreateTouchEvent(PP_INPUTEVENT_TYPE_TOUCHSTART, |
| 341 pp::FloatPoint(12, 23)))); |
| 342 // Without calling StartTrackingLatency() first, TraceInputLatency() won't |
| 343 // take effect and will return false; |
| 344 ASSERT_FALSE(last_latency_tracking_successful_); |
| 345 |
| 346 input_event_private_interface_->StartTrackingLatency( |
| 347 instance_->pp_instance()); |
| 348 |
| 349 ASSERT_TRUE(SimulateInputEvent(CreateTouchEvent(PP_INPUTEVENT_TYPE_TOUCHSTART, |
| 350 pp::FloatPoint(12, 23)))); |
| 351 ASSERT_TRUE(last_latency_tracking_successful_); |
| 352 |
| 353 PASS(); |
| 354 } |
| 355 |
| 324 std::string TestInputEvent::TestEvents() { | 356 std::string TestInputEvent::TestEvents() { |
| 325 // Request all input event classes. | 357 // Request all input event classes. |
| 326 input_event_interface_->RequestInputEvents(instance_->pp_instance(), | 358 input_event_interface_->RequestInputEvents(instance_->pp_instance(), |
| 327 PP_INPUTEVENT_CLASS_MOUSE | | 359 PP_INPUTEVENT_CLASS_MOUSE | |
| 328 PP_INPUTEVENT_CLASS_WHEEL | | 360 PP_INPUTEVENT_CLASS_WHEEL | |
| 329 PP_INPUTEVENT_CLASS_KEYBOARD | | 361 PP_INPUTEVENT_CLASS_KEYBOARD | |
| 330 PP_INPUTEVENT_CLASS_TOUCH); | 362 PP_INPUTEVENT_CLASS_TOUCH); |
| 331 PostMessageBarrier(); | 363 PostMessageBarrier(); |
| 332 | 364 |
| 333 // Send the events and check that we received them. | 365 // Send the events and check that we received them. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // See comment in TestAcceptTouchEvent_1. | 446 // See comment in TestAcceptTouchEvent_1. |
| 415 instance_->set_remove_plugin(false); | 447 instance_->set_remove_plugin(false); |
| 416 input_event_interface_->RequestInputEvents(instance_->pp_instance(), | 448 input_event_interface_->RequestInputEvents(instance_->pp_instance(), |
| 417 PP_INPUTEVENT_CLASS_MOUSE | | 449 PP_INPUTEVENT_CLASS_MOUSE | |
| 418 PP_INPUTEVENT_CLASS_WHEEL | | 450 PP_INPUTEVENT_CLASS_WHEEL | |
| 419 PP_INPUTEVENT_CLASS_KEYBOARD); | 451 PP_INPUTEVENT_CLASS_KEYBOARD); |
| 420 input_event_interface_->RequestInputEvents(instance_->pp_instance(), | 452 input_event_interface_->RequestInputEvents(instance_->pp_instance(), |
| 421 PP_INPUTEVENT_CLASS_TOUCH); | 453 PP_INPUTEVENT_CLASS_TOUCH); |
| 422 PASS(); | 454 PASS(); |
| 423 } | 455 } |
| OLD | NEW |