| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 int gesture_event_type() const { return gesture_event_type_; } | 238 int gesture_event_type() const { return gesture_event_type_; } |
| 239 InputEventAckState ack_result() const { return ack_result_; } | 239 InputEventAckState ack_result() const { return ack_result_; } |
| 240 | 240 |
| 241 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { | 241 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { |
| 242 use_fake_physical_backing_size_ = true; | 242 use_fake_physical_backing_size_ = true; |
| 243 mock_physical_backing_size_ = mock_physical_backing_size; | 243 mock_physical_backing_size_ = mock_physical_backing_size; |
| 244 } | 244 } |
| 245 void ClearMockPhysicalBackingSize() { | 245 void ClearMockPhysicalBackingSize() { |
| 246 use_fake_physical_backing_size_ = false; | 246 use_fake_physical_backing_size_ = false; |
| 247 } | 247 } |
| 248 void SetScreenInfo(const blink::WebScreenInfo& screen_info) { |
| 249 screen_info_ = screen_info; |
| 250 } |
| 248 | 251 |
| 249 // RenderWidgetHostView override. | 252 // RenderWidgetHostView override. |
| 250 gfx::Rect GetViewBounds() const override { return bounds_; } | 253 gfx::Rect GetViewBounds() const override { return bounds_; } |
| 251 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, | 254 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, |
| 252 InputEventAckState ack_result) override { | 255 InputEventAckState ack_result) override { |
| 253 acked_event_ = touch.event; | 256 acked_event_ = touch.event; |
| 254 ++acked_event_count_; | 257 ++acked_event_count_; |
| 255 } | 258 } |
| 256 void WheelEventAck(const WebMouseWheelEvent& event, | 259 void WheelEventAck(const WebMouseWheelEvent& event, |
| 257 InputEventAckState ack_result) override { | 260 InputEventAckState ack_result) override { |
| 258 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 261 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 259 return; | 262 return; |
| 260 unhandled_wheel_event_count_++; | 263 unhandled_wheel_event_count_++; |
| 261 unhandled_wheel_event_ = event; | 264 unhandled_wheel_event_ = event; |
| 262 } | 265 } |
| 263 void GestureEventAck(const WebGestureEvent& event, | 266 void GestureEventAck(const WebGestureEvent& event, |
| 264 InputEventAckState ack_result) override { | 267 InputEventAckState ack_result) override { |
| 265 gesture_event_type_ = event.type; | 268 gesture_event_type_ = event.type; |
| 266 ack_result_ = ack_result; | 269 ack_result_ = ack_result; |
| 267 } | 270 } |
| 268 gfx::Size GetPhysicalBackingSize() const override { | 271 gfx::Size GetPhysicalBackingSize() const override { |
| 269 if (use_fake_physical_backing_size_) | 272 if (use_fake_physical_backing_size_) |
| 270 return mock_physical_backing_size_; | 273 return mock_physical_backing_size_; |
| 271 return TestRenderWidgetHostView::GetPhysicalBackingSize(); | 274 return TestRenderWidgetHostView::GetPhysicalBackingSize(); |
| 272 } | 275 } |
| 276 void GetScreenInfo(blink::WebScreenInfo* screen_info) override { |
| 277 *screen_info = screen_info_; |
| 278 } |
| 273 #if defined(USE_AURA) | 279 #if defined(USE_AURA) |
| 274 ~TestView() override { | 280 ~TestView() override { |
| 275 // Simulate the mouse exit event dispatched when an aura window is | 281 // Simulate the mouse exit event dispatched when an aura window is |
| 276 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED | 282 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED |
| 277 // into WebInputEvent::MouseMove.) | 283 // into WebInputEvent::MouseMove.) |
| 278 rwh_->input_router()->SendMouseEvent( | 284 rwh_->input_router()->SendMouseEvent( |
| 279 MouseEventWithLatencyInfo( | 285 MouseEventWithLatencyInfo( |
| 280 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove), | 286 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove), |
| 281 ui::LatencyInfo())); | 287 ui::LatencyInfo())); |
| 282 } | 288 } |
| 283 #endif | 289 #endif |
| 284 | 290 |
| 285 protected: | 291 protected: |
| 286 WebMouseWheelEvent unhandled_wheel_event_; | 292 WebMouseWheelEvent unhandled_wheel_event_; |
| 287 int unhandled_wheel_event_count_; | 293 int unhandled_wheel_event_count_; |
| 288 WebTouchEvent acked_event_; | 294 WebTouchEvent acked_event_; |
| 289 int acked_event_count_; | 295 int acked_event_count_; |
| 290 int gesture_event_type_; | 296 int gesture_event_type_; |
| 291 gfx::Rect bounds_; | 297 gfx::Rect bounds_; |
| 292 bool use_fake_physical_backing_size_; | 298 bool use_fake_physical_backing_size_; |
| 293 gfx::Size mock_physical_backing_size_; | 299 gfx::Size mock_physical_backing_size_; |
| 294 InputEventAckState ack_result_; | 300 InputEventAckState ack_result_; |
| 301 blink::WebScreenInfo screen_info_; |
| 295 | 302 |
| 296 DISALLOW_COPY_AND_ASSIGN(TestView); | 303 DISALLOW_COPY_AND_ASSIGN(TestView); |
| 297 }; | 304 }; |
| 298 | 305 |
| 299 // MockRenderWidgetHostDelegate -------------------------------------------- | 306 // MockRenderWidgetHostDelegate -------------------------------------------- |
| 300 | 307 |
| 301 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 308 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
| 302 public: | 309 public: |
| 303 MockRenderWidgetHostDelegate() | 310 MockRenderWidgetHostDelegate() |
| 304 : prehandle_keyboard_event_(false), | 311 : prehandle_keyboard_event_(false), |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 class RenderWidgetHostWithSourceTest | 604 class RenderWidgetHostWithSourceTest |
| 598 : public RenderWidgetHostTest, | 605 : public RenderWidgetHostTest, |
| 599 public testing::WithParamInterface<WebGestureDevice> {}; | 606 public testing::WithParamInterface<WebGestureDevice> {}; |
| 600 #endif // GTEST_HAS_PARAM_TEST | 607 #endif // GTEST_HAS_PARAM_TEST |
| 601 | 608 |
| 602 } // namespace | 609 } // namespace |
| 603 | 610 |
| 604 // ----------------------------------------------------------------------------- | 611 // ----------------------------------------------------------------------------- |
| 605 | 612 |
| 606 TEST_F(RenderWidgetHostTest, Resize) { | 613 TEST_F(RenderWidgetHostTest, Resize) { |
| 607 // The initial bounds is the empty rect, and the screen info hasn't been sent | 614 // The initial bounds is the empty rect, so setting it to the same thing |
| 608 // yet, so setting it to the same thing shouldn't send the resize message. | 615 // shouldn't send the resize message. |
| 609 view_->set_bounds(gfx::Rect()); | 616 view_->set_bounds(gfx::Rect()); |
| 610 host_->WasResized(); | 617 host_->WasResized(); |
| 611 EXPECT_FALSE(host_->resize_ack_pending_); | 618 EXPECT_FALSE(host_->resize_ack_pending_); |
| 612 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 619 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 613 | 620 |
| 614 // No resize ack if the physical backing gets set, but the view bounds are | 621 // No resize ack if the physical backing gets set, but the view bounds are |
| 615 // zero. | 622 // zero. |
| 616 view_->SetMockPhysicalBackingSize(gfx::Size(200, 200)); | 623 view_->SetMockPhysicalBackingSize(gfx::Size(200, 200)); |
| 617 host_->WasResized(); | 624 host_->WasResized(); |
| 618 EXPECT_FALSE(host_->resize_ack_pending_); | 625 EXPECT_FALSE(host_->resize_ack_pending_); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); | 719 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); |
| 713 | 720 |
| 714 // A different size should be sent again, however. | 721 // A different size should be sent again, however. |
| 715 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); | 722 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); |
| 716 host_->WasResized(); | 723 host_->WasResized(); |
| 717 EXPECT_FALSE(host_->resize_ack_pending_); | 724 EXPECT_FALSE(host_->resize_ack_pending_); |
| 718 EXPECT_EQ(gfx::Size(0, 31), host_->old_resize_params_->new_size); | 725 EXPECT_EQ(gfx::Size(0, 31), host_->old_resize_params_->new_size); |
| 719 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 726 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 720 } | 727 } |
| 721 | 728 |
| 729 // Test that a resize event is sent if WasResized() is called after a |
| 730 // WebScreenInfo change. |
| 731 TEST_F(RenderWidgetHostTest, ResizeScreenInfo) { |
| 732 blink::WebScreenInfo screen_info; |
| 733 screen_info.deviceScaleFactor = 1.f; |
| 734 screen_info.rect = blink::WebRect(0, 0, 800, 600); |
| 735 screen_info.availableRect = blink::WebRect(0, 0, 800, 600); |
| 736 screen_info.orientationAngle = 0; |
| 737 screen_info.orientationType = blink::WebScreenOrientationPortraitPrimary; |
| 738 |
| 739 view_->SetScreenInfo(screen_info); |
| 740 host_->WasResized(); |
| 741 EXPECT_FALSE(host_->resize_ack_pending_); |
| 742 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 743 process_->sink().ClearMessages(); |
| 744 |
| 745 screen_info.orientationAngle = 180; |
| 746 screen_info.orientationType = blink::WebScreenOrientationLandscapePrimary; |
| 747 |
| 748 view_->SetScreenInfo(screen_info); |
| 749 host_->WasResized(); |
| 750 EXPECT_FALSE(host_->resize_ack_pending_); |
| 751 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 752 process_->sink().ClearMessages(); |
| 753 |
| 754 screen_info.deviceScaleFactor = 2.f; |
| 755 |
| 756 view_->SetScreenInfo(screen_info); |
| 757 host_->WasResized(); |
| 758 EXPECT_FALSE(host_->resize_ack_pending_); |
| 759 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 760 process_->sink().ClearMessages(); |
| 761 |
| 762 // No screen change. |
| 763 view_->SetScreenInfo(screen_info); |
| 764 host_->WasResized(); |
| 765 EXPECT_FALSE(host_->resize_ack_pending_); |
| 766 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 767 } |
| 768 |
| 722 // Test for crbug.com/25097. If a renderer crashes between a resize and the | 769 // Test for crbug.com/25097. If a renderer crashes between a resize and the |
| 723 // corresponding update message, we must be sure to clear the resize ack logic. | 770 // corresponding update message, we must be sure to clear the resize ack logic. |
| 724 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { | 771 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { |
| 725 // Clear the first Resize message that carried screen info. | 772 // Clear the first Resize message that carried screen info. |
| 726 process_->sink().ClearMessages(); | 773 process_->sink().ClearMessages(); |
| 727 | 774 |
| 728 // Setting the bounds to a "real" rect should send out the notification. | 775 // Setting the bounds to a "real" rect should send out the notification. |
| 729 gfx::Rect original_size(0, 0, 100, 100); | 776 gfx::Rect original_size(0, 0, 100, 100); |
| 730 view_->set_bounds(original_size); | 777 view_->set_bounds(original_size); |
| 731 host_->WasResized(); | 778 host_->WasResized(); |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 // Having an initial size set means that the size information had been sent | 1540 // Having an initial size set means that the size information had been sent |
| 1494 // with the reqiest to new up the RenderView and so subsequent WasResized | 1541 // with the reqiest to new up the RenderView and so subsequent WasResized |
| 1495 // calls should not result in new IPC (unless the size has actually changed). | 1542 // calls should not result in new IPC (unless the size has actually changed). |
| 1496 host_->WasResized(); | 1543 host_->WasResized(); |
| 1497 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1544 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 1498 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1545 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
| 1499 EXPECT_TRUE(host_->resize_ack_pending_); | 1546 EXPECT_TRUE(host_->resize_ack_pending_); |
| 1500 } | 1547 } |
| 1501 | 1548 |
| 1502 } // namespace content | 1549 } // namespace content |
| OLD | NEW |