| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/browser/gpu/compositor_util.h" | 20 #include "content/browser/gpu/compositor_util.h" |
| 21 #include "content/browser/renderer_host/input/input_router_impl.h" | 21 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 22 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 22 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 23 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 24 #include "content/common/edit_command.h" |
| 24 #include "content/common/input/synthetic_web_input_event_builders.h" | 25 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 25 #include "content/common/input_messages.h" | 26 #include "content/common/input_messages.h" |
| 26 #include "content/common/resize_params.h" | 27 #include "content/common/resize_params.h" |
| 27 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/test/mock_render_process_host.h" | 30 #include "content/public/test/mock_render_process_host.h" |
| 30 #include "content/public/test/test_browser_context.h" | 31 #include "content/public/test/test_browser_context.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "content/test/test_render_view_host.h" | 33 #include "content/test/test_render_view_host.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 void SimulateKeyboardEvent(WebInputEvent::Type type) { | 545 void SimulateKeyboardEvent(WebInputEvent::Type type) { |
| 545 SimulateKeyboardEvent(type, 0); | 546 SimulateKeyboardEvent(type, 0); |
| 546 } | 547 } |
| 547 | 548 |
| 548 void SimulateKeyboardEvent(WebInputEvent::Type type, int modifiers) { | 549 void SimulateKeyboardEvent(WebInputEvent::Type type, int modifiers) { |
| 549 NativeWebKeyboardEvent native_event(type, modifiers, | 550 NativeWebKeyboardEvent native_event(type, modifiers, |
| 550 GetNextSimulatedEventTimeSeconds()); | 551 GetNextSimulatedEventTimeSeconds()); |
| 551 host_->ForwardKeyboardEvent(native_event); | 552 host_->ForwardKeyboardEvent(native_event); |
| 552 } | 553 } |
| 553 | 554 |
| 555 void SimulateKeyboardEventWithCommands(WebInputEvent::Type type) { |
| 556 NativeWebKeyboardEvent native_event(type, 0, |
| 557 GetNextSimulatedEventTimeSeconds()); |
| 558 EditCommands commands; |
| 559 commands.emplace_back("name", "value"); |
| 560 host_->ForwardKeyboardEventWithCommands(native_event, &commands); |
| 561 } |
| 562 |
| 554 void SimulateMouseEvent(WebInputEvent::Type type) { | 563 void SimulateMouseEvent(WebInputEvent::Type type) { |
| 555 host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type)); | 564 host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type)); |
| 556 } | 565 } |
| 557 | 566 |
| 558 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type, | 567 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type, |
| 559 const ui::LatencyInfo& ui_latency) { | 568 const ui::LatencyInfo& ui_latency) { |
| 560 host_->ForwardMouseEventWithLatencyInfo( | 569 host_->ForwardMouseEventWithLatencyInfo( |
| 561 SyntheticWebMouseEventBuilder::Build(type), | 570 SyntheticWebMouseEventBuilder::Build(type), |
| 562 ui_latency); | 571 ui_latency); |
| 563 } | 572 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 941 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 933 InputMsg_HandleInputEvent::ID)); | 942 InputMsg_HandleInputEvent::ID)); |
| 934 process_->sink().ClearMessages(); | 943 process_->sink().ClearMessages(); |
| 935 | 944 |
| 936 // Send the simulated response from the renderer back. | 945 // Send the simulated response from the renderer back. |
| 937 SendInputEventACK(WebInputEvent::RawKeyDown, | 946 SendInputEventACK(WebInputEvent::RawKeyDown, |
| 938 INPUT_EVENT_ACK_STATE_CONSUMED); | 947 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 939 EXPECT_FALSE(delegate_->unhandled_keyboard_event_called()); | 948 EXPECT_FALSE(delegate_->unhandled_keyboard_event_called()); |
| 940 } | 949 } |
| 941 | 950 |
| 951 TEST_F(RenderWidgetHostTest, SendEditCommandsBeforeKeyEvent) { |
| 952 // Clear any messages unrelated to this test. |
| 953 process_->sink().ClearMessages(); |
| 954 EXPECT_EQ(0U, process_->sink().message_count()); |
| 955 |
| 956 // Simulate a keyboard event. |
| 957 SimulateKeyboardEventWithCommands(WebInputEvent::RawKeyDown); |
| 958 |
| 959 // Make sure we sent commands and key event to the renderer. |
| 960 EXPECT_EQ(2U, process_->sink().message_count()); |
| 961 EXPECT_EQ(InputMsg_SetEditCommandsForNextKeyEvent::ID, |
| 962 process_->sink().GetMessageAt(0)->type()); |
| 963 EXPECT_EQ(InputMsg_HandleInputEvent::ID, |
| 964 process_->sink().GetMessageAt(1)->type()); |
| 965 process_->sink().ClearMessages(); |
| 966 |
| 967 // Send the simulated response from the renderer back. |
| 968 SendInputEventACK(WebInputEvent::RawKeyDown, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 969 } |
| 970 |
| 942 TEST_F(RenderWidgetHostTest, PreHandleRawKeyDownEvent) { | 971 TEST_F(RenderWidgetHostTest, PreHandleRawKeyDownEvent) { |
| 943 // Simulate the situation that the browser handled the key down event during | 972 // Simulate the situation that the browser handled the key down event during |
| 944 // pre-handle phrase. | 973 // pre-handle phrase. |
| 945 delegate_->set_prehandle_keyboard_event(true); | 974 delegate_->set_prehandle_keyboard_event(true); |
| 946 process_->sink().ClearMessages(); | 975 process_->sink().ClearMessages(); |
| 947 | 976 |
| 948 // Simulate a keyboard event. | 977 // Simulate a keyboard event. |
| 949 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 978 SimulateKeyboardEventWithCommands(WebInputEvent::RawKeyDown); |
| 950 | 979 |
| 951 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called()); | 980 EXPECT_TRUE(delegate_->prehandle_keyboard_event_called()); |
| 952 EXPECT_EQ(WebInputEvent::RawKeyDown, | 981 EXPECT_EQ(WebInputEvent::RawKeyDown, |
| 953 delegate_->prehandle_keyboard_event_type()); | 982 delegate_->prehandle_keyboard_event_type()); |
| 954 | 983 |
| 955 // Make sure the RawKeyDown event is not sent to the renderer. | 984 // Make sure the commands and key event are not sent to the renderer. |
| 956 EXPECT_EQ(0U, process_->sink().message_count()); | 985 EXPECT_EQ(0U, process_->sink().message_count()); |
| 957 | 986 |
| 958 // The browser won't pre-handle a Char event. | 987 // The browser won't pre-handle a Char event. |
| 959 delegate_->set_prehandle_keyboard_event(false); | 988 delegate_->set_prehandle_keyboard_event(false); |
| 960 | 989 |
| 961 // Forward the Char event. | 990 // Forward the Char event. |
| 962 SimulateKeyboardEvent(WebInputEvent::Char); | 991 SimulateKeyboardEvent(WebInputEvent::Char); |
| 963 | 992 |
| 964 // Make sure the Char event is suppressed. | 993 // Make sure the Char event is suppressed. |
| 965 EXPECT_EQ(0U, process_->sink().message_count()); | 994 EXPECT_EQ(0U, process_->sink().message_count()); |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 ui::LatencyInfo()); | 1743 ui::LatencyInfo()); |
| 1715 | 1744 |
| 1716 | 1745 |
| 1717 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1746 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
| 1718 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1747 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
| 1719 | 1748 |
| 1720 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1749 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
| 1721 } | 1750 } |
| 1722 | 1751 |
| 1723 } // namespace content | 1752 } // namespace content |
| OLD | NEW |