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

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

Issue 235003005: Consolidate all touch/gesture related constants in content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 7 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/renderer_host/input/gesture_event_queue.h" 9 #include "content/browser/renderer_host/input/gesture_event_queue.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 10 #include "content/browser/renderer_host/input/input_router_client.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 protected: 139 protected:
140 // testing::Test 140 // testing::Test
141 virtual void SetUp() OVERRIDE { 141 virtual void SetUp() OVERRIDE {
142 browser_context_.reset(new TestBrowserContext()); 142 browser_context_.reset(new TestBrowserContext());
143 process_.reset(new MockRenderProcessHost(browser_context_.get())); 143 process_.reset(new MockRenderProcessHost(browser_context_.get()));
144 client_.reset(new MockInputRouterClient()); 144 client_.reset(new MockInputRouterClient());
145 ack_handler_.reset(new MockInputAckHandler()); 145 ack_handler_.reset(new MockInputAckHandler());
146 CommandLine* command_line = CommandLine::ForCurrentProcess(); 146 CommandLine* command_line = CommandLine::ForCurrentProcess();
147 command_line->AppendSwitch(switches::kValidateInputEventStream); 147 command_line->AppendSwitch(switches::kValidateInputEventStream);
148 input_router_.reset(new InputRouterImpl( 148 input_router_.reset(new InputRouterImpl(process_.get(),
149 process_.get(), client_.get(), ack_handler_.get(), MSG_ROUTING_NONE)); 149 client_.get(),
150 input_router_->gesture_event_queue_.set_debounce_enabled_for_testing( 150 ack_handler_.get(),
151 false); 151 MSG_ROUTING_NONE,
152 config_));
152 client_->set_input_router(input_router()); 153 client_->set_input_router(input_router());
153 ack_handler_->set_input_router(input_router()); 154 ack_handler_->set_input_router(input_router());
154 } 155 }
155 156
156 virtual void TearDown() OVERRIDE { 157 virtual void TearDown() OVERRIDE {
157 // Process all pending tasks to avoid leaks. 158 // Process all pending tasks to avoid leaks.
158 base::MessageLoop::current()->RunUntilIdle(); 159 base::MessageLoop::current()->RunUntilIdle();
159 160
160 input_router_.reset(); 161 input_router_.reset();
161 client_.reset(); 162 client_.reset();
162 process_.reset(); 163 process_.reset();
163 browser_context_.reset(); 164 browser_context_.reset();
164 } 165 }
165 166
167 void SetUpForTouchAckTimeoutTest(int timeout_ms) {
168 config_.touch_config.touch_ack_timeout_delay =
169 base::TimeDelta::FromMilliseconds(timeout_ms);
170 config_.touch_config.touch_ack_timeout_supported = true;
171 TearDown();
172 SetUp();
173 }
174
166 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) { 175 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) {
167 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); 176 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
168 NativeWebKeyboardEvent native_event; 177 NativeWebKeyboardEvent native_event;
169 memcpy(&native_event, &event, sizeof(event)); 178 memcpy(&native_event, &event, sizeof(event));
170 input_router_->SendKeyboardEvent( 179 input_router_->SendKeyboardEvent(
171 native_event, 180 native_event,
172 ui::LatencyInfo(), 181 ui::LatencyInfo(),
173 is_shortcut); 182 is_shortcut);
174 } 183 }
175 184
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 process_->sink().ClearMessages(); 332 process_->sink().ClearMessages();
324 return count; 333 return count;
325 } 334 }
326 335
327 static void RunTasksAndWait(base::TimeDelta delay) { 336 static void RunTasksAndWait(base::TimeDelta delay) {
328 base::MessageLoop::current()->PostDelayedTask( 337 base::MessageLoop::current()->PostDelayedTask(
329 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 338 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
330 base::MessageLoop::current()->Run(); 339 base::MessageLoop::current()->Run();
331 } 340 }
332 341
342 InputRouterImpl::Config config_;
333 scoped_ptr<MockRenderProcessHost> process_; 343 scoped_ptr<MockRenderProcessHost> process_;
334 scoped_ptr<MockInputRouterClient> client_; 344 scoped_ptr<MockInputRouterClient> client_;
335 scoped_ptr<MockInputAckHandler> ack_handler_; 345 scoped_ptr<MockInputAckHandler> ack_handler_;
336 scoped_ptr<InputRouterImpl> input_router_; 346 scoped_ptr<InputRouterImpl> input_router_;
337 347
338 private: 348 private:
339 base::MessageLoopForUI message_loop_; 349 base::MessageLoopForUI message_loop_;
340 SyntheticWebTouchEvent touch_event_; 350 SyntheticWebTouchEvent touch_event_;
341 351
342 scoped_ptr<TestBrowserContext> browser_context_; 352 scoped_ptr<TestBrowserContext> browser_context_;
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1014 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1005 1015
1006 SendInputEventACK(WebInputEvent::GesturePinchUpdate, 1016 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
1007 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1017 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1008 // Now that the Tap has been ACKed, the ShowPress events should receive 1018 // Now that the Tap has been ACKed, the ShowPress events should receive
1009 // synthetic acks, and fire immediately. 1019 // synthetic acks, and fire immediately.
1010 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); 1020 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
1011 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount()); 1021 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount());
1012 } 1022 }
1013 1023
1014 // Test that touch ack timeout behavior is properly configured via the command 1024 // Test that touch ack timeout behavior is properly toggled by view update flags
1015 // line, and toggled by view update flags and allowed touch actions. 1025 // and allowed touch actions.
1016 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { 1026 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) {
1017 // Unless explicitly supported via the command-line, the touch timeout should 1027 const int timeout_ms = 1;
1018 // be disabled. 1028 SetUpForTouchAckTimeoutTest(timeout_ms);
1019 EXPECT_FALSE(TouchEventTimeoutEnabled());
1020
1021 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1022 switches::kTouchAckTimeoutDelayMs, "1");
1023 TearDown();
1024 SetUp();
1025 ASSERT_TRUE(TouchEventTimeoutEnabled()); 1029 ASSERT_TRUE(TouchEventTimeoutEnabled());
1026 1030
1027 // Verify that the touch ack timeout fires upon the delayed ack. 1031 // Verify that the touch ack timeout fires upon the delayed ack.
1028 PressTouchPoint(1, 1); 1032 PressTouchPoint(1, 1);
1029 SendTouchEvent(); 1033 SendTouchEvent();
1030 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1034 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1031 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1035 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1032 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); 1036 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
1033 1037
1034 // The timed-out event should have been ack'ed. 1038 // The timed-out event should have been ack'ed.
1035 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1039 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1036 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1040 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1037 1041
1038 // Ack'ing the timed-out event should fire a TouchCancel. 1042 // Ack'ing the timed-out event should fire a TouchCancel.
1039 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 1043 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1040 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1044 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1041 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1045 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1042 1046
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // should be restored. 1092 // should be restored.
1089 PressTouchPoint(1, 1); 1093 PressTouchPoint(1, 1);
1090 SendTouchEvent(); 1094 SendTouchEvent();
1091 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1095 EXPECT_TRUE(TouchEventTimeoutEnabled());
1092 } 1096 }
1093 1097
1094 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by 1098 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
1095 // the touch timeout. 1099 // the touch timeout.
1096 TEST_F(InputRouterImplTest, 1100 TEST_F(InputRouterImplTest,
1097 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { 1101 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) {
1098 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1102 const int timeout_ms = 1;
1099 switches::kTouchAckTimeoutDelayMs, "1"); 1103 SetUpForTouchAckTimeoutTest(timeout_ms);
1100 TearDown();
1101 SetUp();
1102 ASSERT_TRUE(TouchEventTimeoutEnabled()); 1104 ASSERT_TRUE(TouchEventTimeoutEnabled());
1103 OnHasTouchEventHandlers(true); 1105 OnHasTouchEventHandlers(true);
1104 1106
1105 // Start a touch sequence. 1107 // Start a touch sequence.
1106 PressTouchPoint(1, 1); 1108 PressTouchPoint(1, 1);
1107 SendTouchEvent(); 1109 SendTouchEvent();
1108 1110
1109 // TOUCH_ACTION_NONE should disable the timeout. 1111 // TOUCH_ACTION_NONE should disable the timeout.
1110 OnSetTouchAction(TOUCH_ACTION_NONE); 1112 OnSetTouchAction(TOUCH_ACTION_NONE);
1111 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 1113 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1112 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1114 EXPECT_FALSE(TouchEventTimeoutEnabled());
1113 1115
1114 // End the touch sequence. 1116 // End the touch sequence.
1115 ReleaseTouchPoint(0); 1117 ReleaseTouchPoint(0);
1116 SendTouchEvent(); 1118 SendTouchEvent();
1117 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); 1119 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1118 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1120 EXPECT_FALSE(TouchEventTimeoutEnabled());
1119 ack_handler_->GetAndResetAckCount(); 1121 ack_handler_->GetAndResetAckCount();
1120 GetSentMessageCountAndResetSink(); 1122 GetSentMessageCountAndResetSink();
1121 1123
1122 // Start another touch sequence. While this does restore the touch timeout 1124 // Start another touch sequence. While this does restore the touch timeout
1123 // the timeout will not apply until the *next* touch sequence. This affords a 1125 // the timeout will not apply until the *next* touch sequence. This affords a
1124 // touch-action response from the renderer without racing against the timeout. 1126 // touch-action response from the renderer without racing against the timeout.
1125 PressTouchPoint(1, 1); 1127 PressTouchPoint(1, 1);
1126 SendTouchEvent(); 1128 SendTouchEvent();
1127 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1129 EXPECT_TRUE(TouchEventTimeoutEnabled());
1128 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1130 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1129 1131
1130 // Delay the ack. The timeout should *not* fire. 1132 // Delay the ack. The timeout should *not* fire.
1131 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); 1133 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
1132 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1134 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1133 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1135 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1134 1136
1135 // Finally send the ack. The touch sequence should not have been cancelled. 1137 // Finally send the ack. The touch sequence should not have been cancelled.
1136 SendInputEventACK(WebInputEvent::TouchStart, 1138 SendInputEventACK(WebInputEvent::TouchStart,
1137 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1139 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1138 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1140 EXPECT_TRUE(TouchEventTimeoutEnabled());
1139 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1141 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1140 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1142 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1141 1143
1142 // End the sequence. 1144 // End the sequence.
1143 ReleaseTouchPoint(0); 1145 ReleaseTouchPoint(0);
1144 SendTouchEvent(); 1146 SendTouchEvent();
1145 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); 1147 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1146 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1148 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1147 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1149 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1148 1150
1149 // A new touch sequence should (finally) be subject to the timeout. 1151 // A new touch sequence should (finally) be subject to the timeout.
1150 PressTouchPoint(1, 1); 1152 PressTouchPoint(1, 1);
1151 SendTouchEvent(); 1153 SendTouchEvent();
1152 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1154 EXPECT_TRUE(TouchEventTimeoutEnabled());
1153 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1155 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1154 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1156 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1155 1157
1156 // Wait for the touch ack timeout to fire. 1158 // Wait for the touch ack timeout to fire.
1157 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); 1159 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1));
1158 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1160 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1159 } 1161 }
1160 1162
1161 // Test that TouchActionFilter::ResetTouchAction is called before the 1163 // Test that TouchActionFilter::ResetTouchAction is called before the
1162 // first touch event for a touch sequence reaches the renderer. 1164 // first touch event for a touch sequence reaches the renderer.
1163 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) { 1165 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) {
1164 OnHasTouchEventHandlers(true); 1166 OnHasTouchEventHandlers(true);
1165 1167
1166 // Sequence 1. 1168 // Sequence 1.
1167 PressTouchPoint(1, 1); 1169 PressTouchPoint(1, 1);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 1430
1429 // Ack the second scroll. 1431 // Ack the second scroll.
1430 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1432 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
1431 INPUT_EVENT_ACK_STATE_CONSUMED); 1433 INPUT_EVENT_ACK_STATE_CONSUMED);
1432 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1434 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1433 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1435 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1434 EXPECT_EQ(0, client_->in_flight_event_count()); 1436 EXPECT_EQ(0, client_->in_flight_event_count());
1435 } 1437 }
1436 1438
1437 } // namespace content 1439 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698