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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); | 191 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); |
192 }; | 192 }; |
193 | 193 |
194 namespace { | 194 namespace { |
195 | 195 |
196 // RenderWidgetHostProcess ----------------------------------------------------- | 196 // RenderWidgetHostProcess ----------------------------------------------------- |
197 | 197 |
198 class RenderWidgetHostProcess : public MockRenderProcessHost { | 198 class RenderWidgetHostProcess : public MockRenderProcessHost { |
199 public: | 199 public: |
200 explicit RenderWidgetHostProcess(BrowserContext* browser_context) | 200 explicit RenderWidgetHostProcess(BrowserContext* browser_context) |
201 : MockRenderProcessHost(browser_context), | 201 : MockRenderProcessHost(browser_context) { |
202 update_msg_reply_flags_(0) { | |
203 } | 202 } |
204 ~RenderWidgetHostProcess() override {} | 203 ~RenderWidgetHostProcess() override {} |
205 | 204 |
206 void set_update_msg_reply_flags(int flags) { | |
207 update_msg_reply_flags_ = flags; | |
208 } | |
209 | |
210 // Fills the given update parameters with resonable default values. | |
211 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); | |
212 | |
213 bool HasConnection() const override { return true; } | 205 bool HasConnection() const override { return true; } |
214 | 206 |
215 protected: | 207 protected: |
216 // Indicates the flags that should be sent with a repaint request. This | |
217 // only has an effect when update_msg_should_reply_ is true. | |
218 int update_msg_reply_flags_; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); | 208 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); |
221 }; | 209 }; |
222 | 210 |
223 void RenderWidgetHostProcess::InitUpdateRectParams( | |
224 ViewHostMsg_UpdateRect_Params* params) { | |
225 const int w = 100, h = 100; | |
226 | |
227 params->view_size = gfx::Size(w, h); | |
228 params->flags = update_msg_reply_flags_; | |
229 } | |
230 | |
231 // TestView -------------------------------------------------------------------- | 211 // TestView -------------------------------------------------------------------- |
232 | 212 |
233 // This test view allows us to specify the size, and keep track of acked | 213 // This test view allows us to specify the size, and keep track of acked |
234 // touch-events. | 214 // touch-events. |
235 class TestView : public TestRenderWidgetHostView { | 215 class TestView : public TestRenderWidgetHostView { |
236 public: | 216 public: |
237 explicit TestView(RenderWidgetHostImpl* rwh) | 217 explicit TestView(RenderWidgetHostImpl* rwh) |
238 : TestRenderWidgetHostView(rwh), | 218 : TestRenderWidgetHostView(rwh), |
239 unhandled_wheel_event_count_(0), | 219 unhandled_wheel_event_count_(0), |
240 acked_event_count_(0), | 220 acked_event_count_(0), |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // ----------------------------------------------------------------------------- | 610 // ----------------------------------------------------------------------------- |
631 | 611 |
632 TEST_F(RenderWidgetHostTest, Resize) { | 612 TEST_F(RenderWidgetHostTest, Resize) { |
633 // The initial bounds is the empty rect, and the screen info hasn't been sent | 613 // The initial bounds is the empty rect, and the screen info hasn't been sent |
634 // yet, so setting it to the same thing shouldn't send the resize message. | 614 // yet, so setting it to the same thing shouldn't send the resize message. |
635 view_->set_bounds(gfx::Rect()); | 615 view_->set_bounds(gfx::Rect()); |
636 host_->WasResized(); | 616 host_->WasResized(); |
637 EXPECT_FALSE(host_->resize_ack_pending_); | 617 EXPECT_FALSE(host_->resize_ack_pending_); |
638 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 618 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
639 | 619 |
640 // Setting the bounds to a "real" rect should send out the notification. | 620 // No resize ack if the physical backing gets set, but the view bounds are |
| 621 // zero. |
| 622 view_->SetMockPhysicalBackingSize(gfx::Size(200, 200)); |
| 623 host_->WasResized(); |
| 624 EXPECT_FALSE(host_->resize_ack_pending_); |
| 625 |
| 626 // Setting the view bounds to nonzero should send out the notification. |
641 // but should not expect ack for empty physical backing size. | 627 // but should not expect ack for empty physical backing size. |
642 gfx::Rect original_size(0, 0, 100, 100); | 628 gfx::Rect original_size(0, 0, 100, 100); |
643 process_->sink().ClearMessages(); | 629 process_->sink().ClearMessages(); |
644 view_->set_bounds(original_size); | 630 view_->set_bounds(original_size); |
645 view_->SetMockPhysicalBackingSize(gfx::Size()); | 631 view_->SetMockPhysicalBackingSize(gfx::Size()); |
646 host_->WasResized(); | 632 host_->WasResized(); |
647 EXPECT_FALSE(host_->resize_ack_pending_); | 633 EXPECT_FALSE(host_->resize_ack_pending_); |
648 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size); | 634 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size); |
649 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 635 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
650 | 636 |
651 // Setting the bounds to a "real" rect should send out the notification. | 637 // Setting the bounds and physical backing size to nonzero should send out |
652 // but should not expect ack for only physical backing size change. | 638 // the notification and expect an ack. |
653 process_->sink().ClearMessages(); | 639 process_->sink().ClearMessages(); |
654 view_->ClearMockPhysicalBackingSize(); | 640 view_->ClearMockPhysicalBackingSize(); |
655 host_->WasResized(); | 641 host_->WasResized(); |
656 EXPECT_FALSE(host_->resize_ack_pending_); | 642 EXPECT_TRUE(host_->resize_ack_pending_); |
657 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size); | 643 EXPECT_EQ(original_size.size(), host_->old_resize_params_->new_size); |
658 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 644 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 645 ViewHostMsg_UpdateRect_Params params; |
| 646 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
| 647 params.view_size = original_size.size(); |
| 648 host_->OnUpdateRect(params); |
| 649 EXPECT_FALSE(host_->resize_ack_pending_); |
659 | 650 |
660 // Send out a update that's not a resize ack after setting resize ack pending | 651 // Send out a update that's not a resize ack after setting resize ack pending |
661 // flag. This should not clean the resize ack pending flag. | 652 // flag. This should not clean the resize ack pending flag. |
662 process_->sink().ClearMessages(); | 653 process_->sink().ClearMessages(); |
663 gfx::Rect second_size(0, 0, 110, 110); | 654 gfx::Rect second_size(0, 0, 110, 110); |
664 EXPECT_FALSE(host_->resize_ack_pending_); | 655 EXPECT_FALSE(host_->resize_ack_pending_); |
665 view_->set_bounds(second_size); | 656 view_->set_bounds(second_size); |
666 host_->WasResized(); | 657 host_->WasResized(); |
667 EXPECT_TRUE(host_->resize_ack_pending_); | 658 EXPECT_TRUE(host_->resize_ack_pending_); |
668 ViewHostMsg_UpdateRect_Params params; | 659 params.flags = 0; |
669 process_->InitUpdateRectParams(¶ms); | 660 params.view_size = gfx::Size(100, 100); |
670 host_->OnUpdateRect(params); | 661 host_->OnUpdateRect(params); |
671 EXPECT_TRUE(host_->resize_ack_pending_); | 662 EXPECT_TRUE(host_->resize_ack_pending_); |
672 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size); | 663 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size); |
673 | 664 |
674 // Sending out a new notification should NOT send out a new IPC message since | 665 // Sending out a new notification should NOT send out a new IPC message since |
675 // a resize ACK is pending. | 666 // a resize ACK is pending. |
676 gfx::Rect third_size(0, 0, 120, 120); | 667 gfx::Rect third_size(0, 0, 120, 120); |
677 process_->sink().ClearMessages(); | 668 process_->sink().ClearMessages(); |
678 view_->set_bounds(third_size); | 669 view_->set_bounds(third_size); |
679 host_->WasResized(); | 670 host_->WasResized(); |
680 EXPECT_TRUE(host_->resize_ack_pending_); | 671 EXPECT_TRUE(host_->resize_ack_pending_); |
681 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size); | 672 EXPECT_EQ(second_size.size(), host_->old_resize_params_->new_size); |
682 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 673 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
683 | 674 |
684 // Send a update that's a resize ack, but for the original_size we sent. Since | 675 // Send a update that's a resize ack, but for the original_size we sent. Since |
685 // this isn't the second_size, the message handler should immediately send | 676 // this isn't the second_size, the message handler should immediately send |
686 // a new resize message for the new size to the renderer. | 677 // a new resize message for the new size to the renderer. |
687 process_->sink().ClearMessages(); | 678 process_->sink().ClearMessages(); |
688 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; | 679 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
689 params.view_size = original_size.size(); | 680 params.view_size = original_size.size(); |
690 host_->OnUpdateRect(params); | 681 host_->OnUpdateRect(params); |
691 EXPECT_TRUE(host_->resize_ack_pending_); | 682 EXPECT_TRUE(host_->resize_ack_pending_); |
692 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size); | 683 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size); |
693 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 684 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
694 | 685 |
695 // Send the resize ack for the latest size. | 686 // Send the resize ack for the latest size. |
696 process_->sink().ClearMessages(); | 687 process_->sink().ClearMessages(); |
| 688 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
697 params.view_size = third_size.size(); | 689 params.view_size = third_size.size(); |
698 host_->OnUpdateRect(params); | 690 host_->OnUpdateRect(params); |
699 EXPECT_FALSE(host_->resize_ack_pending_); | 691 EXPECT_FALSE(host_->resize_ack_pending_); |
700 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size); | 692 EXPECT_EQ(third_size.size(), host_->old_resize_params_->new_size); |
701 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); | 693 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); |
702 | 694 |
703 // Now clearing the bounds should send out a notification but we shouldn't | 695 // Now clearing the bounds should send out a notification but we shouldn't |
704 // expect a resize ack (since the renderer won't ack empty sizes). The message | 696 // expect a resize ack (since the renderer won't ack empty sizes). The message |
705 // should contain the new size (0x0) and not the previous one that we skipped | 697 // should contain the new size (0x0) and not the previous one that we skipped |
706 process_->sink().ClearMessages(); | 698 process_->sink().ClearMessages(); |
707 view_->set_bounds(gfx::Rect()); | 699 view_->set_bounds(gfx::Rect()); |
708 host_->WasResized(); | 700 host_->WasResized(); |
709 EXPECT_FALSE(host_->resize_ack_pending_); | 701 EXPECT_FALSE(host_->resize_ack_pending_); |
710 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size); | 702 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size); |
711 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 703 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); | 791 BrowserThreadImpl ui_thread(BrowserThread::UI, base::MessageLoop::current()); |
800 // Hide the widget, it should have sent out a message to the renderer. | 792 // Hide the widget, it should have sent out a message to the renderer. |
801 EXPECT_FALSE(host_->is_hidden_); | 793 EXPECT_FALSE(host_->is_hidden_); |
802 host_->WasHidden(); | 794 host_->WasHidden(); |
803 EXPECT_TRUE(host_->is_hidden_); | 795 EXPECT_TRUE(host_->is_hidden_); |
804 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID)); | 796 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID)); |
805 | 797 |
806 // Send it an update as from the renderer. | 798 // Send it an update as from the renderer. |
807 process_->sink().ClearMessages(); | 799 process_->sink().ClearMessages(); |
808 ViewHostMsg_UpdateRect_Params params; | 800 ViewHostMsg_UpdateRect_Params params; |
809 process_->InitUpdateRectParams(¶ms); | 801 params.view_size = gfx::Size(100, 100); |
810 host_->OnUpdateRect(params); | 802 host_->OnUpdateRect(params); |
811 | 803 |
812 // Now unhide. | 804 // Now unhide. |
813 process_->sink().ClearMessages(); | 805 process_->sink().ClearMessages(); |
814 host_->WasShown(ui::LatencyInfo()); | 806 host_->WasShown(ui::LatencyInfo()); |
815 EXPECT_FALSE(host_->is_hidden_); | 807 EXPECT_FALSE(host_->is_hidden_); |
816 | 808 |
817 // It should have sent out a restored message with a request to paint. | 809 // It should have sent out a restored message with a request to paint. |
818 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( | 810 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( |
819 ViewMsg_WasShown::ID); | 811 ViewMsg_WasShown::ID); |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 // Having an initial size set means that the size information had been sent | 1461 // Having an initial size set means that the size information had been sent |
1470 // with the reqiest to new up the RenderView and so subsequent WasResized | 1462 // with the reqiest to new up the RenderView and so subsequent WasResized |
1471 // calls should not result in new IPC (unless the size has actually changed). | 1463 // calls should not result in new IPC (unless the size has actually changed). |
1472 host_->WasResized(); | 1464 host_->WasResized(); |
1473 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1465 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
1474 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1466 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
1475 EXPECT_TRUE(host_->resize_ack_pending_); | 1467 EXPECT_TRUE(host_->resize_ack_pending_); |
1476 } | 1468 } |
1477 | 1469 |
1478 } // namespace content | 1470 } // namespace content |
OLD | NEW |