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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 1391843006: Embed keyboard shortcut bit in WebKeyboardEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 5 years, 2 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <math.h> 5 #include <math.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 event = &gesture; 73 event = &gesture;
74 } else if (type == WebInputEvent::MouseWheel) { 74 } else if (type == WebInputEvent::MouseWheel) {
75 static WebMouseWheelEvent wheel; 75 static WebMouseWheelEvent wheel;
76 event = &wheel; 76 event = &wheel;
77 } 77 }
78 CHECK(event); 78 CHECK(event);
79 event->type = type; 79 event->type = type;
80 return *event; 80 return *event;
81 } 81 }
82 82
83 bool GetIsShortcutFromHandleInputEventMessage(const IPC::Message* msg) {
84 InputMsg_HandleInputEvent::Schema::Param param;
85 InputMsg_HandleInputEvent::Read(msg, &param);
86 return base::get<2>(param);
87 }
88
89 template<typename MSG_T, typename ARG_T1> 83 template<typename MSG_T, typename ARG_T1>
90 void ExpectIPCMessageWithArg1(const IPC::Message* msg, const ARG_T1& arg1) { 84 void ExpectIPCMessageWithArg1(const IPC::Message* msg, const ARG_T1& arg1) {
91 ASSERT_EQ(MSG_T::ID, msg->type()); 85 ASSERT_EQ(MSG_T::ID, msg->type());
92 typename MSG_T::Schema::Param param; 86 typename MSG_T::Schema::Param param;
93 ASSERT_TRUE(MSG_T::Read(msg, &param)); 87 ASSERT_TRUE(MSG_T::Read(msg, &param));
94 EXPECT_EQ(arg1, base::get<0>(param)); 88 EXPECT_EQ(arg1, base::get<0>(param));
95 } 89 }
96 90
97 template<typename MSG_T, typename ARG_T1, typename ARG_T2> 91 template<typename MSG_T, typename ARG_T1, typename ARG_T2>
98 void ExpectIPCMessageWithArg2(const IPC::Message* msg, 92 void ExpectIPCMessageWithArg2(const IPC::Message* msg,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 config_.touch_config.desktop_touch_ack_timeout_delay = 169 config_.touch_config.desktop_touch_ack_timeout_delay =
176 base::TimeDelta::FromMilliseconds(desktop_timeout_ms); 170 base::TimeDelta::FromMilliseconds(desktop_timeout_ms);
177 config_.touch_config.mobile_touch_ack_timeout_delay = 171 config_.touch_config.mobile_touch_ack_timeout_delay =
178 base::TimeDelta::FromMilliseconds(mobile_timeout_ms); 172 base::TimeDelta::FromMilliseconds(mobile_timeout_ms);
179 config_.touch_config.touch_ack_timeout_supported = true; 173 config_.touch_config.touch_ack_timeout_supported = true;
180 TearDown(); 174 TearDown();
181 SetUp(); 175 SetUp();
182 input_router()->NotifySiteIsMobileOptimized(false); 176 input_router()->NotifySiteIsMobileOptimized(false);
183 } 177 }
184 178
185 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) { 179 void SimulateKeyboardEvent(WebInputEvent::Type type) {
186 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); 180 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
187 NativeWebKeyboardEvent native_event; 181 NativeWebKeyboardEvent native_event;
188 memcpy(&native_event, &event, sizeof(event)); 182 memcpy(&native_event, &event, sizeof(event));
189 NativeWebKeyboardEventWithLatencyInfo key_event(native_event); 183 NativeWebKeyboardEventWithLatencyInfo key_event(native_event);
190 input_router_->SendKeyboardEvent(key_event, is_shortcut); 184 input_router_->SendKeyboardEvent(key_event);
191 } 185 }
192 186
193 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) { 187 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
194 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo( 188 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(
195 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise))); 189 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise)));
196 } 190 }
197 191
198 void SimulateMouseEvent(WebInputEvent::Type type, int x, int y) { 192 void SimulateMouseEvent(WebInputEvent::Type type, int x, int y) {
199 input_router_->SendMouseEvent(MouseEventWithLatencyInfo( 193 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(
200 SyntheticWebMouseEventBuilder::Build(type, x, y, 0))); 194 SyntheticWebMouseEventBuilder::Build(type, x, y, 0)));
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0)); 604 scoped_ptr<IPC::Message> response(new InputHostMsg_MoveCaret_ACK(0));
611 input_router_->OnMessageReceived(*response); 605 input_router_->OnMessageReceived(*response);
612 } 606 }
613 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); 607 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
614 } 608 }
615 609
616 TEST_F(InputRouterImplTest, HandledInputEvent) { 610 TEST_F(InputRouterImplTest, HandledInputEvent) {
617 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED); 611 client_->set_filter_state(INPUT_EVENT_ACK_STATE_CONSUMED);
618 612
619 // Simulate a keyboard event. 613 // Simulate a keyboard event.
620 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); 614 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
621 615
622 // Make sure no input event is sent to the renderer. 616 // Make sure no input event is sent to the renderer.
623 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); 617 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
624 618
625 // OnKeyboardEventAck should be triggered without actual ack. 619 // OnKeyboardEventAck should be triggered without actual ack.
626 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 620 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
627 621
628 // As the event was acked already, keyboard event queue should be 622 // As the event was acked already, keyboard event queue should be
629 // empty. 623 // empty.
630 ASSERT_EQ(NULL, input_router_->GetLastKeyboardEvent()); 624 ASSERT_EQ(NULL, input_router_->GetLastKeyboardEvent());
631 } 625 }
632 626
633 TEST_F(InputRouterImplTest, ClientCanceledKeyboardEvent) { 627 TEST_F(InputRouterImplTest, ClientCanceledKeyboardEvent) {
634 client_->set_filter_state(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 628 client_->set_filter_state(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
635 629
636 // Simulate a keyboard event that has no consumer. 630 // Simulate a keyboard event that has no consumer.
637 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); 631 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
638 632
639 // Make sure no input event is sent to the renderer. 633 // Make sure no input event is sent to the renderer.
640 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); 634 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
641 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 635 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
642 636
643 637
644 // Simulate a keyboard event that should be dropped. 638 // Simulate a keyboard event that should be dropped.
645 client_->set_filter_state(INPUT_EVENT_ACK_STATE_UNKNOWN); 639 client_->set_filter_state(INPUT_EVENT_ACK_STATE_UNKNOWN);
646 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); 640 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
647 641
648 // Make sure no input event is sent to the renderer, and no ack is sent. 642 // Make sure no input event is sent to the renderer, and no ack is sent.
649 EXPECT_EQ(0u, GetSentMessageCountAndResetSink()); 643 EXPECT_EQ(0u, GetSentMessageCountAndResetSink());
650 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 644 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
651 } 645 }
652 646
653 TEST_F(InputRouterImplTest, ShortcutKeyboardEvent) {
654 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, true);
655 EXPECT_TRUE(GetIsShortcutFromHandleInputEventMessage(
656 process_->sink().GetMessageAt(0)));
657
658 process_->sink().ClearMessages();
659
660 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false);
661 EXPECT_FALSE(GetIsShortcutFromHandleInputEventMessage(
662 process_->sink().GetMessageAt(0)));
663 }
664
665 TEST_F(InputRouterImplTest, NoncorrespondingKeyEvents) { 647 TEST_F(InputRouterImplTest, NoncorrespondingKeyEvents) {
666 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); 648 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
667 649
668 SendInputEventACK(WebInputEvent::KeyUp, 650 SendInputEventACK(WebInputEvent::KeyUp,
669 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 651 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
670 EXPECT_TRUE(ack_handler_->unexpected_event_ack_called()); 652 EXPECT_TRUE(ack_handler_->unexpected_event_ack_called());
671 } 653 }
672 654
673 // Tests ported from RenderWidgetHostTest -------------------------------------- 655 // Tests ported from RenderWidgetHostTest --------------------------------------
674 656
675 TEST_F(InputRouterImplTest, HandleKeyEventsWeSent) { 657 TEST_F(InputRouterImplTest, HandleKeyEventsWeSent) {
676 // Simulate a keyboard event. 658 // Simulate a keyboard event.
677 SimulateKeyboardEvent(WebInputEvent::RawKeyDown, false); 659 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
678 ASSERT_TRUE(input_router_->GetLastKeyboardEvent()); 660 ASSERT_TRUE(input_router_->GetLastKeyboardEvent());
679 EXPECT_EQ(WebInputEvent::RawKeyDown, 661 EXPECT_EQ(WebInputEvent::RawKeyDown,
680 input_router_->GetLastKeyboardEvent()->type); 662 input_router_->GetLastKeyboardEvent()->type);
681 663
682 // Make sure we sent the input event to the renderer. 664 // Make sure we sent the input event to the renderer.
683 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 665 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
684 InputMsg_HandleInputEvent::ID)); 666 InputMsg_HandleInputEvent::ID));
685 process_->sink().ClearMessages(); 667 process_->sink().ClearMessages();
686 668
687 // Send the simulated response from the renderer back. 669 // Send the simulated response from the renderer back.
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 client_overscroll = client_->GetAndResetOverscroll(); 1811 client_overscroll = client_->GetAndResetOverscroll();
1830 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, 1812 EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
1831 client_overscroll.accumulated_overscroll); 1813 client_overscroll.accumulated_overscroll);
1832 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, 1814 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
1833 client_overscroll.latest_overscroll_delta); 1815 client_overscroll.latest_overscroll_delta);
1834 EXPECT_EQ(wheel_overscroll.current_fling_velocity, 1816 EXPECT_EQ(wheel_overscroll.current_fling_velocity,
1835 client_overscroll.current_fling_velocity); 1817 client_overscroll.current_fling_velocity);
1836 } 1818 }
1837 1819
1838 } // namespace content 1820 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698