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

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

Issue 628763003: Support InputRouter recycling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates Created 6 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"
9 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/renderer_host/input/gesture_event_queue.h" 10 #include "content/browser/renderer_host/input/gesture_event_queue.h"
12 #include "content/browser/renderer_host/input/input_router_client.h" 11 #include "content/browser/renderer_host/input/input_router_client.h"
13 #include "content/browser/renderer_host/input/input_router_impl.h" 12 #include "content/browser/renderer_host/input/input_router_impl.h"
14 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" 13 #include "content/browser/renderer_host/input/mock_input_ack_handler.h"
15 #include "content/browser/renderer_host/input/mock_input_router_client.h" 14 #include "content/browser/renderer_host/input/mock_input_router_client.h"
16 #include "content/common/content_constants_internal.h" 15 #include "content/common/content_constants_internal.h"
17 #include "content/common/edit_command.h" 16 #include "content/common/edit_command.h"
18 #include "content/common/input/synthetic_web_input_event_builders.h" 17 #include "content/common/input/synthetic_web_input_event_builders.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 InputRouterImplTest() {} 143 InputRouterImplTest() {}
145 virtual ~InputRouterImplTest() {} 144 virtual ~InputRouterImplTest() {}
146 145
147 protected: 146 protected:
148 // testing::Test 147 // testing::Test
149 virtual void SetUp() override { 148 virtual void SetUp() override {
150 browser_context_.reset(new TestBrowserContext()); 149 browser_context_.reset(new TestBrowserContext());
151 process_.reset(new MockRenderProcessHost(browser_context_.get())); 150 process_.reset(new MockRenderProcessHost(browser_context_.get()));
152 client_.reset(new MockInputRouterClient()); 151 client_.reset(new MockInputRouterClient());
153 ack_handler_.reset(new MockInputAckHandler()); 152 ack_handler_.reset(new MockInputAckHandler());
154 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
155 command_line->AppendSwitch(switches::kValidateInputEventStream);
156 input_router_.reset(new InputRouterImpl(process_.get(), 153 input_router_.reset(new InputRouterImpl(process_.get(),
157 client_.get(), 154 client_.get(),
158 ack_handler_.get(), 155 ack_handler_.get(),
159 MSG_ROUTING_NONE, 156 MSG_ROUTING_NONE,
160 config_)); 157 config_));
161 client_->set_input_router(input_router()); 158 client_->set_input_router(input_router());
162 ack_handler_->set_input_router(input_router()); 159 ack_handler_->set_input_router(input_router());
163 } 160 }
164 161
165 virtual void TearDown() override { 162 virtual void TearDown() override {
166 // Process all pending tasks to avoid leaks. 163 // Process all pending tasks to avoid leaks.
167 base::MessageLoop::current()->RunUntilIdle(); 164 base::MessageLoop::current()->RunUntilIdle();
168 165
169 input_router_.reset(); 166 input_router_.reset();
170 client_.reset(); 167 client_.reset();
171 process_.reset(); 168 process_.reset();
172 browser_context_.reset(); 169 browser_context_.reset();
173 } 170 }
174 171
175 void SetUpForTouchAckTimeoutTest(int timeout_ms) { 172 void SetUpForTouchAckTimeoutTest(int timeout_ms) {
176 config_.touch_config.touch_ack_timeout_delay = 173 config_.touch_config.touch_ack_timeout_delay =
177 base::TimeDelta::FromMilliseconds(timeout_ms); 174 base::TimeDelta::FromMilliseconds(timeout_ms);
178 config_.touch_config.touch_ack_timeout_supported = true; 175 config_.touch_config.touch_ack_timeout_supported = true;
176 config_.validate_event_stream = true;
179 TearDown(); 177 TearDown();
180 SetUp(); 178 SetUp();
181 } 179 }
182 180
183 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) { 181 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) {
184 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); 182 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
185 NativeWebKeyboardEvent native_event; 183 NativeWebKeyboardEvent native_event;
186 memcpy(&native_event, &event, sizeof(event)); 184 memcpy(&native_event, &event, sizeof(event));
187 input_router_->SendKeyboardEvent( 185 input_router_->SendKeyboardEvent(
188 native_event, 186 native_event,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 278 }
281 279
282 bool TouchEventQueueEmpty() const { 280 bool TouchEventQueueEmpty() const {
283 return input_router()->touch_event_queue_.empty(); 281 return input_router()->touch_event_queue_.empty();
284 } 282 }
285 283
286 bool TouchEventTimeoutEnabled() const { 284 bool TouchEventTimeoutEnabled() const {
287 return input_router()->touch_event_queue_.IsAckTimeoutEnabled(); 285 return input_router()->touch_event_queue_.IsAckTimeoutEnabled();
288 } 286 }
289 287
290 void Flush() const { 288 void RequestFlushedNotification() const {
291 return input_router_->Flush(); 289 return input_router_->RequestFlushedNotification();
292 } 290 }
293 291
294 size_t GetAndResetDidFlushCount() { 292 size_t GetAndResetDidFlushCount() {
295 return client_->GetAndResetDidFlushCount(); 293 return client_->GetAndResetDidFlushCount();
296 } 294 }
297 295
298 bool HasPendingEvents() const { 296 bool HasPendingEvents() const {
299 return input_router_->HasPendingEvents(); 297 return input_router_->HasPendingEvents();
300 } 298 }
301 299
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 614 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
617 EXPECT_EQ(WebInputEvent::TouchMove, 615 EXPECT_EQ(WebInputEvent::TouchMove,
618 ack_handler_->acked_touch_event().event.type); 616 ack_handler_->acked_touch_event().event.type);
619 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 617 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
620 } 618 }
621 619
622 // Tests that the touch-queue is emptied after a page stops listening for touch 620 // Tests that the touch-queue is emptied after a page stops listening for touch
623 // events and the outstanding ack is received. 621 // events and the outstanding ack is received.
624 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { 622 TEST_F(InputRouterImplTest, TouchEventQueueFlush) {
625 OnHasTouchEventHandlers(true); 623 OnHasTouchEventHandlers(true);
626 EXPECT_TRUE(client_->has_touch_handler());
627 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 624 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
628 EXPECT_TRUE(TouchEventQueueEmpty()); 625 EXPECT_TRUE(TouchEventQueueEmpty());
629 626
630 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); 627 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
631 628
632 // Send a touch-press event. 629 // Send a touch-press event.
633 PressTouchPoint(1, 1); 630 PressTouchPoint(1, 1);
634 SendTouchEvent(); 631 SendTouchEvent();
635 MoveTouchPoint(0, 2, 2); 632 MoveTouchPoint(0, 2, 2);
636 MoveTouchPoint(0, 3, 3); 633 MoveTouchPoint(0, 3, 3);
637 EXPECT_FALSE(TouchEventQueueEmpty()); 634 EXPECT_FALSE(TouchEventQueueEmpty());
638 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 635 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
639 636
640 // The page stops listening for touch-events. Note that flushing is deferred 637 // The page stops listening for touch-events. Note that flushing is deferred
641 // until the outstanding ack is received. 638 // until the outstanding ack is received.
642 OnHasTouchEventHandlers(false); 639 OnHasTouchEventHandlers(false);
643 EXPECT_FALSE(client_->has_touch_handler());
644 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 640 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
645 EXPECT_FALSE(TouchEventQueueEmpty()); 641 EXPECT_FALSE(TouchEventQueueEmpty());
646 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); 642 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
647 643
648 // After the ack, the touch-event queue should be empty, and none of the 644 // After the ack, the touch-event queue should be empty, and none of the
649 // flushed touch-events should have been sent to the renderer. 645 // flushed touch-events should have been sent to the renderer.
650 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 646 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
651 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 647 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
652 EXPECT_TRUE(TouchEventQueueEmpty()); 648 EXPECT_TRUE(TouchEventQueueEmpty());
653 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent()); 649 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent());
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED); 1350 SendInputEventACK(WebInputEvent::GestureTap, INPUT_EVENT_ACK_STATE_CONSUMED);
1355 EXPECT_EQ(0, client_->in_flight_event_count()); 1351 EXPECT_EQ(0, client_->in_flight_event_count());
1356 } 1352 }
1357 1353
1358 // Test that the router will call the client's |DidFlush| after all events have 1354 // Test that the router will call the client's |DidFlush| after all events have
1359 // been dispatched following a call to |Flush|. 1355 // been dispatched following a call to |Flush|.
1360 TEST_F(InputRouterImplTest, InputFlush) { 1356 TEST_F(InputRouterImplTest, InputFlush) {
1361 EXPECT_FALSE(HasPendingEvents()); 1357 EXPECT_FALSE(HasPendingEvents());
1362 1358
1363 // Flushing an empty router should immediately trigger DidFlush. 1359 // Flushing an empty router should immediately trigger DidFlush.
1364 Flush(); 1360 RequestFlushedNotification();
1365 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1361 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1366 EXPECT_FALSE(HasPendingEvents()); 1362 EXPECT_FALSE(HasPendingEvents());
1367 1363
1368 // Queue a TouchStart. 1364 // Queue a TouchStart.
1369 OnHasTouchEventHandlers(true); 1365 OnHasTouchEventHandlers(true);
1370 PressTouchPoint(1, 1); 1366 PressTouchPoint(1, 1);
1371 SendTouchEvent(); 1367 SendTouchEvent();
1372 EXPECT_TRUE(HasPendingEvents()); 1368 EXPECT_TRUE(HasPendingEvents());
1373 1369
1374 // DidFlush should be called only after the event is ack'ed. 1370 // DidFlush should be called only after the event is ack'ed.
1375 Flush(); 1371 RequestFlushedNotification();
1376 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1372 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1377 SendInputEventACK(WebInputEvent::TouchStart, 1373 SendInputEventACK(WebInputEvent::TouchStart,
1378 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1374 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1379 EXPECT_EQ(1U, GetAndResetDidFlushCount()); 1375 EXPECT_EQ(1U, GetAndResetDidFlushCount());
1380 1376
1381 // Ensure different types of enqueued events will prevent the DidFlush call 1377 // Ensure different types of enqueued events will prevent the DidFlush call
1382 // until all such events have been fully dispatched. 1378 // until all such events have been fully dispatched.
1383 MoveTouchPoint(0, 50, 50); 1379 MoveTouchPoint(0, 50, 50);
1384 SendTouchEvent(); 1380 SendTouchEvent();
1385 ASSERT_TRUE(HasPendingEvents()); 1381 ASSERT_TRUE(HasPendingEvents());
1386 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, 1382 SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
1387 blink::WebGestureDeviceTouchscreen); 1383 blink::WebGestureDeviceTouchscreen);
1388 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, 1384 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
1389 blink::WebGestureDeviceTouchscreen); 1385 blink::WebGestureDeviceTouchscreen);
1390 SimulateGestureEvent(WebInputEvent::GesturePinchBegin, 1386 SimulateGestureEvent(WebInputEvent::GesturePinchBegin,
1391 blink::WebGestureDeviceTouchscreen); 1387 blink::WebGestureDeviceTouchscreen);
1392 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, 1388 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate,
1393 blink::WebGestureDeviceTouchscreen); 1389 blink::WebGestureDeviceTouchscreen);
1394 Flush(); 1390 RequestFlushedNotification();
1395 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1391 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1396 1392
1397 // Repeated flush calls should have no effect. 1393 // Repeated flush calls should have no effect.
1398 Flush(); 1394 RequestFlushedNotification();
1399 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1395 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1400 1396
1401 // There are still pending gestures. 1397 // There are still pending gestures.
1402 SendInputEventACK(WebInputEvent::TouchMove, 1398 SendInputEventACK(WebInputEvent::TouchMove,
1403 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1399 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1404 EXPECT_EQ(0U, GetAndResetDidFlushCount()); 1400 EXPECT_EQ(0U, GetAndResetDidFlushCount());
1405 EXPECT_TRUE(HasPendingEvents()); 1401 EXPECT_TRUE(HasPendingEvents());
1406 1402
1407 // One more gesture to go. 1403 // One more gesture to go.
1408 SendInputEventACK(WebInputEvent::GestureScrollUpdate, 1404 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 1706
1711 client_overscroll = client_->GetAndResetOverscroll(); 1707 client_overscroll = client_->GetAndResetOverscroll();
1712 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, 1708 EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
1713 client_overscroll.accumulated_overscroll); 1709 client_overscroll.accumulated_overscroll);
1714 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, 1710 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
1715 client_overscroll.latest_overscroll_delta); 1711 client_overscroll.latest_overscroll_delta);
1716 EXPECT_EQ(wheel_overscroll.current_fling_velocity, 1712 EXPECT_EQ(wheel_overscroll.current_fling_velocity,
1717 client_overscroll.current_fling_velocity); 1713 client_overscroll.current_fling_velocity);
1718 } 1714 }
1719 1715
1716 TEST_F(InputRouterImplTest, Recycle) {
1717 // TODO(jdduke): Implement.
1718 }
1719
1720 } // namespace content 1720 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698