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 "extensions/browser/api/system_display/display_info_provider.h"
7 #include "ash/ash_switches.h"
8 #include "ash/content/display/screen_orientation_controller_chromeos.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/display/window_tree_host_manager.h"
11 #include "ash/screen_util.h"
12 #include "ash/shell.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/display_manager_test_api.h"
15 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
16 #include "base/command_line.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
19 #include "extensions/common/api/system_display.h"
20 #include "ui/gfx/display.h"
21 #include "ui/gfx/geometry/rect.h"
23 namespace extensions
{
26 class DisplayInfoProviderChromeosTest
: public ash::test::AshTestBase
{
28 DisplayInfoProviderChromeosTest() {}
30 ~DisplayInfoProviderChromeosTest() override
{}
32 void SetUp() override
{
33 base::CommandLine::ForCurrentProcess()->AppendSwitch(
34 ash::switches::kAshUseFirstDisplayAsInternal
);
35 ash::test::AshTestBase::SetUp();
39 void CallSetDisplayUnitInfo(
40 const std::string
& display_id
,
41 const api::system_display::DisplayProperties
& info
,
44 // Reset error messsage.
46 *success
= DisplayInfoProvider::Get()->SetInfo(display_id
, info
, error
);
49 bool DisplayExists(int64 display_id
) const {
50 const gfx::Display
& display
=
51 GetDisplayManager()->GetDisplayForId(display_id
);
52 return display
.id() != gfx::Display::kInvalidDisplayID
;
55 ash::DisplayManager
* GetDisplayManager() const {
56 return ash::Shell::GetInstance()->display_manager();
59 ash::WindowTreeHostManager
* GetWindowTreeHostManager() const {
60 return ash::Shell::GetInstance()->window_tree_host_manager();
63 std::string
SystemInfoDisplayInsetsToString(
64 const api::system_display::Insets
& insets
) const {
65 // Order to match gfx::Insets::ToString().
66 return base::StringPrintf(
67 "%d,%d,%d,%d", insets
.top
, insets
.left
, insets
.bottom
, insets
.right
);
70 std::string
SystemInfoDisplayBoundsToString(
71 const api::system_display::Bounds
& bounds
) const {
72 // Order to match gfx::Rect::ToString().
73 return base::StringPrintf(
74 "%d,%d %dx%d", bounds
.left
, bounds
.top
, bounds
.width
, bounds
.height
);
78 DISALLOW_COPY_AND_ASSIGN(DisplayInfoProviderChromeosTest
);
81 TEST_F(DisplayInfoProviderChromeosTest
, GetBasic
) {
82 UpdateDisplay("500x600,400x520");
83 DisplayInfo result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
85 ASSERT_EQ(2u, result
.size());
88 ASSERT_TRUE(base::StringToInt64(result
[0]->id
, &display_id
))
89 << "Display id must be convertable to integer: " << result
[0]->id
;
91 ASSERT_TRUE(DisplayExists(display_id
)) << display_id
<< " not found";
92 EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
93 EXPECT_EQ("0,0,0,0", SystemInfoDisplayInsetsToString(result
[0]->overscan
));
94 EXPECT_EQ(0, result
[0]->rotation
);
95 EXPECT_TRUE(result
[0]->is_primary
);
96 EXPECT_EQ(96, result
[0]->dpi_x
);
97 EXPECT_EQ(96, result
[0]->dpi_y
);
98 EXPECT_TRUE(result
[0]->mirroring_source_id
.empty());
99 EXPECT_TRUE(result
[0]->is_enabled
);
101 ASSERT_TRUE(base::StringToInt64(result
[1]->id
, &display_id
))
102 << "Display id must be convertable to integer: " << result
[0]->id
;
104 ASSERT_TRUE(DisplayExists(display_id
)) << display_id
<< " not found";
105 EXPECT_EQ(GetDisplayManager()->GetDisplayNameForId(display_id
),
107 // The second display is positioned left of the primary display, whose width
109 EXPECT_EQ("500,0 400x520",
110 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
111 EXPECT_EQ("0,0,0,0", SystemInfoDisplayInsetsToString(result
[1]->overscan
));
112 EXPECT_EQ(0, result
[1]->rotation
);
113 EXPECT_FALSE(result
[1]->is_primary
);
114 EXPECT_EQ(96, result
[1]->dpi_x
);
115 EXPECT_EQ(96, result
[1]->dpi_y
);
116 EXPECT_TRUE(result
[1]->mirroring_source_id
.empty());
117 EXPECT_TRUE(result
[1]->is_enabled
);
120 TEST_F(DisplayInfoProviderChromeosTest
, GetRotation
) {
121 UpdateDisplay("500x600/r");
122 DisplayInfo result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
124 ASSERT_EQ(1u, result
.size());
127 ASSERT_TRUE(base::StringToInt64(result
[0]->id
, &display_id
))
128 << "Display id must be convertable to integer: " << result
[0]->id
;
130 ASSERT_TRUE(DisplayExists(display_id
)) << display_id
<< " not found";
131 EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
132 EXPECT_EQ(90, result
[0]->rotation
);
134 GetDisplayManager()->SetDisplayRotation(display_id
, gfx::Display::ROTATE_270
,
135 gfx::Display::ROTATION_SOURCE_ACTIVE
);
137 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
139 ASSERT_EQ(1u, result
.size());
141 EXPECT_EQ(base::Int64ToString(display_id
), result
[0]->id
);
142 EXPECT_EQ("0,0 600x500", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
143 EXPECT_EQ(270, result
[0]->rotation
);
145 GetDisplayManager()->SetDisplayRotation(display_id
, gfx::Display::ROTATE_180
,
146 gfx::Display::ROTATION_SOURCE_ACTIVE
);
148 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
150 ASSERT_EQ(1u, result
.size());
152 EXPECT_EQ(base::Int64ToString(display_id
), result
[0]->id
);
153 EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
154 EXPECT_EQ(180, result
[0]->rotation
);
156 GetDisplayManager()->SetDisplayRotation(display_id
, gfx::Display::ROTATE_0
,
157 gfx::Display::ROTATION_SOURCE_ACTIVE
);
159 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
161 ASSERT_EQ(1u, result
.size());
163 EXPECT_EQ(base::Int64ToString(display_id
), result
[0]->id
);
164 EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
165 EXPECT_EQ(0, result
[0]->rotation
);
168 TEST_F(DisplayInfoProviderChromeosTest
, GetHiDPI
) {
169 UpdateDisplay("500x600,400x520*2");
171 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
173 ASSERT_EQ(2u, result
.size());
175 EXPECT_EQ("0,0 500x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
176 EXPECT_EQ(96, result
[0]->dpi_x
);
177 EXPECT_EQ(96, result
[0]->dpi_y
);
179 EXPECT_EQ("500,0 200x260",
180 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
181 EXPECT_EQ(2 * 96, result
[1]->dpi_x
);
182 EXPECT_EQ(2 * 96, result
[1]->dpi_y
);
184 GetWindowTreeHostManager()->SwapPrimaryDisplay();
186 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
188 ASSERT_EQ(2u, result
.size());
190 EXPECT_EQ("-500,0 500x600",
191 SystemInfoDisplayBoundsToString(result
[0]->bounds
));
192 EXPECT_EQ(96, result
[0]->dpi_x
);
193 EXPECT_EQ(96, result
[0]->dpi_y
);
195 EXPECT_EQ("0,0 200x260", SystemInfoDisplayBoundsToString(result
[1]->bounds
));
196 EXPECT_EQ(2 * 96, result
[1]->dpi_x
);
197 EXPECT_EQ(2 * 96, result
[1]->dpi_y
);
200 TEST_F(DisplayInfoProviderChromeosTest
, GetVisibleArea
) {
201 UpdateDisplay("640x720*2/o, 400x520/o");
203 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
205 ASSERT_EQ(2u, result
.size());
208 ASSERT_TRUE(base::StringToInt64(result
[1]->id
, &display_id
))
209 << "Display id must be convertable to integer: " << result
[1]->id
;
210 ASSERT_TRUE(DisplayExists(display_id
)) << display_id
<< " not found";
212 // Default overscan is 5%.
213 EXPECT_EQ("304,0 380x494",
214 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
215 EXPECT_EQ("13,10,13,10",
216 SystemInfoDisplayInsetsToString(result
[1]->overscan
));
218 GetDisplayManager()->SetOverscanInsets(display_id
,
219 gfx::Insets(20, 30, 50, 60));
220 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
222 ASSERT_EQ(2u, result
.size());
224 EXPECT_EQ(base::Int64ToString(display_id
), result
[1]->id
);
225 EXPECT_EQ("304,0 310x450",
226 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
227 EXPECT_EQ("20,30,50,60",
228 SystemInfoDisplayInsetsToString(result
[1]->overscan
));
230 // Set insets for the primary screen. Note that it has 2x scale.
231 ASSERT_TRUE(base::StringToInt64(result
[0]->id
, &display_id
))
232 << "Display id must be convertable to integer: " << result
[0]->id
;
233 ASSERT_TRUE(DisplayExists(display_id
)) << display_id
<< " not found";
235 EXPECT_EQ("0,0 304x342", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
236 EXPECT_EQ("9,8,9,8", SystemInfoDisplayInsetsToString(result
[0]->overscan
));
238 GetDisplayManager()->SetOverscanInsets(display_id
,
239 gfx::Insets(10, 20, 30, 40));
240 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
242 ASSERT_EQ(2u, result
.size());
244 EXPECT_EQ(base::Int64ToString(display_id
), result
[0]->id
);
245 EXPECT_EQ("0,0 260x320", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
246 EXPECT_EQ("10,20,30,40",
247 SystemInfoDisplayInsetsToString(result
[0]->overscan
));
250 TEST_F(DisplayInfoProviderChromeosTest
, GetMirroring
) {
251 UpdateDisplay("600x600, 400x520/o");
253 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
255 ASSERT_EQ(2u, result
.size());
257 int64 display_id_primary
;
258 ASSERT_TRUE(base::StringToInt64(result
[0]->id
, &display_id_primary
))
259 << "Display id must be convertable to integer: " << result
[0]->id
;
260 ASSERT_TRUE(DisplayExists(display_id_primary
)) << display_id_primary
263 int64 display_id_secondary
;
264 ASSERT_TRUE(base::StringToInt64(result
[1]->id
, &display_id_secondary
))
265 << "Display id must be convertable to integer: " << result
[1]->id
;
266 ASSERT_TRUE(DisplayExists(display_id_secondary
)) << display_id_secondary
269 ASSERT_FALSE(GetDisplayManager()->IsInMirrorMode());
270 EXPECT_TRUE(result
[0]->mirroring_source_id
.empty());
271 EXPECT_TRUE(result
[1]->mirroring_source_id
.empty());
273 GetDisplayManager()->SetMirrorMode(true);
274 ASSERT_TRUE(GetDisplayManager()->IsInMirrorMode());
276 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
278 ASSERT_EQ(1u, result
.size());
279 EXPECT_EQ(base::Int64ToString(display_id_primary
), result
[0]->id
);
280 EXPECT_EQ(base::Int64ToString(display_id_secondary
),
281 result
[0]->mirroring_source_id
);
283 GetDisplayManager()->SetMirrorMode(false);
284 ASSERT_FALSE(GetDisplayManager()->IsInMirrorMode());
286 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
288 ASSERT_EQ(2u, result
.size());
289 EXPECT_EQ(base::Int64ToString(display_id_primary
), result
[0]->id
);
290 EXPECT_TRUE(result
[0]->mirroring_source_id
.empty());
291 EXPECT_EQ(base::Int64ToString(display_id_secondary
), result
[1]->id
);
292 EXPECT_TRUE(result
[1]->mirroring_source_id
.empty());
295 TEST_F(DisplayInfoProviderChromeosTest
, GetBounds
) {
296 UpdateDisplay("600x600, 400x520");
297 GetDisplayManager()->SetLayoutForCurrentDisplays(
298 ash::DisplayLayout::FromInts(ash::DisplayLayout::LEFT
, -40));
300 DisplayInfo result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
302 ASSERT_EQ(2u, result
.size());
303 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
304 EXPECT_EQ("-400,-40 400x520",
305 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
307 GetDisplayManager()->SetLayoutForCurrentDisplays(
308 ash::DisplayLayout::FromInts(ash::DisplayLayout::TOP
, 40));
310 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
312 ASSERT_EQ(2u, result
.size());
313 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
314 EXPECT_EQ("40,-520 400x520",
315 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
317 GetDisplayManager()->SetLayoutForCurrentDisplays(
318 ash::DisplayLayout::FromInts(ash::DisplayLayout::BOTTOM
, 80));
320 result
= DisplayInfoProvider::Get()->GetAllDisplaysInfo();
321 ASSERT_EQ(2u, result
.size());
322 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result
[0]->bounds
));
323 EXPECT_EQ("80,600 400x520",
324 SystemInfoDisplayBoundsToString(result
[1]->bounds
));
327 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginLeftExact
) {
328 UpdateDisplay("1200x600,520x400");
330 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
331 api::system_display::DisplayProperties info
;
332 info
.bounds_origin_x
.reset(new int(-520));
333 info
.bounds_origin_y
.reset(new int(50));
335 bool success
= false;
337 CallSetDisplayUnitInfo(
338 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
340 ASSERT_TRUE(success
);
341 ASSERT_TRUE(error
.empty());
343 EXPECT_EQ("-520,50 520x400", secondary
.bounds().ToString());
346 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginRightExact
) {
347 UpdateDisplay("1200x600,520x400");
349 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
350 api::system_display::DisplayProperties info
;
351 info
.bounds_origin_x
.reset(new int(1200));
352 info
.bounds_origin_y
.reset(new int(100));
354 bool success
= false;
356 CallSetDisplayUnitInfo(
357 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
359 ASSERT_TRUE(success
);
360 ASSERT_TRUE(error
.empty());
362 EXPECT_EQ("1200,100 520x400", secondary
.bounds().ToString());
365 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginTopExact
) {
366 UpdateDisplay("1200x600,520x400");
368 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
369 api::system_display::DisplayProperties info
;
370 info
.bounds_origin_x
.reset(new int(1100));
371 info
.bounds_origin_y
.reset(new int(-400));
373 bool success
= false;
375 CallSetDisplayUnitInfo(
376 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
378 ASSERT_TRUE(success
);
379 ASSERT_TRUE(error
.empty());
381 EXPECT_EQ("1100,-400 520x400", secondary
.bounds().ToString());
384 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginBottomExact
) {
385 UpdateDisplay("1200x600,520x400");
387 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
388 api::system_display::DisplayProperties info
;
389 info
.bounds_origin_x
.reset(new int(-350));
390 info
.bounds_origin_y
.reset(new int(600));
392 bool success
= false;
394 CallSetDisplayUnitInfo(
395 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
397 ASSERT_TRUE(success
);
398 ASSERT_TRUE(error
.empty());
400 EXPECT_EQ("-350,600 520x400", secondary
.bounds().ToString());
403 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginSameCenter
) {
404 UpdateDisplay("1200x600,520x400");
406 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
407 api::system_display::DisplayProperties info
;
408 info
.bounds_origin_x
.reset(new int(340));
409 info
.bounds_origin_y
.reset(new int(100));
411 bool success
= false;
413 CallSetDisplayUnitInfo(
414 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
416 ASSERT_TRUE(success
);
417 ASSERT_TRUE(error
.empty());
419 EXPECT_EQ("1200,100 520x400", secondary
.bounds().ToString());
422 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginLeftOutside
) {
423 UpdateDisplay("1200x600,520x400");
425 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
426 api::system_display::DisplayProperties info
;
427 info
.bounds_origin_x
.reset(new int(-1040));
428 info
.bounds_origin_y
.reset(new int(100));
430 bool success
= false;
432 CallSetDisplayUnitInfo(
433 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
435 ASSERT_TRUE(success
);
436 ASSERT_TRUE(error
.empty());
438 EXPECT_EQ("-520,100 520x400", secondary
.bounds().ToString());
441 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginTopOutside
) {
442 UpdateDisplay("1200x600,520x400");
444 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
445 api::system_display::DisplayProperties info
;
446 info
.bounds_origin_x
.reset(new int(-360));
447 info
.bounds_origin_y
.reset(new int(-301));
449 bool success
= false;
451 CallSetDisplayUnitInfo(
452 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
454 ASSERT_TRUE(success
);
455 ASSERT_TRUE(error
.empty());
457 EXPECT_EQ("-360,-400 520x400", secondary
.bounds().ToString());
460 TEST_F(DisplayInfoProviderChromeosTest
,
461 SetBoundsOriginLeftButSharesBottomSide
) {
462 UpdateDisplay("1200x600,1000x100");
464 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
465 api::system_display::DisplayProperties info
;
466 info
.bounds_origin_x
.reset(new int(-650));
467 info
.bounds_origin_y
.reset(new int(700));
469 bool success
= false;
471 CallSetDisplayUnitInfo(
472 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
474 ASSERT_TRUE(success
);
475 ASSERT_TRUE(error
.empty());
477 EXPECT_EQ("-650,600 1000x100", secondary
.bounds().ToString());
480 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginRightButSharesTopSide
) {
481 UpdateDisplay("1200x600,1000x100");
483 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
484 api::system_display::DisplayProperties info
;
485 info
.bounds_origin_x
.reset(new int(850));
486 info
.bounds_origin_y
.reset(new int(-150));
488 bool success
= false;
490 CallSetDisplayUnitInfo(
491 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
493 ASSERT_TRUE(success
);
494 ASSERT_TRUE(error
.empty());
496 EXPECT_EQ("850,-100 1000x100", secondary
.bounds().ToString());
499 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginTopButSharesLeftSide
) {
500 UpdateDisplay("1200x600,1000x100/l");
502 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
503 api::system_display::DisplayProperties info
;
504 info
.bounds_origin_x
.reset(new int(-150));
505 info
.bounds_origin_y
.reset(new int(-650));
507 bool success
= false;
509 CallSetDisplayUnitInfo(
510 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
512 ASSERT_TRUE(success
);
513 ASSERT_TRUE(error
.empty());
515 EXPECT_EQ("-100,-650 100x1000", secondary
.bounds().ToString());
518 TEST_F(DisplayInfoProviderChromeosTest
,
519 SetBoundsOriginBottomButSharesRightSide
) {
520 UpdateDisplay("1200x600,1000x100/l");
522 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
523 api::system_display::DisplayProperties info
;
524 info
.bounds_origin_x
.reset(new int(1350));
525 info
.bounds_origin_y
.reset(new int(450));
527 bool success
= false;
529 CallSetDisplayUnitInfo(
530 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
532 ASSERT_TRUE(success
);
533 ASSERT_TRUE(error
.empty());
535 EXPECT_EQ("1200,450 100x1000", secondary
.bounds().ToString());
538 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginPrimaryHiDPI
) {
539 UpdateDisplay("1200x600*2,500x500");
541 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
542 api::system_display::DisplayProperties info
;
543 info
.bounds_origin_x
.reset(new int(250));
544 info
.bounds_origin_y
.reset(new int(-100));
546 bool success
= false;
548 CallSetDisplayUnitInfo(
549 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
551 ASSERT_TRUE(success
);
552 ASSERT_TRUE(error
.empty());
554 EXPECT_EQ("600,-100 500x500", secondary
.bounds().ToString());
557 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginSecondaryHiDPI
) {
558 UpdateDisplay("1200x600,600x1000*2");
560 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
561 api::system_display::DisplayProperties info
;
562 info
.bounds_origin_x
.reset(new int(450));
563 info
.bounds_origin_y
.reset(new int(-100));
565 bool success
= false;
567 CallSetDisplayUnitInfo(
568 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
570 ASSERT_TRUE(success
);
571 ASSERT_TRUE(error
.empty());
573 EXPECT_EQ("450,-500 300x500", secondary
.bounds().ToString());
576 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginOutOfBounds
) {
577 UpdateDisplay("1200x600,600x1000*2");
579 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
580 api::system_display::DisplayProperties info
;
581 info
.bounds_origin_x
.reset(new int(0x200001));
582 info
.bounds_origin_y
.reset(new int(-100));
584 bool success
= false;
586 CallSetDisplayUnitInfo(
587 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
589 ASSERT_FALSE(success
);
590 ASSERT_EQ("Bounds origin x out of bounds.", error
);
592 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
595 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginOutOfBoundsNegative
) {
596 UpdateDisplay("1200x600,600x1000*2");
598 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
599 api::system_display::DisplayProperties info
;
600 info
.bounds_origin_x
.reset(new int(300));
601 info
.bounds_origin_y
.reset(new int(-0x200001));
603 bool success
= false;
605 CallSetDisplayUnitInfo(
606 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
608 ASSERT_FALSE(success
);
609 ASSERT_EQ("Bounds origin y out of bounds.", error
);
611 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
614 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginMaxValues
) {
615 UpdateDisplay("1200x4600,600x1000*2");
617 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
618 api::system_display::DisplayProperties info
;
619 info
.bounds_origin_x
.reset(new int(200000));
620 info
.bounds_origin_y
.reset(new int(10));
622 bool success
= false;
624 CallSetDisplayUnitInfo(
625 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
627 ASSERT_TRUE(success
);
628 EXPECT_TRUE(error
.empty());
630 EXPECT_EQ("1200,10 300x500", secondary
.bounds().ToString());
633 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginOnPrimary
) {
634 UpdateDisplay("1200x600,600x1000*2");
636 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
637 api::system_display::DisplayProperties info
;
638 info
.bounds_origin_x
.reset(new int(300));
639 info
.is_primary
.reset(new bool(true));
641 bool success
= false;
643 CallSetDisplayUnitInfo(
644 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
646 ASSERT_FALSE(success
);
647 ASSERT_EQ("Bounds origin not allowed for the primary display.", error
);
649 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
650 // The operation failed because the primary property would be set before
651 // setting bounds. The primary display shouldn't have been changed, though.
652 EXPECT_NE(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary
.id());
655 TEST_F(DisplayInfoProviderChromeosTest
, SetBoundsOriginWithMirroring
) {
656 UpdateDisplay("1200x600,600x1000*2");
658 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
659 const gfx::Display
& primary
= ash::Shell::GetScreen()->GetPrimaryDisplay();
661 api::system_display::DisplayProperties info
;
662 info
.bounds_origin_x
.reset(new int(300));
663 info
.mirroring_source_id
.reset(
664 new std::string(base::Int64ToString(primary
.id())));
666 bool success
= false;
668 CallSetDisplayUnitInfo(
669 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
671 ASSERT_FALSE(success
);
672 ASSERT_EQ("No other parameter should be set alongside mirroringSourceId.",
676 TEST_F(DisplayInfoProviderChromeosTest
, SetRotation
) {
677 UpdateDisplay("1200x600,600x1000*2");
679 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
680 api::system_display::DisplayProperties info
;
681 info
.rotation
.reset(new int(90));
683 bool success
= false;
685 CallSetDisplayUnitInfo(
686 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
688 ASSERT_TRUE(success
);
689 EXPECT_TRUE(error
.empty());
691 EXPECT_EQ("1200,0 500x300", secondary
.bounds().ToString());
692 EXPECT_EQ(gfx::Display::ROTATE_90
, secondary
.rotation());
694 info
.rotation
.reset(new int(270));
695 CallSetDisplayUnitInfo(
696 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
698 ASSERT_TRUE(success
);
699 EXPECT_TRUE(error
.empty());
701 EXPECT_EQ("1200,0 500x300", secondary
.bounds().ToString());
702 EXPECT_EQ(gfx::Display::ROTATE_270
, secondary
.rotation());
704 info
.rotation
.reset(new int(180));
705 // Switch primary display.
706 info
.is_primary
.reset(new bool(true));
707 CallSetDisplayUnitInfo(
708 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
710 ASSERT_TRUE(success
);
711 EXPECT_TRUE(error
.empty());
713 EXPECT_EQ("0,0 300x500", secondary
.bounds().ToString());
714 EXPECT_EQ(gfx::Display::ROTATE_180
, secondary
.rotation());
715 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary
.id());
717 info
.rotation
.reset(new int(0));
718 CallSetDisplayUnitInfo(
719 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
721 ASSERT_TRUE(success
);
722 EXPECT_TRUE(error
.empty());
724 EXPECT_EQ("0,0 300x500", secondary
.bounds().ToString());
725 EXPECT_EQ(gfx::Display::ROTATE_0
, secondary
.rotation());
726 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary
.id());
729 // Tests that rotation changes made before entering maximize mode are restored
730 // upon exiting maximize mode, and that a rotation lock is not set.
731 TEST_F(DisplayInfoProviderChromeosTest
, SetRotationBeforeMaximizeMode
) {
732 ash::ScreenOrientationController
* screen_orientation_controller
=
733 ash::Shell::GetInstance()->screen_orientation_controller();
734 api::system_display::DisplayProperties info
;
735 info
.rotation
.reset(new int(90));
737 bool success
= false;
739 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()),
740 info
, &success
, &error
);
742 ASSERT_TRUE(success
);
743 EXPECT_TRUE(error
.empty());
744 EXPECT_FALSE(screen_orientation_controller
->rotation_locked());
746 // Entering maximize mode enables accelerometer screen rotations.
747 ash::Shell::GetInstance()
748 ->maximize_mode_controller()
749 ->EnableMaximizeModeWindowManager(true);
750 // Rotation lock should not activate because DisplayInfoProvider::SetInfo()
751 // was called when not in maximize mode.
752 EXPECT_FALSE(screen_orientation_controller
->rotation_locked());
754 // ScreenOrientationController rotations override display info.
755 screen_orientation_controller
->SetDisplayRotation(
756 gfx::Display::ROTATE_0
, gfx::Display::ROTATION_SOURCE_ACTIVE
);
757 EXPECT_EQ(gfx::Display::ROTATE_0
, GetCurrentInternalDisplayRotation());
759 // Exiting maximize mode should restore the initial rotation
760 ash::Shell::GetInstance()
761 ->maximize_mode_controller()
762 ->EnableMaximizeModeWindowManager(false);
763 EXPECT_EQ(gfx::Display::ROTATE_90
, GetCurrentInternalDisplayRotation());
766 // Tests that rotation changes made during maximize mode lock the display
767 // against accelerometer rotations.
768 TEST_F(DisplayInfoProviderChromeosTest
, SetRotationDuringMaximizeMode
) {
769 // Entering maximize mode enables accelerometer screen rotations.
770 ash::Shell::GetInstance()
771 ->maximize_mode_controller()
772 ->EnableMaximizeModeWindowManager(true);
774 ASSERT_FALSE(ash::Shell::GetInstance()
775 ->screen_orientation_controller()
776 ->rotation_locked());
778 api::system_display::DisplayProperties info
;
779 info
.rotation
.reset(new int(90));
781 bool success
= false;
783 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()),
784 info
, &success
, &error
);
786 ASSERT_TRUE(success
);
787 EXPECT_TRUE(error
.empty());
788 EXPECT_TRUE(ash::Shell::GetInstance()
789 ->screen_orientation_controller()
790 ->rotation_locked());
793 TEST_F(DisplayInfoProviderChromeosTest
, SetInvalidRotation
) {
794 UpdateDisplay("1200x600,600x1000*2");
796 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
797 api::system_display::DisplayProperties info
;
798 info
.rotation
.reset(new int(91));
800 bool success
= false;
802 CallSetDisplayUnitInfo(
803 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
805 ASSERT_FALSE(success
);
806 EXPECT_EQ("Invalid rotation.", error
);
809 TEST_F(DisplayInfoProviderChromeosTest
, SetNegativeOverscan
) {
810 UpdateDisplay("1200x600,600x1000*2");
812 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
813 api::system_display::DisplayProperties info
;
814 info
.overscan
.reset(new api::system_display::Insets
);
815 info
.overscan
->left
= -10;
817 bool success
= false;
819 CallSetDisplayUnitInfo(
820 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
822 ASSERT_FALSE(success
);
823 EXPECT_EQ("Negative overscan not allowed.", error
);
825 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
827 info
.overscan
->left
= 0;
828 info
.overscan
->right
= -200;
830 CallSetDisplayUnitInfo(
831 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
833 ASSERT_FALSE(success
);
834 EXPECT_EQ("Negative overscan not allowed.", error
);
836 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
838 info
.overscan
->right
= 0;
839 info
.overscan
->top
= -300;
841 CallSetDisplayUnitInfo(
842 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
844 ASSERT_FALSE(success
);
845 EXPECT_EQ("Negative overscan not allowed.", error
);
847 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
849 info
.overscan
->right
= 0;
850 info
.overscan
->top
= -1000;
852 CallSetDisplayUnitInfo(
853 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
855 ASSERT_FALSE(success
);
856 EXPECT_EQ("Negative overscan not allowed.", error
);
858 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
860 info
.overscan
->right
= 0;
861 info
.overscan
->top
= 0;
863 CallSetDisplayUnitInfo(
864 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
866 ASSERT_TRUE(success
);
867 EXPECT_TRUE(error
.empty());
869 EXPECT_EQ("1200,0 300x500", secondary
.bounds().ToString());
872 TEST_F(DisplayInfoProviderChromeosTest
, SetOverscanLargerThanHorizontalBounds
) {
873 UpdateDisplay("1200x600,600x1000*2");
875 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
876 api::system_display::DisplayProperties info
;
877 info
.overscan
.reset(new api::system_display::Insets
);
878 // Horizontal overscan is 151, which would make the bounds width 149.
879 info
.overscan
->left
= 50;
880 info
.overscan
->top
= 10;
881 info
.overscan
->right
= 101;
882 info
.overscan
->bottom
= 20;
884 bool success
= false;
886 CallSetDisplayUnitInfo(
887 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
889 ASSERT_FALSE(success
);
890 EXPECT_EQ("Horizontal overscan is more than half of the screen width.",
894 TEST_F(DisplayInfoProviderChromeosTest
, SetOverscanLargerThanVerticalBounds
) {
895 UpdateDisplay("1200x600,600x1000");
897 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
898 api::system_display::DisplayProperties info
;
899 info
.overscan
.reset(new api::system_display::Insets
);
900 // Vertical overscan is 501, which would make the bounds height 499.
901 info
.overscan
->left
= 20;
902 info
.overscan
->top
= 250;
903 info
.overscan
->right
= 101;
904 info
.overscan
->bottom
= 251;
906 bool success
= false;
908 CallSetDisplayUnitInfo(
909 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
911 ASSERT_FALSE(success
);
912 EXPECT_EQ("Vertical overscan is more than half of the screen height.", error
);
915 TEST_F(DisplayInfoProviderChromeosTest
, SetOverscan
) {
916 UpdateDisplay("1200x600,600x1000*2");
918 const gfx::Display
& secondary
= ash::ScreenUtil::GetSecondaryDisplay();
919 api::system_display::DisplayProperties info
;
920 info
.overscan
.reset(new api::system_display::Insets
);
921 info
.overscan
->left
= 20;
922 info
.overscan
->top
= 199;
923 info
.overscan
->right
= 130;
924 info
.overscan
->bottom
= 51;
926 bool success
= false;
928 CallSetDisplayUnitInfo(
929 base::Int64ToString(secondary
.id()), info
, &success
, &error
);
931 ASSERT_TRUE(success
);
932 EXPECT_TRUE(error
.empty());
934 EXPECT_EQ("1200,0 150x250", secondary
.bounds().ToString());
935 const gfx::Insets overscan
=
936 GetDisplayManager()->GetOverscanInsets(secondary
.id());
938 EXPECT_EQ(20, overscan
.left());
939 EXPECT_EQ(199, overscan
.top());
940 EXPECT_EQ(130, overscan
.right());
941 EXPECT_EQ(51, overscan
.bottom());
944 TEST_F(DisplayInfoProviderChromeosTest
, SetOverscanForInternal
) {
945 UpdateDisplay("1200x600,600x1000*2");
946 const int64 internal_display_id
=
947 ash::test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
949 api::system_display::DisplayProperties info
;
950 info
.overscan
.reset(new api::system_display::Insets
);
951 // Vertical overscan is 501, which would make the bounds height 499.
952 info
.overscan
->left
= 20;
953 info
.overscan
->top
= 20;
954 info
.overscan
->right
= 20;
955 info
.overscan
->bottom
= 20;
957 bool success
= false;
959 CallSetDisplayUnitInfo(
960 base::Int64ToString(internal_display_id
), info
, &success
, &error
);
962 ASSERT_FALSE(success
);
963 EXPECT_EQ("Overscan changes not allowed for the internal monitor.", error
);
967 } // namespace extensions