Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / display_info_provider_chromeos_unittest.cc
bloba1b71ace90be767d5b7563837aef367f2b90f75a
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 {
24 namespace {
26 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase {
27 public:
28 DisplayInfoProviderChromeosTest() {}
30 ~DisplayInfoProviderChromeosTest() override {}
32 void SetUp() override {
33 base::CommandLine::ForCurrentProcess()->AppendSwitch(
34 ash::switches::kAshUseFirstDisplayAsInternal);
35 ash::test::AshTestBase::SetUp();
38 protected:
39 void CallSetDisplayUnitInfo(
40 const std::string& display_id,
41 const api::system_display::DisplayProperties& info,
42 bool* success,
43 std::string* error) {
44 // Reset error messsage.
45 (*error).clear();
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);
77 private:
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());
87 int64 display_id;
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),
106 result[1]->name);
107 // The second display is positioned left of the primary display, whose width
108 // is 500.
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());
126 int64 display_id;
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, GetDPI) {
169 UpdateDisplay("500x600,400x520*2");
170 DisplayInfo result;
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 // DPI should be 96 (native dpi) * 200 (display) / 400 (native) when ui scale
182 // is 2.
183 EXPECT_EQ(96 / 2, result[1]->dpi_x);
184 EXPECT_EQ(96 / 2, result[1]->dpi_y);
186 GetWindowTreeHostManager()->SwapPrimaryDisplay();
188 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
190 ASSERT_EQ(2u, result.size());
192 EXPECT_EQ("-500,0 500x600",
193 SystemInfoDisplayBoundsToString(result[0]->bounds));
194 EXPECT_EQ(96, result[0]->dpi_x);
195 EXPECT_EQ(96, result[0]->dpi_y);
197 EXPECT_EQ("0,0 200x260", SystemInfoDisplayBoundsToString(result[1]->bounds));
198 EXPECT_EQ(96 / 2, result[1]->dpi_x);
199 EXPECT_EQ(96 / 2, result[1]->dpi_y);
202 TEST_F(DisplayInfoProviderChromeosTest, GetVisibleArea) {
203 UpdateDisplay("640x720*2/o, 400x520/o");
204 DisplayInfo result;
205 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
207 ASSERT_EQ(2u, result.size());
209 int64 display_id;
210 ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id))
211 << "Display id must be convertable to integer: " << result[1]->id;
212 ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
214 // Default overscan is 5%.
215 EXPECT_EQ("304,0 380x494",
216 SystemInfoDisplayBoundsToString(result[1]->bounds));
217 EXPECT_EQ("13,10,13,10",
218 SystemInfoDisplayInsetsToString(result[1]->overscan));
220 GetDisplayManager()->SetOverscanInsets(display_id,
221 gfx::Insets(20, 30, 50, 60));
222 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
224 ASSERT_EQ(2u, result.size());
226 EXPECT_EQ(base::Int64ToString(display_id), result[1]->id);
227 EXPECT_EQ("304,0 310x450",
228 SystemInfoDisplayBoundsToString(result[1]->bounds));
229 EXPECT_EQ("20,30,50,60",
230 SystemInfoDisplayInsetsToString(result[1]->overscan));
232 // Set insets for the primary screen. Note that it has 2x scale.
233 ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id))
234 << "Display id must be convertable to integer: " << result[0]->id;
235 ASSERT_TRUE(DisplayExists(display_id)) << display_id << " not found";
237 EXPECT_EQ("0,0 304x342", SystemInfoDisplayBoundsToString(result[0]->bounds));
238 EXPECT_EQ("9,8,9,8", SystemInfoDisplayInsetsToString(result[0]->overscan));
240 GetDisplayManager()->SetOverscanInsets(display_id,
241 gfx::Insets(10, 20, 30, 40));
242 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
244 ASSERT_EQ(2u, result.size());
246 EXPECT_EQ(base::Int64ToString(display_id), result[0]->id);
247 EXPECT_EQ("0,0 260x320", SystemInfoDisplayBoundsToString(result[0]->bounds));
248 EXPECT_EQ("10,20,30,40",
249 SystemInfoDisplayInsetsToString(result[0]->overscan));
252 TEST_F(DisplayInfoProviderChromeosTest, GetMirroring) {
253 UpdateDisplay("600x600, 400x520/o");
254 DisplayInfo result;
255 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
257 ASSERT_EQ(2u, result.size());
259 int64 display_id_primary;
260 ASSERT_TRUE(base::StringToInt64(result[0]->id, &display_id_primary))
261 << "Display id must be convertable to integer: " << result[0]->id;
262 ASSERT_TRUE(DisplayExists(display_id_primary)) << display_id_primary
263 << " not found";
265 int64 display_id_secondary;
266 ASSERT_TRUE(base::StringToInt64(result[1]->id, &display_id_secondary))
267 << "Display id must be convertable to integer: " << result[1]->id;
268 ASSERT_TRUE(DisplayExists(display_id_secondary)) << display_id_secondary
269 << " not found";
271 ASSERT_FALSE(GetDisplayManager()->IsInMirrorMode());
272 EXPECT_TRUE(result[0]->mirroring_source_id.empty());
273 EXPECT_TRUE(result[1]->mirroring_source_id.empty());
275 GetDisplayManager()->SetMirrorMode(true);
276 ASSERT_TRUE(GetDisplayManager()->IsInMirrorMode());
278 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
280 ASSERT_EQ(1u, result.size());
281 EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id);
282 EXPECT_EQ(base::Int64ToString(display_id_secondary),
283 result[0]->mirroring_source_id);
285 GetDisplayManager()->SetMirrorMode(false);
286 ASSERT_FALSE(GetDisplayManager()->IsInMirrorMode());
288 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
290 ASSERT_EQ(2u, result.size());
291 EXPECT_EQ(base::Int64ToString(display_id_primary), result[0]->id);
292 EXPECT_TRUE(result[0]->mirroring_source_id.empty());
293 EXPECT_EQ(base::Int64ToString(display_id_secondary), result[1]->id);
294 EXPECT_TRUE(result[1]->mirroring_source_id.empty());
297 TEST_F(DisplayInfoProviderChromeosTest, GetBounds) {
298 UpdateDisplay("600x600, 400x520");
299 GetDisplayManager()->SetLayoutForCurrentDisplays(
300 ash::DisplayLayout::FromInts(ash::DisplayLayout::LEFT, -40));
302 DisplayInfo result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
304 ASSERT_EQ(2u, result.size());
305 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds));
306 EXPECT_EQ("-400,-40 400x520",
307 SystemInfoDisplayBoundsToString(result[1]->bounds));
309 GetDisplayManager()->SetLayoutForCurrentDisplays(
310 ash::DisplayLayout::FromInts(ash::DisplayLayout::TOP, 40));
312 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
314 ASSERT_EQ(2u, result.size());
315 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds));
316 EXPECT_EQ("40,-520 400x520",
317 SystemInfoDisplayBoundsToString(result[1]->bounds));
319 GetDisplayManager()->SetLayoutForCurrentDisplays(
320 ash::DisplayLayout::FromInts(ash::DisplayLayout::BOTTOM, 80));
322 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
323 ASSERT_EQ(2u, result.size());
324 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0]->bounds));
325 EXPECT_EQ("80,600 400x520",
326 SystemInfoDisplayBoundsToString(result[1]->bounds));
329 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) {
330 UpdateDisplay("1200x600,520x400");
332 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
333 api::system_display::DisplayProperties info;
334 info.bounds_origin_x.reset(new int(-520));
335 info.bounds_origin_y.reset(new int(50));
337 bool success = false;
338 std::string error;
339 CallSetDisplayUnitInfo(
340 base::Int64ToString(secondary.id()), info, &success, &error);
342 ASSERT_TRUE(success);
343 ASSERT_TRUE(error.empty());
345 EXPECT_EQ("-520,50 520x400", secondary.bounds().ToString());
348 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginRightExact) {
349 UpdateDisplay("1200x600,520x400");
351 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
352 api::system_display::DisplayProperties info;
353 info.bounds_origin_x.reset(new int(1200));
354 info.bounds_origin_y.reset(new int(100));
356 bool success = false;
357 std::string error;
358 CallSetDisplayUnitInfo(
359 base::Int64ToString(secondary.id()), info, &success, &error);
361 ASSERT_TRUE(success);
362 ASSERT_TRUE(error.empty());
364 EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString());
367 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopExact) {
368 UpdateDisplay("1200x600,520x400");
370 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
371 api::system_display::DisplayProperties info;
372 info.bounds_origin_x.reset(new int(1100));
373 info.bounds_origin_y.reset(new int(-400));
375 bool success = false;
376 std::string error;
377 CallSetDisplayUnitInfo(
378 base::Int64ToString(secondary.id()), info, &success, &error);
380 ASSERT_TRUE(success);
381 ASSERT_TRUE(error.empty());
383 EXPECT_EQ("1100,-400 520x400", secondary.bounds().ToString());
386 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginBottomExact) {
387 UpdateDisplay("1200x600,520x400");
389 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
390 api::system_display::DisplayProperties info;
391 info.bounds_origin_x.reset(new int(-350));
392 info.bounds_origin_y.reset(new int(600));
394 bool success = false;
395 std::string error;
396 CallSetDisplayUnitInfo(
397 base::Int64ToString(secondary.id()), info, &success, &error);
399 ASSERT_TRUE(success);
400 ASSERT_TRUE(error.empty());
402 EXPECT_EQ("-350,600 520x400", secondary.bounds().ToString());
405 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSameCenter) {
406 UpdateDisplay("1200x600,520x400");
408 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
409 api::system_display::DisplayProperties info;
410 info.bounds_origin_x.reset(new int(340));
411 info.bounds_origin_y.reset(new int(100));
413 bool success = false;
414 std::string error;
415 CallSetDisplayUnitInfo(
416 base::Int64ToString(secondary.id()), info, &success, &error);
418 ASSERT_TRUE(success);
419 ASSERT_TRUE(error.empty());
421 EXPECT_EQ("1200,100 520x400", secondary.bounds().ToString());
424 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftOutside) {
425 UpdateDisplay("1200x600,520x400");
427 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
428 api::system_display::DisplayProperties info;
429 info.bounds_origin_x.reset(new int(-1040));
430 info.bounds_origin_y.reset(new int(100));
432 bool success = false;
433 std::string error;
434 CallSetDisplayUnitInfo(
435 base::Int64ToString(secondary.id()), info, &success, &error);
437 ASSERT_TRUE(success);
438 ASSERT_TRUE(error.empty());
440 EXPECT_EQ("-520,100 520x400", secondary.bounds().ToString());
443 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopOutside) {
444 UpdateDisplay("1200x600,520x400");
446 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
447 api::system_display::DisplayProperties info;
448 info.bounds_origin_x.reset(new int(-360));
449 info.bounds_origin_y.reset(new int(-301));
451 bool success = false;
452 std::string error;
453 CallSetDisplayUnitInfo(
454 base::Int64ToString(secondary.id()), info, &success, &error);
456 ASSERT_TRUE(success);
457 ASSERT_TRUE(error.empty());
459 EXPECT_EQ("-360,-400 520x400", secondary.bounds().ToString());
462 TEST_F(DisplayInfoProviderChromeosTest,
463 SetBoundsOriginLeftButSharesBottomSide) {
464 UpdateDisplay("1200x600,1000x100");
466 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
467 api::system_display::DisplayProperties info;
468 info.bounds_origin_x.reset(new int(-650));
469 info.bounds_origin_y.reset(new int(700));
471 bool success = false;
472 std::string error;
473 CallSetDisplayUnitInfo(
474 base::Int64ToString(secondary.id()), info, &success, &error);
476 ASSERT_TRUE(success);
477 ASSERT_TRUE(error.empty());
479 EXPECT_EQ("-650,600 1000x100", secondary.bounds().ToString());
482 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginRightButSharesTopSide) {
483 UpdateDisplay("1200x600,1000x100");
485 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
486 api::system_display::DisplayProperties info;
487 info.bounds_origin_x.reset(new int(850));
488 info.bounds_origin_y.reset(new int(-150));
490 bool success = false;
491 std::string error;
492 CallSetDisplayUnitInfo(
493 base::Int64ToString(secondary.id()), info, &success, &error);
495 ASSERT_TRUE(success);
496 ASSERT_TRUE(error.empty());
498 EXPECT_EQ("850,-100 1000x100", secondary.bounds().ToString());
501 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginTopButSharesLeftSide) {
502 UpdateDisplay("1200x600,1000x100/l");
504 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
505 api::system_display::DisplayProperties info;
506 info.bounds_origin_x.reset(new int(-150));
507 info.bounds_origin_y.reset(new int(-650));
509 bool success = false;
510 std::string error;
511 CallSetDisplayUnitInfo(
512 base::Int64ToString(secondary.id()), info, &success, &error);
514 ASSERT_TRUE(success);
515 ASSERT_TRUE(error.empty());
517 EXPECT_EQ("-100,-650 100x1000", secondary.bounds().ToString());
520 TEST_F(DisplayInfoProviderChromeosTest,
521 SetBoundsOriginBottomButSharesRightSide) {
522 UpdateDisplay("1200x600,1000x100/l");
524 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
525 api::system_display::DisplayProperties info;
526 info.bounds_origin_x.reset(new int(1350));
527 info.bounds_origin_y.reset(new int(450));
529 bool success = false;
530 std::string error;
531 CallSetDisplayUnitInfo(
532 base::Int64ToString(secondary.id()), info, &success, &error);
534 ASSERT_TRUE(success);
535 ASSERT_TRUE(error.empty());
537 EXPECT_EQ("1200,450 100x1000", secondary.bounds().ToString());
540 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginPrimaryHiDPI) {
541 UpdateDisplay("1200x600*2,500x500");
543 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
544 api::system_display::DisplayProperties info;
545 info.bounds_origin_x.reset(new int(250));
546 info.bounds_origin_y.reset(new int(-100));
548 bool success = false;
549 std::string error;
550 CallSetDisplayUnitInfo(
551 base::Int64ToString(secondary.id()), info, &success, &error);
553 ASSERT_TRUE(success);
554 ASSERT_TRUE(error.empty());
556 EXPECT_EQ("600,-100 500x500", secondary.bounds().ToString());
559 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginSecondaryHiDPI) {
560 UpdateDisplay("1200x600,600x1000*2");
562 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
563 api::system_display::DisplayProperties info;
564 info.bounds_origin_x.reset(new int(450));
565 info.bounds_origin_y.reset(new int(-100));
567 bool success = false;
568 std::string error;
569 CallSetDisplayUnitInfo(
570 base::Int64ToString(secondary.id()), info, &success, &error);
572 ASSERT_TRUE(success);
573 ASSERT_TRUE(error.empty());
575 EXPECT_EQ("450,-500 300x500", secondary.bounds().ToString());
578 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBounds) {
579 UpdateDisplay("1200x600,600x1000*2");
581 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
582 api::system_display::DisplayProperties info;
583 info.bounds_origin_x.reset(new int(0x200001));
584 info.bounds_origin_y.reset(new int(-100));
586 bool success = false;
587 std::string error;
588 CallSetDisplayUnitInfo(
589 base::Int64ToString(secondary.id()), info, &success, &error);
591 ASSERT_FALSE(success);
592 ASSERT_EQ("Bounds origin x out of bounds.", error);
594 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
597 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOutOfBoundsNegative) {
598 UpdateDisplay("1200x600,600x1000*2");
600 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
601 api::system_display::DisplayProperties info;
602 info.bounds_origin_x.reset(new int(300));
603 info.bounds_origin_y.reset(new int(-0x200001));
605 bool success = false;
606 std::string error;
607 CallSetDisplayUnitInfo(
608 base::Int64ToString(secondary.id()), info, &success, &error);
610 ASSERT_FALSE(success);
611 ASSERT_EQ("Bounds origin y out of bounds.", error);
613 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
616 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginMaxValues) {
617 UpdateDisplay("1200x4600,600x1000*2");
619 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
620 api::system_display::DisplayProperties info;
621 info.bounds_origin_x.reset(new int(200000));
622 info.bounds_origin_y.reset(new int(10));
624 bool success = false;
625 std::string error;
626 CallSetDisplayUnitInfo(
627 base::Int64ToString(secondary.id()), info, &success, &error);
629 ASSERT_TRUE(success);
630 EXPECT_TRUE(error.empty());
632 EXPECT_EQ("1200,10 300x500", secondary.bounds().ToString());
635 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginOnPrimary) {
636 UpdateDisplay("1200x600,600x1000*2");
638 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
639 api::system_display::DisplayProperties info;
640 info.bounds_origin_x.reset(new int(300));
641 info.is_primary.reset(new bool(true));
643 bool success = false;
644 std::string error;
645 CallSetDisplayUnitInfo(
646 base::Int64ToString(secondary.id()), info, &success, &error);
648 ASSERT_FALSE(success);
649 ASSERT_EQ("Bounds origin not allowed for the primary display.", error);
651 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
652 // The operation failed because the primary property would be set before
653 // setting bounds. The primary display shouldn't have been changed, though.
654 EXPECT_NE(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary.id());
657 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginWithMirroring) {
658 UpdateDisplay("1200x600,600x1000*2");
660 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
661 const gfx::Display& primary = ash::Shell::GetScreen()->GetPrimaryDisplay();
663 api::system_display::DisplayProperties info;
664 info.bounds_origin_x.reset(new int(300));
665 info.mirroring_source_id.reset(
666 new std::string(base::Int64ToString(primary.id())));
668 bool success = false;
669 std::string error;
670 CallSetDisplayUnitInfo(
671 base::Int64ToString(secondary.id()), info, &success, &error);
673 ASSERT_FALSE(success);
674 ASSERT_EQ("No other parameter should be set alongside mirroringSourceId.",
675 error);
678 TEST_F(DisplayInfoProviderChromeosTest, SetRotation) {
679 UpdateDisplay("1200x600,600x1000*2");
681 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
682 api::system_display::DisplayProperties info;
683 info.rotation.reset(new int(90));
685 bool success = false;
686 std::string error;
687 CallSetDisplayUnitInfo(
688 base::Int64ToString(secondary.id()), info, &success, &error);
690 ASSERT_TRUE(success);
691 EXPECT_TRUE(error.empty());
693 EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString());
694 EXPECT_EQ(gfx::Display::ROTATE_90, secondary.rotation());
696 info.rotation.reset(new int(270));
697 CallSetDisplayUnitInfo(
698 base::Int64ToString(secondary.id()), info, &success, &error);
700 ASSERT_TRUE(success);
701 EXPECT_TRUE(error.empty());
703 EXPECT_EQ("1200,0 500x300", secondary.bounds().ToString());
704 EXPECT_EQ(gfx::Display::ROTATE_270, secondary.rotation());
706 info.rotation.reset(new int(180));
707 // Switch primary display.
708 info.is_primary.reset(new bool(true));
709 CallSetDisplayUnitInfo(
710 base::Int64ToString(secondary.id()), info, &success, &error);
712 ASSERT_TRUE(success);
713 EXPECT_TRUE(error.empty());
715 EXPECT_EQ("0,0 300x500", secondary.bounds().ToString());
716 EXPECT_EQ(gfx::Display::ROTATE_180, secondary.rotation());
717 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary.id());
719 info.rotation.reset(new int(0));
720 CallSetDisplayUnitInfo(
721 base::Int64ToString(secondary.id()), info, &success, &error);
723 ASSERT_TRUE(success);
724 EXPECT_TRUE(error.empty());
726 EXPECT_EQ("0,0 300x500", secondary.bounds().ToString());
727 EXPECT_EQ(gfx::Display::ROTATE_0, secondary.rotation());
728 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().id(), secondary.id());
731 // Tests that rotation changes made before entering maximize mode are restored
732 // upon exiting maximize mode, and that a rotation lock is not set.
733 TEST_F(DisplayInfoProviderChromeosTest, SetRotationBeforeMaximizeMode) {
734 ash::ScreenOrientationController* screen_orientation_controller =
735 ash::Shell::GetInstance()->screen_orientation_controller();
736 api::system_display::DisplayProperties info;
737 info.rotation.reset(new int(90));
739 bool success = false;
740 std::string error;
741 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()),
742 info, &success, &error);
744 ASSERT_TRUE(success);
745 EXPECT_TRUE(error.empty());
746 EXPECT_FALSE(screen_orientation_controller->rotation_locked());
748 // Entering maximize mode enables accelerometer screen rotations.
749 ash::Shell::GetInstance()
750 ->maximize_mode_controller()
751 ->EnableMaximizeModeWindowManager(true);
752 // Rotation lock should not activate because DisplayInfoProvider::SetInfo()
753 // was called when not in maximize mode.
754 EXPECT_FALSE(screen_orientation_controller->rotation_locked());
756 // ScreenOrientationController rotations override display info.
757 screen_orientation_controller->SetDisplayRotation(
758 gfx::Display::ROTATE_0, gfx::Display::ROTATION_SOURCE_ACTIVE);
759 EXPECT_EQ(gfx::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
761 // Exiting maximize mode should restore the initial rotation
762 ash::Shell::GetInstance()
763 ->maximize_mode_controller()
764 ->EnableMaximizeModeWindowManager(false);
765 EXPECT_EQ(gfx::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
768 // Tests that rotation changes made during maximize mode lock the display
769 // against accelerometer rotations.
770 TEST_F(DisplayInfoProviderChromeosTest, SetRotationDuringMaximizeMode) {
771 // Entering maximize mode enables accelerometer screen rotations.
772 ash::Shell::GetInstance()
773 ->maximize_mode_controller()
774 ->EnableMaximizeModeWindowManager(true);
776 ASSERT_FALSE(ash::Shell::GetInstance()
777 ->screen_orientation_controller()
778 ->rotation_locked());
780 api::system_display::DisplayProperties info;
781 info.rotation.reset(new int(90));
783 bool success = false;
784 std::string error;
785 CallSetDisplayUnitInfo(base::Int64ToString(gfx::Display::InternalDisplayId()),
786 info, &success, &error);
788 ASSERT_TRUE(success);
789 EXPECT_TRUE(error.empty());
790 EXPECT_TRUE(ash::Shell::GetInstance()
791 ->screen_orientation_controller()
792 ->rotation_locked());
795 TEST_F(DisplayInfoProviderChromeosTest, SetInvalidRotation) {
796 UpdateDisplay("1200x600,600x1000*2");
798 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
799 api::system_display::DisplayProperties info;
800 info.rotation.reset(new int(91));
802 bool success = false;
803 std::string error;
804 CallSetDisplayUnitInfo(
805 base::Int64ToString(secondary.id()), info, &success, &error);
807 ASSERT_FALSE(success);
808 EXPECT_EQ("Invalid rotation.", error);
811 TEST_F(DisplayInfoProviderChromeosTest, SetNegativeOverscan) {
812 UpdateDisplay("1200x600,600x1000*2");
814 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
815 api::system_display::DisplayProperties info;
816 info.overscan.reset(new api::system_display::Insets);
817 info.overscan->left = -10;
819 bool success = false;
820 std::string error;
821 CallSetDisplayUnitInfo(
822 base::Int64ToString(secondary.id()), info, &success, &error);
824 ASSERT_FALSE(success);
825 EXPECT_EQ("Negative overscan not allowed.", error);
827 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
829 info.overscan->left = 0;
830 info.overscan->right = -200;
832 CallSetDisplayUnitInfo(
833 base::Int64ToString(secondary.id()), info, &success, &error);
835 ASSERT_FALSE(success);
836 EXPECT_EQ("Negative overscan not allowed.", error);
838 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
840 info.overscan->right = 0;
841 info.overscan->top = -300;
843 CallSetDisplayUnitInfo(
844 base::Int64ToString(secondary.id()), info, &success, &error);
846 ASSERT_FALSE(success);
847 EXPECT_EQ("Negative overscan not allowed.", error);
849 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
851 info.overscan->right = 0;
852 info.overscan->top = -1000;
854 CallSetDisplayUnitInfo(
855 base::Int64ToString(secondary.id()), info, &success, &error);
857 ASSERT_FALSE(success);
858 EXPECT_EQ("Negative overscan not allowed.", error);
860 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
862 info.overscan->right = 0;
863 info.overscan->top = 0;
865 CallSetDisplayUnitInfo(
866 base::Int64ToString(secondary.id()), info, &success, &error);
868 ASSERT_TRUE(success);
869 EXPECT_TRUE(error.empty());
871 EXPECT_EQ("1200,0 300x500", secondary.bounds().ToString());
874 TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanHorizontalBounds) {
875 UpdateDisplay("1200x600,600x1000*2");
877 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
878 api::system_display::DisplayProperties info;
879 info.overscan.reset(new api::system_display::Insets);
880 // Horizontal overscan is 151, which would make the bounds width 149.
881 info.overscan->left = 50;
882 info.overscan->top = 10;
883 info.overscan->right = 101;
884 info.overscan->bottom = 20;
886 bool success = false;
887 std::string error;
888 CallSetDisplayUnitInfo(
889 base::Int64ToString(secondary.id()), info, &success, &error);
891 ASSERT_FALSE(success);
892 EXPECT_EQ("Horizontal overscan is more than half of the screen width.",
893 error);
896 TEST_F(DisplayInfoProviderChromeosTest, SetOverscanLargerThanVerticalBounds) {
897 UpdateDisplay("1200x600,600x1000");
899 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
900 api::system_display::DisplayProperties info;
901 info.overscan.reset(new api::system_display::Insets);
902 // Vertical overscan is 501, which would make the bounds height 499.
903 info.overscan->left = 20;
904 info.overscan->top = 250;
905 info.overscan->right = 101;
906 info.overscan->bottom = 251;
908 bool success = false;
909 std::string error;
910 CallSetDisplayUnitInfo(
911 base::Int64ToString(secondary.id()), info, &success, &error);
913 ASSERT_FALSE(success);
914 EXPECT_EQ("Vertical overscan is more than half of the screen height.", error);
917 TEST_F(DisplayInfoProviderChromeosTest, SetOverscan) {
918 UpdateDisplay("1200x600,600x1000*2");
920 const gfx::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
921 api::system_display::DisplayProperties info;
922 info.overscan.reset(new api::system_display::Insets);
923 info.overscan->left = 20;
924 info.overscan->top = 199;
925 info.overscan->right = 130;
926 info.overscan->bottom = 51;
928 bool success = false;
929 std::string error;
930 CallSetDisplayUnitInfo(
931 base::Int64ToString(secondary.id()), info, &success, &error);
933 ASSERT_TRUE(success);
934 EXPECT_TRUE(error.empty());
936 EXPECT_EQ("1200,0 150x250", secondary.bounds().ToString());
937 const gfx::Insets overscan =
938 GetDisplayManager()->GetOverscanInsets(secondary.id());
940 EXPECT_EQ(20, overscan.left());
941 EXPECT_EQ(199, overscan.top());
942 EXPECT_EQ(130, overscan.right());
943 EXPECT_EQ(51, overscan.bottom());
946 TEST_F(DisplayInfoProviderChromeosTest, SetOverscanForInternal) {
947 UpdateDisplay("1200x600,600x1000*2");
948 const int64 internal_display_id =
949 ash::test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
951 api::system_display::DisplayProperties info;
952 info.overscan.reset(new api::system_display::Insets);
953 // Vertical overscan is 501, which would make the bounds height 499.
954 info.overscan->left = 20;
955 info.overscan->top = 20;
956 info.overscan->right = 20;
957 info.overscan->bottom = 20;
959 bool success = false;
960 std::string error;
961 CallSetDisplayUnitInfo(
962 base::Int64ToString(internal_display_id), info, &success, &error);
964 ASSERT_FALSE(success);
965 EXPECT_EQ("Overscan changes not allowed for the internal monitor.", error);
968 } // namespace
969 } // namespace extensions