File: managed_display_info_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (178 lines) | stat: -rw-r--r-- 8,454 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/display/manager/managed_display_info.h"

#include "base/test/gtest_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display_switches.h"
#include "ui/display/manager/display_change_observer.h"
#include "ui/display/manager/test/fake_display_snapshot.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/display_color_spaces.h"
#include "ui/gfx/geometry/rounded_corners_f.h"

#include "ui/display/manager/touch_device_manager.h"

namespace display {

using DisplayInfoTest = testing::Test;

TEST_F(DisplayInfoTest, CreateFromSpec) {
  ManagedDisplayInfo info =
      ManagedDisplayInfo::CreateFromSpecWithID("200x100", 10);
  EXPECT_EQ(10, info.id());
  EXPECT_EQ(gfx::Rect(0, 0, 200, 100), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(200, 100), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_0, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  EXPECT_EQ(gfx::Insets(), info.overscan_insets_in_dip());
  EXPECT_EQ(gfx::RoundedCornersF(0.0), info.panel_corners_radii());

  info = ManagedDisplayInfo::CreateFromSpecWithID("10+20-300x400*2/o", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(288, 380), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_0, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  EXPECT_EQ(gfx::Insets::TLBR(5, 3, 5, 3), info.overscan_insets_in_dip());
  EXPECT_EQ(gfx::RoundedCornersF(0.0), info.panel_corners_radii());

  info = ManagedDisplayInfo::CreateFromSpecWithID("10+20-300x400*2/oh", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(288, 380), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_0, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(gfx::ColorSpace::CreateHDR10(),
                                    gfx::BufferFormat::BGRA_1010102),
            info.display_color_spaces());
  EXPECT_EQ(gfx::Insets::TLBR(5, 3, 5, 3), info.overscan_insets_in_dip());

  info = ManagedDisplayInfo::CreateFromSpecWithID("10+20-300x400*2/ob", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(288, 380), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_0, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  EXPECT_EQ(gfx::Insets::TLBR(5, 3, 5, 3), info.overscan_insets_in_dip());

  info = ManagedDisplayInfo::CreateFromSpecWithID("10+20-300x400*2/or", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(380, 288), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_90, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  // TODO(oshima): This should be rotated too. Fix this.
  EXPECT_EQ(gfx::Insets::TLBR(5, 3, 5, 3), info.overscan_insets_in_dip());

  info =
      ManagedDisplayInfo::CreateFromSpecWithID("10+20-300x400*2/or@1.5~16", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(gfx::Size(380, 288), info.size_in_pixel());
  EXPECT_EQ(Display::ROTATE_90, info.GetActiveRotation());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  EXPECT_EQ(gfx::Insets::TLBR(5, 3, 5, 3), info.overscan_insets_in_dip());
  EXPECT_EQ(gfx::Insets::TLBR(10, 6, 10, 6), info.GetOverscanInsetsInPixel());
  EXPECT_EQ(gfx::RoundedCornersF(16.0), info.panel_corners_radii());

  info = ManagedDisplayInfo::CreateFromSpecWithID(
      "10+20-300x400*2/l@1.5~16|16|10|10", 10);
  EXPECT_EQ(gfx::Rect(10, 20, 300, 400), info.bounds_in_native());
  EXPECT_EQ(Display::ROTATE_270, info.GetActiveRotation());
  EXPECT_EQ(1.5f, info.zoom_factor());
  EXPECT_EQ(gfx::DisplayColorSpaces(), info.display_color_spaces());
  EXPECT_EQ(gfx::RoundedCornersF(16.0, 16.0, 10.0, 10.0),
            info.panel_corners_radii());

  info = ManagedDisplayInfo::CreateFromSpecWithID(
      "250x200#300x200|250x200%59.9|150x100%60|150x100*2|200x150*1.25%30", 10);

  EXPECT_EQ(gfx::Rect(0, 0, 250, 200), info.bounds_in_native());
  EXPECT_EQ(5u, info.display_modes().size());
  // Modes are sorted in DIP for external display.
  EXPECT_EQ(gfx::Size(150, 100), info.display_modes()[0].size());
  EXPECT_EQ(gfx::Size(150, 100), info.display_modes()[1].size());
  EXPECT_EQ(gfx::Size(200, 150), info.display_modes()[2].size());
  EXPECT_EQ(gfx::Size(250, 200), info.display_modes()[3].size());
  EXPECT_EQ(gfx::Size(300, 200), info.display_modes()[4].size());

  EXPECT_EQ(60.0f, info.display_modes()[0].refresh_rate());
  EXPECT_EQ(60.0f, info.display_modes()[1].refresh_rate());
  EXPECT_EQ(30.0f, info.display_modes()[2].refresh_rate());
  EXPECT_EQ(59.9f, info.display_modes()[3].refresh_rate());
  EXPECT_EQ(60.0f, info.display_modes()[4].refresh_rate());

  EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  EXPECT_EQ(1.0f, info.display_modes()[1].device_scale_factor());
  EXPECT_EQ(1.25f, info.display_modes()[2].device_scale_factor());
  EXPECT_EQ(1.0f, info.display_modes()[3].device_scale_factor());
  EXPECT_EQ(1.0f, info.display_modes()[4].device_scale_factor());

  EXPECT_FALSE(info.display_modes()[0].native());
  EXPECT_FALSE(info.display_modes()[1].native());
  EXPECT_FALSE(info.display_modes()[2].native());
  EXPECT_FALSE(info.display_modes()[3].native());
  EXPECT_TRUE(info.display_modes()[4].native());

  info = ManagedDisplayInfo::CreateFromSpecWithID(
      "250x200*2#300x200|250x200*1.25|150x100", 10);

  EXPECT_EQ(gfx::Size(150, 100), info.display_modes()[0].size());
  EXPECT_EQ(gfx::Size(300, 200), info.display_modes()[1].size());
  EXPECT_EQ(gfx::Size(250, 200), info.display_modes()[2].size());
  EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  EXPECT_EQ(2.0f, info.display_modes()[1].device_scale_factor());
  EXPECT_EQ(1.25f, info.display_modes()[2].device_scale_factor());

  info = ManagedDisplayInfo::CreateFromSpecWithID(
      "250x200*2#300x200|250x200*1.25|150x100~16|16|10|10", 10);
  EXPECT_EQ(gfx::Size(150, 100), info.display_modes()[0].size());
  EXPECT_EQ(gfx::Size(300, 200), info.display_modes()[1].size());
  EXPECT_EQ(gfx::Size(250, 200), info.display_modes()[2].size());
  EXPECT_EQ(2.0f, info.display_modes()[0].device_scale_factor());
  EXPECT_EQ(2.0f, info.display_modes()[1].device_scale_factor());
  EXPECT_EQ(1.25f, info.display_modes()[2].device_scale_factor());
  EXPECT_EQ(gfx::RoundedCornersF(16.0, 16.0, 10.0, 10.0),
            info.panel_corners_radii());
}

TEST_F(DisplayInfoTest, ExpectDeathWhenInvalidNumberOfRadiiProvided) {
  EXPECT_DCHECK_DEATH(
      ManagedDisplayInfo::CreateFromSpecWithID("200x100~10|15", 10));

  EXPECT_DCHECK_DEATH(
      ManagedDisplayInfo::CreateFromSpecWithID("200x100~10|10|15", 10));
}

TEST_F(DisplayInfoTest, ExpectDeathWhenInvalidDisplayRadiusProvided) {
  EXPECT_DCHECK_DEATH(
      ManagedDisplayInfo::CreateFromSpecWithID("200x100~1f", 10));

  EXPECT_DCHECK_DEATH(
      ManagedDisplayInfo::CreateFromSpecWithID("200x100~10.5", 10));
}

TEST_F(DisplayInfoTest, TestToStringFormat) {
  ManagedDisplayInfo info =
      ManagedDisplayInfo::CreateFromSpecWithID("200x100", 10);

  EXPECT_EQ(info.ToString(),
            "ManagedDisplayInfo[10] port_display_id=10, edid_display_id=20, "
            "native bounds=0,0 200x100, size=200x100, "
            "device-scale=1, display-zoom=1, overscan=x:0,0 y:0,0, rotation=0, "
            "touchscreen=unknown, "
            "panel_corners_radii=0.000000,0.000000,0.000000,0.000000, "
            "panel_orientation=Normal, detected=true, "
            "color_space="
            "{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}");

  EXPECT_EQ(info.ToFullString(),
            "ManagedDisplayInfo[10] port_display_id=10, edid_display_id=20, "
            "native bounds=0,0 200x100, size=200x100, "
            "device-scale=1, display-zoom=1, overscan=x:0,0 y:0,0, rotation=0, "
            "touchscreen=unknown, "
            "panel_corners_radii=0.000000,0.000000,0.000000,0.000000, "
            "panel_orientation=Normal, detected=true, "
            "color_space="
            "{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}, "
            "display_modes==(200x100@60P(N) 1)");
}

}  // namespace display