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

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

Issue 536059: Mac: Coalesce scroll events. (Closed)
Patch Set: test Created 10 years, 11 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
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/gfx/canvas.h" 5 #include "app/gfx/canvas.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/keyboard_codes.h" 7 #include "base/keyboard_codes.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/renderer_host/backing_store.h" 11 #include "chrome/browser/renderer_host/backing_store.h"
12 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 12 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using WebKit::WebInputEvent; 16 using WebKit::WebInputEvent;
17 using WebKit::WebMouseWheelEvent;
17 18
18 // RenderWidgetHostProcess ----------------------------------------------------- 19 // RenderWidgetHostProcess -----------------------------------------------------
19 20
20 class RenderWidgetHostProcess : public MockRenderProcessHost { 21 class RenderWidgetHostProcess : public MockRenderProcessHost {
21 public: 22 public:
22 explicit RenderWidgetHostProcess(Profile* profile) 23 explicit RenderWidgetHostProcess(Profile* profile)
23 : MockRenderProcessHost(profile), 24 : MockRenderProcessHost(profile),
24 current_update_buf_(NULL), 25 current_update_buf_(NULL),
25 update_msg_should_reply_(false), 26 update_msg_should_reply_(false),
26 update_msg_reply_flags_(0) { 27 update_msg_reply_flags_(0) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // RenderWidgetHostView override. 113 // RenderWidgetHostView override.
113 virtual gfx::Rect GetViewBounds() const { 114 virtual gfx::Rect GetViewBounds() const {
114 return bounds_; 115 return bounds_;
115 } 116 }
116 117
117 protected: 118 protected:
118 gfx::Rect bounds_; 119 gfx::Rect bounds_;
119 DISALLOW_COPY_AND_ASSIGN(TestView); 120 DISALLOW_COPY_AND_ASSIGN(TestView);
120 }; 121 };
121 122
122 // MockRenderWidgetHostTest ---------------------------------------------------- 123 // MockRenderWidgetHost ----------------------------------------------------
123 124
124 class MockRenderWidgetHost : public RenderWidgetHost { 125 class MockRenderWidgetHost : public RenderWidgetHost {
125 public: 126 public:
126 MockRenderWidgetHost(RenderProcessHost* process, int routing_id) 127 MockRenderWidgetHost(RenderProcessHost* process, int routing_id)
127 : RenderWidgetHost(process, routing_id), 128 : RenderWidgetHost(process, routing_id),
128 prehandle_keyboard_event_(false), 129 prehandle_keyboard_event_(false),
129 prehandle_keyboard_event_called_(false), 130 prehandle_keyboard_event_called_(false),
130 prehandle_keyboard_event_type_(WebInputEvent::Undefined), 131 prehandle_keyboard_event_type_(WebInputEvent::Undefined),
131 unhandled_keyboard_event_called_(false), 132 unhandled_keyboard_event_called_(false),
132 unhandled_keyboard_event_type_(WebInputEvent::Undefined) { 133 unhandled_keyboard_event_type_(WebInputEvent::Undefined) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 host_->OnMessageReceived(*response); 214 host_->OnMessageReceived(*response);
214 } 215 }
215 216
216 void SimulateKeyboardEvent(WebInputEvent::Type type) { 217 void SimulateKeyboardEvent(WebInputEvent::Type type) {
217 NativeWebKeyboardEvent key_event; 218 NativeWebKeyboardEvent key_event;
218 key_event.type = type; 219 key_event.type = type;
219 key_event.windowsKeyCode = base::VKEY_L; // non-null made up value. 220 key_event.windowsKeyCode = base::VKEY_L; // non-null made up value.
220 host_->ForwardKeyboardEvent(key_event); 221 host_->ForwardKeyboardEvent(key_event);
221 } 222 }
222 223
224 void SimulateWheelEvent(float dX, float dY, int modifiers) {
225 WebMouseWheelEvent wheel_event;
226 wheel_event.type = WebInputEvent::MouseWheel;
227 wheel_event.deltaX = dX;
228 wheel_event.deltaY = dY;
229 wheel_event.modifiers = modifiers;
230 host_->ForwardWheelEvent(wheel_event);
231 }
232
223 MessageLoopForUI message_loop_; 233 MessageLoopForUI message_loop_;
224 234
225 scoped_ptr<TestingProfile> profile_; 235 scoped_ptr<TestingProfile> profile_;
226 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. 236 RenderWidgetHostProcess* process_; // Deleted automatically by the widget.
227 scoped_ptr<MockRenderWidgetHost> host_; 237 scoped_ptr<MockRenderWidgetHost> host_;
228 scoped_ptr<TestView> view_; 238 scoped_ptr<TestView> view_;
229 239
230 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 240 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
231 }; 241 };
232 242
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 EXPECT_EQ(ViewMsg_HandleInputEvent::ID, 559 EXPECT_EQ(ViewMsg_HandleInputEvent::ID,
550 process_->sink().GetMessageAt(0)->type()); 560 process_->sink().GetMessageAt(0)->type());
551 process_->sink().ClearMessages(); 561 process_->sink().ClearMessages();
552 562
553 // Send the simulated response from the renderer back. 563 // Send the simulated response from the renderer back.
554 SendInputEventACK(WebInputEvent::KeyUp, false); 564 SendInputEventACK(WebInputEvent::KeyUp, false);
555 565
556 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); 566 EXPECT_TRUE(host_->unhandled_keyboard_event_called());
557 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type()); 567 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type());
558 } 568 }
569
570 TEST_F(RenderWidgetHostTest, CoalescesWheelEvents) {
571 process_->sink().ClearMessages();
572
573 // Simulate wheel events.
574 SimulateWheelEvent(0, -5, 0); // sent directly
575 SimulateWheelEvent(0, -10, 0); // enqueued
576 SimulateWheelEvent(8, -6, 0); // coalesced into previous event
577 SimulateWheelEvent(9, -7, 1); // enqueued, different modifiers
578
579 // Check that only the first event was sent.
580 EXPECT_EQ(1U, process_->sink().message_count());
581 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
582 ViewMsg_HandleInputEvent::ID));
583 process_->sink().ClearMessages();
584
585 // Check that the ACK sends the second message.
586 SendInputEventACK(WebInputEvent::MouseWheel, true);
587 EXPECT_EQ(1U, process_->sink().message_count());
588 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
589 ViewMsg_HandleInputEvent::ID));
590 process_->sink().ClearMessages();
591
592 // One more time.
593 SendInputEventACK(WebInputEvent::MouseWheel, true);
594 EXPECT_EQ(1U, process_->sink().message_count());
595 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
596 ViewMsg_HandleInputEvent::ID));
597 process_->sink().ClearMessages();
598
599 // After the final ack, the queue should be empty.
600 SendInputEventACK(WebInputEvent::MouseWheel, true);
601 EXPECT_EQ(0U, process_->sink().message_count());
602 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698