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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 | 947 |
948 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, | 948 EXPECT_CALL(observer, OnWindowPaintScheduled(view_->window_, |
949 gfx::Rect(5, 5, 5, 5))); | 949 gfx::Rect(5, 5, 5, 5))); |
950 view_->OnSwapCompositorFrame( | 950 view_->OnSwapCompositorFrame( |
951 0, MakeDelegatedFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); | 951 0, MakeDelegatedFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5))); |
952 testing::Mock::VerifyAndClearExpectations(&observer); | 952 testing::Mock::VerifyAndClearExpectations(&observer); |
953 | 953 |
954 view_->window_->RemoveObserver(&observer); | 954 view_->window_->RemoveObserver(&observer); |
955 } | 955 } |
956 | 956 |
| 957 TEST_F(RenderWidgetHostViewAuraTest, Resize) { |
| 958 gfx::Size size1(100, 100); |
| 959 gfx::Size size2(200, 200); |
| 960 gfx::Size size3(300, 300); |
| 961 |
| 962 aura::Window* root_window = parent_view_->GetNativeView()->GetRootWindow(); |
| 963 view_->InitAsChild(NULL); |
| 964 aura::client::ParentWindowWithContext( |
| 965 view_->GetNativeView(), root_window, gfx::Rect(size1)); |
| 966 view_->WasShown(); |
| 967 view_->SetSize(size1); |
| 968 view_->OnSwapCompositorFrame( |
| 969 0, MakeDelegatedFrame(1.f, size1, gfx::Rect(size1))); |
| 970 ui::DrawWaiterForTest::WaitForCommit( |
| 971 root_window->GetHost()->compositor()); |
| 972 ViewHostMsg_UpdateRect_Params update_params; |
| 973 update_params.view_size = size1; |
| 974 update_params.scale_factor = 1.f; |
| 975 update_params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
| 976 widget_host_->OnMessageReceived( |
| 977 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params)); |
| 978 sink_->ClearMessages(); |
| 979 // Resize logic is idle (no pending resize, no pending commit). |
| 980 EXPECT_EQ(size1.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 981 |
| 982 // Resize renderer, should produce a Resize message |
| 983 view_->SetSize(size2); |
| 984 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 985 EXPECT_EQ(1u, sink_->message_count()); |
| 986 { |
| 987 const IPC::Message* msg = sink_->GetMessageAt(0); |
| 988 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
| 989 ViewMsg_Resize::Param params; |
| 990 ViewMsg_Resize::Read(msg, ¶ms); |
| 991 EXPECT_EQ(size2.ToString(), params.a.new_size.ToString()); |
| 992 } |
| 993 // Send resize ack to observe new Resize messages. |
| 994 update_params.view_size = size2; |
| 995 widget_host_->OnMessageReceived( |
| 996 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params)); |
| 997 sink_->ClearMessages(); |
| 998 |
| 999 // Resize renderer again, before receiving a frame. Should not produce a |
| 1000 // Resize message. |
| 1001 view_->SetSize(size3); |
| 1002 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 1003 EXPECT_EQ(0u, sink_->message_count()); |
| 1004 |
| 1005 // Receive a frame of the new size, should be skipped and not produce a Resize |
| 1006 // message. |
| 1007 view_->OnSwapCompositorFrame( |
| 1008 0, MakeDelegatedFrame(1.f, size3, gfx::Rect(size3))); |
| 1009 // Expect the frame ack; |
| 1010 EXPECT_EQ(1u, sink_->message_count()); |
| 1011 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type()); |
| 1012 sink_->ClearMessages(); |
| 1013 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 1014 |
| 1015 // Receive a frame of the correct size, should not be skipped and, and should |
| 1016 // produce a Resize message after the commit. |
| 1017 view_->OnSwapCompositorFrame( |
| 1018 0, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); |
| 1019 // No frame ack yet. |
| 1020 EXPECT_EQ(0u, sink_->message_count()); |
| 1021 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 1022 |
| 1023 // Wait for commit, then we should unlock the compositor and send a Resize |
| 1024 // message (and a frame ack) |
| 1025 ui::DrawWaiterForTest::WaitForCommit( |
| 1026 root_window->GetHost()->compositor()); |
| 1027 EXPECT_EQ(size3.ToString(), view_->GetRequestedRendererSize().ToString()); |
| 1028 EXPECT_EQ(2u, sink_->message_count()); |
| 1029 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type()); |
| 1030 { |
| 1031 const IPC::Message* msg = sink_->GetMessageAt(1); |
| 1032 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); |
| 1033 ViewMsg_Resize::Param params; |
| 1034 ViewMsg_Resize::Read(msg, ¶ms); |
| 1035 EXPECT_EQ(size3.ToString(), params.a.new_size.ToString()); |
| 1036 } |
| 1037 update_params.view_size = size3; |
| 1038 widget_host_->OnMessageReceived( |
| 1039 ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params)); |
| 1040 sink_->ClearMessages(); |
| 1041 } |
| 1042 |
957 // Skipped frames should not drop their damage. | 1043 // Skipped frames should not drop their damage. |
958 TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) { | 1044 TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) { |
959 gfx::Rect view_rect(100, 100); | 1045 gfx::Rect view_rect(100, 100); |
960 gfx::Size frame_size = view_rect.size(); | 1046 gfx::Size frame_size = view_rect.size(); |
961 | 1047 |
962 view_->InitAsChild(NULL); | 1048 view_->InitAsChild(NULL); |
963 aura::client::ParentWindowWithContext( | 1049 aura::client::ParentWindowWithContext( |
964 view_->GetNativeView(), | 1050 view_->GetNativeView(), |
965 parent_view_->GetNativeView()->GetRootWindow(), | 1051 parent_view_->GetNativeView()->GetRootWindow(), |
966 gfx::Rect()); | 1052 gfx::Rect()); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 const IPC::Message *message = sink_->GetFirstMessageMatching( | 1500 const IPC::Message *message = sink_->GetFirstMessageMatching( |
1415 ViewMsg_Resize::ID); | 1501 ViewMsg_Resize::ID); |
1416 ASSERT_TRUE(message != NULL); | 1502 ASSERT_TRUE(message != NULL); |
1417 | 1503 |
1418 ViewMsg_Resize::Param params; | 1504 ViewMsg_Resize::Param params; |
1419 ViewMsg_Resize::Read(message, ¶ms); | 1505 ViewMsg_Resize::Read(message, ¶ms); |
1420 EXPECT_EQ(60, params.a.visible_viewport_size.height()); | 1506 EXPECT_EQ(60, params.a.visible_viewport_size.height()); |
1421 } | 1507 } |
1422 | 1508 |
1423 } // namespace content | 1509 } // namespace content |
OLD | NEW |