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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 using blink::WebGestureEvent; | 48 using blink::WebGestureEvent; |
49 using blink::WebInputEvent; | 49 using blink::WebInputEvent; |
50 using blink::WebKeyboardEvent; | 50 using blink::WebKeyboardEvent; |
51 using blink::WebMouseEvent; | 51 using blink::WebMouseEvent; |
52 using blink::WebMouseWheelEvent; | 52 using blink::WebMouseWheelEvent; |
53 using blink::WebTouchEvent; | 53 using blink::WebTouchEvent; |
54 using blink::WebTouchPoint; | 54 using blink::WebTouchPoint; |
55 | 55 |
56 namespace content { | 56 namespace content { |
57 | 57 |
| 58 std::string GetInputMessageTypes(MockRenderProcessHost* process) { |
| 59 std::string result; |
| 60 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
| 61 const IPC::Message* message = process->sink().GetMessageAt(i); |
| 62 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
| 63 InputMsg_HandleInputEvent::Param params; |
| 64 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); |
| 65 const WebInputEvent* event = base::get<0>(params); |
| 66 if (i != 0) |
| 67 result += " "; |
| 68 result += WebInputEventTraits::GetName(event->type); |
| 69 } |
| 70 process->sink().ClearMessages(); |
| 71 return result; |
| 72 } |
| 73 |
58 // MockInputRouter ------------------------------------------------------------- | 74 // MockInputRouter ------------------------------------------------------------- |
59 | 75 |
60 class MockInputRouter : public InputRouter { | 76 class MockInputRouter : public InputRouter { |
61 public: | 77 public: |
62 explicit MockInputRouter(InputRouterClient* client) | 78 explicit MockInputRouter(InputRouterClient* client) |
63 : send_event_called_(false), | 79 : send_event_called_(false), |
64 sent_mouse_event_(false), | 80 sent_mouse_event_(false), |
65 sent_wheel_event_(false), | 81 sent_wheel_event_(false), |
66 sent_keyboard_event_(false), | 82 sent_keyboard_event_(false), |
67 sent_gesture_event_(false), | 83 sent_gesture_event_(false), |
68 send_touch_event_not_cancelled_(false), | 84 send_touch_event_not_cancelled_(false), |
69 message_received_(false), | 85 message_received_(false), |
70 client_(client) { | 86 client_(client) { |
71 } | 87 } |
72 ~MockInputRouter() override {} | 88 ~MockInputRouter() override {} |
73 | 89 |
74 // InputRouter | 90 // InputRouter |
75 bool SendInput(scoped_ptr<IPC::Message> message) override { | 91 bool SendInput(scoped_ptr<IPC::Message> message) override { |
76 send_event_called_ = true; | 92 send_event_called_ = true; |
77 return true; | 93 return true; |
78 } | 94 } |
79 void SendMouseEvent(const MouseEventWithLatencyInfo& mouse_event) override { | 95 void SendMouseEvent(const MouseEventWithLatencyInfo& mouse_event) override { |
80 sent_mouse_event_ = true; | 96 sent_mouse_event_ = true; |
81 } | 97 } |
82 void SendWheelEvent( | 98 void SendWheelEvent( |
83 const MouseWheelEventWithLatencyInfo& wheel_event) override { | 99 const MouseWheelEventWithLatencyInfo& wheel_event) override { |
84 sent_wheel_event_ = true; | 100 sent_wheel_event_ = true; |
85 } | 101 } |
86 void SendKeyboardEvent(const NativeWebKeyboardEventWithLatencyInfo& key_event, | 102 void SendKeyboardEvent( |
87 bool is_shortcut) override { | 103 const NativeWebKeyboardEventWithLatencyInfo& key_event) override { |
88 sent_keyboard_event_ = true; | 104 sent_keyboard_event_ = true; |
89 } | 105 } |
90 void SendGestureEvent( | 106 void SendGestureEvent( |
91 const GestureEventWithLatencyInfo& gesture_event) override { | 107 const GestureEventWithLatencyInfo& gesture_event) override { |
92 sent_gesture_event_ = true; | 108 sent_gesture_event_ = true; |
93 } | 109 } |
94 void SendTouchEvent(const TouchEventWithLatencyInfo& touch_event) override { | 110 void SendTouchEvent(const TouchEventWithLatencyInfo& touch_event) override { |
95 send_touch_event_not_cancelled_ = | 111 send_touch_event_not_cancelled_ = |
96 client_->FilterInputEvent(touch_event.event, touch_event.latency) == | 112 client_->FilterInputEvent(touch_event.event, touch_event.latency) == |
97 INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 113 INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 private: | 336 private: |
321 DISALLOW_COPY_AND_ASSIGN(TestView); | 337 DISALLOW_COPY_AND_ASSIGN(TestView); |
322 }; | 338 }; |
323 | 339 |
324 // MockRenderWidgetHostDelegate -------------------------------------------- | 340 // MockRenderWidgetHostDelegate -------------------------------------------- |
325 | 341 |
326 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 342 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
327 public: | 343 public: |
328 MockRenderWidgetHostDelegate() | 344 MockRenderWidgetHostDelegate() |
329 : prehandle_keyboard_event_(false), | 345 : prehandle_keyboard_event_(false), |
| 346 prehandle_keyboard_event_is_shortcut_(false), |
330 prehandle_keyboard_event_called_(false), | 347 prehandle_keyboard_event_called_(false), |
331 prehandle_keyboard_event_type_(WebInputEvent::Undefined), | 348 prehandle_keyboard_event_type_(WebInputEvent::Undefined), |
332 unhandled_keyboard_event_called_(false), | 349 unhandled_keyboard_event_called_(false), |
333 unhandled_keyboard_event_type_(WebInputEvent::Undefined), | 350 unhandled_keyboard_event_type_(WebInputEvent::Undefined), |
334 handle_wheel_event_(false), | 351 handle_wheel_event_(false), |
335 handle_wheel_event_called_(false) { | 352 handle_wheel_event_called_(false) {} |
336 } | |
337 ~MockRenderWidgetHostDelegate() override {} | 353 ~MockRenderWidgetHostDelegate() override {} |
338 | 354 |
339 // Tests that make sure we ignore keyboard event acknowledgments to events we | 355 // Tests that make sure we ignore keyboard event acknowledgments to events we |
340 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). | 356 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). |
341 bool unhandled_keyboard_event_called() const { | 357 bool unhandled_keyboard_event_called() const { |
342 return unhandled_keyboard_event_called_; | 358 return unhandled_keyboard_event_called_; |
343 } | 359 } |
344 | 360 |
345 WebInputEvent::Type unhandled_keyboard_event_type() const { | 361 WebInputEvent::Type unhandled_keyboard_event_type() const { |
346 return unhandled_keyboard_event_type_; | 362 return unhandled_keyboard_event_type_; |
347 } | 363 } |
348 | 364 |
349 bool prehandle_keyboard_event_called() const { | 365 bool prehandle_keyboard_event_called() const { |
350 return prehandle_keyboard_event_called_; | 366 return prehandle_keyboard_event_called_; |
351 } | 367 } |
352 | 368 |
353 WebInputEvent::Type prehandle_keyboard_event_type() const { | 369 WebInputEvent::Type prehandle_keyboard_event_type() const { |
354 return prehandle_keyboard_event_type_; | 370 return prehandle_keyboard_event_type_; |
355 } | 371 } |
356 | 372 |
357 void set_prehandle_keyboard_event(bool handle) { | 373 void set_prehandle_keyboard_event(bool handle) { |
358 prehandle_keyboard_event_ = handle; | 374 prehandle_keyboard_event_ = handle; |
359 } | 375 } |
360 | 376 |
361 void set_handle_wheel_event(bool handle) { | 377 void set_handle_wheel_event(bool handle) { |
362 handle_wheel_event_ = handle; | 378 handle_wheel_event_ = handle; |
363 } | 379 } |
364 | 380 |
365 bool handle_wheel_event_called() { | 381 void set_prehandle_keyboard_event_is_shortcut(bool is_shortcut) { |
366 return handle_wheel_event_called_; | 382 prehandle_keyboard_event_is_shortcut_ = is_shortcut; |
367 } | 383 } |
368 | 384 |
| 385 bool handle_wheel_event_called() const { return handle_wheel_event_called_; } |
| 386 |
369 protected: | 387 protected: |
370 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 388 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
371 bool* is_keyboard_shortcut) override { | 389 bool* is_keyboard_shortcut) override { |
372 prehandle_keyboard_event_type_ = event.type; | 390 prehandle_keyboard_event_type_ = event.type; |
373 prehandle_keyboard_event_called_ = true; | 391 prehandle_keyboard_event_called_ = true; |
| 392 *is_keyboard_shortcut = prehandle_keyboard_event_is_shortcut_; |
374 return prehandle_keyboard_event_; | 393 return prehandle_keyboard_event_; |
375 } | 394 } |
376 | 395 |
377 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override { | 396 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override { |
378 unhandled_keyboard_event_type_ = event.type; | 397 unhandled_keyboard_event_type_ = event.type; |
379 unhandled_keyboard_event_called_ = true; | 398 unhandled_keyboard_event_called_ = true; |
380 } | 399 } |
381 | 400 |
382 bool HandleWheelEvent(const blink::WebMouseWheelEvent& event) override { | 401 bool HandleWheelEvent(const blink::WebMouseWheelEvent& event) override { |
383 handle_wheel_event_called_ = true; | 402 handle_wheel_event_called_ = true; |
384 return handle_wheel_event_; | 403 return handle_wheel_event_; |
385 } | 404 } |
386 | 405 |
387 void Cut() override {} | 406 void Cut() override {} |
388 void Copy() override {} | 407 void Copy() override {} |
389 void Paste() override {} | 408 void Paste() override {} |
390 void SelectAll() override {} | 409 void SelectAll() override {} |
391 | 410 |
392 private: | 411 private: |
393 bool prehandle_keyboard_event_; | 412 bool prehandle_keyboard_event_; |
| 413 bool prehandle_keyboard_event_is_shortcut_; |
394 bool prehandle_keyboard_event_called_; | 414 bool prehandle_keyboard_event_called_; |
395 WebInputEvent::Type prehandle_keyboard_event_type_; | 415 WebInputEvent::Type prehandle_keyboard_event_type_; |
396 | 416 |
397 bool unhandled_keyboard_event_called_; | 417 bool unhandled_keyboard_event_called_; |
398 WebInputEvent::Type unhandled_keyboard_event_type_; | 418 WebInputEvent::Type unhandled_keyboard_event_type_; |
399 | 419 |
400 bool handle_wheel_event_; | 420 bool handle_wheel_event_; |
401 bool handle_wheel_event_called_; | 421 bool handle_wheel_event_called_; |
402 }; | 422 }; |
403 | 423 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 InputMsg_HandleInputEvent::ID)); | 904 InputMsg_HandleInputEvent::ID)); |
885 process_->sink().ClearMessages(); | 905 process_->sink().ClearMessages(); |
886 | 906 |
887 // Send the simulated response from the renderer back. | 907 // Send the simulated response from the renderer back. |
888 SendInputEventACK(WebInputEvent::RawKeyDown, | 908 SendInputEventACK(WebInputEvent::RawKeyDown, |
889 INPUT_EVENT_ACK_STATE_CONSUMED); | 909 INPUT_EVENT_ACK_STATE_CONSUMED); |
890 EXPECT_FALSE(delegate_->unhandled_keyboard_event_called()); | 910 EXPECT_FALSE(delegate_->unhandled_keyboard_event_called()); |
891 } | 911 } |
892 | 912 |
893 TEST_F(RenderWidgetHostTest, PreHandleRawKeyDownEvent) { | 913 TEST_F(RenderWidgetHostTest, PreHandleRawKeyDownEvent) { |
894 // Simluate the situation that the browser handled the key down event during | 914 // Simulate the situation that the browser handled the key down event during |
895 // pre-handle phrase. | 915 // pre-handle phrase. |
896 delegate_->set_prehandle_keyboard_event(true); | 916 delegate_->set_prehandle_keyboard_event(true); |
897 process_->sink().ClearMessages(); | 917 process_->sink().ClearMessages(); |
898 | 918 |
899 // Simulate a keyboard event. | 919 // Simulate a keyboard event. |
900 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 920 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
901 | 921 |
902 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called()); | 922 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called()); |
903 EXPECT_EQ(WebInputEvent::RawKeyDown, | 923 EXPECT_EQ(WebInputEvent::RawKeyDown, |
904 delegate_->prehandle_keyboard_event_type()); | 924 delegate_->prehandle_keyboard_event_type()); |
(...skipping 20 matching lines...) Expand all Loading... |
925 process_->sink().ClearMessages(); | 945 process_->sink().ClearMessages(); |
926 | 946 |
927 // Send the simulated response from the renderer back. | 947 // Send the simulated response from the renderer back. |
928 SendInputEventACK(WebInputEvent::KeyUp, | 948 SendInputEventACK(WebInputEvent::KeyUp, |
929 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 949 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
930 | 950 |
931 EXPECT_TRUE(delegate_->unhandled_keyboard_event_called()); | 951 EXPECT_TRUE(delegate_->unhandled_keyboard_event_called()); |
932 EXPECT_EQ(WebInputEvent::KeyUp, delegate_->unhandled_keyboard_event_type()); | 952 EXPECT_EQ(WebInputEvent::KeyUp, delegate_->unhandled_keyboard_event_type()); |
933 } | 953 } |
934 | 954 |
| 955 TEST_F(RenderWidgetHostTest, RawKeyDownShortcutEvent) { |
| 956 // Simulate the situation that the browser marks the key down as a keyboard |
| 957 // shortcut, but doesn't consume it in the pre-handle phase. |
| 958 delegate_->set_prehandle_keyboard_event_is_shortcut(true); |
| 959 process_->sink().ClearMessages(); |
| 960 |
| 961 // Simulate a keyboard event. |
| 962 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 963 |
| 964 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called()); |
| 965 EXPECT_EQ(WebInputEvent::RawKeyDown, |
| 966 delegate_->prehandle_keyboard_event_type()); |
| 967 |
| 968 // Make sure the RawKeyDown event is sent to the renderer. |
| 969 EXPECT_EQ(1U, process_->sink().message_count()); |
| 970 EXPECT_EQ("RawKeyDown", GetInputMessageTypes(process_)); |
| 971 process_->sink().ClearMessages(); |
| 972 |
| 973 // Send the simulated response from the renderer back. |
| 974 SendInputEventACK(WebInputEvent::RawKeyDown, |
| 975 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 976 EXPECT_EQ(WebInputEvent::RawKeyDown, |
| 977 delegate_->unhandled_keyboard_event_type()); |
| 978 |
| 979 // The browser won't pre-handle a Char event. |
| 980 delegate_->set_prehandle_keyboard_event_is_shortcut(false); |
| 981 |
| 982 // Forward the Char event. |
| 983 SimulateKeyboardEvent(WebInputEvent::Char); |
| 984 |
| 985 // The Char event is not suppressed; the renderer will ignore it |
| 986 // if the preceding RawKeyDown shortcut goes unhandled. |
| 987 EXPECT_EQ(1U, process_->sink().message_count()); |
| 988 EXPECT_EQ("Char", GetInputMessageTypes(process_)); |
| 989 process_->sink().ClearMessages(); |
| 990 |
| 991 // Send the simulated response from the renderer back. |
| 992 SendInputEventACK(WebInputEvent::Char, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 993 EXPECT_EQ(WebInputEvent::Char, delegate_->unhandled_keyboard_event_type()); |
| 994 |
| 995 // Forward the KeyUp event. |
| 996 SimulateKeyboardEvent(WebInputEvent::KeyUp); |
| 997 |
| 998 // Make sure only KeyUp was sent to the renderer. |
| 999 EXPECT_EQ(1U, process_->sink().message_count()); |
| 1000 EXPECT_EQ("KeyUp", GetInputMessageTypes(process_)); |
| 1001 process_->sink().ClearMessages(); |
| 1002 |
| 1003 // Send the simulated response from the renderer back. |
| 1004 SendInputEventACK(WebInputEvent::KeyUp, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1005 EXPECT_EQ(WebInputEvent::KeyUp, delegate_->unhandled_keyboard_event_type()); |
| 1006 } |
| 1007 |
935 TEST_F(RenderWidgetHostTest, UnhandledWheelEvent) { | 1008 TEST_F(RenderWidgetHostTest, UnhandledWheelEvent) { |
936 SimulateWheelEvent(-5, 0, 0, true); | 1009 SimulateWheelEvent(-5, 0, 0, true); |
937 | 1010 |
938 // Make sure we sent the input event to the renderer. | 1011 // Make sure we sent the input event to the renderer. |
939 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1012 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
940 InputMsg_HandleInputEvent::ID)); | 1013 InputMsg_HandleInputEvent::ID)); |
941 process_->sink().ClearMessages(); | 1014 process_->sink().ClearMessages(); |
942 | 1015 |
943 // Send the simulated response from the renderer back. | 1016 // Send the simulated response from the renderer back. |
944 SendInputEventACK(WebInputEvent::MouseWheel, | 1017 SendInputEventACK(WebInputEvent::MouseWheel, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 | 1200 |
1128 // Test with a long delay to ensure that it does fire this time. | 1201 // Test with a long delay to ensure that it does fire this time. |
1129 host_->StartNewContentRenderingTimeout(); | 1202 host_->StartNewContentRenderingTimeout(); |
1130 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1203 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1131 FROM_HERE, base::MessageLoop::QuitClosure(), | 1204 FROM_HERE, base::MessageLoop::QuitClosure(), |
1132 TimeDelta::FromMicroseconds(20)); | 1205 TimeDelta::FromMicroseconds(20)); |
1133 base::MessageLoop::current()->Run(); | 1206 base::MessageLoop::current()->Run(); |
1134 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); | 1207 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
1135 } | 1208 } |
1136 | 1209 |
1137 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { | |
1138 std::string result; | |
1139 for (size_t i = 0; i < process->sink().message_count(); ++i) { | |
1140 const IPC::Message *message = process->sink().GetMessageAt(i); | |
1141 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | |
1142 InputMsg_HandleInputEvent::Param params; | |
1143 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); | |
1144 const WebInputEvent* event = base::get<0>(params); | |
1145 if (i != 0) | |
1146 result += " "; | |
1147 result += WebInputEventTraits::GetName(event->type); | |
1148 } | |
1149 process->sink().ClearMessages(); | |
1150 return result; | |
1151 } | |
1152 | |
1153 TEST_F(RenderWidgetHostTest, TouchEmulator) { | 1210 TEST_F(RenderWidgetHostTest, TouchEmulator) { |
1154 simulated_event_time_delta_seconds_ = 0.1; | 1211 simulated_event_time_delta_seconds_ = 0.1; |
1155 // Immediately ack all touches instead of sending them to the renderer. | 1212 // Immediately ack all touches instead of sending them to the renderer. |
1156 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); | 1213 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); |
1157 host_->SetTouchEventEmulationEnabled( | 1214 host_->SetTouchEventEmulationEnabled( |
1158 true, ui::GestureProviderConfigType::GENERIC_MOBILE); | 1215 true, ui::GestureProviderConfigType::GENERIC_MOBILE); |
1159 process_->sink().ClearMessages(); | 1216 process_->sink().ClearMessages(); |
1160 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); | 1217 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); |
1161 view_->Show(); | 1218 view_->Show(); |
1162 | 1219 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 // Having an initial size set means that the size information had been sent | 1647 // Having an initial size set means that the size information had been sent |
1591 // with the reqiest to new up the RenderView and so subsequent WasResized | 1648 // with the reqiest to new up the RenderView and so subsequent WasResized |
1592 // calls should not result in new IPC (unless the size has actually changed). | 1649 // calls should not result in new IPC (unless the size has actually changed). |
1593 host_->WasResized(); | 1650 host_->WasResized(); |
1594 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1651 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
1595 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1652 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
1596 EXPECT_TRUE(host_->resize_ack_pending_); | 1653 EXPECT_TRUE(host_->resize_ack_pending_); |
1597 } | 1654 } |
1598 | 1655 |
1599 } // namespace content | 1656 } // namespace content |
OLD | NEW |