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/display/display_controller.h"
8 #include "ash/display/display_layout_store.h"
9 #include "ash/screen_util.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "ash/test/mirror_window_test_api.h"
14 #include "base/format_macros.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/test/event_generator.h"
19 #include "ui/aura/window_observer.h"
20 #include "ui/aura/window_tree_host.h"
21 #include "ui/gfx/display_observer.h"
22 #include "ui/gfx/display.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/gfx/screen_type_delegate.h"
31 using base::StringPrintf
;
35 std::string
ToDisplayName(int64 id
) {
36 return "x-" + base::Int64ToString(id
);
41 class DisplayManagerTest
: public test::AshTestBase
,
42 public gfx::DisplayObserver
,
43 public aura::WindowObserver
{
47 root_window_destroyed_(false) {
49 virtual ~DisplayManagerTest() {}
51 virtual void SetUp() OVERRIDE
{
53 Shell::GetScreen()->AddObserver(this);
54 Shell::GetPrimaryRootWindow()->AddObserver(this);
56 virtual void TearDown() OVERRIDE
{
57 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
58 Shell::GetScreen()->RemoveObserver(this);
59 AshTestBase::TearDown();
62 DisplayManager
* display_manager() {
63 return Shell::GetInstance()->display_manager();
65 const vector
<gfx::Display
>& changed() const { return changed_
; }
66 const vector
<gfx::Display
>& added() const { return added_
; }
68 string
GetCountSummary() const {
69 return StringPrintf("%" PRIuS
" %" PRIuS
" %" PRIuS
,
70 changed_
.size(), added_
.size(), removed_count_
);
77 root_window_destroyed_
= false;
80 bool root_window_destroyed() const {
81 return root_window_destroyed_
;
84 const DisplayInfo
& GetDisplayInfo(const gfx::Display
& display
) {
85 return display_manager()->GetDisplayInfo(display
.id());
88 const DisplayInfo
& GetDisplayInfoAt(int index
) {
89 return GetDisplayInfo(display_manager()->GetDisplayAt(index
));
92 const gfx::Display
& GetDisplayForId(int64 id
) {
93 return display_manager()->GetDisplayForId(id
);
96 const DisplayInfo
& GetDisplayInfoForId(int64 id
) {
97 return GetDisplayInfo(display_manager()->GetDisplayForId(id
));
100 // aura::DisplayObserver overrides:
101 virtual void OnDisplayBoundsChanged(const gfx::Display
& display
) OVERRIDE
{
102 changed_
.push_back(display
);
104 virtual void OnDisplayAdded(const gfx::Display
& new_display
) OVERRIDE
{
105 added_
.push_back(new_display
);
107 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
{
111 // aura::WindowObserver overrides:
112 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
{
113 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window
);
114 root_window_destroyed_
= true;
118 vector
<gfx::Display
> changed_
;
119 vector
<gfx::Display
> added_
;
120 size_t removed_count_
;
121 bool root_window_destroyed_
;
123 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest
);
126 TEST_F(DisplayManagerTest
, UpdateDisplayTest
) {
127 if (!SupportsMultipleDisplays())
130 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
132 // Update primary and add seconary.
133 UpdateDisplay("100+0-500x500,0+501-400x400");
134 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
135 EXPECT_EQ("0,0 500x500",
136 display_manager()->GetDisplayAt(0).bounds().ToString());
138 EXPECT_EQ("1 1 0", GetCountSummary());
139 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
140 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
141 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
142 // Secondary display is on right.
143 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
144 EXPECT_EQ("0,501 400x400",
145 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
149 UpdateDisplay("100+0-500x500");
150 EXPECT_EQ("0 0 1", GetCountSummary());
154 UpdateDisplay("1+1-1000x600");
155 EXPECT_EQ("1 0 0", GetCountSummary());
156 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
157 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
161 UpdateDisplay("1+1-1000x600,1002+0-600x400");
162 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
163 EXPECT_EQ("0 1 0", GetCountSummary());
164 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
165 // Secondary display is on right.
166 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
167 EXPECT_EQ("1002,0 600x400",
168 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
171 // Secondary removed, primary changed.
172 UpdateDisplay("1+1-800x300");
173 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
174 EXPECT_EQ("1 0 1", GetCountSummary());
175 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
176 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
179 // # of display can go to zero when screen is off.
180 const vector
<DisplayInfo
> empty
;
181 display_manager()->OnNativeDisplaysChanged(empty
);
182 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
183 EXPECT_EQ("0 0 0", GetCountSummary());
184 EXPECT_FALSE(root_window_destroyed());
185 // Display configuration stays the same
186 EXPECT_EQ("0,0 800x300",
187 display_manager()->GetDisplayAt(0).bounds().ToString());
190 // Connect to display again
191 UpdateDisplay("100+100-500x400");
192 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
193 EXPECT_EQ("1 0 0", GetCountSummary());
194 EXPECT_FALSE(root_window_destroyed());
195 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
196 EXPECT_EQ("100,100 500x400",
197 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
200 // Go back to zero and wake up with multiple displays.
201 display_manager()->OnNativeDisplaysChanged(empty
);
202 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
203 EXPECT_FALSE(root_window_destroyed());
207 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
208 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
209 EXPECT_EQ("0,0 1000x600",
210 display_manager()->GetDisplayAt(0).bounds().ToString());
211 // Secondary display is on right.
212 EXPECT_EQ("1000,0 600x400",
213 display_manager()->GetDisplayAt(1).bounds().ToString());
214 EXPECT_EQ("1000,1000 600x400",
215 GetDisplayInfoAt(1).bounds_in_native().ToString());
218 // Changing primary will update secondary as well.
219 UpdateDisplay("0+0-800x600,1000+1000-600x400");
220 EXPECT_EQ("2 0 0", GetCountSummary());
222 EXPECT_EQ("0,0 800x600",
223 display_manager()->GetDisplayAt(0).bounds().ToString());
224 EXPECT_EQ("800,0 600x400",
225 display_manager()->GetDisplayAt(1).bounds().ToString());
228 // Test in emulation mode (use_fullscreen_host_window=false)
229 TEST_F(DisplayManagerTest
, EmulatorTest
) {
230 if (!SupportsMultipleDisplays())
233 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
235 display_manager()->AddRemoveDisplay();
236 // Update primary and add seconary.
237 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
238 EXPECT_EQ("0 1 0", GetCountSummary());
241 display_manager()->AddRemoveDisplay();
242 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
243 EXPECT_EQ("0 0 1", GetCountSummary());
246 display_manager()->AddRemoveDisplay();
247 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
248 EXPECT_EQ("0 1 0", GetCountSummary());
252 TEST_F(DisplayManagerTest
, OverscanInsetsTest
) {
253 if (!SupportsMultipleDisplays())
256 UpdateDisplay("0+0-500x500,0+501-400x400");
258 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
259 const DisplayInfo
& display_info1
= GetDisplayInfoAt(0);
260 const DisplayInfo
& display_info2
= GetDisplayInfoAt(1);
261 display_manager()->SetOverscanInsets(
262 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
264 std::vector
<gfx::Display
> changed_displays
= changed();
265 EXPECT_EQ(1u, changed_displays
.size());
266 EXPECT_EQ(display_info2
.id(), changed_displays
[0].id());
267 EXPECT_EQ("0,0 500x500",
268 GetDisplayInfoAt(0).bounds_in_native().ToString());
269 DisplayInfo updated_display_info2
= GetDisplayInfoAt(1);
270 EXPECT_EQ("0,501 400x400",
271 updated_display_info2
.bounds_in_native().ToString());
273 updated_display_info2
.size_in_pixel().ToString());
274 EXPECT_EQ("13,12,11,10",
275 updated_display_info2
.overscan_insets_in_dip().ToString());
276 EXPECT_EQ("500,0 378x376",
277 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
279 // Make sure that SetOverscanInsets() is idempotent.
280 display_manager()->SetOverscanInsets(display_info1
.id(), gfx::Insets());
281 display_manager()->SetOverscanInsets(
282 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
283 EXPECT_EQ("0,0 500x500",
284 GetDisplayInfoAt(0).bounds_in_native().ToString());
285 updated_display_info2
= GetDisplayInfoAt(1);
286 EXPECT_EQ("0,501 400x400",
287 updated_display_info2
.bounds_in_native().ToString());
289 updated_display_info2
.size_in_pixel().ToString());
290 EXPECT_EQ("13,12,11,10",
291 updated_display_info2
.overscan_insets_in_dip().ToString());
293 display_manager()->SetOverscanInsets(
294 display_info2
.id(), gfx::Insets(10, 11, 12, 13));
295 EXPECT_EQ("0,0 500x500",
296 GetDisplayInfoAt(0).bounds_in_native().ToString());
298 GetDisplayInfoAt(1).size_in_pixel().ToString());
299 EXPECT_EQ("10,11,12,13",
300 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
302 // Recreate a new 2nd display. It won't apply the overscan inset because the
303 // new display has a different ID.
304 UpdateDisplay("0+0-500x500");
305 UpdateDisplay("0+0-500x500,0+501-400x400");
306 EXPECT_EQ("0,0 500x500",
307 GetDisplayInfoAt(0).bounds_in_native().ToString());
308 EXPECT_EQ("0,501 400x400",
309 GetDisplayInfoAt(1).bounds_in_native().ToString());
311 // Recreate the displays with the same ID. It should apply the overscan
313 UpdateDisplay("0+0-500x500");
314 std::vector
<DisplayInfo
> display_info_list
;
315 display_info_list
.push_back(display_info1
);
316 display_info_list
.push_back(display_info2
);
317 display_manager()->OnNativeDisplaysChanged(display_info_list
);
318 EXPECT_EQ("1,1 500x500",
319 GetDisplayInfoAt(0).bounds_in_native().ToString());
320 updated_display_info2
= GetDisplayInfoAt(1);
322 updated_display_info2
.size_in_pixel().ToString());
323 EXPECT_EQ("10,11,12,13",
324 updated_display_info2
.overscan_insets_in_dip().ToString());
326 // HiDPI but overscan display. The specified insets size should be doubled.
327 UpdateDisplay("0+0-500x500,0+501-400x400*2");
328 display_manager()->SetOverscanInsets(
329 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
330 EXPECT_EQ("0,0 500x500",
331 GetDisplayInfoAt(0).bounds_in_native().ToString());
332 updated_display_info2
= GetDisplayInfoAt(1);
333 EXPECT_EQ("0,501 400x400",
334 updated_display_info2
.bounds_in_native().ToString());
336 updated_display_info2
.size_in_pixel().ToString());
338 updated_display_info2
.overscan_insets_in_dip().ToString());
339 EXPECT_EQ("8,10,12,14",
340 updated_display_info2
.GetOverscanInsetsInPixel().ToString());
342 // Make sure switching primary display applies the overscan offset only once.
343 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
344 ScreenUtil::GetSecondaryDisplay());
345 EXPECT_EQ("-500,0 500x500",
346 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
347 EXPECT_EQ("0,0 500x500",
348 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
349 bounds_in_native().ToString());
350 EXPECT_EQ("0,501 400x400",
351 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
352 bounds_in_native().ToString());
353 EXPECT_EQ("0,0 188x190",
354 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
357 TEST_F(DisplayManagerTest
, ZeroOverscanInsets
) {
358 if (!SupportsMultipleDisplays())
361 // Make sure the display change events is emitted for overscan inset changes.
362 UpdateDisplay("0+0-500x500,0+501-400x400");
363 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
364 int64 display2_id
= display_manager()->GetDisplayAt(1).id();
367 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
368 EXPECT_EQ(0u, changed().size());
371 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(1, 0, 0, 0));
372 EXPECT_EQ(1u, changed().size());
373 EXPECT_EQ(display2_id
, changed()[0].id());
376 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
377 EXPECT_EQ(1u, changed().size());
378 EXPECT_EQ(display2_id
, changed()[0].id());
381 TEST_F(DisplayManagerTest
, TestDeviceScaleOnlyChange
) {
382 if (!SupportsHostWindowResize())
385 UpdateDisplay("1000x600");
386 aura::WindowTreeHost
* host
= Shell::GetPrimaryRootWindow()->GetHost();
387 EXPECT_EQ(1, host
->compositor()->device_scale_factor());
388 EXPECT_EQ("1000x600",
389 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
390 UpdateDisplay("1000x600*2");
391 EXPECT_EQ(2, host
->compositor()->device_scale_factor());
393 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
396 DisplayInfo
CreateDisplayInfo(int64 id
, const gfx::Rect
& bounds
) {
397 DisplayInfo
info(id
, ToDisplayName(id
), false);
398 info
.SetBounds(bounds
);
402 TEST_F(DisplayManagerTest
, TestNativeDisplaysChanged
) {
403 const int64 internal_display_id
=
404 test::DisplayManagerTestApi(display_manager()).
405 SetFirstDisplayAsInternalDisplay();
406 const int external_id
= 10;
407 const int mirror_id
= 11;
408 const int64 invalid_id
= gfx::Display::kInvalidDisplayID
;
409 const DisplayInfo internal_display_info
=
410 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
411 const DisplayInfo external_display_info
=
412 CreateDisplayInfo(external_id
, gfx::Rect(1, 1, 100, 100));
413 const DisplayInfo mirrored_display_info
=
414 CreateDisplayInfo(mirror_id
, gfx::Rect(0, 0, 500, 500));
416 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
417 EXPECT_EQ(1U, display_manager()->num_connected_displays());
418 std::string default_bounds
=
419 display_manager()->GetDisplayAt(0).bounds().ToString();
421 std::vector
<DisplayInfo
> display_info_list
;
422 // Primary disconnected.
423 display_manager()->OnNativeDisplaysChanged(display_info_list
);
424 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
425 EXPECT_EQ(default_bounds
,
426 display_manager()->GetDisplayAt(0).bounds().ToString());
427 EXPECT_EQ(1U, display_manager()->num_connected_displays());
428 EXPECT_FALSE(display_manager()->IsMirrored());
430 if (!SupportsMultipleDisplays())
433 // External connected while primary was disconnected.
434 display_info_list
.push_back(external_display_info
);
435 display_manager()->OnNativeDisplaysChanged(display_info_list
);
436 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
438 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
439 EXPECT_EQ("1,1 100x100",
440 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
441 EXPECT_EQ(1U, display_manager()->num_connected_displays());
442 EXPECT_FALSE(display_manager()->IsMirrored());
443 EXPECT_EQ(external_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
445 EXPECT_EQ(internal_display_id
, gfx::Display::InternalDisplayId());
447 // Primary connected, with different bounds.
448 display_info_list
.clear();
449 display_info_list
.push_back(internal_display_info
);
450 display_info_list
.push_back(external_display_info
);
451 display_manager()->OnNativeDisplaysChanged(display_info_list
);
452 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
453 EXPECT_EQ(internal_display_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
455 // This combinatino is new, so internal display becomes primary.
456 EXPECT_EQ("0,0 500x500",
457 GetDisplayForId(internal_display_id
).bounds().ToString());
458 EXPECT_EQ("1,1 100x100",
459 GetDisplayInfoForId(10).bounds_in_native().ToString());
460 EXPECT_EQ(2U, display_manager()->num_connected_displays());
461 EXPECT_FALSE(display_manager()->IsMirrored());
462 EXPECT_EQ(ToDisplayName(internal_display_id
),
463 display_manager()->GetDisplayNameForId(internal_display_id
));
466 display_info_list
.clear();
467 display_manager()->OnNativeDisplaysChanged(display_info_list
);
468 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
469 EXPECT_EQ("0,0 500x500",
470 GetDisplayForId(internal_display_id
).bounds().ToString());
471 EXPECT_EQ("1,1 100x100",
472 GetDisplayInfoForId(10).bounds_in_native().ToString());
473 EXPECT_EQ(2U, display_manager()->num_connected_displays());
474 EXPECT_FALSE(display_manager()->IsMirrored());
475 EXPECT_EQ(ToDisplayName(internal_display_id
),
476 display_manager()->GetDisplayNameForId(internal_display_id
));
478 // External display has disconnected then resumed.
479 display_info_list
.push_back(internal_display_info
);
480 display_manager()->OnNativeDisplaysChanged(display_info_list
);
481 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
482 EXPECT_EQ("0,0 500x500",
483 GetDisplayForId(internal_display_id
).bounds().ToString());
484 EXPECT_EQ(1U, display_manager()->num_connected_displays());
485 EXPECT_FALSE(display_manager()->IsMirrored());
487 // External display was changed during suspend.
488 display_info_list
.push_back(external_display_info
);
489 display_manager()->OnNativeDisplaysChanged(display_info_list
);
490 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
491 EXPECT_EQ(2U, display_manager()->num_connected_displays());
492 EXPECT_FALSE(display_manager()->IsMirrored());
495 display_info_list
.clear();
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());
501 // and resume with different external display.
502 display_info_list
.push_back(internal_display_info
);
503 display_info_list
.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
504 display_manager()->OnNativeDisplaysChanged(display_info_list
);
505 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
506 EXPECT_EQ(2U, display_manager()->num_connected_displays());
507 EXPECT_FALSE(display_manager()->IsMirrored());
508 EXPECT_FALSE(display_manager()->IsMirrored());
511 display_info_list
.clear();
512 display_info_list
.push_back(internal_display_info
);
513 display_info_list
.push_back(mirrored_display_info
);
514 display_manager()->OnNativeDisplaysChanged(display_info_list
);
515 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
516 EXPECT_EQ("0,0 500x500",
517 GetDisplayForId(internal_display_id
).bounds().ToString());
518 EXPECT_EQ(2U, display_manager()->num_connected_displays());
519 EXPECT_EQ(11U, display_manager()->mirrored_display_id());
520 EXPECT_TRUE(display_manager()->IsMirrored());
522 // Test display name.
523 EXPECT_EQ(ToDisplayName(internal_display_id
),
524 display_manager()->GetDisplayNameForId(internal_display_id
));
525 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
526 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
527 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
528 // Default name for the id that doesn't exist.
529 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
531 // and exit mirroring.
532 display_info_list
.clear();
533 display_info_list
.push_back(internal_display_info
);
534 display_info_list
.push_back(external_display_info
);
535 display_manager()->OnNativeDisplaysChanged(display_info_list
);
536 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
537 EXPECT_EQ(2U, display_manager()->num_connected_displays());
538 EXPECT_FALSE(display_manager()->IsMirrored());
539 EXPECT_EQ("0,0 500x500",
540 GetDisplayForId(internal_display_id
).bounds().ToString());
541 EXPECT_EQ("500,0 100x100",
542 GetDisplayForId(10).bounds().ToString());
545 display_info_list
.clear();
546 display_info_list
.push_back(external_display_info
);
547 display_manager()->OnNativeDisplaysChanged(display_info_list
);
548 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
549 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
550 EXPECT_EQ("1,1 100x100",
551 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
552 EXPECT_EQ(1U, display_manager()->num_connected_displays());
553 EXPECT_FALSE(display_manager()->IsMirrored());
555 // Switched to another display
556 display_info_list
.clear();
557 display_info_list
.push_back(internal_display_info
);
558 display_manager()->OnNativeDisplaysChanged(display_info_list
);
559 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
562 GetDisplayInfoForId(internal_display_id
).bounds_in_native().ToString());
563 EXPECT_EQ(1U, display_manager()->num_connected_displays());
564 EXPECT_FALSE(display_manager()->IsMirrored());
568 // TODO(scottmg): RootWindow doesn't get resized on Windows
569 // Ash. http://crbug.com/247916.
570 #define MAYBE_TestNativeDisplaysChangedNoInternal \
571 DISABLED_TestNativeDisplaysChangedNoInternal
573 #define MAYBE_TestNativeDisplaysChangedNoInternal \
574 TestNativeDisplaysChangedNoInternal
577 TEST_F(DisplayManagerTest
, MAYBE_TestNativeDisplaysChangedNoInternal
) {
578 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
580 // Don't change the display info if all displays are disconnected.
581 std::vector
<DisplayInfo
> display_info_list
;
582 display_manager()->OnNativeDisplaysChanged(display_info_list
);
583 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
585 // Connect another display which will become primary.
586 const DisplayInfo external_display_info
=
587 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
588 display_info_list
.push_back(external_display_info
);
589 display_manager()->OnNativeDisplaysChanged(display_info_list
);
590 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
591 EXPECT_EQ("1,1 100x100",
592 GetDisplayInfoForId(10).bounds_in_native().ToString());
593 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
594 GetBounds().size().ToString());
598 // Tests that rely on the actual host size/location does not work on windows.
599 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays
600 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays_2ndOnLeft
602 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays
603 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLeft
606 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays
) {
607 UpdateDisplay("200x200,300x300");
608 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
610 aura::Env
* env
= aura::Env::GetInstance();
612 aura::test::EventGenerator
generator(root_windows
[0]);
614 // Set the initial position.
615 generator
.MoveMouseToInHost(350, 150);
616 EXPECT_EQ("350,150", env
->last_mouse_location().ToString());
618 // A mouse pointer will stay in the 2nd display.
619 UpdateDisplay("300x300,200x200");
620 EXPECT_EQ("450,50", env
->last_mouse_location().ToString());
622 // A mouse pointer will be outside of displays and move to the
623 // center of 2nd display.
624 UpdateDisplay("300x300,100x100");
625 EXPECT_EQ("350,50", env
->last_mouse_location().ToString());
627 // 2nd display was disconnected, and the cursor is
628 // now in the 1st display.
629 UpdateDisplay("400x400");
630 EXPECT_EQ("50,350", env
->last_mouse_location().ToString());
632 // 1st display's resolution has changed, and the mouse pointer is
633 // now outside. Move the mouse pointer to the center of 1st display.
634 UpdateDisplay("300x300");
635 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
637 // Move the mouse pointer to the bottom of 1st display.
638 generator
.MoveMouseToInHost(150, 290);
639 EXPECT_EQ("150,290", env
->last_mouse_location().ToString());
641 // The mouse pointer is now on 2nd display.
642 UpdateDisplay("300x280,200x200");
643 EXPECT_EQ("450,10", env
->last_mouse_location().ToString());
646 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays_2ndOnLeft
) {
647 // Set the 2nd display on the left.
648 DisplayLayoutStore
* layout_store
=
649 Shell::GetInstance()->display_manager()->layout_store();
650 DisplayLayout layout
= layout_store
->default_display_layout();
651 layout
.position
= DisplayLayout::LEFT
;
652 layout_store
->SetDefaultDisplayLayout(layout
);
654 UpdateDisplay("200x200,300x300");
655 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
657 EXPECT_EQ("-300,0 300x300",
658 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
660 aura::Env
* env
= aura::Env::GetInstance();
662 // Set the initial position.
663 root_windows
[0]->MoveCursorTo(gfx::Point(-150, 250));
664 EXPECT_EQ("-150,250", env
->last_mouse_location().ToString());
666 // A mouse pointer will stay in 2nd display.
667 UpdateDisplay("300x300,200x300");
668 EXPECT_EQ("-50,150", env
->last_mouse_location().ToString());
670 // A mouse pointer will be outside of displays and move to the
671 // center of 2nd display.
672 UpdateDisplay("300x300,200x100");
673 EXPECT_EQ("-100,50", env
->last_mouse_location().ToString());
675 // 2nd display was disconnected. Mouse pointer should move to
677 UpdateDisplay("300x300");
678 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
681 TEST_F(DisplayManagerTest
, NativeDisplaysChangedAfterPrimaryChange
) {
682 if (!SupportsMultipleDisplays())
685 const int64 internal_display_id
=
686 test::DisplayManagerTestApi(display_manager()).
687 SetFirstDisplayAsInternalDisplay();
688 const DisplayInfo native_display_info
=
689 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
690 const DisplayInfo secondary_display_info
=
691 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
693 std::vector
<DisplayInfo
> display_info_list
;
694 display_info_list
.push_back(native_display_info
);
695 display_info_list
.push_back(secondary_display_info
);
696 display_manager()->OnNativeDisplaysChanged(display_info_list
);
697 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
698 EXPECT_EQ("0,0 500x500",
699 GetDisplayForId(internal_display_id
).bounds().ToString());
700 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
702 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
703 GetDisplayForId(secondary_display_info
.id()));
704 EXPECT_EQ("-500,0 500x500",
705 GetDisplayForId(internal_display_id
).bounds().ToString());
706 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
708 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
709 // nothing changed if the exactly same displays are specified.
710 display_manager()->OnNativeDisplaysChanged(display_info_list
);
711 EXPECT_EQ("-500,0 500x500",
712 GetDisplayForId(internal_display_id
).bounds().ToString());
713 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
716 TEST_F(DisplayManagerTest
, DontRememberBestResolution
) {
717 int display_id
= 1000;
718 DisplayInfo native_display_info
=
719 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
720 std::vector
<DisplayMode
> display_modes
;
721 display_modes
.push_back(
722 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
723 display_modes
.push_back(
724 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
725 display_modes
.push_back(
726 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
728 native_display_info
.set_display_modes(display_modes
);
730 std::vector
<DisplayInfo
> display_info_list
;
731 display_info_list
.push_back(native_display_info
);
732 display_manager()->OnNativeDisplaysChanged(display_info_list
);
736 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
738 // Unsupported resolution.
739 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 4000));
741 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
743 // Supported resolution.
744 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
746 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
747 EXPECT_EQ("800x300", mode
.size
.ToString());
748 EXPECT_EQ(59.0f
, mode
.refresh_rate
);
749 EXPECT_FALSE(mode
.native
);
752 display_manager()->SetDisplayResolution(display_id
, gfx::Size(1000, 500));
754 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
755 EXPECT_EQ("1000x500", mode
.size
.ToString());
756 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
757 EXPECT_TRUE(mode
.native
);
760 TEST_F(DisplayManagerTest
, ResolutionFallback
) {
761 int display_id
= 1000;
762 DisplayInfo native_display_info
=
763 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
764 std::vector
<DisplayMode
> display_modes
;
765 display_modes
.push_back(
766 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
767 display_modes
.push_back(
768 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
769 display_modes
.push_back(
770 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
772 std::vector
<DisplayMode
> copy
= display_modes
;
773 native_display_info
.set_display_modes(copy
);
775 std::vector
<DisplayInfo
> display_info_list
;
776 display_info_list
.push_back(native_display_info
);
777 display_manager()->OnNativeDisplaysChanged(display_info_list
);
779 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
780 DisplayInfo new_native_display_info
=
781 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 400, 500));
782 copy
= display_modes
;
783 new_native_display_info
.set_display_modes(copy
);
784 std::vector
<DisplayInfo
> new_display_info_list
;
785 new_display_info_list
.push_back(new_native_display_info
);
786 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
790 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
791 EXPECT_EQ("400x500", mode
.size
.ToString());
792 EXPECT_EQ(60.0f
, mode
.refresh_rate
);
793 EXPECT_FALSE(mode
.native
);
796 // Best resolution should find itself on the resolutions list.
797 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
798 DisplayInfo new_native_display_info
=
799 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
800 std::vector
<DisplayMode
> copy
= display_modes
;
801 new_native_display_info
.set_display_modes(copy
);
802 std::vector
<DisplayInfo
> new_display_info_list
;
803 new_display_info_list
.push_back(new_native_display_info
);
804 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
808 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
809 EXPECT_EQ("1000x500", mode
.size
.ToString());
810 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
811 EXPECT_TRUE(mode
.native
);
815 TEST_F(DisplayManagerTest
, Rotate
) {
816 if (!SupportsMultipleDisplays())
819 UpdateDisplay("100x200/r,300x400/l");
820 EXPECT_EQ("1,1 100x200",
821 GetDisplayInfoAt(0).bounds_in_native().ToString());
823 GetDisplayInfoAt(0).size_in_pixel().ToString());
825 EXPECT_EQ("1,201 300x400",
826 GetDisplayInfoAt(1).bounds_in_native().ToString());
828 GetDisplayInfoAt(1).size_in_pixel().ToString());
830 UpdateDisplay("100x200/b,300x400");
831 EXPECT_EQ("2 0 0", GetCountSummary());
834 EXPECT_EQ("1,1 100x200",
835 GetDisplayInfoAt(0).bounds_in_native().ToString());
837 GetDisplayInfoAt(0).size_in_pixel().ToString());
839 EXPECT_EQ("1,201 300x400",
840 GetDisplayInfoAt(1).bounds_in_native().ToString());
842 GetDisplayInfoAt(1).size_in_pixel().ToString());
844 // Just Rotating display will change the bounds on both display.
845 UpdateDisplay("100x200/l,300x400");
846 EXPECT_EQ("2 0 0", GetCountSummary());
849 // Updating tothe same configuration should report no changes.
850 UpdateDisplay("100x200/l,300x400");
851 EXPECT_EQ("0 0 0", GetCountSummary());
854 UpdateDisplay("100x200/l,300x400");
855 EXPECT_EQ("0 0 0", GetCountSummary());
858 UpdateDisplay("200x200");
859 EXPECT_EQ("1 0 1", GetCountSummary());
862 UpdateDisplay("200x200/l");
863 EXPECT_EQ("1 0 0", GetCountSummary());
866 TEST_F(DisplayManagerTest
, UIScale
) {
867 UpdateDisplay("1280x800");
868 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
869 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
870 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
871 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
872 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
873 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
874 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
875 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
876 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
878 gfx::Display::SetInternalDisplayId(display_id
);
880 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
881 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
882 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
883 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
884 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
885 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
886 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
887 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
888 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
889 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
890 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
891 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
892 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
893 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
894 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
895 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
897 UpdateDisplay("1366x768");
898 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
899 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
900 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
901 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
902 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
903 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
904 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
905 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
906 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
907 EXPECT_EQ(0.75f
, GetDisplayInfoAt(0).configured_ui_scale());
908 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
909 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
910 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
911 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
912 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
913 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
915 UpdateDisplay("1280x850*2");
916 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
917 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
918 EXPECT_EQ(1.5f
, GetDisplayInfoAt(0).configured_ui_scale());
919 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
920 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
921 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
922 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
923 display_manager()->SetDisplayUIScale(display_id
, 1.0f
);
924 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
925 gfx::Display display
= Shell::GetScreen()->GetPrimaryDisplay();
926 EXPECT_EQ(2.0f
, display
.device_scale_factor());
927 EXPECT_EQ("640x425", display
.bounds().size().ToString());
929 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
930 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
931 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
932 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
933 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
934 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
935 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
936 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
937 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
938 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
940 display_manager()->SetDisplayUIScale(display_id
, 2.0f
);
941 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).configured_ui_scale());
942 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
943 display
= Shell::GetScreen()->GetPrimaryDisplay();
944 EXPECT_EQ(1.0f
, display
.device_scale_factor());
945 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
950 // TODO(scottmg): RootWindow doesn't get resized on Windows
951 // Ash. http://crbug.com/247916.
952 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
954 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
957 TEST_F(DisplayManagerTest
, MAYBE_UpdateMouseCursorAfterRotateZoom
) {
958 // Make sure just rotating will not change native location.
959 UpdateDisplay("300x200,200x150");
960 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
961 aura::Env
* env
= aura::Env::GetInstance();
963 aura::test::EventGenerator
generator1(root_windows
[0]);
964 aura::test::EventGenerator
generator2(root_windows
[1]);
966 // Test on 1st display.
967 generator1
.MoveMouseToInHost(150, 50);
968 EXPECT_EQ("150,50", env
->last_mouse_location().ToString());
969 UpdateDisplay("300x200/r,200x150");
970 EXPECT_EQ("50,149", env
->last_mouse_location().ToString());
972 // Test on 2nd display.
973 generator2
.MoveMouseToInHost(50, 100);
974 EXPECT_EQ("250,100", env
->last_mouse_location().ToString());
975 UpdateDisplay("300x200/r,200x150/l");
976 EXPECT_EQ("249,50", env
->last_mouse_location().ToString());
978 // The native location is now outside, so move to the center
979 // of closest display.
980 UpdateDisplay("300x200/r,100x50/l");
981 EXPECT_EQ("225,50", env
->last_mouse_location().ToString());
983 // Make sure just zooming will not change native location.
984 UpdateDisplay("600x400*2,400x300");
986 // Test on 1st display.
987 generator1
.MoveMouseToInHost(200, 300);
988 EXPECT_EQ("100,150", env
->last_mouse_location().ToString());
989 UpdateDisplay("600x400*2@1.5,400x300");
990 EXPECT_EQ("150,225", env
->last_mouse_location().ToString());
992 // Test on 2nd display.
993 UpdateDisplay("600x400,400x300*2");
994 generator2
.MoveMouseToInHost(200, 250);
995 EXPECT_EQ("700,125", env
->last_mouse_location().ToString());
996 UpdateDisplay("600x400,400x300*2@1.5");
997 EXPECT_EQ("750,187", env
->last_mouse_location().ToString());
999 // The native location is now outside, so move to the
1000 // center of closest display.
1001 UpdateDisplay("600x400,400x200*2@1.5");
1002 EXPECT_EQ("750,75", env
->last_mouse_location().ToString());
1005 class TestDisplayObserver
: public gfx::DisplayObserver
{
1007 TestDisplayObserver() : changed_(false) {}
1008 virtual ~TestDisplayObserver() {}
1010 // gfx::DisplayObserver overrides:
1011 virtual void OnDisplayBoundsChanged(const gfx::Display
& display
) OVERRIDE
{
1013 virtual void OnDisplayAdded(const gfx::Display
& new_display
) OVERRIDE
{
1014 // Mirror window should already be delete before restoring
1015 // the external display.
1016 EXPECT_FALSE(test_api
.GetHost());
1019 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
{
1020 // Mirror window should not be created until the external display
1022 EXPECT_FALSE(test_api
.GetHost());
1026 bool changed_and_reset() {
1027 bool changed
= changed_
;
1033 test::MirrorWindowTestApi test_api
;
1036 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver
);
1039 TEST_F(DisplayManagerTest
, SoftwareMirroring
) {
1040 if (!SupportsMultipleDisplays())
1043 UpdateDisplay("300x400,400x500");
1045 test::MirrorWindowTestApi test_api
;
1046 EXPECT_EQ(NULL
, test_api
.GetHost());
1048 TestDisplayObserver display_observer
;
1049 Shell::GetScreen()->AddObserver(&display_observer
);
1051 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1052 display_manager
->SetSecondDisplayMode(DisplayManager::MIRRORING
);
1053 display_manager
->UpdateDisplays();
1054 EXPECT_TRUE(display_observer
.changed_and_reset());
1055 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1056 EXPECT_EQ("0,0 300x400",
1057 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1058 EXPECT_EQ("400x500", test_api
.GetHost()->GetBounds().size().ToString());
1059 EXPECT_EQ("300x400",
1060 test_api
.GetHost()->window()->bounds().size().ToString());
1061 EXPECT_TRUE(display_manager
->IsMirrored());
1063 display_manager
->SetMirrorMode(false);
1064 EXPECT_TRUE(display_observer
.changed_and_reset());
1065 EXPECT_EQ(NULL
, test_api
.GetHost());
1066 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1067 EXPECT_FALSE(display_manager
->IsMirrored());
1069 // Make sure the mirror window has the pixel size of the
1071 display_manager
->SetMirrorMode(true);
1072 EXPECT_TRUE(display_observer
.changed_and_reset());
1074 UpdateDisplay("300x400@0.5,400x500");
1075 EXPECT_FALSE(display_observer
.changed_and_reset());
1076 EXPECT_EQ("300x400",
1077 test_api
.GetHost()->window()->bounds().size().ToString());
1079 UpdateDisplay("310x410*2,400x500");
1080 EXPECT_FALSE(display_observer
.changed_and_reset());
1081 EXPECT_EQ("310x410",
1082 test_api
.GetHost()->window()->bounds().size().ToString());
1084 UpdateDisplay("320x420/r,400x500");
1085 EXPECT_FALSE(display_observer
.changed_and_reset());
1086 EXPECT_EQ("320x420",
1087 test_api
.GetHost()->window()->bounds().size().ToString());
1089 UpdateDisplay("330x440/r,400x500");
1090 EXPECT_FALSE(display_observer
.changed_and_reset());
1091 EXPECT_EQ("330x440",
1092 test_api
.GetHost()->window()->bounds().size().ToString());
1094 // Overscan insets are ignored.
1095 UpdateDisplay("400x600/o,600x800/o");
1096 EXPECT_FALSE(display_observer
.changed_and_reset());
1097 EXPECT_EQ("400x600",
1098 test_api
.GetHost()->window()->bounds().size().ToString());
1100 Shell::GetScreen()->RemoveObserver(&display_observer
);
1103 TEST_F(DisplayManagerTest
, MirroredLayout
) {
1104 if (!SupportsMultipleDisplays())
1107 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1108 UpdateDisplay("500x500,400x400");
1109 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1110 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1111 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1113 UpdateDisplay("1+0-500x500,1+0-500x500");
1114 EXPECT_TRUE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1115 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1116 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1118 UpdateDisplay("500x500,500x500");
1119 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1120 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1121 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1124 TEST_F(DisplayManagerTest
, InvertLayout
) {
1125 EXPECT_EQ("left, 0",
1126 DisplayLayout(DisplayLayout::RIGHT
, 0).Invert().ToString());
1127 EXPECT_EQ("left, -100",
1128 DisplayLayout(DisplayLayout::RIGHT
, 100).Invert().ToString());
1129 EXPECT_EQ("left, 50",
1130 DisplayLayout(DisplayLayout::RIGHT
, -50).Invert().ToString());
1132 EXPECT_EQ("right, 0",
1133 DisplayLayout(DisplayLayout::LEFT
, 0).Invert().ToString());
1134 EXPECT_EQ("right, -90",
1135 DisplayLayout(DisplayLayout::LEFT
, 90).Invert().ToString());
1136 EXPECT_EQ("right, 60",
1137 DisplayLayout(DisplayLayout::LEFT
, -60).Invert().ToString());
1139 EXPECT_EQ("bottom, 0",
1140 DisplayLayout(DisplayLayout::TOP
, 0).Invert().ToString());
1141 EXPECT_EQ("bottom, -80",
1142 DisplayLayout(DisplayLayout::TOP
, 80).Invert().ToString());
1143 EXPECT_EQ("bottom, 70",
1144 DisplayLayout(DisplayLayout::TOP
, -70).Invert().ToString());
1147 DisplayLayout(DisplayLayout::BOTTOM
, 0).Invert().ToString());
1148 EXPECT_EQ("top, -70",
1149 DisplayLayout(DisplayLayout::BOTTOM
, 70).Invert().ToString());
1150 EXPECT_EQ("top, 80",
1151 DisplayLayout(DisplayLayout::BOTTOM
, -80).Invert().ToString());
1155 // TODO(scottmg): RootWindow doesn't get resized on Windows
1156 // Ash. http://crbug.com/247916.
1157 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1159 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1162 TEST_F(DisplayManagerTest
, MAYBE_UpdateDisplayWithHostOrigin
) {
1163 UpdateDisplay("100x200,300x400");
1164 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1165 aura::Window::Windows root_windows
=
1166 Shell::GetInstance()->GetAllRootWindows();
1167 ASSERT_EQ(2U, root_windows
.size());
1168 aura::WindowTreeHost
* host0
= root_windows
[0]->GetHost();
1169 aura::WindowTreeHost
* host1
= root_windows
[1]->GetHost();
1171 EXPECT_EQ("1,1", host0
->GetBounds().origin().ToString());
1172 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1173 // UpdateDisplay set the origin if it's not set.
1174 EXPECT_NE("1,1", host1
->GetBounds().origin().ToString());
1175 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1177 UpdateDisplay("100x200,200+300-300x400");
1178 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1179 EXPECT_EQ("0,0", host0
->GetBounds().origin().ToString());
1180 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1181 EXPECT_EQ("200,300", host1
->GetBounds().origin().ToString());
1182 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1184 UpdateDisplay("400+500-200x300,300x400");
1185 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1186 EXPECT_EQ("400,500", host0
->GetBounds().origin().ToString());
1187 EXPECT_EQ("200x300", host0
->GetBounds().size().ToString());
1188 EXPECT_EQ("0,0", host1
->GetBounds().origin().ToString());
1189 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1191 UpdateDisplay("100+200-100x200,300+500-200x300");
1192 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1193 EXPECT_EQ("100,200", host0
->GetBounds().origin().ToString());
1194 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1195 EXPECT_EQ("300,500", host1
->GetBounds().origin().ToString());
1196 EXPECT_EQ("200x300", host1
->GetBounds().size().ToString());
1200 class ScreenShutdownTest
: public test::AshTestBase
{
1202 ScreenShutdownTest() {
1204 virtual ~ScreenShutdownTest() {}
1206 virtual void TearDown() OVERRIDE
{
1207 gfx::Screen
* orig_screen
=
1208 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1209 AshTestBase::TearDown();
1210 if (!SupportsMultipleDisplays())
1212 gfx::Screen
* screen
=
1213 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1214 EXPECT_NE(orig_screen
, screen
);
1215 EXPECT_EQ(2, screen
->GetNumDisplays());
1216 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1217 std::vector
<gfx::Display
> all
= screen
->GetAllDisplays();
1218 EXPECT_EQ("500x300", all
[0].size().ToString());
1219 EXPECT_EQ("800x400", all
[1].size().ToString());
1223 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest
);
1226 TEST_F(ScreenShutdownTest
, ScreenAfterShutdown
) {
1227 if (!SupportsMultipleDisplays())
1229 UpdateDisplay("500x300,800x400");