1// Copyright (c) 2013 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.
4
5#include "ash/display/display_info.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace ash {
10namespace {
11
12std::string GetModeSizeInDIP(const gfx::Size& size,
13                             float device_scale_factor,
14                             float ui_scale) {
15  DisplayMode mode;
16  mode.size = size;
17  mode.device_scale_factor = device_scale_factor;
18  mode.ui_scale = ui_scale;
19  return mode.GetSizeInDIP().ToString();
20}
21
22}  // namespace
23
24typedef testing::Test DisplayInfoTest;
25
26TEST_F(DisplayInfoTest, CreateFromSpec) {
27  DisplayInfo info = DisplayInfo::CreateFromSpecWithID("200x100", 10);
28  EXPECT_EQ(10, info.id());
29  EXPECT_EQ("0,0 200x100", info.bounds_in_native().ToString());
30  EXPECT_EQ("200x100", info.size_in_pixel().ToString());
31  EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
32  EXPECT_EQ("0,0,0,0", info.overscan_insets_in_dip().ToString());
33  EXPECT_EQ(1.0f, info.configured_ui_scale());
34
35  info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/o", 10);
36  EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
37  EXPECT_EQ("288x380", info.size_in_pixel().ToString());
38  EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
39  EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
40
41  info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/ob", 10);
42  EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
43  EXPECT_EQ("288x380", info.size_in_pixel().ToString());
44  EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
45  EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
46
47  info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/or", 10);
48  EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
49  EXPECT_EQ("380x288", info.size_in_pixel().ToString());
50  EXPECT_EQ(gfx::Display::ROTATE_90, info.rotation());
51  // TODO(oshima): This should be rotated too. Fix this.
52  EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
53
54  info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/l@1.5", 10);
55  EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
56  EXPECT_EQ(gfx::Display::ROTATE_270, info.rotation());
57  EXPECT_EQ(1.5f, info.configured_ui_scale());
58
59  info = DisplayInfo::CreateFromSpecWithID(
60      "200x200#300x200|200x200%59.9|100x100%60|150x100*2|150x150*1.25%30", 10);
61  EXPECT_EQ("0,0 200x200", info.bounds_in_native().ToString());
62  EXPECT_EQ(5u, info.display_modes().size());
63  EXPECT_EQ("300x200", info.display_modes()[0].size.ToString());
64  EXPECT_EQ("200x200", info.display_modes()[1].size.ToString());
65  EXPECT_EQ("100x100", info.display_modes()[2].size.ToString());
66  EXPECT_EQ("150x100", info.display_modes()[3].size.ToString());
67  EXPECT_EQ("150x150", info.display_modes()[4].size.ToString());
68  EXPECT_EQ(59.9f, info.display_modes()[1].refresh_rate);
69  EXPECT_EQ(60.0f, info.display_modes()[2].refresh_rate);
70  EXPECT_EQ(30.0f, info.display_modes()[4].refresh_rate);
71  EXPECT_EQ(1.0f, info.display_modes()[0].device_scale_factor);
72  EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor);
73  EXPECT_EQ(1.0f, info.display_modes()[2].device_scale_factor);
74  EXPECT_EQ(2.0f, info.display_modes()[3].device_scale_factor);
75  EXPECT_EQ(1.25f, info.display_modes()[4].device_scale_factor);
76  EXPECT_TRUE(info.display_modes()[0].native);
77  EXPECT_FALSE(info.display_modes()[1].native);
78  EXPECT_FALSE(info.display_modes()[2].native);
79  EXPECT_FALSE(info.display_modes()[3].native);
80  EXPECT_FALSE(info.display_modes()[4].native);
81}
82
83TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPNormal) {
84  gfx::Size size(1366, 768);
85  EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.0f, 1.125f));
86  EXPECT_EQ("1366x768", GetModeSizeInDIP(size, 1.0f, 1.0f));
87  EXPECT_EQ("1092x614", GetModeSizeInDIP(size, 1.0f, 0.8f));
88  EXPECT_EQ("853x480", GetModeSizeInDIP(size, 1.0f, 0.625f));
89  EXPECT_EQ("683x384", GetModeSizeInDIP(size, 1.0f, 0.5f));
90}
91
92TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPHiDPI) {
93  gfx::Size size(2560, 1700);
94  EXPECT_EQ("2560x1700", GetModeSizeInDIP(size, 2.0f, 2.0f));
95  EXPECT_EQ("1920x1275", GetModeSizeInDIP(size, 2.0f, 1.5f));
96  EXPECT_EQ("1600x1062", GetModeSizeInDIP(size, 2.0f, 1.25f));
97  EXPECT_EQ("1440x956", GetModeSizeInDIP(size, 2.0f, 1.125f));
98  EXPECT_EQ("1280x850", GetModeSizeInDIP(size, 2.0f, 1.0f));
99  EXPECT_EQ("1024x680", GetModeSizeInDIP(size, 2.0f, 0.8f));
100  EXPECT_EQ("800x531", GetModeSizeInDIP(size, 2.0f, 0.625f));
101  EXPECT_EQ("640x425", GetModeSizeInDIP(size, 2.0f, 0.5f));
102}
103
104TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIP125) {
105  DisplayInfo::SetUse125DSFForUIScaling(true);
106  gfx::Size size(1920, 1080);
107  EXPECT_EQ("2400x1350", GetModeSizeInDIP(size, 1.25f, 1.25));
108  EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 1.25f, 1.0f));
109  EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.25f, 0.8f));
110  EXPECT_EQ("1200x675", GetModeSizeInDIP(size, 1.25f, 0.625f));
111  EXPECT_EQ("960x540", GetModeSizeInDIP(size, 1.25f, 0.5f));
112  DisplayInfo::SetUse125DSFForUIScaling(false);
113}
114
115}  // namespace ash
116