1 // Copyright (c) 2012 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_manager.h"
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_controller.h"
9 #include "ash/display/display_layout_store.h"
10 #include "ash/screen_util.h"
11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/display_manager_test_api.h"
14 #include "ash/test/mirror_window_test_api.h"
15 #include "base/command_line.h"
16 #include "base/format_macros.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
19 #include "ui/aura/env.h"
20 #include "ui/aura/window_observer.h"
21 #include "ui/aura/window_tree_host.h"
22 #include "ui/events/test/event_generator.h"
23 #include "ui/gfx/display.h"
24 #include "ui/gfx/display_observer.h"
25 #include "ui/gfx/font_render_params.h"
26 #include "ui/gfx/screen.h"
27 #include "ui/gfx/screen_type_delegate.h"
34 using base::StringPrintf
;
38 std::string
ToDisplayName(int64 id
) {
39 return "x-" + base::Int64ToString(id
);
44 class DisplayManagerTest
: public test::AshTestBase
,
45 public gfx::DisplayObserver
,
46 public aura::WindowObserver
{
50 root_window_destroyed_(false) {
52 virtual ~DisplayManagerTest() {}
54 virtual void SetUp() OVERRIDE
{
56 Shell::GetScreen()->AddObserver(this);
57 Shell::GetPrimaryRootWindow()->AddObserver(this);
59 virtual void TearDown() OVERRIDE
{
60 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
61 Shell::GetScreen()->RemoveObserver(this);
62 AshTestBase::TearDown();
65 DisplayManager
* display_manager() {
66 return Shell::GetInstance()->display_manager();
68 const vector
<gfx::Display
>& changed() const { return changed_
; }
69 const vector
<gfx::Display
>& added() const { return added_
; }
71 string
GetCountSummary() const {
72 return StringPrintf("%" PRIuS
" %" PRIuS
" %" PRIuS
,
73 changed_
.size(), added_
.size(), removed_count_
);
80 root_window_destroyed_
= false;
83 bool root_window_destroyed() const {
84 return root_window_destroyed_
;
87 const DisplayInfo
& GetDisplayInfo(const gfx::Display
& display
) {
88 return display_manager()->GetDisplayInfo(display
.id());
91 const DisplayInfo
& GetDisplayInfoAt(int index
) {
92 return GetDisplayInfo(display_manager()->GetDisplayAt(index
));
95 const gfx::Display
& GetDisplayForId(int64 id
) {
96 return display_manager()->GetDisplayForId(id
);
99 const DisplayInfo
& GetDisplayInfoForId(int64 id
) {
100 return GetDisplayInfo(display_manager()->GetDisplayForId(id
));
103 // aura::DisplayObserver overrides:
104 virtual void OnDisplayMetricsChanged(const gfx::Display
& display
,
106 changed_
.push_back(display
);
108 virtual void OnDisplayAdded(const gfx::Display
& new_display
) OVERRIDE
{
109 added_
.push_back(new_display
);
111 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
{
115 // aura::WindowObserver overrides:
116 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
{
117 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window
);
118 root_window_destroyed_
= true;
122 vector
<gfx::Display
> changed_
;
123 vector
<gfx::Display
> added_
;
124 size_t removed_count_
;
125 bool root_window_destroyed_
;
127 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest
);
130 TEST_F(DisplayManagerTest
, UpdateDisplayTest
) {
131 if (!SupportsMultipleDisplays())
134 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
136 // Update primary and add seconary.
137 UpdateDisplay("100+0-500x500,0+501-400x400");
138 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
139 EXPECT_EQ("0,0 500x500",
140 display_manager()->GetDisplayAt(0).bounds().ToString());
142 EXPECT_EQ("1 1 0", GetCountSummary());
143 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
144 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
145 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
146 // Secondary display is on right.
147 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
148 EXPECT_EQ("0,501 400x400",
149 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
153 UpdateDisplay("100+0-500x500");
154 EXPECT_EQ("0 0 1", GetCountSummary());
158 UpdateDisplay("1+1-1000x600");
159 EXPECT_EQ("1 0 0", GetCountSummary());
160 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
161 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
165 UpdateDisplay("1+1-1000x600,1002+0-600x400");
166 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
167 EXPECT_EQ("0 1 0", GetCountSummary());
168 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
169 // Secondary display is on right.
170 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
171 EXPECT_EQ("1002,0 600x400",
172 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
175 // Secondary removed, primary changed.
176 UpdateDisplay("1+1-800x300");
177 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
178 EXPECT_EQ("1 0 1", GetCountSummary());
179 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
180 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
183 // # of display can go to zero when screen is off.
184 const vector
<DisplayInfo
> empty
;
185 display_manager()->OnNativeDisplaysChanged(empty
);
186 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
187 EXPECT_EQ("0 0 0", GetCountSummary());
188 EXPECT_FALSE(root_window_destroyed());
189 // Display configuration stays the same
190 EXPECT_EQ("0,0 800x300",
191 display_manager()->GetDisplayAt(0).bounds().ToString());
194 // Connect to display again
195 UpdateDisplay("100+100-500x400");
196 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
197 EXPECT_EQ("1 0 0", GetCountSummary());
198 EXPECT_FALSE(root_window_destroyed());
199 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
200 EXPECT_EQ("100,100 500x400",
201 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
204 // Go back to zero and wake up with multiple displays.
205 display_manager()->OnNativeDisplaysChanged(empty
);
206 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
207 EXPECT_FALSE(root_window_destroyed());
211 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
212 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
213 EXPECT_EQ("0,0 1000x600",
214 display_manager()->GetDisplayAt(0).bounds().ToString());
215 // Secondary display is on right.
216 EXPECT_EQ("1000,0 600x400",
217 display_manager()->GetDisplayAt(1).bounds().ToString());
218 EXPECT_EQ("1000,1000 600x400",
219 GetDisplayInfoAt(1).bounds_in_native().ToString());
222 // Changing primary will update secondary as well.
223 UpdateDisplay("0+0-800x600,1000+1000-600x400");
224 EXPECT_EQ("2 0 0", GetCountSummary());
226 EXPECT_EQ("0,0 800x600",
227 display_manager()->GetDisplayAt(0).bounds().ToString());
228 EXPECT_EQ("800,0 600x400",
229 display_manager()->GetDisplayAt(1).bounds().ToString());
232 // Test in emulation mode (use_fullscreen_host_window=false)
233 TEST_F(DisplayManagerTest
, EmulatorTest
) {
234 if (!SupportsMultipleDisplays())
237 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
239 display_manager()->AddRemoveDisplay();
240 // Update primary and add seconary.
241 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
242 EXPECT_EQ("0 1 0", GetCountSummary());
245 display_manager()->AddRemoveDisplay();
246 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
247 EXPECT_EQ("0 0 1", GetCountSummary());
250 display_manager()->AddRemoveDisplay();
251 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
252 EXPECT_EQ("0 1 0", GetCountSummary());
256 TEST_F(DisplayManagerTest
, OverscanInsetsTest
) {
257 if (!SupportsMultipleDisplays())
260 UpdateDisplay("0+0-500x500,0+501-400x400");
262 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
263 const DisplayInfo
& display_info1
= GetDisplayInfoAt(0);
264 const DisplayInfo
& display_info2
= GetDisplayInfoAt(1);
265 display_manager()->SetOverscanInsets(
266 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
268 std::vector
<gfx::Display
> changed_displays
= changed();
269 EXPECT_EQ(1u, changed_displays
.size());
270 EXPECT_EQ(display_info2
.id(), changed_displays
[0].id());
271 EXPECT_EQ("0,0 500x500",
272 GetDisplayInfoAt(0).bounds_in_native().ToString());
273 DisplayInfo updated_display_info2
= GetDisplayInfoAt(1);
274 EXPECT_EQ("0,501 400x400",
275 updated_display_info2
.bounds_in_native().ToString());
277 updated_display_info2
.size_in_pixel().ToString());
278 EXPECT_EQ("13,12,11,10",
279 updated_display_info2
.overscan_insets_in_dip().ToString());
280 EXPECT_EQ("500,0 378x376",
281 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
283 // Make sure that SetOverscanInsets() is idempotent.
284 display_manager()->SetOverscanInsets(display_info1
.id(), gfx::Insets());
285 display_manager()->SetOverscanInsets(
286 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
287 EXPECT_EQ("0,0 500x500",
288 GetDisplayInfoAt(0).bounds_in_native().ToString());
289 updated_display_info2
= GetDisplayInfoAt(1);
290 EXPECT_EQ("0,501 400x400",
291 updated_display_info2
.bounds_in_native().ToString());
293 updated_display_info2
.size_in_pixel().ToString());
294 EXPECT_EQ("13,12,11,10",
295 updated_display_info2
.overscan_insets_in_dip().ToString());
297 display_manager()->SetOverscanInsets(
298 display_info2
.id(), gfx::Insets(10, 11, 12, 13));
299 EXPECT_EQ("0,0 500x500",
300 GetDisplayInfoAt(0).bounds_in_native().ToString());
302 GetDisplayInfoAt(1).size_in_pixel().ToString());
303 EXPECT_EQ("10,11,12,13",
304 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
306 // Recreate a new 2nd display. It won't apply the overscan inset because the
307 // new display has a different ID.
308 UpdateDisplay("0+0-500x500");
309 UpdateDisplay("0+0-500x500,0+501-400x400");
310 EXPECT_EQ("0,0 500x500",
311 GetDisplayInfoAt(0).bounds_in_native().ToString());
312 EXPECT_EQ("0,501 400x400",
313 GetDisplayInfoAt(1).bounds_in_native().ToString());
315 // Recreate the displays with the same ID. It should apply the overscan
317 UpdateDisplay("0+0-500x500");
318 std::vector
<DisplayInfo
> display_info_list
;
319 display_info_list
.push_back(display_info1
);
320 display_info_list
.push_back(display_info2
);
321 display_manager()->OnNativeDisplaysChanged(display_info_list
);
322 EXPECT_EQ("1,1 500x500",
323 GetDisplayInfoAt(0).bounds_in_native().ToString());
324 updated_display_info2
= GetDisplayInfoAt(1);
326 updated_display_info2
.size_in_pixel().ToString());
327 EXPECT_EQ("10,11,12,13",
328 updated_display_info2
.overscan_insets_in_dip().ToString());
330 // HiDPI but overscan display. The specified insets size should be doubled.
331 UpdateDisplay("0+0-500x500,0+501-400x400*2");
332 display_manager()->SetOverscanInsets(
333 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
334 EXPECT_EQ("0,0 500x500",
335 GetDisplayInfoAt(0).bounds_in_native().ToString());
336 updated_display_info2
= GetDisplayInfoAt(1);
337 EXPECT_EQ("0,501 400x400",
338 updated_display_info2
.bounds_in_native().ToString());
340 updated_display_info2
.size_in_pixel().ToString());
342 updated_display_info2
.overscan_insets_in_dip().ToString());
343 EXPECT_EQ("8,10,12,14",
344 updated_display_info2
.GetOverscanInsetsInPixel().ToString());
346 // Make sure switching primary display applies the overscan offset only once.
347 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
348 ScreenUtil::GetSecondaryDisplay());
349 EXPECT_EQ("-500,0 500x500",
350 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
351 EXPECT_EQ("0,0 500x500",
352 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
353 bounds_in_native().ToString());
354 EXPECT_EQ("0,501 400x400",
355 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
356 bounds_in_native().ToString());
357 EXPECT_EQ("0,0 188x190",
358 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
361 TEST_F(DisplayManagerTest
, ZeroOverscanInsets
) {
362 if (!SupportsMultipleDisplays())
365 // Make sure the display change events is emitted for overscan inset changes.
366 UpdateDisplay("0+0-500x500,0+501-400x400");
367 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
368 int64 display2_id
= display_manager()->GetDisplayAt(1).id();
371 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
372 EXPECT_EQ(0u, changed().size());
375 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(1, 0, 0, 0));
376 EXPECT_EQ(1u, changed().size());
377 EXPECT_EQ(display2_id
, changed()[0].id());
380 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
381 EXPECT_EQ(1u, changed().size());
382 EXPECT_EQ(display2_id
, changed()[0].id());
385 TEST_F(DisplayManagerTest
, TestDeviceScaleOnlyChange
) {
386 if (!SupportsHostWindowResize())
389 UpdateDisplay("1000x600");
390 aura::WindowTreeHost
* host
= Shell::GetPrimaryRootWindow()->GetHost();
391 EXPECT_EQ(1, host
->compositor()->device_scale_factor());
392 EXPECT_EQ("1000x600",
393 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
394 EXPECT_EQ("1 0 0", GetCountSummary());
396 UpdateDisplay("1000x600*2");
397 EXPECT_EQ(2, host
->compositor()->device_scale_factor());
398 EXPECT_EQ("2 0 0", GetCountSummary());
400 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
403 DisplayInfo
CreateDisplayInfo(int64 id
, const gfx::Rect
& bounds
) {
404 DisplayInfo
info(id
, ToDisplayName(id
), false);
405 info
.SetBounds(bounds
);
409 TEST_F(DisplayManagerTest
, TestNativeDisplaysChanged
) {
410 const int64 internal_display_id
=
411 test::DisplayManagerTestApi(display_manager()).
412 SetFirstDisplayAsInternalDisplay();
413 const int external_id
= 10;
414 const int mirror_id
= 11;
415 const int64 invalid_id
= gfx::Display::kInvalidDisplayID
;
416 const DisplayInfo internal_display_info
=
417 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
418 const DisplayInfo external_display_info
=
419 CreateDisplayInfo(external_id
, gfx::Rect(1, 1, 100, 100));
420 const DisplayInfo mirrored_display_info
=
421 CreateDisplayInfo(mirror_id
, gfx::Rect(0, 0, 500, 500));
423 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
424 EXPECT_EQ(1U, display_manager()->num_connected_displays());
425 std::string default_bounds
=
426 display_manager()->GetDisplayAt(0).bounds().ToString();
428 std::vector
<DisplayInfo
> display_info_list
;
429 // Primary disconnected.
430 display_manager()->OnNativeDisplaysChanged(display_info_list
);
431 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
432 EXPECT_EQ(default_bounds
,
433 display_manager()->GetDisplayAt(0).bounds().ToString());
434 EXPECT_EQ(1U, display_manager()->num_connected_displays());
435 EXPECT_FALSE(display_manager()->IsMirrored());
437 if (!SupportsMultipleDisplays())
440 // External connected while primary was disconnected.
441 display_info_list
.push_back(external_display_info
);
442 display_manager()->OnNativeDisplaysChanged(display_info_list
);
443 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
445 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
446 EXPECT_EQ("1,1 100x100",
447 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
448 EXPECT_EQ(1U, display_manager()->num_connected_displays());
449 EXPECT_FALSE(display_manager()->IsMirrored());
450 EXPECT_EQ(external_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
452 EXPECT_EQ(internal_display_id
, gfx::Display::InternalDisplayId());
454 // Primary connected, with different bounds.
455 display_info_list
.clear();
456 display_info_list
.push_back(internal_display_info
);
457 display_info_list
.push_back(external_display_info
);
458 display_manager()->OnNativeDisplaysChanged(display_info_list
);
459 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
460 EXPECT_EQ(internal_display_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
462 // This combinatino is new, so internal display becomes primary.
463 EXPECT_EQ("0,0 500x500",
464 GetDisplayForId(internal_display_id
).bounds().ToString());
465 EXPECT_EQ("1,1 100x100",
466 GetDisplayInfoForId(10).bounds_in_native().ToString());
467 EXPECT_EQ(2U, display_manager()->num_connected_displays());
468 EXPECT_FALSE(display_manager()->IsMirrored());
469 EXPECT_EQ(ToDisplayName(internal_display_id
),
470 display_manager()->GetDisplayNameForId(internal_display_id
));
473 display_info_list
.clear();
474 display_manager()->OnNativeDisplaysChanged(display_info_list
);
475 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
476 EXPECT_EQ("0,0 500x500",
477 GetDisplayForId(internal_display_id
).bounds().ToString());
478 EXPECT_EQ("1,1 100x100",
479 GetDisplayInfoForId(10).bounds_in_native().ToString());
480 EXPECT_EQ(2U, display_manager()->num_connected_displays());
481 EXPECT_FALSE(display_manager()->IsMirrored());
482 EXPECT_EQ(ToDisplayName(internal_display_id
),
483 display_manager()->GetDisplayNameForId(internal_display_id
));
485 // External display has disconnected then resumed.
486 display_info_list
.push_back(internal_display_info
);
487 display_manager()->OnNativeDisplaysChanged(display_info_list
);
488 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
489 EXPECT_EQ("0,0 500x500",
490 GetDisplayForId(internal_display_id
).bounds().ToString());
491 EXPECT_EQ(1U, display_manager()->num_connected_displays());
492 EXPECT_FALSE(display_manager()->IsMirrored());
494 // External display was changed during suspend.
495 display_info_list
.push_back(external_display_info
);
496 display_manager()->OnNativeDisplaysChanged(display_info_list
);
497 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
498 EXPECT_EQ(2U, display_manager()->num_connected_displays());
499 EXPECT_FALSE(display_manager()->IsMirrored());
502 display_info_list
.clear();
503 display_manager()->OnNativeDisplaysChanged(display_info_list
);
504 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
505 EXPECT_EQ(2U, display_manager()->num_connected_displays());
506 EXPECT_FALSE(display_manager()->IsMirrored());
508 // and resume with different external display.
509 display_info_list
.push_back(internal_display_info
);
510 display_info_list
.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
511 display_manager()->OnNativeDisplaysChanged(display_info_list
);
512 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
513 EXPECT_EQ(2U, display_manager()->num_connected_displays());
514 EXPECT_FALSE(display_manager()->IsMirrored());
515 EXPECT_FALSE(display_manager()->IsMirrored());
518 display_info_list
.clear();
519 display_info_list
.push_back(internal_display_info
);
520 display_info_list
.push_back(mirrored_display_info
);
521 display_manager()->OnNativeDisplaysChanged(display_info_list
);
522 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
523 EXPECT_EQ("0,0 500x500",
524 GetDisplayForId(internal_display_id
).bounds().ToString());
525 EXPECT_EQ(2U, display_manager()->num_connected_displays());
526 EXPECT_EQ(11U, display_manager()->mirrored_display_id());
527 EXPECT_TRUE(display_manager()->IsMirrored());
529 // Test display name.
530 EXPECT_EQ(ToDisplayName(internal_display_id
),
531 display_manager()->GetDisplayNameForId(internal_display_id
));
532 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
533 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
534 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
535 // Default name for the id that doesn't exist.
536 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
538 // and exit mirroring.
539 display_info_list
.clear();
540 display_info_list
.push_back(internal_display_info
);
541 display_info_list
.push_back(external_display_info
);
542 display_manager()->OnNativeDisplaysChanged(display_info_list
);
543 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
544 EXPECT_EQ(2U, display_manager()->num_connected_displays());
545 EXPECT_FALSE(display_manager()->IsMirrored());
546 EXPECT_EQ("0,0 500x500",
547 GetDisplayForId(internal_display_id
).bounds().ToString());
548 EXPECT_EQ("500,0 100x100",
549 GetDisplayForId(10).bounds().ToString());
552 display_info_list
.clear();
553 display_info_list
.push_back(external_display_info
);
554 display_manager()->OnNativeDisplaysChanged(display_info_list
);
555 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
556 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
557 EXPECT_EQ("1,1 100x100",
558 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
559 EXPECT_EQ(1U, display_manager()->num_connected_displays());
560 EXPECT_FALSE(display_manager()->IsMirrored());
562 // Switched to another display
563 display_info_list
.clear();
564 display_info_list
.push_back(internal_display_info
);
565 display_manager()->OnNativeDisplaysChanged(display_info_list
);
566 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
569 GetDisplayInfoForId(internal_display_id
).bounds_in_native().ToString());
570 EXPECT_EQ(1U, display_manager()->num_connected_displays());
571 EXPECT_FALSE(display_manager()->IsMirrored());
575 // TODO(scottmg): RootWindow doesn't get resized on Windows
576 // Ash. http://crbug.com/247916.
577 #define MAYBE_TestNativeDisplaysChangedNoInternal \
578 DISABLED_TestNativeDisplaysChangedNoInternal
580 #define MAYBE_TestNativeDisplaysChangedNoInternal \
581 TestNativeDisplaysChangedNoInternal
584 TEST_F(DisplayManagerTest
, MAYBE_TestNativeDisplaysChangedNoInternal
) {
585 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
587 // Don't change the display info if all displays are disconnected.
588 std::vector
<DisplayInfo
> display_info_list
;
589 display_manager()->OnNativeDisplaysChanged(display_info_list
);
590 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
592 // Connect another display which will become primary.
593 const DisplayInfo external_display_info
=
594 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
595 display_info_list
.push_back(external_display_info
);
596 display_manager()->OnNativeDisplaysChanged(display_info_list
);
597 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
598 EXPECT_EQ("1,1 100x100",
599 GetDisplayInfoForId(10).bounds_in_native().ToString());
600 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
601 GetBounds().size().ToString());
605 // Tests that rely on the actual host size/location does not work on windows.
606 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays
607 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays_2ndOnLeft
609 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays
610 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLeft
613 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays
) {
614 UpdateDisplay("200x200,300x300");
615 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
617 aura::Env
* env
= aura::Env::GetInstance();
619 ui::test::EventGenerator
generator(root_windows
[0]);
621 // Set the initial position.
622 generator
.MoveMouseToInHost(350, 150);
623 EXPECT_EQ("350,150", env
->last_mouse_location().ToString());
625 // A mouse pointer will stay in the 2nd display.
626 UpdateDisplay("300x300,200x200");
627 EXPECT_EQ("450,50", env
->last_mouse_location().ToString());
629 // A mouse pointer will be outside of displays and move to the
630 // center of 2nd display.
631 UpdateDisplay("300x300,100x100");
632 EXPECT_EQ("350,50", env
->last_mouse_location().ToString());
634 // 2nd display was disconnected, and the cursor is
635 // now in the 1st display.
636 UpdateDisplay("400x400");
637 EXPECT_EQ("50,350", env
->last_mouse_location().ToString());
639 // 1st display's resolution has changed, and the mouse pointer is
640 // now outside. Move the mouse pointer to the center of 1st display.
641 UpdateDisplay("300x300");
642 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
644 // Move the mouse pointer to the bottom of 1st display.
645 generator
.MoveMouseToInHost(150, 290);
646 EXPECT_EQ("150,290", env
->last_mouse_location().ToString());
648 // The mouse pointer is now on 2nd display.
649 UpdateDisplay("300x280,200x200");
650 EXPECT_EQ("450,10", env
->last_mouse_location().ToString());
653 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays_2ndOnLeft
) {
654 // Set the 2nd display on the left.
655 DisplayLayoutStore
* layout_store
=
656 Shell::GetInstance()->display_manager()->layout_store();
657 DisplayLayout layout
= layout_store
->default_display_layout();
658 layout
.position
= DisplayLayout::LEFT
;
659 layout_store
->SetDefaultDisplayLayout(layout
);
661 UpdateDisplay("200x200,300x300");
662 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
664 EXPECT_EQ("-300,0 300x300",
665 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
667 aura::Env
* env
= aura::Env::GetInstance();
669 // Set the initial position.
670 root_windows
[0]->MoveCursorTo(gfx::Point(-150, 250));
671 EXPECT_EQ("-150,250", env
->last_mouse_location().ToString());
673 // A mouse pointer will stay in 2nd display.
674 UpdateDisplay("300x300,200x300");
675 EXPECT_EQ("-50,150", env
->last_mouse_location().ToString());
677 // A mouse pointer will be outside of displays and move to the
678 // center of 2nd display.
679 UpdateDisplay("300x300,200x100");
680 EXPECT_EQ("-100,50", env
->last_mouse_location().ToString());
682 // 2nd display was disconnected. Mouse pointer should move to
684 UpdateDisplay("300x300");
685 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
688 TEST_F(DisplayManagerTest
, NativeDisplaysChangedAfterPrimaryChange
) {
689 if (!SupportsMultipleDisplays())
692 const int64 internal_display_id
=
693 test::DisplayManagerTestApi(display_manager()).
694 SetFirstDisplayAsInternalDisplay();
695 const DisplayInfo native_display_info
=
696 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
697 const DisplayInfo secondary_display_info
=
698 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
700 std::vector
<DisplayInfo
> display_info_list
;
701 display_info_list
.push_back(native_display_info
);
702 display_info_list
.push_back(secondary_display_info
);
703 display_manager()->OnNativeDisplaysChanged(display_info_list
);
704 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
705 EXPECT_EQ("0,0 500x500",
706 GetDisplayForId(internal_display_id
).bounds().ToString());
707 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
709 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
710 GetDisplayForId(secondary_display_info
.id()));
711 EXPECT_EQ("-500,0 500x500",
712 GetDisplayForId(internal_display_id
).bounds().ToString());
713 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
715 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
716 // nothing changed if the exactly same displays are specified.
717 display_manager()->OnNativeDisplaysChanged(display_info_list
);
718 EXPECT_EQ("-500,0 500x500",
719 GetDisplayForId(internal_display_id
).bounds().ToString());
720 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
723 TEST_F(DisplayManagerTest
, DontRememberBestResolution
) {
724 int display_id
= 1000;
725 DisplayInfo native_display_info
=
726 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
727 std::vector
<DisplayMode
> display_modes
;
728 display_modes
.push_back(
729 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
730 display_modes
.push_back(
731 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
732 display_modes
.push_back(
733 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
735 native_display_info
.set_display_modes(display_modes
);
737 std::vector
<DisplayInfo
> display_info_list
;
738 display_info_list
.push_back(native_display_info
);
739 display_manager()->OnNativeDisplaysChanged(display_info_list
);
742 DisplayMode expected_mode
;
743 expected_mode
.size
= gfx::Size(1000, 500);
745 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
746 EXPECT_TRUE(expected_mode
.IsEquivalent(
747 display_manager()->GetActiveModeForDisplayId(display_id
)));
749 // Unsupported resolution.
750 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 4000));
752 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
753 EXPECT_TRUE(expected_mode
.IsEquivalent(
754 display_manager()->GetActiveModeForDisplayId(display_id
)));
756 // Supported resolution.
757 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
759 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
760 EXPECT_EQ("800x300", mode
.size
.ToString());
761 EXPECT_EQ(59.0f
, mode
.refresh_rate
);
762 EXPECT_FALSE(mode
.native
);
763 expected_mode
.size
= gfx::Size(800, 300);
764 EXPECT_TRUE(expected_mode
.IsEquivalent(
765 display_manager()->GetActiveModeForDisplayId(display_id
)));
768 display_manager()->SetDisplayResolution(display_id
, gfx::Size(1000, 500));
770 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
771 EXPECT_EQ("1000x500", mode
.size
.ToString());
772 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
773 EXPECT_TRUE(mode
.native
);
774 expected_mode
.size
= gfx::Size(1000, 500);
775 EXPECT_TRUE(expected_mode
.IsEquivalent(
776 display_manager()->GetActiveModeForDisplayId(display_id
)));
779 TEST_F(DisplayManagerTest
, ResolutionFallback
) {
780 int display_id
= 1000;
781 DisplayInfo native_display_info
=
782 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
783 std::vector
<DisplayMode
> display_modes
;
784 display_modes
.push_back(
785 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
786 display_modes
.push_back(
787 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
788 display_modes
.push_back(
789 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
791 std::vector
<DisplayMode
> copy
= display_modes
;
792 native_display_info
.set_display_modes(copy
);
794 std::vector
<DisplayInfo
> display_info_list
;
795 display_info_list
.push_back(native_display_info
);
796 display_manager()->OnNativeDisplaysChanged(display_info_list
);
798 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
799 DisplayInfo new_native_display_info
=
800 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 400, 500));
801 copy
= display_modes
;
802 new_native_display_info
.set_display_modes(copy
);
803 std::vector
<DisplayInfo
> new_display_info_list
;
804 new_display_info_list
.push_back(new_native_display_info
);
805 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
809 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
810 EXPECT_EQ("400x500", mode
.size
.ToString());
811 EXPECT_EQ(60.0f
, mode
.refresh_rate
);
812 EXPECT_FALSE(mode
.native
);
815 // Best resolution should find itself on the resolutions list.
816 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
817 DisplayInfo new_native_display_info
=
818 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
819 std::vector
<DisplayMode
> copy
= display_modes
;
820 new_native_display_info
.set_display_modes(copy
);
821 std::vector
<DisplayInfo
> new_display_info_list
;
822 new_display_info_list
.push_back(new_native_display_info
);
823 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
827 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
828 EXPECT_EQ("1000x500", mode
.size
.ToString());
829 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
830 EXPECT_TRUE(mode
.native
);
834 TEST_F(DisplayManagerTest
, Rotate
) {
835 if (!SupportsMultipleDisplays())
838 UpdateDisplay("100x200/r,300x400/l");
839 EXPECT_EQ("1,1 100x200",
840 GetDisplayInfoAt(0).bounds_in_native().ToString());
842 GetDisplayInfoAt(0).size_in_pixel().ToString());
844 EXPECT_EQ("1,201 300x400",
845 GetDisplayInfoAt(1).bounds_in_native().ToString());
847 GetDisplayInfoAt(1).size_in_pixel().ToString());
849 UpdateDisplay("100x200/b,300x400");
850 EXPECT_EQ("2 0 0", GetCountSummary());
853 EXPECT_EQ("1,1 100x200",
854 GetDisplayInfoAt(0).bounds_in_native().ToString());
856 GetDisplayInfoAt(0).size_in_pixel().ToString());
858 EXPECT_EQ("1,201 300x400",
859 GetDisplayInfoAt(1).bounds_in_native().ToString());
861 GetDisplayInfoAt(1).size_in_pixel().ToString());
863 // Just Rotating display will change the bounds on both display.
864 UpdateDisplay("100x200/l,300x400");
865 EXPECT_EQ("2 0 0", GetCountSummary());
868 // Updating to the same configuration should report no changes.
869 UpdateDisplay("100x200/l,300x400");
870 EXPECT_EQ("0 0 0", GetCountSummary());
873 // Rotating 180 degrees should report one change.
874 UpdateDisplay("100x200/r,300x400");
875 EXPECT_EQ("1 0 0", GetCountSummary());
878 UpdateDisplay("200x200");
879 EXPECT_EQ("1 0 1", GetCountSummary());
882 // Rotating 180 degrees should report one change.
883 UpdateDisplay("200x200/u");
884 EXPECT_EQ("1 0 0", GetCountSummary());
887 UpdateDisplay("200x200/l");
888 EXPECT_EQ("1 0 0", GetCountSummary());
891 TEST_F(DisplayManagerTest
, UIScale
) {
892 UpdateDisplay("1280x800");
893 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
894 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
895 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
896 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
897 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
898 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
899 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
900 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
901 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
903 gfx::Display::SetInternalDisplayId(display_id
);
905 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
906 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
907 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
908 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
909 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
910 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
911 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
912 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
913 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
914 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
915 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
916 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
917 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
918 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
919 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
920 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
922 UpdateDisplay("1366x768");
923 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
924 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
925 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
926 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
927 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
928 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
929 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
930 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
931 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
932 EXPECT_EQ(0.75f
, GetDisplayInfoAt(0).configured_ui_scale());
933 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
934 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
935 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
936 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
937 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
938 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
940 UpdateDisplay("1280x850*2");
941 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
942 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
943 EXPECT_EQ(1.5f
, GetDisplayInfoAt(0).configured_ui_scale());
944 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
945 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
946 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
947 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
948 display_manager()->SetDisplayUIScale(display_id
, 1.0f
);
949 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
950 gfx::Display display
= Shell::GetScreen()->GetPrimaryDisplay();
951 EXPECT_EQ(2.0f
, display
.device_scale_factor());
952 EXPECT_EQ("640x425", display
.bounds().size().ToString());
954 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
955 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
956 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
957 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
958 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
959 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
960 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
961 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
962 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
963 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
965 display_manager()->SetDisplayUIScale(display_id
, 2.0f
);
966 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).configured_ui_scale());
967 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
968 display
= Shell::GetScreen()->GetPrimaryDisplay();
969 EXPECT_EQ(1.0f
, display
.device_scale_factor());
970 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
972 // 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
974 UpdateDisplay("1280x850*1.25");
975 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
976 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
977 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
978 display
= Shell::GetScreen()->GetPrimaryDisplay();
979 EXPECT_EQ(1.0f
, display
.device_scale_factor());
980 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
983 TEST_F(DisplayManagerTest
, UIScaleWithDisplayMode
) {
984 int display_id
= 1000;
986 // Setup the display modes with UI-scale.
987 DisplayInfo native_display_info
=
988 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1280, 800));
989 std::vector
<DisplayMode
> display_modes
;
990 const DisplayMode
base_mode(gfx::Size(1280, 800), 60.0f
, false, false);
991 std::vector
<float> scales
=
992 DisplayManager::GetScalesForDisplay(native_display_info
);
993 for (size_t i
= 0; i
< scales
.size(); i
++) {
994 DisplayMode mode
= base_mode
;
995 mode
.ui_scale
= scales
[i
];
996 mode
.native
= (scales
[i
] == 1.0f
);
997 display_modes
.push_back(mode
);
999 native_display_info
.set_display_modes(display_modes
);
1000 std::vector
<DisplayInfo
> display_info_list
;
1001 display_info_list
.push_back(native_display_info
);
1002 display_manager()->OnNativeDisplaysChanged(display_info_list
);
1004 DisplayMode expected_mode
= base_mode
;
1005 EXPECT_TRUE(expected_mode
.IsEquivalent(
1006 display_manager()->GetActiveModeForDisplayId(display_id
)));
1008 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1009 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
1010 EXPECT_TRUE(expected_mode
.IsEquivalent(
1011 display_manager()->GetActiveModeForDisplayId(display_id
)));
1012 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1013 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1014 EXPECT_TRUE(expected_mode
.IsEquivalent(
1015 display_manager()->GetActiveModeForDisplayId(display_id
)));
1016 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1017 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1018 EXPECT_TRUE(expected_mode
.IsEquivalent(
1019 display_manager()->GetActiveModeForDisplayId(display_id
)));
1020 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1021 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1022 EXPECT_TRUE(expected_mode
.IsEquivalent(
1023 display_manager()->GetActiveModeForDisplayId(display_id
)));
1025 gfx::Display::SetInternalDisplayId(display_id
);
1027 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1028 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1029 EXPECT_TRUE(expected_mode
.IsEquivalent(
1030 display_manager()->GetActiveModeForDisplayId(display_id
)));
1031 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1032 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1033 EXPECT_TRUE(expected_mode
.IsEquivalent(
1034 display_manager()->GetActiveModeForDisplayId(display_id
)));
1035 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1036 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1037 expected_mode
.ui_scale
= 1.125f
;
1038 EXPECT_TRUE(expected_mode
.IsEquivalent(
1039 display_manager()->GetActiveModeForDisplayId(display_id
)));
1040 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1041 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1042 expected_mode
.ui_scale
= 0.8f
;
1043 EXPECT_TRUE(expected_mode
.IsEquivalent(
1044 display_manager()->GetActiveModeForDisplayId(display_id
)));
1045 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1046 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1047 EXPECT_TRUE(expected_mode
.IsEquivalent(
1048 display_manager()->GetActiveModeForDisplayId(display_id
)));
1049 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1050 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1051 expected_mode
.ui_scale
= 0.625f
;
1052 EXPECT_TRUE(expected_mode
.IsEquivalent(
1053 display_manager()->GetActiveModeForDisplayId(display_id
)));
1054 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1055 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1056 EXPECT_TRUE(expected_mode
.IsEquivalent(
1057 display_manager()->GetActiveModeForDisplayId(display_id
)));
1058 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1059 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1060 expected_mode
.ui_scale
= 0.5f
;
1061 EXPECT_TRUE(expected_mode
.IsEquivalent(
1062 display_manager()->GetActiveModeForDisplayId(display_id
)));
1065 TEST_F(DisplayManagerTest
, UIScaleUpgradeToHighDPI
) {
1066 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
1067 gfx::Display::SetInternalDisplayId(display_id
);
1068 UpdateDisplay("1920x1080");
1070 DisplayInfo::SetAllowUpgradeToHighDPI(false);
1071 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1072 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1073 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1074 EXPECT_EQ("2160x1215", GetDisplayForId(display_id
).size().ToString());
1076 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1077 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1078 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1079 EXPECT_EQ("960x540", GetDisplayForId(display_id
).size().ToString());
1081 DisplayInfo::SetAllowUpgradeToHighDPI(true);
1082 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1083 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1084 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1085 EXPECT_EQ("2160x1215", GetDisplayForId(display_id
).size().ToString());
1087 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1088 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1089 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1090 EXPECT_EQ("960x540", GetDisplayForId(display_id
).size().ToString());
1092 // Upgrade only works on 1.0f DSF.
1093 UpdateDisplay("1920x1080*2");
1094 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1095 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1096 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1097 EXPECT_EQ("1080x607", GetDisplayForId(display_id
).size().ToString());
1099 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1100 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1101 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1102 EXPECT_EQ("480x270", GetDisplayForId(display_id
).size().ToString());
1106 // TODO(scottmg): RootWindow doesn't get resized on Windows
1107 // Ash. http://crbug.com/247916.
1108 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
1110 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
1113 TEST_F(DisplayManagerTest
, MAYBE_UpdateMouseCursorAfterRotateZoom
) {
1114 // Make sure just rotating will not change native location.
1115 UpdateDisplay("300x200,200x150");
1116 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1117 aura::Env
* env
= aura::Env::GetInstance();
1119 ui::test::EventGenerator
generator1(root_windows
[0]);
1120 ui::test::EventGenerator
generator2(root_windows
[1]);
1122 // Test on 1st display.
1123 generator1
.MoveMouseToInHost(150, 50);
1124 EXPECT_EQ("150,50", env
->last_mouse_location().ToString());
1125 UpdateDisplay("300x200/r,200x150");
1126 EXPECT_EQ("50,149", env
->last_mouse_location().ToString());
1128 // Test on 2nd display.
1129 generator2
.MoveMouseToInHost(50, 100);
1130 EXPECT_EQ("250,100", env
->last_mouse_location().ToString());
1131 UpdateDisplay("300x200/r,200x150/l");
1132 EXPECT_EQ("249,50", env
->last_mouse_location().ToString());
1134 // The native location is now outside, so move to the center
1135 // of closest display.
1136 UpdateDisplay("300x200/r,100x50/l");
1137 EXPECT_EQ("225,50", env
->last_mouse_location().ToString());
1139 // Make sure just zooming will not change native location.
1140 UpdateDisplay("600x400*2,400x300");
1142 // Test on 1st display.
1143 generator1
.MoveMouseToInHost(200, 300);
1144 EXPECT_EQ("100,150", env
->last_mouse_location().ToString());
1145 UpdateDisplay("600x400*2@1.5,400x300");
1146 EXPECT_EQ("150,225", env
->last_mouse_location().ToString());
1148 // Test on 2nd display.
1149 UpdateDisplay("600x400,400x300*2");
1150 generator2
.MoveMouseToInHost(200, 250);
1151 EXPECT_EQ("700,125", env
->last_mouse_location().ToString());
1152 UpdateDisplay("600x400,400x300*2@1.5");
1153 EXPECT_EQ("750,187", env
->last_mouse_location().ToString());
1155 // The native location is now outside, so move to the
1156 // center of closest display.
1157 UpdateDisplay("600x400,400x200*2@1.5");
1158 EXPECT_EQ("750,75", env
->last_mouse_location().ToString());
1161 class TestDisplayObserver
: public gfx::DisplayObserver
{
1163 TestDisplayObserver() : changed_(false) {}
1164 virtual ~TestDisplayObserver() {}
1166 // gfx::DisplayObserver overrides:
1167 virtual void OnDisplayMetricsChanged(const gfx::Display
&,uint32_t) OVERRIDE
{}
1168 virtual void OnDisplayAdded(const gfx::Display
& new_display
) OVERRIDE
{
1169 // Mirror window should already be delete before restoring
1170 // the external display.
1171 EXPECT_FALSE(test_api
.GetHost());
1174 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
{
1175 // Mirror window should not be created until the external display
1177 EXPECT_FALSE(test_api
.GetHost());
1181 bool changed_and_reset() {
1182 bool changed
= changed_
;
1188 test::MirrorWindowTestApi test_api
;
1191 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver
);
1194 TEST_F(DisplayManagerTest
, SoftwareMirroring
) {
1195 if (!SupportsMultipleDisplays())
1198 UpdateDisplay("300x400,400x500");
1200 test::MirrorWindowTestApi test_api
;
1201 EXPECT_EQ(NULL
, test_api
.GetHost());
1203 TestDisplayObserver display_observer
;
1204 Shell::GetScreen()->AddObserver(&display_observer
);
1206 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1207 display_manager
->SetSecondDisplayMode(DisplayManager::MIRRORING
);
1208 display_manager
->UpdateDisplays();
1209 EXPECT_TRUE(display_observer
.changed_and_reset());
1210 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1211 EXPECT_EQ("0,0 300x400",
1212 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1213 EXPECT_EQ("400x500", test_api
.GetHost()->GetBounds().size().ToString());
1214 EXPECT_EQ("300x400",
1215 test_api
.GetHost()->window()->bounds().size().ToString());
1216 EXPECT_TRUE(display_manager
->IsMirrored());
1218 display_manager
->SetMirrorMode(false);
1219 EXPECT_TRUE(display_observer
.changed_and_reset());
1220 EXPECT_EQ(NULL
, test_api
.GetHost());
1221 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1222 EXPECT_FALSE(display_manager
->IsMirrored());
1224 // Make sure the mirror window has the pixel size of the
1226 display_manager
->SetMirrorMode(true);
1227 EXPECT_TRUE(display_observer
.changed_and_reset());
1229 UpdateDisplay("300x400@0.5,400x500");
1230 EXPECT_FALSE(display_observer
.changed_and_reset());
1231 EXPECT_EQ("300x400",
1232 test_api
.GetHost()->window()->bounds().size().ToString());
1234 UpdateDisplay("310x410*2,400x500");
1235 EXPECT_FALSE(display_observer
.changed_and_reset());
1236 EXPECT_EQ("310x410",
1237 test_api
.GetHost()->window()->bounds().size().ToString());
1239 UpdateDisplay("320x420/r,400x500");
1240 EXPECT_FALSE(display_observer
.changed_and_reset());
1241 EXPECT_EQ("320x420",
1242 test_api
.GetHost()->window()->bounds().size().ToString());
1244 UpdateDisplay("330x440/r,400x500");
1245 EXPECT_FALSE(display_observer
.changed_and_reset());
1246 EXPECT_EQ("330x440",
1247 test_api
.GetHost()->window()->bounds().size().ToString());
1249 // Overscan insets are ignored.
1250 UpdateDisplay("400x600/o,600x800/o");
1251 EXPECT_FALSE(display_observer
.changed_and_reset());
1252 EXPECT_EQ("400x600",
1253 test_api
.GetHost()->window()->bounds().size().ToString());
1255 Shell::GetScreen()->RemoveObserver(&display_observer
);
1258 TEST_F(DisplayManagerTest
, MirroredLayout
) {
1259 if (!SupportsMultipleDisplays())
1262 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1263 UpdateDisplay("500x500,400x400");
1264 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1265 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1266 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1268 UpdateDisplay("1+0-500x500,1+0-500x500");
1269 EXPECT_TRUE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1270 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1271 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1273 UpdateDisplay("500x500,500x500");
1274 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1275 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1276 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1279 TEST_F(DisplayManagerTest
, InvertLayout
) {
1280 EXPECT_EQ("left, 0",
1281 DisplayLayout(DisplayLayout::RIGHT
, 0).Invert().ToString());
1282 EXPECT_EQ("left, -100",
1283 DisplayLayout(DisplayLayout::RIGHT
, 100).Invert().ToString());
1284 EXPECT_EQ("left, 50",
1285 DisplayLayout(DisplayLayout::RIGHT
, -50).Invert().ToString());
1287 EXPECT_EQ("right, 0",
1288 DisplayLayout(DisplayLayout::LEFT
, 0).Invert().ToString());
1289 EXPECT_EQ("right, -90",
1290 DisplayLayout(DisplayLayout::LEFT
, 90).Invert().ToString());
1291 EXPECT_EQ("right, 60",
1292 DisplayLayout(DisplayLayout::LEFT
, -60).Invert().ToString());
1294 EXPECT_EQ("bottom, 0",
1295 DisplayLayout(DisplayLayout::TOP
, 0).Invert().ToString());
1296 EXPECT_EQ("bottom, -80",
1297 DisplayLayout(DisplayLayout::TOP
, 80).Invert().ToString());
1298 EXPECT_EQ("bottom, 70",
1299 DisplayLayout(DisplayLayout::TOP
, -70).Invert().ToString());
1302 DisplayLayout(DisplayLayout::BOTTOM
, 0).Invert().ToString());
1303 EXPECT_EQ("top, -70",
1304 DisplayLayout(DisplayLayout::BOTTOM
, 70).Invert().ToString());
1305 EXPECT_EQ("top, 80",
1306 DisplayLayout(DisplayLayout::BOTTOM
, -80).Invert().ToString());
1310 // TODO(scottmg): RootWindow doesn't get resized on Windows
1311 // Ash. http://crbug.com/247916.
1312 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1314 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1317 TEST_F(DisplayManagerTest
, MAYBE_UpdateDisplayWithHostOrigin
) {
1318 UpdateDisplay("100x200,300x400");
1319 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1320 aura::Window::Windows root_windows
=
1321 Shell::GetInstance()->GetAllRootWindows();
1322 ASSERT_EQ(2U, root_windows
.size());
1323 aura::WindowTreeHost
* host0
= root_windows
[0]->GetHost();
1324 aura::WindowTreeHost
* host1
= root_windows
[1]->GetHost();
1326 EXPECT_EQ("1,1", host0
->GetBounds().origin().ToString());
1327 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1328 // UpdateDisplay set the origin if it's not set.
1329 EXPECT_NE("1,1", host1
->GetBounds().origin().ToString());
1330 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1332 UpdateDisplay("100x200,200+300-300x400");
1333 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1334 EXPECT_EQ("0,0", host0
->GetBounds().origin().ToString());
1335 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1336 EXPECT_EQ("200,300", host1
->GetBounds().origin().ToString());
1337 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1339 UpdateDisplay("400+500-200x300,300x400");
1340 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1341 EXPECT_EQ("400,500", host0
->GetBounds().origin().ToString());
1342 EXPECT_EQ("200x300", host0
->GetBounds().size().ToString());
1343 EXPECT_EQ("0,0", host1
->GetBounds().origin().ToString());
1344 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1346 UpdateDisplay("100+200-100x200,300+500-200x300");
1347 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1348 EXPECT_EQ("100,200", host0
->GetBounds().origin().ToString());
1349 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1350 EXPECT_EQ("300,500", host1
->GetBounds().origin().ToString());
1351 EXPECT_EQ("200x300", host1
->GetBounds().size().ToString());
1355 class ScreenShutdownTest
: public test::AshTestBase
{
1357 ScreenShutdownTest() {
1359 virtual ~ScreenShutdownTest() {}
1361 virtual void TearDown() OVERRIDE
{
1362 gfx::Screen
* orig_screen
=
1363 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1364 AshTestBase::TearDown();
1365 if (!SupportsMultipleDisplays())
1367 gfx::Screen
* screen
=
1368 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1369 EXPECT_NE(orig_screen
, screen
);
1370 EXPECT_EQ(2, screen
->GetNumDisplays());
1371 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1372 std::vector
<gfx::Display
> all
= screen
->GetAllDisplays();
1373 EXPECT_EQ("500x300", all
[0].size().ToString());
1374 EXPECT_EQ("800x400", all
[1].size().ToString());
1378 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest
);
1381 TEST_F(ScreenShutdownTest
, ScreenAfterShutdown
) {
1382 if (!SupportsMultipleDisplays())
1384 UpdateDisplay("500x300,800x400");
1388 #if defined(OS_CHROMEOS)
1391 // A helper class that sets the display configuration and starts ash.
1392 // This is to make sure the font configuration happens during ash
1393 // initialization process.
1394 class FontTestHelper
: public test::AshTestBase
{
1401 FontTestHelper(float scale
, DisplayType display_type
) {
1402 gfx::ClearFontRenderParamsCacheForTest();
1403 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1404 if (display_type
== INTERNAL
)
1405 command_line
->AppendSwitch(switches::kAshUseFirstDisplayAsInternal
);
1406 command_line
->AppendSwitchASCII(switches::kAshHostWindowBounds
,
1407 StringPrintf("1000x800*%f", scale
));
1411 virtual ~FontTestHelper() {
1415 // test::AshTestBase:
1416 virtual void TestBody() OVERRIDE
{
1421 DISALLOW_COPY_AND_ASSIGN(FontTestHelper
);
1425 bool IsTextSubpixelPositioningEnabled() {
1426 gfx::FontRenderParams params
=
1427 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(false), NULL
);
1428 return params
.subpixel_positioning
;
1433 typedef testing::Test DisplayManagerFontTest
;
1435 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100Internal
) {
1436 FontTestHelper
helper(1.0f
, FontTestHelper::INTERNAL
);
1438 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1439 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1442 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125Internal
) {
1443 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1445 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1446 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1449 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200Internal
) {
1450 FontTestHelper
helper(2.0f
, FontTestHelper::INTERNAL
);
1452 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1453 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1456 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100External
) {
1457 FontTestHelper
helper(1.0f
, FontTestHelper::EXTERNAL
);
1459 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1460 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1463 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125External
) {
1464 FontTestHelper
helper(1.25f
, FontTestHelper::EXTERNAL
);
1466 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1467 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1470 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200External
) {
1471 FontTestHelper
helper(2.0f
, FontTestHelper::EXTERNAL
);
1473 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1474 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1477 #endif // OS_CHROMEOS