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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 138163016: [DevTools] Touch emulation in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mouse move drops Created 6 years, 8 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 (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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 30 matching lines...) Expand all
41 41
42 #if defined(OS_WIN) || defined(USE_AURA) 42 #if defined(OS_WIN) || defined(USE_AURA)
43 #include "content/browser/renderer_host/ui_events_helper.h" 43 #include "content/browser/renderer_host/ui_events_helper.h"
44 #include "ui/events/event.h" 44 #include "ui/events/event.h"
45 #endif 45 #endif
46 46
47 using base::TimeDelta; 47 using base::TimeDelta;
48 using blink::WebGestureEvent; 48 using blink::WebGestureEvent;
49 using blink::WebInputEvent; 49 using blink::WebInputEvent;
50 using blink::WebKeyboardEvent; 50 using blink::WebKeyboardEvent;
51 using blink::WebMouseEvent;
51 using blink::WebMouseWheelEvent; 52 using blink::WebMouseWheelEvent;
52 using blink::WebTouchEvent; 53 using blink::WebTouchEvent;
53 using blink::WebTouchPoint; 54 using blink::WebTouchPoint;
54 55
55 namespace content { 56 namespace content {
56 57
57 // TestOverscrollDelegate ------------------------------------------------------ 58 // TestOverscrollDelegate ------------------------------------------------------
58 59
59 class TestOverscrollDelegate : public OverscrollControllerDelegate { 60 class TestOverscrollDelegate : public OverscrollControllerDelegate {
60 public: 61 public:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 193
193 class MockRenderWidgetHost : public RenderWidgetHostImpl { 194 class MockRenderWidgetHost : public RenderWidgetHostImpl {
194 public: 195 public:
195 MockRenderWidgetHost( 196 MockRenderWidgetHost(
196 RenderWidgetHostDelegate* delegate, 197 RenderWidgetHostDelegate* delegate,
197 RenderProcessHost* process, 198 RenderProcessHost* process,
198 int routing_id) 199 int routing_id)
199 : RenderWidgetHostImpl(delegate, process, routing_id, false), 200 : RenderWidgetHostImpl(delegate, process, routing_id, false),
200 unresponsive_timer_fired_(false) { 201 unresponsive_timer_fired_(false) {
201 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get()); 202 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get());
203 acked_touch_event_type_ = blink::WebInputEvent::Undefined;
202 } 204 }
203 205
204 // Allow poking at a few private members. 206 // Allow poking at a few private members.
205 using RenderWidgetHostImpl::OnUpdateRect; 207 using RenderWidgetHostImpl::OnUpdateRect;
206 using RenderWidgetHostImpl::RendererExited; 208 using RenderWidgetHostImpl::RendererExited;
207 using RenderWidgetHostImpl::last_requested_size_; 209 using RenderWidgetHostImpl::last_requested_size_;
208 using RenderWidgetHostImpl::is_hidden_; 210 using RenderWidgetHostImpl::is_hidden_;
209 using RenderWidgetHostImpl::resize_ack_pending_; 211 using RenderWidgetHostImpl::resize_ack_pending_;
210 using RenderWidgetHostImpl::input_router_; 212 using RenderWidgetHostImpl::input_router_;
211 213
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 256
255 void set_debounce_interval_time_ms(int delay_ms) { 257 void set_debounce_interval_time_ms(int delay_ms) {
256 gesture_event_queue(). 258 gesture_event_queue().
257 set_debounce_interval_time_ms_for_testing(delay_ms); 259 set_debounce_interval_time_ms_for_testing(delay_ms);
258 } 260 }
259 261
260 bool TouchEventQueueEmpty() const { 262 bool TouchEventQueueEmpty() const {
261 return touch_event_queue().empty(); 263 return touch_event_queue().empty();
262 } 264 }
263 265
266 virtual void OnTouchEventAck(
jdduke (slow) 2014/04/10 16:49:46 Is there a reason you didn't re-use the touch ack
dgozman 2014/04/10 17:38:03 Touch emulator handles ack before view and consume
jdduke (slow) 2014/04/10 17:40:22 Of course, silly me! Still lgtm :)
267 const TouchEventWithLatencyInfo& event,
268 InputEventAckState ack_result) OVERRIDE {
269 // Sniff touch acks.
270 acked_touch_event_type_ = event.event.type;
271 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result);
272 }
273
274 WebInputEvent::Type acked_touch_event_type() const {
275 return acked_touch_event_type_;
276 }
277
264 bool ScrollStateIsContentScrolling() const { 278 bool ScrollStateIsContentScrolling() const {
265 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; 279 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
266 } 280 }
267 281
268 bool ScrollStateIsOverscrolling() const { 282 bool ScrollStateIsOverscrolling() const {
269 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; 283 return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
270 } 284 }
271 285
272 bool ScrollStateIsUnknown() const { 286 bool ScrollStateIsUnknown() const {
273 return scroll_state() == OverscrollController::STATE_UNKNOWN; 287 return scroll_state() == OverscrollController::STATE_UNKNOWN;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const GestureEventQueue& gesture_event_queue() const { 328 const GestureEventQueue& gesture_event_queue() const {
315 return input_router_impl_->gesture_event_queue_; 329 return input_router_impl_->gesture_event_queue_;
316 } 330 }
317 331
318 GestureEventQueue& gesture_event_queue() { 332 GestureEventQueue& gesture_event_queue() {
319 return input_router_impl_->gesture_event_queue_; 333 return input_router_impl_->gesture_event_queue_;
320 } 334 }
321 335
322 private: 336 private:
323 bool unresponsive_timer_fired_; 337 bool unresponsive_timer_fired_;
338 WebInputEvent::Type acked_touch_event_type_;
324 339
325 // |input_router_impl_| and |mock_input_router_| are owned by 340 // |input_router_impl_| and |mock_input_router_| are owned by
326 // RenderWidgetHostImpl. The handles below are provided for convenience so 341 // RenderWidgetHostImpl. The handles below are provided for convenience so
327 // that we don't have to reinterpret_cast it all the time. 342 // that we don't have to reinterpret_cast it all the time.
328 InputRouterImpl* input_router_impl_; 343 InputRouterImpl* input_router_impl_;
329 MockInputRouter* mock_input_router_; 344 MockInputRouter* mock_input_router_;
330 345
331 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_; 346 scoped_ptr<TestOverscrollDelegate> overscroll_delegate_;
332 347
333 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); 348 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 bool handle_wheel_event_called_; 590 bool handle_wheel_event_called_;
576 }; 591 };
577 592
578 // RenderWidgetHostTest -------------------------------------------------------- 593 // RenderWidgetHostTest --------------------------------------------------------
579 594
580 class RenderWidgetHostTest : public testing::Test { 595 class RenderWidgetHostTest : public testing::Test {
581 public: 596 public:
582 RenderWidgetHostTest() 597 RenderWidgetHostTest()
583 : process_(NULL), 598 : process_(NULL),
584 handle_key_press_event_(false), 599 handle_key_press_event_(false),
585 handle_mouse_event_(false) { 600 handle_mouse_event_(false),
601 simulated_event_time_delta_seconds_(0) {
602 last_simulated_event_time_seconds_ =
603 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
586 } 604 }
587 virtual ~RenderWidgetHostTest() { 605 virtual ~RenderWidgetHostTest() {
588 } 606 }
589 607
590 bool KeyPressEventCallback(const NativeWebKeyboardEvent& /* event */) { 608 bool KeyPressEventCallback(const NativeWebKeyboardEvent& /* event */) {
591 return handle_key_press_event_; 609 return handle_key_press_event_;
592 } 610 }
593 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) { 611 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) {
594 return handle_mouse_event_; 612 return handle_mouse_event_;
595 } 613 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 } 656 }
639 657
640 void SendInputEventACK(WebInputEvent::Type type, 658 void SendInputEventACK(WebInputEvent::Type type,
641 InputEventAckState ack_result) { 659 InputEventAckState ack_result) {
642 scoped_ptr<IPC::Message> response( 660 scoped_ptr<IPC::Message> response(
643 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result, 661 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result,
644 ui::LatencyInfo())); 662 ui::LatencyInfo()));
645 host_->OnMessageReceived(*response); 663 host_->OnMessageReceived(*response);
646 } 664 }
647 665
666 double GetNextSimulatedEventTimeSeconds() {
667 last_simulated_event_time_seconds_ += simulated_event_time_delta_seconds_;
668 return last_simulated_event_time_seconds_;
669 }
670
648 void SimulateKeyboardEvent(WebInputEvent::Type type) { 671 void SimulateKeyboardEvent(WebInputEvent::Type type) {
649 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); 672 SimulateKeyboardEvent(type, 0);
650 NativeWebKeyboardEvent native_event; 673 }
651 memcpy(&native_event, &event, sizeof(event)); 674
675 void SimulateKeyboardEvent(WebInputEvent::Type type, int modifiers) {
676 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type);
677 event.modifiers = modifiers;
678 NativeWebKeyboardEvent native_event;
679 memcpy(&native_event, &event, sizeof(event));
652 host_->ForwardKeyboardEvent(native_event); 680 host_->ForwardKeyboardEvent(native_event);
653 } 681 }
654 682
655 void SimulateMouseEvent(WebInputEvent::Type type) { 683 void SimulateMouseEvent(WebInputEvent::Type type) {
656 host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type)); 684 host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
657 } 685 }
658 686
659 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type, 687 void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
660 const ui::LatencyInfo& ui_latency) { 688 const ui::LatencyInfo& ui_latency) {
661 host_->ForwardMouseEventWithLatencyInfo( 689 host_->ForwardMouseEventWithLatencyInfo(
(...skipping 10 matching lines...) Expand all
672 float dY, 700 float dY,
673 int modifiers, 701 int modifiers,
674 bool precise, 702 bool precise,
675 const ui::LatencyInfo& ui_latency) { 703 const ui::LatencyInfo& ui_latency) {
676 host_->ForwardWheelEventWithLatencyInfo( 704 host_->ForwardWheelEventWithLatencyInfo(
677 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise), 705 SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
678 ui_latency); 706 ui_latency);
679 } 707 }
680 708
681 void SimulateMouseMove(int x, int y, int modifiers) { 709 void SimulateMouseMove(int x, int y, int modifiers) {
682 host_->ForwardMouseEvent( 710 SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false);
683 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove, 711 }
684 x, 712
685 y, 713 void SimulateMouseEvent(
686 modifiers)); 714 WebInputEvent::Type type, int x, int y, int modifiers, bool pressed) {
715 WebMouseEvent event =
716 SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers);
717 if (pressed)
718 event.button = WebMouseEvent::ButtonLeft;
719 event.timeStampSeconds = GetNextSimulatedEventTimeSeconds();
720 host_->ForwardMouseEvent(event);
687 } 721 }
688 722
689 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) { 723 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
690 host_->ForwardWheelEvent(SyntheticWebMouseWheelEventBuilder::Build(phase)); 724 host_->ForwardWheelEvent(SyntheticWebMouseWheelEventBuilder::Build(phase));
691 } 725 }
692 726
693 // Inject provided synthetic WebGestureEvent instance. 727 // Inject provided synthetic WebGestureEvent instance.
694 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) { 728 void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
695 host_->ForwardGestureEvent(gesture_event); 729 host_->ForwardGestureEvent(gesture_event);
696 } 730 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 base::MessageLoopForUI message_loop_; 815 base::MessageLoopForUI message_loop_;
782 816
783 scoped_ptr<TestBrowserContext> browser_context_; 817 scoped_ptr<TestBrowserContext> browser_context_;
784 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. 818 RenderWidgetHostProcess* process_; // Deleted automatically by the widget.
785 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; 819 scoped_ptr<MockRenderWidgetHostDelegate> delegate_;
786 scoped_ptr<MockRenderWidgetHost> host_; 820 scoped_ptr<MockRenderWidgetHost> host_;
787 scoped_ptr<TestView> view_; 821 scoped_ptr<TestView> view_;
788 scoped_ptr<gfx::Screen> screen_; 822 scoped_ptr<gfx::Screen> screen_;
789 bool handle_key_press_event_; 823 bool handle_key_press_event_;
790 bool handle_mouse_event_; 824 bool handle_mouse_event_;
825 double last_simulated_event_time_seconds_;
826 double simulated_event_time_delta_seconds_;
791 827
792 private: 828 private:
793 SyntheticWebTouchEvent touch_event_; 829 SyntheticWebTouchEvent touch_event_;
794 830
795 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 831 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
796 }; 832 };
797 833
798 #if GTEST_HAS_PARAM_TEST 834 #if GTEST_HAS_PARAM_TEST
799 // RenderWidgetHostWithSourceTest ---------------------------------------------- 835 // RenderWidgetHostWithSourceTest ----------------------------------------------
800 836
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode()); 2410 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->current_mode());
2375 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode()); 2411 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
2376 2412
2377 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, 2413 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
2378 WebGestureEvent::Touchscreen); 2414 WebGestureEvent::Touchscreen);
2379 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 2415 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
2380 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); 2416 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
2381 process_->sink().ClearMessages(); 2417 process_->sink().ClearMessages();
2382 } 2418 }
2383 2419
2420 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) {
2421 const WebInputEvent* event = NULL;
2422 ui::LatencyInfo latency_info;
2423 bool is_keyboard_shortcut;
2424 std::string result;
2425 for (size_t i = 0; i < process->sink().message_count(); ++i) {
2426 const IPC::Message *message = process->sink().GetMessageAt(i);
2427 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
2428 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(
2429 message, &event, &latency_info, &is_keyboard_shortcut));
2430 if (i != 0)
2431 result += " ";
2432 result += WebInputEventTraits::GetName(event->type);
2433 }
2434 process->sink().ClearMessages();
2435 return result;
2436 }
2437
2438 TEST_F(RenderWidgetHostTest, TouchEmulator) {
2439 simulated_event_time_delta_seconds_ = 0.1;
2440 host_->DisableGestureDebounce();
2441 // Immediately ack all touches instead of sending them to the renderer.
2442 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
2443 host_->OnMessageReceived(
2444 ViewHostMsg_SetTouchEventEmulationEnabled(0, true, true));
2445 process_->sink().ClearMessages();
2446 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
2447 view_->Show();
2448
2449 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false);
2450 EXPECT_EQ(0U, process_->sink().message_count());
2451
2452 // Mouse press becomes touch start which in turn becomes tap.
2453 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
2454 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
2455 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
2456 SendInputEventACK(WebInputEvent::GestureTapDown,
2457 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2458
2459 // Mouse drag generates touch move, cancels tap and starts scroll.
2460 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
2461 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2462 EXPECT_EQ(
2463 "GestureTapCancel GestureScrollBegin GestureScrollUpdate",
2464 GetInputMessageTypes(process_));
2465 SendInputEventACK(WebInputEvent::GestureTapCancel,
2466 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2467 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2468 INPUT_EVENT_ACK_STATE_CONSUMED);
2469 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2470 INPUT_EVENT_ACK_STATE_CONSUMED);
2471 EXPECT_EQ(0U, process_->sink().message_count());
2472
2473 // Mouse drag with shift becomes pinch.
2474 SimulateMouseEvent(
2475 WebInputEvent::MouseMove, 10, 40, WebInputEvent::ShiftKey, true);
2476 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2477 EXPECT_EQ("GesturePinchBegin",
2478 GetInputMessageTypes(process_));
2479 SendInputEventACK(WebInputEvent::GesturePinchBegin,
2480 INPUT_EVENT_ACK_STATE_CONSUMED);
2481 EXPECT_EQ(0U, process_->sink().message_count());
2482
2483 SimulateMouseEvent(
2484 WebInputEvent::MouseMove, 10, 50, WebInputEvent::ShiftKey, true);
2485 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2486 EXPECT_EQ("GesturePinchUpdate",
2487 GetInputMessageTypes(process_));
2488 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
2489 INPUT_EVENT_ACK_STATE_CONSUMED);
2490 EXPECT_EQ(0U, process_->sink().message_count());
2491
2492 // Mouse drag without shift becomes scroll again.
2493 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 60, 0, true);
2494 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2495 EXPECT_EQ("GesturePinchEnd GestureScrollUpdate",
2496 GetInputMessageTypes(process_));
2497 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2498 INPUT_EVENT_ACK_STATE_CONSUMED);
2499 EXPECT_EQ(0U, process_->sink().message_count());
2500
2501 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 70, 0, true);
2502 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2503 EXPECT_EQ("GestureScrollUpdate",
2504 GetInputMessageTypes(process_));
2505 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2506 INPUT_EVENT_ACK_STATE_CONSUMED);
2507 EXPECT_EQ(0U, process_->sink().message_count());
2508
2509 SimulateMouseEvent(WebInputEvent::MouseUp, 10, 70, 0, true);
2510 EXPECT_EQ(WebInputEvent::TouchEnd, host_->acked_touch_event_type());
2511 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_));
2512 SendInputEventACK(WebInputEvent::GestureScrollEnd,
2513 INPUT_EVENT_ACK_STATE_CONSUMED);
2514 EXPECT_EQ(0U, process_->sink().message_count());
2515
2516 // Mouse move does nothing.
2517 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 80, 0, false);
2518 EXPECT_EQ(0U, process_->sink().message_count());
2519
2520 // Another mouse down continues scroll.
2521 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 80, 0, true);
2522 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
2523 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
2524 SendInputEventACK(WebInputEvent::GestureTapDown,
2525 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2526 EXPECT_EQ(0U, process_->sink().message_count());
2527
2528 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 100, 0, true);
2529 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2530 EXPECT_EQ(
2531 "GestureTapCancel GestureScrollBegin GestureScrollUpdate",
2532 GetInputMessageTypes(process_));
2533 SendInputEventACK(WebInputEvent::GestureTapCancel,
2534 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2535 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2536 INPUT_EVENT_ACK_STATE_CONSUMED);
2537 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2538 INPUT_EVENT_ACK_STATE_CONSUMED);
2539 EXPECT_EQ(0U, process_->sink().message_count());
2540
2541 // Another pinch.
2542 SimulateMouseEvent(
2543 WebInputEvent::MouseMove, 10, 110, WebInputEvent::ShiftKey, true);
2544 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2545 EXPECT_EQ("GesturePinchBegin",
2546 GetInputMessageTypes(process_));
2547 SendInputEventACK(WebInputEvent::GesturePinchBegin,
2548 INPUT_EVENT_ACK_STATE_CONSUMED);
2549 EXPECT_EQ(0U, process_->sink().message_count());
2550
2551 SimulateMouseEvent(
2552 WebInputEvent::MouseMove, 10, 120, WebInputEvent::ShiftKey, true);
2553 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2554 EXPECT_EQ("GesturePinchUpdate",
2555 GetInputMessageTypes(process_));
2556 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
2557 INPUT_EVENT_ACK_STATE_CONSUMED);
2558 EXPECT_EQ(0U, process_->sink().message_count());
2559
2560 // Turn off emulation during a pinch.
2561 host_->OnMessageReceived(
2562 ViewHostMsg_SetTouchEventEmulationEnabled(0, false, false));
2563 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
2564 EXPECT_EQ("GesturePinchEnd GestureScrollEnd",
2565 GetInputMessageTypes(process_));
2566 SendInputEventACK(WebInputEvent::GesturePinchEnd,
2567 INPUT_EVENT_ACK_STATE_CONSUMED);
2568 SendInputEventACK(WebInputEvent::GestureScrollEnd,
2569 INPUT_EVENT_ACK_STATE_CONSUMED);
2570 EXPECT_EQ(0U, process_->sink().message_count());
2571
2572 // Mouse event should pass untouched.
2573 SimulateMouseEvent(
2574 WebInputEvent::MouseMove, 10, 10, WebInputEvent::ShiftKey, true);
2575 EXPECT_EQ("MouseMove", GetInputMessageTypes(process_));
2576 SendInputEventACK(WebInputEvent::MouseMove,
2577 INPUT_EVENT_ACK_STATE_CONSUMED);
2578 EXPECT_EQ(0U, process_->sink().message_count());
2579
2580 // Turn on emulation.
2581 host_->OnMessageReceived(
2582 ViewHostMsg_SetTouchEventEmulationEnabled(0, true, true));
2583 EXPECT_EQ(0U, process_->sink().message_count());
2584
2585 // Another touch.
2586 SimulateMouseEvent(WebInputEvent::MouseDown, 10, 10, 0, true);
2587 EXPECT_EQ(WebInputEvent::TouchStart, host_->acked_touch_event_type());
2588 EXPECT_EQ("GestureTapDown", GetInputMessageTypes(process_));
2589 SendInputEventACK(WebInputEvent::GestureTapDown,
2590 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2591 EXPECT_EQ(0U, process_->sink().message_count());
2592
2593 // Scroll.
2594 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 30, 0, true);
2595 EXPECT_EQ(WebInputEvent::TouchMove, host_->acked_touch_event_type());
2596 EXPECT_EQ(
2597 "GestureTapCancel GestureScrollBegin GestureScrollUpdate",
2598 GetInputMessageTypes(process_));
2599 SendInputEventACK(WebInputEvent::GestureTapCancel,
2600 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
2601 SendInputEventACK(WebInputEvent::GestureScrollBegin,
2602 INPUT_EVENT_ACK_STATE_CONSUMED);
2603 SendInputEventACK(WebInputEvent::GestureScrollUpdate,
2604 INPUT_EVENT_ACK_STATE_CONSUMED);
2605
2606 // Turn off emulation during a scroll.
2607 host_->OnMessageReceived(
2608 ViewHostMsg_SetTouchEventEmulationEnabled(0, false, false));
2609 EXPECT_EQ(WebInputEvent::TouchCancel, host_->acked_touch_event_type());
2610
2611 EXPECT_EQ("GestureScrollEnd", GetInputMessageTypes(process_));
2612 SendInputEventACK(WebInputEvent::GestureScrollEnd,
2613 INPUT_EVENT_ACK_STATE_CONSUMED);
2614 EXPECT_EQ(0U, process_->sink().message_count());
2615 }
2616
2384 #define TEST_InputRouterRoutes_NOARGS(INPUTMSG) \ 2617 #define TEST_InputRouterRoutes_NOARGS(INPUTMSG) \
2385 TEST_F(RenderWidgetHostTest, InputRouterRoutes##INPUTMSG) { \ 2618 TEST_F(RenderWidgetHostTest, InputRouterRoutes##INPUTMSG) { \
2386 host_->SetupForInputRouterTest(); \ 2619 host_->SetupForInputRouterTest(); \
2387 host_->INPUTMSG(); \ 2620 host_->INPUTMSG(); \
2388 EXPECT_TRUE(host_->mock_input_router()->send_event_called_); \ 2621 EXPECT_TRUE(host_->mock_input_router()->send_event_called_); \
2389 } 2622 }
2390 2623
2391 TEST_InputRouterRoutes_NOARGS(Focus); 2624 TEST_InputRouterRoutes_NOARGS(Focus);
2392 TEST_InputRouterRoutes_NOARGS(Blur); 2625 TEST_InputRouterRoutes_NOARGS(Blur);
2393 TEST_InputRouterRoutes_NOARGS(LostCapture); 2626 TEST_InputRouterRoutes_NOARGS(LostCapture);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 2847
2615 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). 2848 // Tests RWHI::ForwardTouchEventWithLatencyInfo().
2616 PressTouchPoint(0, 1); 2849 PressTouchPoint(0, 1);
2617 SendTouchEvent(); 2850 SendTouchEvent();
2618 CheckLatencyInfoComponentInMessage( 2851 CheckLatencyInfoComponentInMessage(
2619 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); 2852 process_, GetLatencyComponentId(), WebInputEvent::TouchStart);
2620 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 2853 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
2621 } 2854 }
2622 2855
2623 } // namespace content 2856 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/browser/resources/devtools/devtools_pinch_cursor.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698