PermissionRequestCreatorApiary: switch from deprecated "namespace" to "eventType"
[chromium-blink-merge.git] / ash / display / display_info_unittest.cc
blob01362b43ceaa61d679aa39e98548f62593bc6862
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.
5 #include "ash/display/display_info.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace ash {
10 namespace {
12 std::string GetModeSizeInDIP(const gfx::Size& size,
13 float device_scale_factor,
14 float ui_scale,
15 bool is_internal) {
16 DisplayMode mode;
17 mode.size = size;
18 mode.device_scale_factor = device_scale_factor;
19 mode.ui_scale = ui_scale;
20 return mode.GetSizeInDIP(is_internal).ToString();
23 } // namespace
25 typedef testing::Test DisplayInfoTest;
27 TEST_F(DisplayInfoTest, CreateFromSpec) {
28 DisplayInfo info = DisplayInfo::CreateFromSpecWithID("200x100", 10);
29 EXPECT_EQ(10, info.id());
30 EXPECT_EQ("0,0 200x100", info.bounds_in_native().ToString());
31 EXPECT_EQ("200x100", info.size_in_pixel().ToString());
32 EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
33 EXPECT_EQ("0,0,0,0", info.overscan_insets_in_dip().ToString());
34 EXPECT_EQ(1.0f, info.configured_ui_scale());
36 info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/o", 10);
37 EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
38 EXPECT_EQ("288x380", info.size_in_pixel().ToString());
39 EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
40 EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
42 info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/ob", 10);
43 EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
44 EXPECT_EQ("288x380", info.size_in_pixel().ToString());
45 EXPECT_EQ(gfx::Display::ROTATE_0, info.rotation());
46 EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
48 info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/or", 10);
49 EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
50 EXPECT_EQ("380x288", info.size_in_pixel().ToString());
51 EXPECT_EQ(gfx::Display::ROTATE_90, info.rotation());
52 // TODO(oshima): This should be rotated too. Fix this.
53 EXPECT_EQ("5,3,5,3", info.overscan_insets_in_dip().ToString());
55 info = DisplayInfo::CreateFromSpecWithID("10+20-300x400*2/l@1.5", 10);
56 EXPECT_EQ("10,20 300x400", info.bounds_in_native().ToString());
57 EXPECT_EQ(gfx::Display::ROTATE_270, info.rotation());
58 EXPECT_EQ(1.5f, info.configured_ui_scale());
60 info = DisplayInfo::CreateFromSpecWithID(
61 "200x200#300x200|200x200%59.9|100x100%60|150x100*2|150x150*1.25%30", 10);
63 EXPECT_EQ("0,0 200x200", info.bounds_in_native().ToString());
64 EXPECT_EQ(5u, info.display_modes().size());
65 // Modes are sorted in DIP for external display.
66 EXPECT_EQ("150x100", info.display_modes()[0].size.ToString());
67 EXPECT_EQ("100x100", info.display_modes()[1].size.ToString());
68 EXPECT_EQ("150x150", info.display_modes()[2].size.ToString());
69 EXPECT_EQ("200x200", info.display_modes()[3].size.ToString());
70 EXPECT_EQ("300x200", info.display_modes()[4].size.ToString());
72 EXPECT_EQ(0.0f, info.display_modes()[0].refresh_rate);
73 EXPECT_EQ(60.0f, info.display_modes()[1].refresh_rate);
74 EXPECT_EQ(30.0f, info.display_modes()[2].refresh_rate);
75 EXPECT_EQ(59.9f, info.display_modes()[3].refresh_rate);
76 EXPECT_EQ(0.0f, info.display_modes()[4].refresh_rate);
78 EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor);
79 EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor);
80 EXPECT_EQ(1.25f, info.display_modes()[2].device_scale_factor);
81 EXPECT_EQ(1.0f, info.display_modes()[3].device_scale_factor);
82 EXPECT_EQ(1.0f, info.display_modes()[4].device_scale_factor);
84 EXPECT_FALSE(info.display_modes()[0].native);
85 EXPECT_FALSE(info.display_modes()[1].native);
86 EXPECT_FALSE(info.display_modes()[2].native);
87 EXPECT_FALSE(info.display_modes()[3].native);
88 EXPECT_TRUE(info.display_modes()[4].native);
91 TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPNormal) {
92 gfx::Size size(1366, 768);
93 EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.0f, 1.125f, true));
94 EXPECT_EQ("1366x768", GetModeSizeInDIP(size, 1.0f, 1.0f, true));
95 EXPECT_EQ("1092x614", GetModeSizeInDIP(size, 1.0f, 0.8f, true));
96 EXPECT_EQ("853x480", GetModeSizeInDIP(size, 1.0f, 0.625f, true));
97 EXPECT_EQ("683x384", GetModeSizeInDIP(size, 1.0f, 0.5f, true));
100 TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIPHiDPI) {
101 gfx::Size size(2560, 1700);
102 EXPECT_EQ("2560x1700", GetModeSizeInDIP(size, 2.0f, 2.0f, true));
103 EXPECT_EQ("1920x1275", GetModeSizeInDIP(size, 2.0f, 1.5f, true));
104 EXPECT_EQ("1600x1062", GetModeSizeInDIP(size, 2.0f, 1.25f, true));
105 EXPECT_EQ("1440x956", GetModeSizeInDIP(size, 2.0f, 1.125f, true));
106 EXPECT_EQ("1280x850", GetModeSizeInDIP(size, 2.0f, 1.0f, true));
107 EXPECT_EQ("1024x680", GetModeSizeInDIP(size, 2.0f, 0.8f, true));
108 EXPECT_EQ("800x531", GetModeSizeInDIP(size, 2.0f, 0.625f, true));
109 EXPECT_EQ("640x425", GetModeSizeInDIP(size, 2.0f, 0.5f, true));
112 TEST_F(DisplayInfoTest, DisplayModeGetSizeInDIP125) {
113 DisplayInfo::SetUse125DSFForUIScaling(true);
114 gfx::Size size(1920, 1080);
115 EXPECT_EQ("2400x1350", GetModeSizeInDIP(size, 1.25f, 1.25f, true));
116 EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 1.25f, 1.0f, true));
117 EXPECT_EQ("1536x864", GetModeSizeInDIP(size, 1.25f, 0.8f, true));
118 EXPECT_EQ("1200x675", GetModeSizeInDIP(size, 1.25f, 0.625f, true));
119 EXPECT_EQ("960x540", GetModeSizeInDIP(size, 1.25f, 0.5f, true));
120 DisplayInfo::SetUse125DSFForUIScaling(false);
123 TEST_F(DisplayInfoTest, DisplayModeGetSizeForExternal4K) {
124 DisplayInfo::SetUse125DSFForUIScaling(true);
125 gfx::Size size(3840, 2160);
126 EXPECT_EQ("1920x1080", GetModeSizeInDIP(size, 2.0f, 1.0f, false));
127 EXPECT_EQ("3072x1728", GetModeSizeInDIP(size, 1.25f, 1.0f, false));
128 EXPECT_EQ("3840x2160", GetModeSizeInDIP(size, 1.0f, 1.0f, false));
129 DisplayInfo::SetUse125DSFForUIScaling(false);
132 } // namespace ash