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

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

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

Powered by Google App Engine
This is Rietveld 408576698