| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 TestInputEvent::~TestInputEvent() { | 47 TestInputEvent::~TestInputEvent() { |
| 48 // Remove the special listener that only responds to a | 48 // Remove the special listener that only responds to a |
| 49 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added. | 49 // FINISHED_WAITING_MESSAGE string. See Init for where it gets added. |
| 50 std::string js_code; | 50 std::string js_code; |
| 51 js_code += "var plugin = document.getElementById('plugin');" | 51 js_code += "var plugin = document.getElementById('plugin');" |
| 52 "plugin.removeEventListener('message'," | 52 "plugin.removeEventListener('message'," |
| 53 " plugin.wait_for_messages_handler);" | 53 " plugin.wait_for_messages_handler);" |
| 54 "delete plugin.wait_for_messages_handler;"; | 54 "delete plugin.wait_for_messages_handler;"; |
| 55 pp::Var exception; | 55 instance_->EvalScript(js_code); |
| 56 instance_->ExecuteScript(js_code, &exception); | |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool TestInputEvent::Init() { | 58 bool TestInputEvent::Init() { |
| 60 input_event_interface_ = static_cast<const PPB_InputEvent*>( | 59 input_event_interface_ = static_cast<const PPB_InputEvent*>( |
| 61 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); | 60 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); |
| 62 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>( | 61 mouse_input_event_interface_ = static_cast<const PPB_MouseInputEvent*>( |
| 63 pp::Module::Get()->GetBrowserInterface( | 62 pp::Module::Get()->GetBrowserInterface( |
| 64 PPB_MOUSE_INPUT_EVENT_INTERFACE)); | 63 PPB_MOUSE_INPUT_EVENT_INTERFACE)); |
| 65 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>( | 64 wheel_input_event_interface_ = static_cast<const PPB_WheelInputEvent*>( |
| 66 pp::Module::Get()->GetBrowserInterface( | 65 pp::Module::Get()->GetBrowserInterface( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 87 js_code += "var plugin = document.getElementById('plugin');" | 86 js_code += "var plugin = document.getElementById('plugin');" |
| 88 "var wait_for_messages_handler = function(message_event) {" | 87 "var wait_for_messages_handler = function(message_event) {" |
| 89 " if (!IsTestingMessage(message_event.data) &&" | 88 " if (!IsTestingMessage(message_event.data) &&" |
| 90 " message_event.data === '" FINISHED_WAITING_MESSAGE "') {" | 89 " message_event.data === '" FINISHED_WAITING_MESSAGE "') {" |
| 91 " plugin.postMessage('" FINISHED_WAITING_MESSAGE "');" | 90 " plugin.postMessage('" FINISHED_WAITING_MESSAGE "');" |
| 92 " }" | 91 " }" |
| 93 "};" | 92 "};" |
| 94 "plugin.addEventListener('message', wait_for_messages_handler);" | 93 "plugin.addEventListener('message', wait_for_messages_handler);" |
| 95 // Stash it on the plugin so we can remove it in the destructor. | 94 // Stash it on the plugin so we can remove it in the destructor. |
| 96 "plugin.wait_for_messages_handler = wait_for_messages_handler;"; | 95 "plugin.wait_for_messages_handler = wait_for_messages_handler;"; |
| 97 pp::Var exception; | 96 instance_->EvalScript(js_code); |
| 98 instance_->ExecuteScript(js_code, &exception); | |
| 99 success = success && exception.is_undefined(); | |
| 100 | 97 |
| 101 return success; | 98 return success; |
| 102 } | 99 } |
| 103 | 100 |
| 104 pp::InputEvent TestInputEvent::CreateMouseEvent( | 101 pp::InputEvent TestInputEvent::CreateMouseEvent( |
| 105 PP_InputEvent_Type type, | 102 PP_InputEvent_Type type, |
| 106 PP_InputEvent_MouseButton buttons) { | 103 PP_InputEvent_MouseButton buttons) { |
| 107 return pp::MouseInputEvent( | 104 return pp::MouseInputEvent( |
| 108 instance_, | 105 instance_, |
| 109 type, | 106 type, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 SimulateInputEvent(CreateWheelEvent())); | 278 SimulateInputEvent(CreateWheelEvent())); |
| 282 ASSERT_FALSE( | 279 ASSERT_FALSE( |
| 283 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN, | 280 SimulateInputEvent(CreateKeyEvent(PP_INPUTEVENT_TYPE_KEYDOWN, |
| 284 kSpaceChar))); | 281 kSpaceChar))); |
| 285 ASSERT_FALSE( | 282 ASSERT_FALSE( |
| 286 SimulateInputEvent(CreateCharEvent(kSpaceString))); | 283 SimulateInputEvent(CreateCharEvent(kSpaceString))); |
| 287 | 284 |
| 288 PASS(); | 285 PASS(); |
| 289 } | 286 } |
| 290 | 287 |
| OLD | NEW |