1 // Copyright 2014 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/browser/renderer_host/render_widget_host_view_base.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
9 #include "ui/gfx/display.h"
15 gfx::Display
CreateDisplay(int width
, int height
, int angle
) {
17 display
.SetRotationAsDegree(angle
);
18 display
.set_bounds(gfx::Rect(width
, height
));
23 } // anonymous namespace
25 TEST(RenderWidgetHostViewBaseTest
, OrientationTypeForMobile
) {
26 // Square display (width == height).
28 gfx::Display display
= CreateDisplay(100, 100, 0);
29 EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary
,
30 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
32 display
= CreateDisplay(200, 200, 90);
33 EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary
,
34 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
36 display
= CreateDisplay(0, 0, 180);
37 EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary
,
38 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
40 display
= CreateDisplay(10000, 10000, 270);
41 EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary
,
42 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
45 // natural width > natural height.
47 gfx::Display display
= CreateDisplay(1, 0, 0);
48 EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary
,
49 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
51 display
= CreateDisplay(19999, 20000, 90);
52 EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary
,
53 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
55 display
= CreateDisplay(200, 100, 180);
56 EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary
,
57 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
59 display
= CreateDisplay(1, 10000, 270);
60 EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary
,
61 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
64 // natural width < natural height.
66 gfx::Display display
= CreateDisplay(0, 1, 0);
67 EXPECT_EQ(blink::WebScreenOrientationPortraitPrimary
,
68 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
70 display
= CreateDisplay(20000, 19999, 90);
71 EXPECT_EQ(blink::WebScreenOrientationLandscapePrimary
,
72 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
74 display
= CreateDisplay(100, 200, 180);
75 EXPECT_EQ(blink::WebScreenOrientationPortraitSecondary
,
76 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
78 display
= CreateDisplay(10000, 1, 270);
79 EXPECT_EQ(blink::WebScreenOrientationLandscapeSecondary
,
80 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display
));
84 TEST(RenderWidgetHostViewBaseTest
, OrientationTypeForDesktop
) {
85 // On Desktop, the primary orientation is the first computed one so a test
86 // similar to OrientationTypeForMobile is not possible.
87 // Instead this test will only check one configuration and verify that the
88 // method reports two landscape and two portrait orientations with one primary
89 // and one secondary for each.
91 // natural width > natural height.
93 gfx::Display display
= CreateDisplay(1, 0, 0);
94 blink::WebScreenOrientationType landscape_1
=
95 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
96 EXPECT_TRUE(landscape_1
== blink::WebScreenOrientationLandscapePrimary
||
97 landscape_1
== blink::WebScreenOrientationLandscapeSecondary
);
99 display
= CreateDisplay(200, 100, 180);
100 blink::WebScreenOrientationType landscape_2
=
101 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
102 EXPECT_TRUE(landscape_2
== blink::WebScreenOrientationLandscapePrimary
||
103 landscape_2
== blink::WebScreenOrientationLandscapeSecondary
);
105 EXPECT_NE(landscape_1
, landscape_2
);
107 display
= CreateDisplay(19999, 20000, 90);
108 blink::WebScreenOrientationType portrait_1
=
109 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
110 EXPECT_TRUE(portrait_1
== blink::WebScreenOrientationPortraitPrimary
||
111 portrait_1
== blink::WebScreenOrientationPortraitSecondary
);
113 display
= CreateDisplay(1, 10000, 270);
114 blink::WebScreenOrientationType portrait_2
=
115 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
116 EXPECT_TRUE(portrait_2
== blink::WebScreenOrientationPortraitPrimary
||
117 portrait_2
== blink::WebScreenOrientationPortraitSecondary
);
119 EXPECT_NE(portrait_1
, portrait_2
);
124 } // namespace content