| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (!iter.ReadData(&data, &data_length)) | |
| 316 return NULL; | |
| 317 return reinterpret_cast<const WebInputEvent*>(data); | |
| 318 } | |
| 319 | |
| 320 } // namespace | 311 } // namespace |
| 321 | 312 |
| 322 class RenderWidgetHostViewAuraTest : public testing::Test { | 313 class RenderWidgetHostViewAuraTest : public testing::Test { |
| 323 public: | 314 public: |
| 324 RenderWidgetHostViewAuraTest() | 315 RenderWidgetHostViewAuraTest() |
| 325 : widget_host_uses_shutdown_to_destroy_(false), | 316 : widget_host_uses_shutdown_to_destroy_(false), |
| 326 is_guest_view_hack_(false), | 317 is_guest_view_hack_(false), |
| 327 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 318 browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
| 328 | 319 |
| 329 void SetUpEnvironment() { | 320 void SetUpEnvironment() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but | 381 // Here should be base::MemoryPressureListener::NotifyMemoryPressure, but |
| 391 // since the RendererFrameManager is installing a MemoryPressureListener | 382 // since the RendererFrameManager is installing a MemoryPressureListener |
| 392 // which uses ObserverListThreadSafe, which furthermore remembers the | 383 // which uses ObserverListThreadSafe, which furthermore remembers the |
| 393 // message loop for the thread it was created in. Between tests, the | 384 // message loop for the thread it was created in. Between tests, the |
| 394 // RendererFrameManager singleton survives and and the MessageLoop gets | 385 // RendererFrameManager singleton survives and and the MessageLoop gets |
| 395 // destroyed. The correct fix would be to have ObserverListThreadSafe look | 386 // destroyed. The correct fix would be to have ObserverListThreadSafe look |
| 396 // up the proper message loop every time (see crbug.com/443824.) | 387 // up the proper message loop every time (see crbug.com/443824.) |
| 397 RendererFrameManager::GetInstance()->OnMemoryPressure(level); | 388 RendererFrameManager::GetInstance()->OnMemoryPressure(level); |
| 398 } | 389 } |
| 399 | 390 |
| 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 | |
| 409 protected: | 391 protected: |
| 410 // If true, then calls RWH::Shutdown() instead of deleting RWH. | 392 // If true, then calls RWH::Shutdown() instead of deleting RWH. |
| 411 bool widget_host_uses_shutdown_to_destroy_; | 393 bool widget_host_uses_shutdown_to_destroy_; |
| 412 | 394 |
| 413 bool is_guest_view_hack_; | 395 bool is_guest_view_hack_; |
| 414 | 396 |
| 415 base::MessageLoopForUI message_loop_; | 397 base::MessageLoopForUI message_loop_; |
| 416 BrowserThreadImpl browser_thread_for_ui_; | 398 BrowserThreadImpl browser_thread_for_ui_; |
| 417 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 399 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 418 scoped_ptr<BrowserContext> browser_context_; | 400 scoped_ptr<BrowserContext> browser_context_; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 } | 573 } |
| 592 | 574 |
| 593 // Inject synthetic GestureFlingStart events. | 575 // Inject synthetic GestureFlingStart events. |
| 594 void SimulateGestureFlingStartEvent(float velocityX, | 576 void SimulateGestureFlingStartEvent(float velocityX, |
| 595 float velocityY, | 577 float velocityY, |
| 596 blink::WebGestureDevice sourceDevice) { | 578 blink::WebGestureDevice sourceDevice) { |
| 597 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( | 579 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( |
| 598 velocityX, velocityY, sourceDevice)); | 580 velocityX, velocityY, sourceDevice)); |
| 599 } | 581 } |
| 600 | 582 |
| 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 |
| 601 bool ScrollStateIsContentScrolling() const { | 592 bool ScrollStateIsContentScrolling() const { |
| 602 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; | 593 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; |
| 603 } | 594 } |
| 604 | 595 |
| 605 bool ScrollStateIsOverscrolling() const { | 596 bool ScrollStateIsOverscrolling() const { |
| 606 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; | 597 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; |
| 607 } | 598 } |
| 608 | 599 |
| 609 bool ScrollStateIsUnknown() const { | 600 bool ScrollStateIsUnknown() const { |
| 610 return scroll_state() == OverscrollController::STATE_UNKNOWN; | 601 return scroll_state() == OverscrollController::STATE_UNKNOWN; |
| (...skipping 2462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3073 | 3064 |
| 3074 const NativeWebKeyboardEvent* event = delegate_.last_event(); | 3065 const NativeWebKeyboardEvent* event = delegate_.last_event(); |
| 3075 EXPECT_NE(nullptr, event); | 3066 EXPECT_NE(nullptr, event); |
| 3076 if (event) { | 3067 if (event) { |
| 3077 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); | 3068 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); |
| 3078 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), | 3069 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), |
| 3079 event->nativeKeyCode); | 3070 event->nativeKeyCode); |
| 3080 } | 3071 } |
| 3081 } | 3072 } |
| 3082 | 3073 |
| 3083 TEST_F(RenderWidgetHostViewAuraTest, SetCanScrollForWebMouseWheelEvent) { | |
| 3084 view_->InitAsChild(NULL); | |
| 3085 view_->Show(); | |
| 3086 | |
| 3087 sink_->ClearMessages(); | |
| 3088 | |
| 3089 // Simulates the mouse wheel event with ctrl modifier applied. | |
| 3090 ui::MouseWheelEvent event(gfx::Vector2d(1, 1), | |
| 3091 gfx::Point(), gfx::Point(), | |
| 3092 ui::EF_CONTROL_DOWN, 0); | |
| 3093 view_->OnMouseEvent(&event); | |
| 3094 | |
| 3095 const WebInputEvent* input_event = | |
| 3096 GetInputEventFromMessage(*sink_->GetMessageAt(0)); | |
| 3097 const WebMouseWheelEvent* wheel_event = | |
| 3098 static_cast<const WebMouseWheelEvent*>(input_event); | |
| 3099 // Check if the canScroll set to false when ctrl-scroll is generated from | |
| 3100 // mouse wheel event. | |
| 3101 EXPECT_FALSE(wheel_event->canScroll); | |
| 3102 sink_->ClearMessages(); | |
| 3103 | |
| 3104 // Ack'ing the outstanding event should flush the pending event queue. | |
| 3105 SendInputEventACK(blink::WebInputEvent::MouseWheel, | |
| 3106 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 3107 | |
| 3108 // Simulates the mouse wheel event with no modifier applied. | |
| 3109 event = ui::MouseWheelEvent(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(), | |
| 3110 ui::EF_NONE, 0); | |
| 3111 | |
| 3112 view_->OnMouseEvent(&event); | |
| 3113 | |
| 3114 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0)); | |
| 3115 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 3116 // Check if the canScroll set to true when no modifier is applied to the | |
| 3117 // mouse wheel event. | |
| 3118 EXPECT_TRUE(wheel_event->canScroll); | |
| 3119 sink_->ClearMessages(); | |
| 3120 | |
| 3121 SendInputEventACK(blink::WebInputEvent::MouseWheel, | |
| 3122 INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 3123 | |
| 3124 // Simulates the scroll event with ctrl modifier applied. | |
| 3125 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::Point(2, 2), ui::EventTimeForNow(), | |
| 3126 ui::EF_CONTROL_DOWN, 0, 5, 0, 5, 2); | |
| 3127 view_->OnScrollEvent(&scroll); | |
| 3128 | |
| 3129 input_event = GetInputEventFromMessage(*sink_->GetMessageAt(0)); | |
| 3130 wheel_event = static_cast<const WebMouseWheelEvent*>(input_event); | |
| 3131 // Check if the canScroll set to true when ctrl-touchpad-scroll is generated | |
| 3132 // from scroll event. | |
| 3133 EXPECT_TRUE(wheel_event->canScroll); | |
| 3134 } | |
| 3135 | |
| 3136 } // namespace content | 3074 } // namespace content |
| OLD | NEW |