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

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

Issue 23416003: Add content::RenderWidgetHost::MouseEventCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/renderer_host/backing_store.h" 10 #include "content/browser/renderer_host/backing_store.h"
11 #include "content/browser/renderer_host/input/gesture_event_filter.h" 11 #include "content/browser/renderer_host/input/gesture_event_filter.h"
12 #include "content/browser/renderer_host/input/immediate_input_router.h" 12 #include "content/browser/renderer_host/input/immediate_input_router.h"
13 #include "content/browser/renderer_host/input/tap_suppression_controller.h" 13 #include "content/browser/renderer_host/input/tap_suppression_controller.h"
14 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h" 14 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h"
15 #include "content/browser/renderer_host/input/touch_event_queue.h" 15 #include "content/browser/renderer_host/input/touch_event_queue.h"
16 #include "content/browser/renderer_host/overscroll_controller.h" 16 #include "content/browser/renderer_host/overscroll_controller.h"
17 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 17 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
18 #include "content/browser/renderer_host/render_widget_host_delegate.h" 18 #include "content/browser/renderer_host/render_widget_host_delegate.h"
19 #include "content/browser/renderer_host/test_render_view_host.h" 19 #include "content/browser/renderer_host/test_render_view_host.h"
20 #include "content/common/input_messages.h" 20 #include "content/common/input_messages.h"
21 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
22 #include "content/port/browser/render_widget_host_view_port.h" 22 #include "content/port/browser/render_widget_host_view_port.h"
23 #include "content/public/browser/mouse_listener.h"
23 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
27 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
28 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
29 #include "content/public/test/test_browser_context.h" 30 #include "content/public/test/test_browser_context.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/keycodes/keyboard_codes.h" 32 #include "ui/base/keycodes/keyboard_codes.h"
32 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void set_handle_key_press_event(bool handle) { 122 void set_handle_key_press_event(bool handle) {
122 handle_key_press_event_ = handle; 123 handle_key_press_event_ = handle;
123 } 124 }
124 125
125 private: 126 private:
126 bool handle_key_press_event_; 127 bool handle_key_press_event_;
127 128
128 DISALLOW_COPY_AND_ASSIGN(MockKeyboardListener); 129 DISALLOW_COPY_AND_ASSIGN(MockKeyboardListener);
129 }; 130 };
130 131
132 // MockMouseListener --------------------------------------------------------
133 class MockMouseListener : public MouseListener {
134 public:
135 MockMouseListener()
136 : handle_mouse_event_(false) {
137 }
138 virtual ~MockMouseListener() {}
139
140 // MouseListener:
141 virtual bool HandleMouseEvent(const WebKit::WebMouseEvent& event) OVERRIDE {
142 return handle_mouse_event_;
143 }
144
145 void set_handle_mouse_event(bool handle) {
146 handle_mouse_event_ = handle;
147 }
148
149 private:
150 bool handle_mouse_event_;
151 };
152
131 // MockInputRouter ------------------------------------------------------------- 153 // MockInputRouter -------------------------------------------------------------
132 154
133 class MockInputRouter : public InputRouter { 155 class MockInputRouter : public InputRouter {
134 public: 156 public:
135 explicit MockInputRouter(InputRouterClient* client) 157 explicit MockInputRouter(InputRouterClient* client)
136 : send_event_called_(false), 158 : send_event_called_(false),
137 sent_mouse_event_(false), 159 sent_mouse_event_(false),
138 sent_wheel_event_(false), 160 sent_wheel_event_(false),
139 sent_keyboard_event_(false), 161 sent_keyboard_event_(false),
140 sent_gesture_event_(false), 162 sent_gesture_event_(false),
(...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 2555 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2534 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2556 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2535 2557
2536 host_->mock_input_router()->sent_keyboard_event_ = false; 2558 host_->mock_input_router()->sent_keyboard_event_ = false;
2537 SimulateKeyboardEvent(WebInputEvent::Char); 2559 SimulateKeyboardEvent(WebInputEvent::Char);
2538 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2560 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2539 2561
2540 host_->RemoveKeyboardListener(keyboard_listener_.get()); 2562 host_->RemoveKeyboardListener(keyboard_listener_.get());
2541 } 2563 }
2542 2564
2565 TEST_F(RenderWidgetHostTest, MouseListenerCanHandleEvent) {
2566 host_->SetupForInputRouterTest();
2567
2568 MockMouseListener mouse_listener;
2569 host_->AddMouseListener(&mouse_listener);
2570
2571 mouse_listener.set_handle_mouse_event(true);
2572 SimulateMouseEvent(WebInputEvent::MouseDown);
2573
2574 EXPECT_FALSE(host_->mock_input_router()->sent_mouse_event_);
2575
2576 mouse_listener.set_handle_mouse_event(false);
2577 SimulateMouseEvent(WebInputEvent::MouseDown);
2578
2579 EXPECT_TRUE(host_->mock_input_router()->sent_mouse_event_);
2580
2581 host_->RemoveMouseListener(&mouse_listener);
2582 }
2583
2543 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) { 2584 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) {
2544 host_->SetupForInputRouterTest(); 2585 host_->SetupForInputRouterTest();
2545 2586
2546 SendInputEventACK(WebInputEvent::RawKeyDown, 2587 SendInputEventACK(WebInputEvent::RawKeyDown,
2547 INPUT_EVENT_ACK_STATE_CONSUMED); 2588 INPUT_EVENT_ACK_STATE_CONSUMED);
2548 2589
2549 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2590 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2550 } 2591 }
2551 2592
2552 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) { 2593 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) {
(...skipping 14 matching lines...) Expand all
2567 2608
2568 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { 2609 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) {
2569 host_->SetupForInputRouterTest(); 2610 host_->SetupForInputRouterTest();
2570 2611
2571 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 2612 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2572 2613
2573 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2614 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2574 } 2615 }
2575 2616
2576 } // namespace content 2617 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698