OLD | NEW |
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 private: | 316 private: |
317 aura::Window* owner_; | 317 aura::Window* owner_; |
318 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager); | 318 DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager); |
319 }; | 319 }; |
320 | 320 |
321 class MockWindowObserver : public aura::WindowObserver { | 321 class MockWindowObserver : public aura::WindowObserver { |
322 public: | 322 public: |
323 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); | 323 MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&)); |
324 }; | 324 }; |
325 | 325 |
| 326 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { |
| 327 PickleIterator iter(message); |
| 328 const char* data; |
| 329 int data_length; |
| 330 if (!iter.ReadData(&data, &data_length)) |
| 331 return NULL; |
| 332 return reinterpret_cast<const WebInputEvent*>(data); |
| 333 } |
| 334 |
326 } // namespace | 335 } // namespace |
327 | 336 |
328 class RenderWidgetHostViewAuraTest : public testing::Test { | 337 class RenderWidgetHostViewAuraTest : public testing::Test { |
329 public: | 338 public: |
330 RenderWidgetHostViewAuraTest() | 339 RenderWidgetHostViewAuraTest() |
331 : widget_host_uses_shutdown_to_destroy_(false), | 340 : widget_host_uses_shutdown_to_destroy_(false), |
332 is_guest_view_hack_(false), | 341 is_guest_view_hack_(false), |
333 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 342 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
334 | 343 |
335 void SetUpEnvironment() { | 344 void SetUpEnvironment() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but | 405 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but |
397 // since the RendererFrameManager is installing a MemoryPressureListener | 406 // since the RendererFrameManager is installing a MemoryPressureListener |
398 // which uses ObserverListThreadSafe, which furthermore remembers the | 407 // which uses ObserverListThreadSafe, which furthermore remembers the |
399 // message loop for the thread it was created in. Between tests, the | 408 // message loop for the thread it was created in. Between tests, the |
400 // RendererFrameManager singleton survives and and the MessageLoop gets | 409 // RendererFrameManager singleton survives and and the MessageLoop gets |
401 // destroyed. The correct fix would be to have ObserverListThreadSafe look | 410 // destroyed. The correct fix would be to have ObserverListThreadSafe look |
402 // up the proper message loop every time (see crbug.com/443824.) | 411 // up the proper message loop every time (see crbug.com/443824.) |
403 RendererFrameManager::GetInstance()->OnMemoryPressure(level); | 412 RendererFrameManager::GetInstance()->OnMemoryPressure(level); |
404 } | 413 } |
405 | 414 |
| 415 void SendInputEventACK(WebInputEvent::Type type, |
| 416 InputEventAckState ack_result) { |
| 417 InputHostMsg_HandleInputEvent_ACK_Params ack; |
| 418 ack.type = type; |
| 419 ack.state = ack_result; |
| 420 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 421 widget_host_->OnMessageReceived(response); |
| 422 } |
| 423 |
406 protected: | 424 protected: |
407 // If true, then calls RWH::Shutdown() instead of deleting RWH. | 425 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
408 bool widget_host_uses_shutdown_to_destroy_; | 426 bool widget_host_uses_shutdown_to_destroy_; |
409 | 427 |
410 bool is_guest_view_hack_; | 428 bool is_guest_view_hack_; |
411 | 429 |
412 base::MessageLoopForUI message_loop_; | 430 base::MessageLoopForUI message_loop_; |
413 BrowserThreadImpl browser_thread_for_ui_; | 431 BrowserThreadImpl browser_thread_for_ui_; |
414 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 432 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
415 scoped_ptr<BrowserContext> browser_context_; | 433 scoped_ptr<BrowserContext> browser_context_; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 606 } |
589 | 607 |
590 // Inject synthetic GestureFlingStart events. | 608 // Inject synthetic GestureFlingStart events. |
591 void SimulateGestureFlingStartEvent(float velocityX, | 609 void SimulateGestureFlingStartEvent(float velocityX, |
592 float velocityY, | 610 float velocityY, |
593 blink::WebGestureDevice sourceDevice) { | 611 blink::WebGestureDevice sourceDevice) { |
594 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( | 612 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( |
595 velocityX, velocityY, sourceDevice)); | 613 velocityX, velocityY, sourceDevice)); |
596 } | 614 } |
597 | 615 |
598 void SendInputEventACK(WebInputEvent::Type type, | |
599 InputEventAckState ack_result) { | |
600 InputHostMsg_HandleInputEvent_ACK_Params ack; | |
601 ack.type = type; | |
602 ack.state = ack_result; | |
603 InputHostMsg_HandleInputEvent_ACK response(0, ack); | |
604 widget_host_->OnMessageReceived(response); | |
605 } | |
606 | |
607 bool ScrollStateIsContentScrolling() const { | 616 bool ScrollStateIsContentScrolling() const { |
608 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; | 617 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; |
609 } | 618 } |
610 | 619 |
611 bool ScrollStateIsOverscrolling() const { | 620 bool ScrollStateIsOverscrolling() const { |
612 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; | 621 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; |
613 } | 622 } |
614 | 623 |
615 bool ScrollStateIsUnknown() const { | 624 bool ScrollStateIsUnknown() const { |
616 return scroll_state() == OverscrollController::STATE_UNKNOWN; | 625 return scroll_state() == OverscrollController::STATE_UNKNOWN; |
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 | 3081 |
3073 const NativeWebKeyboardEvent* event = delegate_.last_event(); | 3082 const NativeWebKeyboardEvent* event = delegate_.last_event(); |
3074 EXPECT_NE(nullptr, event); | 3083 EXPECT_NE(nullptr, event); |
3075 if (event) { | 3084 if (event) { |
3076 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); | 3085 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); |
3077 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), | 3086 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), |
3078 event->nativeKeyCode); | 3087 event->nativeKeyCode); |
3079 } | 3088 } |
3080 } | 3089 } |
3081 | 3090 |
| 3091 TEST_F(RenderWidgetHostViewAuraTest, SetCanScrollForWebMouseWheelEvent) { |
| 3092 view_->InitAsChild(NULL); |
| 3093 view_->Show(); |
| 3094 |
| 3095 sink_->ClearMessages(); |
| 3096 |
| 3097 // Simulates the mouse wheel event with ctrl modifier applied. |
| 3098 ui::MouseWheelEvent event(gfx::Vector2d(1, 1), |
| 3099 gfx::Point(), gfx::Point(), |
| 3100 ui::EF_CONTROL_DOWN, 0); |
| 3101 view_->OnMouseEvent(&event); |
| 3102 |
| 3103 const WebInputEvent* input_event = |
| 3104 GetInputEventFromMessage(*sink_->GetMessageAt(0)); |
| 3105 const WebMouseWheelEvent* wheel_event = |
| 3106 static_cast<const WebMouseWheelEvent*>(input_event); |
| 3107 // Check if the canScroll set to false when ctrl-scroll is generated from |
| 3108 // mouse wheel event. |
| 3109 EXPECT_FALSE(wheel_event->canScroll); |
| 3110 sink_->ClearMessages(); |
| 3111 |
| 3112 // Ack'ing the outstanding event should flush the pending event queue. |
| 3113 SendInputEventACK(blink::WebInputEvent::MouseWheel, |
| 3114 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3115 |
| 3116 // Simulates the mouse wheel event with no modifier applied. |
| 3117 event = ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(), |
| 3118 ui::EF_NONE, 0); |
| 3119 |
| 3120 view_->OnMouseEvent(&event); |
| 3121 |
| 3122 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0)); |
| 3123 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); |
| 3124 // Check if the canScroll set to true when no modifier is applied to the |
| 3125 // mouse wheel event. |
| 3126 EXPECT_TRUE(wheel_event->canScroll); |
| 3127 sink_->ClearMessages(); |
| 3128 |
| 3129 SendInputEventACK(blink::WebInputEvent::MouseWheel, |
| 3130 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 3131 |
| 3132 // Simulates the scroll event with ctrl modifier applied. |
| 3133 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::Point(2, 2), ui::EventTimeForNow(), |
| 3134 ui::EF_CONTROL_DOWN, 0, 5, 0, 5, 2); |
| 3135 view_->OnScrollEvent(&scroll); |
| 3136 |
| 3137 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0)); |
| 3138 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); |
| 3139 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated |
| 3140 // from scroll event. |
| 3141 EXPECT_TRUE(wheel_event->canScroll); |
| 3142 } |
| 3143 |
3082 } // namespace content | 3144 } // namespace content |
OLD | NEW |