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

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

Issue 739013008: Explicitly suppress scrolling for wheel events that will trigger zooming (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 private: 301 private:
302 aura::Window* owner_; 302 aura::Window* owner_;
303 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager); 303 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
304 }; 304 };
305 305
306 class MockWindowObserver : public aura::WindowObserver { 306 class MockWindowObserver : public aura::WindowObserver {
307 public: 307 public:
308 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); 308 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&));
309 }; 309 };
310 310
311 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
312 PickleIterator iter(message);
313 const char* data;
314 int data_length;
315 if (!message.ReadData(&iter, &data, &data_length))
316 return NULL;
317 return reinterpret_cast<const WebInputEvent*>(data);
318 }
319
311 } // namespace 320 } // namespace
312 321
313 class RenderWidgetHostViewAuraTest : public testing::Test { 322 class RenderWidgetHostViewAuraTest : public testing::Test {
314 public: 323 public:
315 RenderWidgetHostViewAuraTest() 324 RenderWidgetHostViewAuraTest()
316 : widget_host_uses_shutdown_to_destroy_(false), 325 : widget_host_uses_shutdown_to_destroy_(false),
317 is_guest_view_hack_(false), 326 is_guest_view_hack_(false),
318 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} 327 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
319 328
320 void SetUpEnvironment() { 329 void SetUpEnvironment() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but 390 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
382 // since the RendererFrameManager is installing a MemoryPressureListener 391 // since the RendererFrameManager is installing a MemoryPressureListener
383 // which uses ObserverListThreadSafe, which furthermore remembers the 392 // which uses ObserverListThreadSafe, which furthermore remembers the
384 // message loop for the thread it was created in. Between tests, the 393 // message loop for the thread it was created in. Between tests, the
385 // RendererFrameManager singleton survives and and the MessageLoop gets 394 // RendererFrameManager singleton survives and and the MessageLoop gets
386 // destroyed. The correct fix would be to have ObserverListThreadSafe look 395 // destroyed. The correct fix would be to have ObserverListThreadSafe look
387 // up the proper message loop every time (see crbug.com/443824.) 396 // up the proper message loop every time (see crbug.com/443824.)
388 RendererFrameManager::GetInstance()->OnMemoryPressure(level); 397 RendererFrameManager::GetInstance()->OnMemoryPressure(level);
389 } 398 }
390 399
400 void SendInputEventACK(WebInputEvent::Type type,
401 InputEventAckState ack_result) {
402 InputHostMsg_HandleInputEvent_ACK_Params ack;
403 ack.type = type;
404 ack.state = ack_result;
405 InputHostMsg_HandleInputEvent_ACK response(0, ack);
406 widget_host_->OnMessageReceived(response);
407 }
408
391 protected: 409 protected:
392 // If true, then calls RWH::Shutdown() instead of deleting RWH. 410 // If true, then calls RWH::Shutdown() instead of deleting RWH.
393 bool widget_host_uses_shutdown_to_destroy_; 411 bool widget_host_uses_shutdown_to_destroy_;
394 412
395 bool is_guest_view_hack_; 413 bool is_guest_view_hack_;
396 414
397 base::MessageLoopForUI message_loop_; 415 base::MessageLoopForUI message_loop_;
398 BrowserThreadImpl browser_thread_for_ui_; 416 BrowserThreadImpl browser_thread_for_ui_;
399 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; 417 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
400 scoped_ptr<BrowserContext> browser_context_; 418 scoped_ptr<BrowserContext> browser_context_;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 591 }
574 592
575 // Inject synthetic GestureFlingStart events. 593 // Inject synthetic GestureFlingStart events.
576 void SimulateGestureFlingStartEvent(float velocityX, 594 void SimulateGestureFlingStartEvent(float velocityX,
577 float velocityY, 595 float velocityY,
578 blink::WebGestureDevice sourceDevice) { 596 blink::WebGestureDevice sourceDevice) {
579 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( 597 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
580 velocityX, velocityY, sourceDevice)); 598 velocityX, velocityY, sourceDevice));
581 } 599 }
582 600
583 void SendInputEventACK(WebInputEvent::Type type,
584 InputEventAckState ack_result) {
585 InputHostMsg_HandleInputEvent_ACK_Params ack;
586 ack.type = type;
587 ack.state = ack_result;
588 InputHostMsg_HandleInputEvent_ACK response(0, ack);
589 widget_host_->OnMessageReceived(response);
590 }
591
592 bool ScrollStateIsContentScrolling() const { 601 bool ScrollStateIsContentScrolling() const {
593 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; 602 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
594 } 603 }
595 604
596 bool ScrollStateIsOverscrolling() const { 605 bool ScrollStateIsOverscrolling() const {
597 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; 606 return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
598 } 607 }
599 608
600 bool ScrollStateIsUnknown() const { 609 bool ScrollStateIsUnknown() const {
601 return scroll_state() == OverscrollController::STATE_UNKNOWN; 610 return scroll_state() == OverscrollController::STATE_UNKNOWN;
(...skipping 2461 matching lines...) Expand 10 before | Expand all | Expand 10 after
3063 3072
3064 const NativeWebKeyboardEvent* event = delegate_.last_event(); 3073 const NativeWebKeyboardEvent* event = delegate_.last_event();
3065 EXPECT_NE(nullptr, event); 3074 EXPECT_NE(nullptr, event);
3066 if (event) { 3075 if (event) {
3067 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); 3076 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode);
3068 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), 3077 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()),
3069 event->nativeKeyCode); 3078 event->nativeKeyCode);
3070 } 3079 }
3071 } 3080 }
3072 3081
3082 TEST_F(RenderWidgetHostViewAuraTest, SetCanScrollForWebMouseWheelEvent) {
3083 view_->InitAsChild(NULL);
3084 view_->Show();
3085
3086 sink_->ClearMessages();
3087
3088 // Simulates the mouse wheel event with ctrl modifier applied.
3089 ui::MouseWheelEvent event(gfx::Vector2d(1, 1),
3090 gfx::Point(), gfx::Point(),
3091 ui::EF_CONTROL_DOWN, 0);
3092 view_->OnMouseEvent(&event);
3093
3094 const WebInputEvent* input_event =
3095 GetInputEventFromMessage(*sink_->GetMessageAt(0));
3096 const WebMouseWheelEvent* wheel_event =
3097 static_cast<const WebMouseWheelEvent*>(input_event);
3098 // Check if the canScroll set to false when ctrl-scroll is generated from
3099 // mouse wheel event.
3100 EXPECT_FALSE(wheel_event->canScroll);
3101 sink_->ClearMessages();
3102
3103 // Ack'ing the outstanding event should flush the pending event queue.
3104 SendInputEventACK(blink::WebInputEvent::MouseWheel,
3105 INPUT_EVENT_ACK_STATE_CONSUMED);
3106
3107 // Simulates the mouse wheel event with no modifier applied.
3108 event = ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(),
3109 ui::EF_NONE, 0);
3110
3111 view_->OnMouseEvent(&event);
3112
3113 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0));
3114 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
3115 // Check if the canScroll set to true when no modifier is applied to the
3116 // mouse wheel event.
3117 EXPECT_TRUE(wheel_event->canScroll);
3118 sink_->ClearMessages();
3119
3120 SendInputEventACK(blink::WebInputEvent::MouseWheel,
3121 INPUT_EVENT_ACK_STATE_CONSUMED);
3122
3123 // Simulates the scroll event with ctrl modifier applied.
3124 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::Point(2, 2), ui::EventTimeForNow(),
3125 ui::EF_CONTROL_DOWN, 0, 5, 0, 5, 2);
3126 view_->OnScrollEvent(&scroll);
3127
3128 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0));
3129 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event);
3130 // Check if the canScroll set to true when ctrl-tpuchpad-scroll is generated
Rick Byers 2014/12/20 21:44:54 nit: typo, "tpuchpad"
3131 // from scroll event.
3132 EXPECT_TRUE(wheel_event->canScroll);
3133 }
3134
3073 } // namespace content 3135 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698