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

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

Issue 8920005: Add TestingInstance::EvalScript method which posts a message that the test page can eval(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
OLDNEW
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 29 matching lines...) Expand all
40 keyboard_input_event_interface_(NULL), 40 keyboard_input_event_interface_(NULL),
41 view_rect_(), 41 view_rect_(),
42 expected_input_event_(0), 42 expected_input_event_(0),
43 received_expected_event_(false), 43 received_expected_event_(false),
44 received_finish_message_(false) { 44 received_finish_message_(false) {
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("TESTING_MESSAGE:ExecuteScript:");
dmichael (off chromium) 2011/12/16 22:38:56 Could you instead add an "ExecuteScript" convenien
bbudge 2011/12/16 23:24:06 Good idea. Done. On 2011/12/16 22:38:56, dmichael
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_->PostMessage(pp::Var(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(
67 PPB_WHEEL_INPUT_EVENT_INTERFACE)); 66 PPB_WHEEL_INPUT_EVENT_INTERFACE));
68 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>( 67 keyboard_input_event_interface_ = static_cast<const PPB_KeyboardInputEvent*>(
69 pp::Module::Get()->GetBrowserInterface( 68 pp::Module::Get()->GetBrowserInterface(
70 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); 69 PPB_KEYBOARD_INPUT_EVENT_INTERFACE));
71 70
72 bool success = 71 bool success =
73 input_event_interface_ && 72 input_event_interface_ &&
74 mouse_input_event_interface_ && 73 mouse_input_event_interface_ &&
75 wheel_input_event_interface_ && 74 wheel_input_event_interface_ &&
76 keyboard_input_event_interface_ && 75 keyboard_input_event_interface_ &&
77 InitTestingInterface(); 76 InitTestingInterface();
78 77
79 // Set up a listener for our message that signals that all input events have 78 // Set up a listener for our message that signals that all input events have
80 // been received. 79 // been received.
81 std::string js_code; 80 std::string js_code("TESTING_MESSAGE:ExecuteScript:");
82 // Note the following code is dependent on some features of test_case.html. 81 // Note the following code is dependent on some features of test_case.html.
83 // E.g., it is assumed that the DOM element where the plugin is embedded has 82 // E.g., it is assumed that the DOM element where the plugin is embedded has
84 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows 83 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows
85 // us to ignore the messages that are intended for use by the testing 84 // us to ignore the messages that are intended for use by the testing
86 // framework itself. 85 // framework itself.
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_->PostMessage(pp::Var(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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698