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
3 // found in the LICENSE file.
5 #include "content/common/view_messages.h"
6 #include "content/public/test/render_widget_test.h"
7 #include "content/renderer/render_widget.h"
11 TEST_F(RenderWidgetTest
, OnResize
) {
12 // The initial bounds is empty, so setting it to the same thing should do
14 ViewMsg_Resize_Params resize_params
;
15 resize_params
.screen_info
= blink::WebScreenInfo();
16 resize_params
.new_size
= gfx::Size();
17 resize_params
.physical_backing_size
= gfx::Size();
18 resize_params
.top_controls_height
= 0.f
;
19 resize_params
.top_controls_shrink_blink_size
= false;
20 resize_params
.resizer_rect
= gfx::Rect();
21 resize_params
.is_fullscreen_granted
= false;
22 resize_params
.needs_resize_ack
= false;
23 OnResize(resize_params
);
24 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
26 // Setting empty physical backing size should not send the ack.
27 resize_params
.new_size
= gfx::Size(10, 10);
28 OnResize(resize_params
);
29 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
31 // Setting the bounds to a "real" rect should send the ack.
32 render_thread_
->sink().ClearMessages();
33 gfx::Size
size(100, 100);
34 resize_params
.new_size
= size
;
35 resize_params
.physical_backing_size
= size
;
36 resize_params
.needs_resize_ack
= true;
37 OnResize(resize_params
);
38 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
41 widget()->DidCompleteSwapBuffers();
43 // Setting the same size again should not send the ack.
44 resize_params
.needs_resize_ack
= false;
45 OnResize(resize_params
);
46 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
48 // Resetting the rect to empty should not send the ack.
49 resize_params
.new_size
= gfx::Size();
50 resize_params
.physical_backing_size
= gfx::Size();
51 OnResize(resize_params
);
52 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
54 // Changing the screen info should not send the ack.
55 resize_params
.screen_info
.orientationAngle
= 90;
56 OnResize(resize_params
);
57 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
59 resize_params
.screen_info
.orientationType
=
60 blink::WebScreenOrientationPortraitPrimary
;
61 OnResize(resize_params
);
62 EXPECT_EQ(resize_params
.needs_resize_ack
, next_paint_is_resize_ack());
65 class RenderWidgetInitialSizeTest
: public RenderWidgetTest
{
67 RenderWidgetInitialSizeTest()
68 : RenderWidgetTest(), initial_size_(200, 100) {}
71 scoped_ptr
<ViewMsg_Resize_Params
> InitialSizeParams() override
{
72 scoped_ptr
<ViewMsg_Resize_Params
> initial_size_params(
73 new ViewMsg_Resize_Params());
74 initial_size_params
->new_size
= initial_size_
;
75 initial_size_params
->physical_backing_size
= initial_size_
;
76 initial_size_params
->needs_resize_ack
= true;
77 return initial_size_params
.Pass();
80 gfx::Size initial_size_
;
83 TEST_F(RenderWidgetInitialSizeTest
, InitialSize
) {
84 EXPECT_EQ(initial_size_
, widget()->size());
85 EXPECT_EQ(initial_size_
, gfx::Size(widget()->webwidget()->size()));
86 EXPECT_TRUE(next_paint_is_resize_ack());
90 } // namespace content