Chromium Code Reviews| Index: ppapi/tests/test_input_event.cc |
| =================================================================== |
| --- ppapi/tests/test_input_event.cc (revision 114053) |
| +++ ppapi/tests/test_input_event.cc (working copy) |
| @@ -39,7 +39,14 @@ |
| wheel_input_event_interface_(NULL), |
| keyboard_input_event_interface_(NULL), |
| view_rect_(), |
| - expected_input_event_(0), |
| + expected_event_type_(PP_INPUTEVENT_TYPE_UNDEFINED), |
| + expected_mouse_buttons_(PP_INPUTEVENT_MOUSEBUTTON_LEFT), |
| + expected_mouse_click_count_(0), |
| + expected_wheel_delta_(0, 0), |
| + expected_wheel_ticks_(0, 0), |
| + expected_wheel_scroll_by_page_(PP_FALSE), |
| + expected_key_code_(0), |
| + expected_char_text_(), |
|
dmichael (off chromium)
2011/12/13 23:40:55
As we discussed on IM, I think you've uncovered a
bbudge
2011/12/14 03:00:05
Done.
|
| received_expected_event_(false), |
| received_finish_message_(false) { |
| } |
| @@ -52,8 +59,10 @@ |
| "plugin.removeEventListener('message'," |
| " plugin.wait_for_messages_handler);" |
| "delete plugin.wait_for_messages_handler;"; |
| - pp::Var exception; |
| - instance_->ExecuteScript(js_code, &exception); |
| + pp::Var script(js_code); |
| + PP_Var exception = PP_MakeUndefined(); |
| + testing_interface_->ExecuteScript( |
| + instance_->pp_instance(), script.pp_var(), &exception); |
| } |
| bool TestInputEvent::Init() { |
| @@ -94,9 +103,11 @@ |
| "plugin.addEventListener('message', wait_for_messages_handler);" |
| // Stash it on the plugin so we can remove it in the destructor. |
| "plugin.wait_for_messages_handler = wait_for_messages_handler;"; |
| - pp::Var exception; |
| - instance_->ExecuteScript(js_code, &exception); |
| - success = success && exception.is_undefined(); |
| + pp::Var script(js_code); |
| + PP_Var exception = PP_MakeUndefined(); |
| + testing_interface_->ExecuteScript( |
| + instance_->pp_instance(), script.pp_var(), &exception); |
| + success = success && exception.type == PP_VARTYPE_UNDEFINED; |
| return success; |
| } |
| @@ -104,6 +115,9 @@ |
| pp::InputEvent TestInputEvent::CreateMouseEvent( |
| PP_InputEvent_Type type, |
| PP_InputEvent_MouseButton buttons) { |
| + expected_event_type_ = type; |
| + expected_mouse_buttons_ = buttons; |
| + expected_mouse_click_count_ = 1; |
| return pp::MouseInputEvent( |
| instance_, |
| type, |
| @@ -116,17 +130,23 @@ |
| } |
| pp::InputEvent TestInputEvent::CreateWheelEvent() { |
| + expected_event_type_ = PP_INPUTEVENT_TYPE_WHEEL; |
| + expected_wheel_delta_ = pp::FloatPoint(1, 2); |
| + expected_wheel_ticks_ = pp::FloatPoint(3, 4); |
| + expected_wheel_scroll_by_page_ = PP_TRUE; |
| return pp::WheelInputEvent( |
| instance_, |
| 100, // time_stamp |
| 0, // modifiers |
| - pp::FloatPoint(1, 2), |
| - pp::FloatPoint(3, 4), |
| - PP_TRUE); // scroll_by_page |
| + expected_wheel_delta_, |
| + expected_wheel_ticks_, |
| + true); |
| } |
| pp::InputEvent TestInputEvent::CreateKeyEvent(PP_InputEvent_Type type, |
| uint32_t key_code) { |
| + expected_event_type_ = type; |
| + expected_key_code_ = key_code; |
| return pp::KeyboardInputEvent( |
| instance_, |
| type, |
| @@ -137,9 +157,11 @@ |
| } |
| pp::InputEvent TestInputEvent::CreateCharEvent(const std::string& text) { |
| + expected_event_type_ = PP_INPUTEVENT_TYPE_CHAR; |
| + expected_char_text_ = text; |
| return pp::KeyboardInputEvent( |
| instance_, |
| - PP_INPUTEVENT_TYPE_CHAR, |
| + expected_event_type_, |
| 100, // time_stamp |
| 0, // modifiers |
| 0, // keycode |
| @@ -150,7 +172,6 @@ |
| // we have received all resulting events from the browser. |
| bool TestInputEvent::SimulateInputEvent( |
| const pp::InputEvent& input_event) { |
| - expected_input_event_ = pp::InputEvent(input_event.pp_resource()); |
| received_expected_event_ = false; |
| received_finish_message_ = false; |
| testing_interface_->SimulateInputEvent(instance_->pp_instance(), |
| @@ -160,27 +181,23 @@ |
| return received_finish_message_ && received_expected_event_; |
| } |
| -bool TestInputEvent::AreEquivalentEvents(PP_Resource received, |
| - PP_Resource expected) { |
| - if (!input_event_interface_->IsInputEvent(received) || |
| - !input_event_interface_->IsInputEvent(expected)) { |
| +bool TestInputEvent::IsExpectedEvent(PP_Resource input_event) { |
| + if (!input_event_interface_->IsInputEvent(input_event)) { |
| return false; |
| } |
| - |
| // Test common fields, except modifiers and time stamp, which may be changed |
| // by the browser. |
| - int32_t received_type = input_event_interface_->GetType(received); |
| - int32_t expected_type = input_event_interface_->GetType(expected); |
| - if (received_type != expected_type) { |
| + int32_t event_type = input_event_interface_->GetType(input_event); |
| + if (event_type != expected_event_type_) { |
| // Allow key down events to match "raw" key down events. |
| - if (expected_type != PP_INPUTEVENT_TYPE_KEYDOWN && |
| - received_type != PP_INPUTEVENT_TYPE_RAWKEYDOWN) { |
| + if (expected_event_type_ != PP_INPUTEVENT_TYPE_KEYDOWN && |
| + event_type != PP_INPUTEVENT_TYPE_RAWKEYDOWN) { |
| return false; |
| } |
| } |
| // Test event type-specific fields. |
| - switch (input_event_interface_->GetType(received)) { |
| + switch (event_type) { |
| case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| case PP_INPUTEVENT_TYPE_MOUSEUP: |
| case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
| @@ -189,35 +206,32 @@ |
| // Check mouse fields, except position and movement, which may be |
| // modified by the renderer. |
| return |
| - mouse_input_event_interface_->GetButton(received) == |
| - mouse_input_event_interface_->GetButton(expected) && |
| - mouse_input_event_interface_->GetClickCount(received) == |
| - mouse_input_event_interface_->GetClickCount(expected); |
| + mouse_input_event_interface_->GetButton(input_event) == |
| + expected_mouse_buttons_ && |
| + mouse_input_event_interface_->GetClickCount(input_event) == |
| + expected_mouse_click_count_; |
| case PP_INPUTEVENT_TYPE_WHEEL: |
| return |
| - pp::FloatPoint(wheel_input_event_interface_->GetDelta(received)) == |
| - pp::FloatPoint(wheel_input_event_interface_->GetDelta(expected)) && |
| - pp::FloatPoint(wheel_input_event_interface_->GetTicks(received)) == |
| - pp::FloatPoint(wheel_input_event_interface_->GetTicks(expected)) && |
| - wheel_input_event_interface_->GetScrollByPage(received) == |
| - wheel_input_event_interface_->GetScrollByPage(expected); |
| + pp::FloatPoint(wheel_input_event_interface_->GetDelta(input_event)) == |
| + expected_wheel_delta_ && |
| + pp::FloatPoint(wheel_input_event_interface_->GetTicks(input_event)) == |
| + expected_wheel_ticks_ && |
| + wheel_input_event_interface_->GetScrollByPage(input_event) == |
| + expected_wheel_scroll_by_page_; |
| case PP_INPUTEVENT_TYPE_RAWKEYDOWN: |
| case PP_INPUTEVENT_TYPE_KEYDOWN: |
| case PP_INPUTEVENT_TYPE_KEYUP: |
| return |
| - keyboard_input_event_interface_->GetKeyCode(received) == |
| - keyboard_input_event_interface_->GetKeyCode(expected); |
| + keyboard_input_event_interface_->GetKeyCode(input_event) == |
| + expected_key_code_; |
| case PP_INPUTEVENT_TYPE_CHAR: |
| return |
| - keyboard_input_event_interface_->GetKeyCode(received) == |
| - keyboard_input_event_interface_->GetKeyCode(expected) && |
| pp::Var(pp::Var::PassRef(), |
| - keyboard_input_event_interface_->GetCharacterText(received)) == |
| - pp::Var(pp::Var::PassRef(), |
| - keyboard_input_event_interface_->GetCharacterText(expected)); |
| + keyboard_input_event_interface_->GetCharacterText(input_event)) == |
| + pp::Var(expected_char_text_); |
| default: |
| break; |
| @@ -230,9 +244,7 @@ |
| // Some events may cause extra events to be generated, so look for the |
| // first one that matches. |
| if (!received_expected_event_) { |
| - received_expected_event_ = AreEquivalentEvents( |
| - input_event.pp_resource(), |
| - expected_input_event_.pp_resource()); |
| + received_expected_event_ = IsExpectedEvent(input_event.pp_resource()); |
| } |
| // Handle all input events. |
| return true; |