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_info.h"
10 #include "ash/display/display_layout_store.h"
11 #include "ash/display/display_util.h"
12 #include "ash/display/mirror_window_controller.h"
13 #include "ash/screen_util.h"
14 #include "ash/shell.h"
15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/display_manager_test_api.h"
17 #include "ash/test/mirror_window_test_api.h"
18 #include "ash/wm/window_state.h"
19 #include "base/command_line.h"
20 #include "base/format_macros.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/stringprintf.h"
23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/env.h"
25 #include "ui/aura/window_observer.h"
26 #include "ui/aura/window_tree_host.h"
27 #include "ui/events/test/event_generator.h"
28 #include "ui/gfx/display.h"
29 #include "ui/gfx/display_observer.h"
30 #include "ui/gfx/font_render_params.h"
31 #include "ui/gfx/screen.h"
32 #include "ui/gfx/screen_type_delegate.h"
39 using base::StringPrintf
;
43 std::string
ToDisplayName(int64 id
) {
44 return "x-" + base::Int64ToString(id
);
49 class DisplayManagerTest
: public test::AshTestBase
,
50 public gfx::DisplayObserver
,
51 public aura::WindowObserver
{
55 root_window_destroyed_(false),
56 changed_metrics_(0U) {
58 ~DisplayManagerTest() override
{}
60 void SetUp() override
{
62 Shell::GetScreen()->AddObserver(this);
63 Shell::GetPrimaryRootWindow()->AddObserver(this);
65 void TearDown() override
{
66 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
67 Shell::GetScreen()->RemoveObserver(this);
68 AshTestBase::TearDown();
71 DisplayManager
* display_manager() {
72 return Shell::GetInstance()->display_manager();
74 const vector
<gfx::Display
>& changed() const { return changed_
; }
75 const vector
<gfx::Display
>& added() const { return added_
; }
76 uint32_t changed_metrics() const { return changed_metrics_
; }
78 string
GetCountSummary() const {
79 return StringPrintf("%" PRIuS
" %" PRIuS
" %" PRIuS
,
80 changed_
.size(), added_
.size(), removed_count_
);
87 changed_metrics_
= 0U;
88 root_window_destroyed_
= false;
91 bool root_window_destroyed() const {
92 return root_window_destroyed_
;
95 const DisplayInfo
& GetDisplayInfo(const gfx::Display
& display
) {
96 return display_manager()->GetDisplayInfo(display
.id());
99 const DisplayInfo
& GetDisplayInfoAt(int index
) {
100 return GetDisplayInfo(display_manager()->GetDisplayAt(index
));
103 const gfx::Display
& GetDisplayForId(int64 id
) {
104 return display_manager()->GetDisplayForId(id
);
107 const DisplayInfo
& GetDisplayInfoForId(int64 id
) {
108 return GetDisplayInfo(display_manager()->GetDisplayForId(id
));
111 // aura::DisplayObserver overrides:
112 void OnDisplayMetricsChanged(const gfx::Display
& display
,
113 uint32_t changed_metrics
) override
{
114 changed_
.push_back(display
);
115 changed_metrics_
|= changed_metrics
;
117 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
118 added_
.push_back(new_display
);
120 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
124 // aura::WindowObserver overrides:
125 void OnWindowDestroying(aura::Window
* window
) override
{
126 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window
);
127 root_window_destroyed_
= true;
131 vector
<gfx::Display
> changed_
;
132 vector
<gfx::Display
> added_
;
133 size_t removed_count_
;
134 bool root_window_destroyed_
;
135 uint32_t changed_metrics_
;
137 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest
);
140 TEST_F(DisplayManagerTest
, UpdateDisplayTest
) {
141 if (!SupportsMultipleDisplays())
144 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
146 // Update primary and add seconary.
147 UpdateDisplay("100+0-500x500,0+501-400x400");
148 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
149 EXPECT_EQ("0,0 500x500",
150 display_manager()->GetDisplayAt(0).bounds().ToString());
152 EXPECT_EQ("1 1 0", GetCountSummary());
153 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
154 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
155 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
156 // Secondary display is on right.
157 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
158 EXPECT_EQ("0,501 400x400",
159 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
163 UpdateDisplay("100+0-500x500");
164 EXPECT_EQ("0 0 1", GetCountSummary());
168 UpdateDisplay("1+1-1000x600");
169 EXPECT_EQ("1 0 0", GetCountSummary());
170 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
171 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
175 UpdateDisplay("1+1-1000x600,1002+0-600x400");
176 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
177 EXPECT_EQ("0 1 0", GetCountSummary());
178 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
179 // Secondary display is on right.
180 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
181 EXPECT_EQ("1002,0 600x400",
182 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
185 // Secondary removed, primary changed.
186 UpdateDisplay("1+1-800x300");
187 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
188 EXPECT_EQ("1 0 1", GetCountSummary());
189 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
190 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
193 // # of display can go to zero when screen is off.
194 const vector
<DisplayInfo
> empty
;
195 display_manager()->OnNativeDisplaysChanged(empty
);
196 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
197 EXPECT_EQ("0 0 0", GetCountSummary());
198 EXPECT_FALSE(root_window_destroyed());
199 // Display configuration stays the same
200 EXPECT_EQ("0,0 800x300",
201 display_manager()->GetDisplayAt(0).bounds().ToString());
204 // Connect to display again
205 UpdateDisplay("100+100-500x400");
206 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
207 EXPECT_EQ("1 0 0", GetCountSummary());
208 EXPECT_FALSE(root_window_destroyed());
209 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
210 EXPECT_EQ("100,100 500x400",
211 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
214 // Go back to zero and wake up with multiple displays.
215 display_manager()->OnNativeDisplaysChanged(empty
);
216 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
217 EXPECT_FALSE(root_window_destroyed());
221 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
222 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
223 EXPECT_EQ("0,0 1000x600",
224 display_manager()->GetDisplayAt(0).bounds().ToString());
225 // Secondary display is on right.
226 EXPECT_EQ("1000,0 600x400",
227 display_manager()->GetDisplayAt(1).bounds().ToString());
228 EXPECT_EQ("1000,1000 600x400",
229 GetDisplayInfoAt(1).bounds_in_native().ToString());
232 // Changing primary will update secondary as well.
233 UpdateDisplay("0+0-800x600,1000+1000-600x400");
234 EXPECT_EQ("2 0 0", GetCountSummary());
236 EXPECT_EQ("0,0 800x600",
237 display_manager()->GetDisplayAt(0).bounds().ToString());
238 EXPECT_EQ("800,0 600x400",
239 display_manager()->GetDisplayAt(1).bounds().ToString());
242 TEST_F(DisplayManagerTest
, ScaleOnlyChange
) {
243 if (!SupportsMultipleDisplays())
245 display_manager()->ToggleDisplayScaleFactor();
246 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
247 EXPECT_TRUE(changed_metrics() &
248 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
251 // Test in emulation mode (use_fullscreen_host_window=false)
252 TEST_F(DisplayManagerTest
, EmulatorTest
) {
253 if (!SupportsMultipleDisplays())
256 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
258 display_manager()->AddRemoveDisplay();
259 // Update primary and add seconary.
260 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
261 EXPECT_EQ("0 1 0", GetCountSummary());
264 display_manager()->AddRemoveDisplay();
265 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
266 EXPECT_EQ("0 0 1", GetCountSummary());
269 display_manager()->AddRemoveDisplay();
270 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
271 EXPECT_EQ("0 1 0", GetCountSummary());
275 // Tests support for 3 displays.
276 TEST_F(DisplayManagerTest
, UpdateThreeDisplaysTest
) {
277 if (!SupportsMultipleDisplays())
280 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
282 // Test with three displays.
283 UpdateDisplay("0+0-640x480,640+0-320x200,960+0-400x300");
284 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
285 EXPECT_EQ("0,0 640x480",
286 display_manager()->GetDisplayAt(0).bounds().ToString());
287 EXPECT_EQ("640,0 320x200",
288 display_manager()->GetDisplayAt(1).bounds().ToString());
289 EXPECT_EQ("960,0 400x300",
290 display_manager()->GetDisplayAt(2).bounds().ToString());
292 EXPECT_EQ("1 2 0", GetCountSummary());
293 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
294 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
295 EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), added()[1].id());
296 EXPECT_EQ("0,0 640x480", changed()[0].bounds().ToString());
297 // Secondary and terniary displays are on right.
298 EXPECT_EQ("640,0 320x200", added()[0].bounds().ToString());
299 EXPECT_EQ("640,0 320x200",
300 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
301 EXPECT_EQ("960,0 400x300", added()[1].bounds().ToString());
302 EXPECT_EQ("960,0 400x300",
303 GetDisplayInfo(added()[1]).bounds_in_native().ToString());
307 TEST_F(DisplayManagerTest
, OverscanInsetsTest
) {
308 if (!SupportsMultipleDisplays())
311 UpdateDisplay("0+0-500x500,0+501-400x400");
313 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
314 const DisplayInfo
& display_info1
= GetDisplayInfoAt(0);
315 const DisplayInfo
& display_info2
= GetDisplayInfoAt(1);
316 display_manager()->SetOverscanInsets(
317 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
319 std::vector
<gfx::Display
> changed_displays
= changed();
320 EXPECT_EQ(1u, changed_displays
.size());
321 EXPECT_EQ(display_info2
.id(), changed_displays
[0].id());
322 EXPECT_EQ("0,0 500x500",
323 GetDisplayInfoAt(0).bounds_in_native().ToString());
324 DisplayInfo updated_display_info2
= GetDisplayInfoAt(1);
325 EXPECT_EQ("0,501 400x400",
326 updated_display_info2
.bounds_in_native().ToString());
328 updated_display_info2
.size_in_pixel().ToString());
329 EXPECT_EQ("13,12,11,10",
330 updated_display_info2
.overscan_insets_in_dip().ToString());
331 EXPECT_EQ("500,0 378x376",
332 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
334 // Make sure that SetOverscanInsets() is idempotent.
335 display_manager()->SetOverscanInsets(display_info1
.id(), gfx::Insets());
336 display_manager()->SetOverscanInsets(
337 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
338 EXPECT_EQ("0,0 500x500",
339 GetDisplayInfoAt(0).bounds_in_native().ToString());
340 updated_display_info2
= GetDisplayInfoAt(1);
341 EXPECT_EQ("0,501 400x400",
342 updated_display_info2
.bounds_in_native().ToString());
344 updated_display_info2
.size_in_pixel().ToString());
345 EXPECT_EQ("13,12,11,10",
346 updated_display_info2
.overscan_insets_in_dip().ToString());
348 display_manager()->SetOverscanInsets(
349 display_info2
.id(), gfx::Insets(10, 11, 12, 13));
350 EXPECT_EQ("0,0 500x500",
351 GetDisplayInfoAt(0).bounds_in_native().ToString());
353 GetDisplayInfoAt(1).size_in_pixel().ToString());
354 EXPECT_EQ("10,11,12,13",
355 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
357 // Recreate a new 2nd display. It won't apply the overscan inset because the
358 // new display has a different ID.
359 UpdateDisplay("0+0-500x500");
360 UpdateDisplay("0+0-500x500,0+501-400x400");
361 EXPECT_EQ("0,0 500x500",
362 GetDisplayInfoAt(0).bounds_in_native().ToString());
363 EXPECT_EQ("0,501 400x400",
364 GetDisplayInfoAt(1).bounds_in_native().ToString());
366 // Recreate the displays with the same ID. It should apply the overscan
368 UpdateDisplay("0+0-500x500");
369 std::vector
<DisplayInfo
> display_info_list
;
370 display_info_list
.push_back(display_info1
);
371 display_info_list
.push_back(display_info2
);
372 display_manager()->OnNativeDisplaysChanged(display_info_list
);
373 EXPECT_EQ("1,1 500x500",
374 GetDisplayInfoAt(0).bounds_in_native().ToString());
375 updated_display_info2
= GetDisplayInfoAt(1);
377 updated_display_info2
.size_in_pixel().ToString());
378 EXPECT_EQ("10,11,12,13",
379 updated_display_info2
.overscan_insets_in_dip().ToString());
381 // HiDPI but overscan display. The specified insets size should be doubled.
382 UpdateDisplay("0+0-500x500,0+501-400x400*2");
383 display_manager()->SetOverscanInsets(
384 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
385 EXPECT_EQ("0,0 500x500",
386 GetDisplayInfoAt(0).bounds_in_native().ToString());
387 updated_display_info2
= GetDisplayInfoAt(1);
388 EXPECT_EQ("0,501 400x400",
389 updated_display_info2
.bounds_in_native().ToString());
391 updated_display_info2
.size_in_pixel().ToString());
393 updated_display_info2
.overscan_insets_in_dip().ToString());
394 EXPECT_EQ("8,10,12,14",
395 updated_display_info2
.GetOverscanInsetsInPixel().ToString());
397 // Make sure switching primary display applies the overscan offset only once.
398 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
399 ScreenUtil::GetSecondaryDisplay());
400 EXPECT_EQ("-500,0 500x500",
401 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
402 EXPECT_EQ("0,0 500x500",
403 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
404 bounds_in_native().ToString());
405 EXPECT_EQ("0,501 400x400",
406 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
407 bounds_in_native().ToString());
408 EXPECT_EQ("0,0 188x190",
409 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
411 // Make sure just moving the overscan area should property notify observers.
412 UpdateDisplay("0+0-500x500");
413 int64 primary_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
414 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 20, 20));
415 EXPECT_EQ("0,0 480x480",
416 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
418 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(10, 10, 10, 10));
419 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
421 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
422 EXPECT_EQ("0,0 480x480",
423 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
425 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 0, 0));
426 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
428 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
429 EXPECT_EQ("0,0 500x500",
430 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
433 TEST_F(DisplayManagerTest
, ZeroOverscanInsets
) {
434 if (!SupportsMultipleDisplays())
437 // Make sure the display change events is emitted for overscan inset changes.
438 UpdateDisplay("0+0-500x500,0+501-400x400");
439 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
440 int64 display2_id
= display_manager()->GetDisplayAt(1).id();
443 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
444 EXPECT_EQ(0u, changed().size());
447 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(1, 0, 0, 0));
448 EXPECT_EQ(1u, changed().size());
449 EXPECT_EQ(display2_id
, changed()[0].id());
452 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
453 EXPECT_EQ(1u, changed().size());
454 EXPECT_EQ(display2_id
, changed()[0].id());
457 TEST_F(DisplayManagerTest
, TestDeviceScaleOnlyChange
) {
458 if (!SupportsHostWindowResize())
461 UpdateDisplay("1000x600");
462 aura::WindowTreeHost
* host
= Shell::GetPrimaryRootWindow()->GetHost();
463 EXPECT_EQ(1, host
->compositor()->device_scale_factor());
464 EXPECT_EQ("1000x600",
465 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
466 EXPECT_EQ("1 0 0", GetCountSummary());
468 UpdateDisplay("1000x600*2");
469 EXPECT_EQ(2, host
->compositor()->device_scale_factor());
470 EXPECT_EQ("2 0 0", GetCountSummary());
472 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
475 DisplayInfo
CreateDisplayInfo(int64 id
, const gfx::Rect
& bounds
) {
476 DisplayInfo
info(id
, ToDisplayName(id
), false);
477 info
.SetBounds(bounds
);
481 TEST_F(DisplayManagerTest
, TestNativeDisplaysChanged
) {
482 const int64 internal_display_id
=
483 test::DisplayManagerTestApi(display_manager()).
484 SetFirstDisplayAsInternalDisplay();
485 const int external_id
= 10;
486 const int mirror_id
= 11;
487 const int64 invalid_id
= gfx::Display::kInvalidDisplayID
;
488 const DisplayInfo internal_display_info
=
489 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
490 const DisplayInfo external_display_info
=
491 CreateDisplayInfo(external_id
, gfx::Rect(1, 1, 100, 100));
492 const DisplayInfo mirroring_display_info
=
493 CreateDisplayInfo(mirror_id
, gfx::Rect(0, 0, 500, 500));
495 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
496 EXPECT_EQ(1U, display_manager()->num_connected_displays());
497 std::string default_bounds
=
498 display_manager()->GetDisplayAt(0).bounds().ToString();
500 std::vector
<DisplayInfo
> display_info_list
;
501 // Primary disconnected.
502 display_manager()->OnNativeDisplaysChanged(display_info_list
);
503 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
504 EXPECT_EQ(default_bounds
,
505 display_manager()->GetDisplayAt(0).bounds().ToString());
506 EXPECT_EQ(1U, display_manager()->num_connected_displays());
507 EXPECT_FALSE(display_manager()->IsInMirrorMode());
509 if (!SupportsMultipleDisplays())
512 // External connected while primary was disconnected.
513 display_info_list
.push_back(external_display_info
);
514 display_manager()->OnNativeDisplaysChanged(display_info_list
);
515 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
517 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
518 EXPECT_EQ("1,1 100x100",
519 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
520 EXPECT_EQ(1U, display_manager()->num_connected_displays());
521 EXPECT_FALSE(display_manager()->IsInMirrorMode());
522 EXPECT_EQ(external_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
524 EXPECT_EQ(internal_display_id
, gfx::Display::InternalDisplayId());
526 // Primary connected, with different bounds.
527 display_info_list
.clear();
528 display_info_list
.push_back(internal_display_info
);
529 display_info_list
.push_back(external_display_info
);
530 display_manager()->OnNativeDisplaysChanged(display_info_list
);
531 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
532 EXPECT_EQ(internal_display_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
534 // This combinatino is new, so internal display becomes primary.
535 EXPECT_EQ("0,0 500x500",
536 GetDisplayForId(internal_display_id
).bounds().ToString());
537 EXPECT_EQ("1,1 100x100",
538 GetDisplayInfoForId(10).bounds_in_native().ToString());
539 EXPECT_EQ(2U, display_manager()->num_connected_displays());
540 EXPECT_FALSE(display_manager()->IsInMirrorMode());
541 EXPECT_EQ(ToDisplayName(internal_display_id
),
542 display_manager()->GetDisplayNameForId(internal_display_id
));
545 display_info_list
.clear();
546 display_manager()->OnNativeDisplaysChanged(display_info_list
);
547 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
548 EXPECT_EQ("0,0 500x500",
549 GetDisplayForId(internal_display_id
).bounds().ToString());
550 EXPECT_EQ("1,1 100x100",
551 GetDisplayInfoForId(10).bounds_in_native().ToString());
552 EXPECT_EQ(2U, display_manager()->num_connected_displays());
553 EXPECT_FALSE(display_manager()->IsInMirrorMode());
554 EXPECT_EQ(ToDisplayName(internal_display_id
),
555 display_manager()->GetDisplayNameForId(internal_display_id
));
557 // External display has disconnected then resumed.
558 display_info_list
.push_back(internal_display_info
);
559 display_manager()->OnNativeDisplaysChanged(display_info_list
);
560 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
561 EXPECT_EQ("0,0 500x500",
562 GetDisplayForId(internal_display_id
).bounds().ToString());
563 EXPECT_EQ(1U, display_manager()->num_connected_displays());
564 EXPECT_FALSE(display_manager()->IsInMirrorMode());
566 // External display was changed during suspend.
567 display_info_list
.push_back(external_display_info
);
568 display_manager()->OnNativeDisplaysChanged(display_info_list
);
569 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
570 EXPECT_EQ(2U, display_manager()->num_connected_displays());
571 EXPECT_FALSE(display_manager()->IsInMirrorMode());
574 display_info_list
.clear();
575 display_manager()->OnNativeDisplaysChanged(display_info_list
);
576 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
577 EXPECT_EQ(2U, display_manager()->num_connected_displays());
578 EXPECT_FALSE(display_manager()->IsInMirrorMode());
580 // and resume with different external display.
581 display_info_list
.push_back(internal_display_info
);
582 display_info_list
.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
583 display_manager()->OnNativeDisplaysChanged(display_info_list
);
584 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
585 EXPECT_EQ(2U, display_manager()->num_connected_displays());
586 EXPECT_FALSE(display_manager()->IsInMirrorMode());
587 EXPECT_FALSE(display_manager()->IsInMirrorMode());
590 display_info_list
.clear();
591 display_info_list
.push_back(internal_display_info
);
592 display_info_list
.push_back(mirroring_display_info
);
593 display_manager()->OnNativeDisplaysChanged(display_info_list
);
594 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
595 EXPECT_EQ("0,0 500x500",
596 GetDisplayForId(internal_display_id
).bounds().ToString());
597 EXPECT_EQ(2U, display_manager()->num_connected_displays());
598 EXPECT_EQ(11U, display_manager()->mirroring_display_id());
599 EXPECT_TRUE(display_manager()->IsInMirrorMode());
601 // Test display name.
602 EXPECT_EQ(ToDisplayName(internal_display_id
),
603 display_manager()->GetDisplayNameForId(internal_display_id
));
604 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
605 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
606 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
607 // Default name for the id that doesn't exist.
608 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
610 // and exit mirroring.
611 display_info_list
.clear();
612 display_info_list
.push_back(internal_display_info
);
613 display_info_list
.push_back(external_display_info
);
614 display_manager()->OnNativeDisplaysChanged(display_info_list
);
615 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
616 EXPECT_EQ(2U, display_manager()->num_connected_displays());
617 EXPECT_FALSE(display_manager()->IsInMirrorMode());
618 EXPECT_EQ("0,0 500x500",
619 GetDisplayForId(internal_display_id
).bounds().ToString());
620 EXPECT_EQ("500,0 100x100",
621 GetDisplayForId(10).bounds().ToString());
624 display_info_list
.clear();
625 display_info_list
.push_back(external_display_info
);
626 display_manager()->OnNativeDisplaysChanged(display_info_list
);
627 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
628 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
629 EXPECT_EQ("1,1 100x100",
630 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
631 EXPECT_EQ(1U, display_manager()->num_connected_displays());
632 EXPECT_FALSE(display_manager()->IsInMirrorMode());
634 // Switched to another display
635 display_info_list
.clear();
636 display_info_list
.push_back(internal_display_info
);
637 display_manager()->OnNativeDisplaysChanged(display_info_list
);
638 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
641 GetDisplayInfoForId(internal_display_id
).bounds_in_native().ToString());
642 EXPECT_EQ(1U, display_manager()->num_connected_displays());
643 EXPECT_FALSE(display_manager()->IsInMirrorMode());
646 // Make sure crash does not happen if add and remove happens at the same time.
647 // See: crbug.com/414394
648 TEST_F(DisplayManagerTest
, DisplayAddRemoveAtTheSameTime
) {
649 if (!SupportsMultipleDisplays())
652 UpdateDisplay("100+0-500x500,0+501-400x400");
654 const int64 primary_id
= DisplayController::GetPrimaryDisplayId();
655 const int64 secondary_id
= ScreenUtil::GetSecondaryDisplay().id();
657 DisplayInfo primary_info
= display_manager()->GetDisplayInfo(primary_id
);
658 DisplayInfo secondary_info
= display_manager()->GetDisplayInfo(secondary_id
);
660 // An id which is different from primary and secondary.
661 const int64 third_id
= primary_id
+ secondary_id
;
663 DisplayInfo third_info
=
664 CreateDisplayInfo(third_id
, gfx::Rect(0, 0, 600, 600));
666 std::vector
<DisplayInfo
> display_info_list
;
667 display_info_list
.push_back(third_info
);
668 display_info_list
.push_back(secondary_info
);
669 display_manager()->OnNativeDisplaysChanged(display_info_list
);
671 EXPECT_EQ(third_id
, DisplayController::GetPrimaryDisplayId());
672 EXPECT_EQ("600x600", GetDisplayForId(third_id
).size().ToString());
673 EXPECT_EQ(secondary_id
, ScreenUtil::GetSecondaryDisplay().id());
677 // TODO(scottmg): RootWindow doesn't get resized on Windows
678 // Ash. http://crbug.com/247916.
679 #define MAYBE_TestNativeDisplaysChangedNoInternal \
680 DISABLED_TestNativeDisplaysChangedNoInternal
682 #define MAYBE_TestNativeDisplaysChangedNoInternal \
683 TestNativeDisplaysChangedNoInternal
686 TEST_F(DisplayManagerTest
, MAYBE_TestNativeDisplaysChangedNoInternal
) {
687 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
689 // Don't change the display info if all displays are disconnected.
690 std::vector
<DisplayInfo
> display_info_list
;
691 display_manager()->OnNativeDisplaysChanged(display_info_list
);
692 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
694 // Connect another display which will become primary.
695 const DisplayInfo external_display_info
=
696 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
697 display_info_list
.push_back(external_display_info
);
698 display_manager()->OnNativeDisplaysChanged(display_info_list
);
699 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
700 EXPECT_EQ("1,1 100x100",
701 GetDisplayInfoForId(10).bounds_in_native().ToString());
702 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
703 GetBounds().size().ToString());
706 TEST_F(DisplayManagerTest
, NativeDisplaysChangedAfterPrimaryChange
) {
707 if (!SupportsMultipleDisplays())
710 const int64 internal_display_id
=
711 test::DisplayManagerTestApi(display_manager()).
712 SetFirstDisplayAsInternalDisplay();
713 const DisplayInfo native_display_info
=
714 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
715 const DisplayInfo secondary_display_info
=
716 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
718 std::vector
<DisplayInfo
> display_info_list
;
719 display_info_list
.push_back(native_display_info
);
720 display_info_list
.push_back(secondary_display_info
);
721 display_manager()->OnNativeDisplaysChanged(display_info_list
);
722 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
723 EXPECT_EQ("0,0 500x500",
724 GetDisplayForId(internal_display_id
).bounds().ToString());
725 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
727 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
728 GetDisplayForId(secondary_display_info
.id()));
729 EXPECT_EQ("-500,0 500x500",
730 GetDisplayForId(internal_display_id
).bounds().ToString());
731 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
733 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
734 // nothing changed if the exactly same displays are specified.
735 display_manager()->OnNativeDisplaysChanged(display_info_list
);
736 EXPECT_EQ("-500,0 500x500",
737 GetDisplayForId(internal_display_id
).bounds().ToString());
738 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
741 TEST_F(DisplayManagerTest
, DontRememberBestResolution
) {
742 int display_id
= 1000;
743 DisplayInfo native_display_info
=
744 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
745 std::vector
<DisplayMode
> display_modes
;
746 display_modes
.push_back(
747 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
748 display_modes
.push_back(
749 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
750 display_modes
.push_back(
751 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
753 native_display_info
.SetDisplayModes(display_modes
);
755 std::vector
<DisplayInfo
> display_info_list
;
756 display_info_list
.push_back(native_display_info
);
757 display_manager()->OnNativeDisplaysChanged(display_info_list
);
760 DisplayMode expected_mode
;
761 expected_mode
.size
= gfx::Size(1000, 500);
763 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
764 EXPECT_TRUE(expected_mode
.IsEquivalent(
765 display_manager()->GetActiveModeForDisplayId(display_id
)));
767 // Unsupported resolution.
768 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 4000));
770 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
771 EXPECT_TRUE(expected_mode
.IsEquivalent(
772 display_manager()->GetActiveModeForDisplayId(display_id
)));
774 // Supported resolution.
775 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
777 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
778 EXPECT_EQ("800x300", mode
.size
.ToString());
779 EXPECT_EQ(59.0f
, mode
.refresh_rate
);
780 EXPECT_FALSE(mode
.native
);
781 expected_mode
.size
= gfx::Size(800, 300);
782 EXPECT_TRUE(expected_mode
.IsEquivalent(
783 display_manager()->GetActiveModeForDisplayId(display_id
)));
786 display_manager()->SetDisplayResolution(display_id
, gfx::Size(1000, 500));
788 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
789 EXPECT_EQ("1000x500", mode
.size
.ToString());
790 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
791 EXPECT_TRUE(mode
.native
);
792 expected_mode
.size
= gfx::Size(1000, 500);
793 EXPECT_TRUE(expected_mode
.IsEquivalent(
794 display_manager()->GetActiveModeForDisplayId(display_id
)));
797 TEST_F(DisplayManagerTest
, ResolutionFallback
) {
798 int display_id
= 1000;
799 DisplayInfo native_display_info
=
800 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
801 std::vector
<DisplayMode
> display_modes
;
802 display_modes
.push_back(
803 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
804 display_modes
.push_back(
805 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
806 display_modes
.push_back(
807 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
809 std::vector
<DisplayMode
> copy
= display_modes
;
810 native_display_info
.SetDisplayModes(copy
);
812 std::vector
<DisplayInfo
> display_info_list
;
813 display_info_list
.push_back(native_display_info
);
814 display_manager()->OnNativeDisplaysChanged(display_info_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, 400, 500));
819 copy
= display_modes
;
820 new_native_display_info
.SetDisplayModes(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("400x500", mode
.size
.ToString());
829 EXPECT_EQ(60.0f
, mode
.refresh_rate
);
830 EXPECT_FALSE(mode
.native
);
833 // Best resolution should find itself on the resolutions list.
834 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
835 DisplayInfo new_native_display_info
=
836 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
837 std::vector
<DisplayMode
> copy
= display_modes
;
838 new_native_display_info
.SetDisplayModes(copy
);
839 std::vector
<DisplayInfo
> new_display_info_list
;
840 new_display_info_list
.push_back(new_native_display_info
);
841 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
845 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
846 EXPECT_EQ("1000x500", mode
.size
.ToString());
847 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
848 EXPECT_TRUE(mode
.native
);
852 TEST_F(DisplayManagerTest
, Rotate
) {
853 if (!SupportsMultipleDisplays())
856 UpdateDisplay("100x200/r,300x400/l");
857 EXPECT_EQ("1,1 100x200",
858 GetDisplayInfoAt(0).bounds_in_native().ToString());
860 GetDisplayInfoAt(0).size_in_pixel().ToString());
862 EXPECT_EQ("1,201 300x400",
863 GetDisplayInfoAt(1).bounds_in_native().ToString());
865 GetDisplayInfoAt(1).size_in_pixel().ToString());
867 UpdateDisplay("100x200/b,300x400");
868 EXPECT_EQ("2 0 0", GetCountSummary());
871 EXPECT_EQ("1,1 100x200",
872 GetDisplayInfoAt(0).bounds_in_native().ToString());
874 GetDisplayInfoAt(0).size_in_pixel().ToString());
876 EXPECT_EQ("1,201 300x400",
877 GetDisplayInfoAt(1).bounds_in_native().ToString());
879 GetDisplayInfoAt(1).size_in_pixel().ToString());
881 // Just Rotating display will change the bounds on both display.
882 UpdateDisplay("100x200/l,300x400");
883 EXPECT_EQ("2 0 0", GetCountSummary());
886 // Updating to the same configuration should report no changes.
887 UpdateDisplay("100x200/l,300x400");
888 EXPECT_EQ("0 0 0", GetCountSummary());
891 // Rotating 180 degrees should report one change.
892 UpdateDisplay("100x200/r,300x400");
893 EXPECT_EQ("1 0 0", GetCountSummary());
896 UpdateDisplay("200x200");
897 EXPECT_EQ("1 0 1", GetCountSummary());
900 // Rotating 180 degrees should report one change.
901 UpdateDisplay("200x200/u");
902 EXPECT_EQ("1 0 0", GetCountSummary());
905 UpdateDisplay("200x200/l");
906 EXPECT_EQ("1 0 0", GetCountSummary());
909 TEST_F(DisplayManagerTest
, UIScale
) {
910 DisplayInfo::SetUse125DSFForUIScaling(false);
912 UpdateDisplay("1280x800");
913 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
914 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
915 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
916 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
917 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
918 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
919 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
920 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
921 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
923 test::DisplayManagerTestApi(display_manager())
924 .SetInternalDisplayId(display_id
);
926 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
927 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
928 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
929 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
930 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
931 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
932 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
933 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
934 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
935 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
936 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
937 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
938 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
939 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
940 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
941 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
943 UpdateDisplay("1366x768");
944 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
945 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
946 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
947 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
948 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
949 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
950 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
951 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
952 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
953 EXPECT_EQ(0.75f
, GetDisplayInfoAt(0).configured_ui_scale());
954 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
955 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
956 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
957 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
958 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
959 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
961 UpdateDisplay("1280x850*2");
962 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
963 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
964 EXPECT_EQ(1.5f
, GetDisplayInfoAt(0).configured_ui_scale());
965 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
966 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
967 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
968 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
969 display_manager()->SetDisplayUIScale(display_id
, 1.0f
);
970 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
971 gfx::Display display
= Shell::GetScreen()->GetPrimaryDisplay();
972 EXPECT_EQ(2.0f
, display
.device_scale_factor());
973 EXPECT_EQ("640x425", display
.bounds().size().ToString());
975 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
976 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
977 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
978 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
979 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
980 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
981 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
982 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
983 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
984 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
986 display_manager()->SetDisplayUIScale(display_id
, 2.0f
);
987 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).configured_ui_scale());
988 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
989 display
= Shell::GetScreen()->GetPrimaryDisplay();
990 EXPECT_EQ(1.0f
, display
.device_scale_factor());
991 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
993 // 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
995 UpdateDisplay("1280x850*1.25");
996 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
997 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
998 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
999 display
= Shell::GetScreen()->GetPrimaryDisplay();
1000 EXPECT_EQ(1.0f
, display
.device_scale_factor());
1001 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
1004 TEST_F(DisplayManagerTest
, UIScaleWithDisplayMode
) {
1005 int display_id
= 1000;
1007 // Setup the display modes with UI-scale.
1008 DisplayInfo native_display_info
=
1009 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1280, 800));
1010 std::vector
<DisplayMode
> display_modes
;
1011 const DisplayMode
base_mode(gfx::Size(1280, 800), 60.0f
, false, false);
1012 std::vector
<DisplayMode
> mode_list
= CreateInternalDisplayModeList(base_mode
);
1013 native_display_info
.SetDisplayModes(mode_list
);
1015 std::vector
<DisplayInfo
> display_info_list
;
1016 display_info_list
.push_back(native_display_info
);
1017 display_manager()->OnNativeDisplaysChanged(display_info_list
);
1019 DisplayMode expected_mode
= base_mode
;
1020 EXPECT_TRUE(expected_mode
.IsEquivalent(
1021 display_manager()->GetActiveModeForDisplayId(display_id
)));
1023 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1024 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
1025 EXPECT_TRUE(expected_mode
.IsEquivalent(
1026 display_manager()->GetActiveModeForDisplayId(display_id
)));
1027 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
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
, 0.75f
);
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
, 0.625f
);
1036 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1037 EXPECT_TRUE(expected_mode
.IsEquivalent(
1038 display_manager()->GetActiveModeForDisplayId(display_id
)));
1040 test::DisplayManagerTestApi(display_manager())
1041 .SetInternalDisplayId(display_id
);
1043 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1044 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1045 EXPECT_TRUE(expected_mode
.IsEquivalent(
1046 display_manager()->GetActiveModeForDisplayId(display_id
)));
1047 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1048 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1049 EXPECT_TRUE(expected_mode
.IsEquivalent(
1050 display_manager()->GetActiveModeForDisplayId(display_id
)));
1051 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1052 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1053 expected_mode
.ui_scale
= 1.125f
;
1054 EXPECT_TRUE(expected_mode
.IsEquivalent(
1055 display_manager()->GetActiveModeForDisplayId(display_id
)));
1056 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1057 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1058 expected_mode
.ui_scale
= 0.8f
;
1059 EXPECT_TRUE(expected_mode
.IsEquivalent(
1060 display_manager()->GetActiveModeForDisplayId(display_id
)));
1061 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1062 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1063 EXPECT_TRUE(expected_mode
.IsEquivalent(
1064 display_manager()->GetActiveModeForDisplayId(display_id
)));
1065 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1066 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1067 expected_mode
.ui_scale
= 0.625f
;
1068 EXPECT_TRUE(expected_mode
.IsEquivalent(
1069 display_manager()->GetActiveModeForDisplayId(display_id
)));
1070 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1071 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1072 EXPECT_TRUE(expected_mode
.IsEquivalent(
1073 display_manager()->GetActiveModeForDisplayId(display_id
)));
1074 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1075 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1076 expected_mode
.ui_scale
= 0.5f
;
1077 EXPECT_TRUE(expected_mode
.IsEquivalent(
1078 display_manager()->GetActiveModeForDisplayId(display_id
)));
1081 TEST_F(DisplayManagerTest
, Use125DSFRorUIScaling
) {
1082 DisplayInfo::SetUse125DSFForUIScaling(true);
1084 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
1085 test::DisplayManagerTestApi(display_manager())
1086 .SetInternalDisplayId(display_id
);
1088 UpdateDisplay("1920x1080*1.25");
1089 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1090 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1092 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1093 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1094 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1095 EXPECT_EQ("1536x864", GetDisplayForId(display_id
).size().ToString());
1097 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1098 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1099 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1100 EXPECT_EQ("960x540", GetDisplayForId(display_id
).size().ToString());
1102 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1103 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1104 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1105 EXPECT_EQ("2400x1350", GetDisplayForId(display_id
).size().ToString());
1107 DisplayInfo::SetUse125DSFForUIScaling(false);
1111 // TODO(scottmg): RootWindow doesn't get resized on Windows
1112 // Ash. http://crbug.com/247916.
1113 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
1115 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
1118 TEST_F(DisplayManagerTest
, MAYBE_UpdateMouseCursorAfterRotateZoom
) {
1119 // Make sure just rotating will not change native location.
1120 UpdateDisplay("300x200,200x150");
1121 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1122 aura::Env
* env
= aura::Env::GetInstance();
1124 ui::test::EventGenerator
generator1(root_windows
[0]);
1125 ui::test::EventGenerator
generator2(root_windows
[1]);
1127 // Test on 1st display.
1128 generator1
.MoveMouseToInHost(150, 50);
1129 EXPECT_EQ("150,50", env
->last_mouse_location().ToString());
1130 UpdateDisplay("300x200/r,200x150");
1131 EXPECT_EQ("50,149", env
->last_mouse_location().ToString());
1133 // Test on 2nd display.
1134 generator2
.MoveMouseToInHost(50, 100);
1135 EXPECT_EQ("250,100", env
->last_mouse_location().ToString());
1136 UpdateDisplay("300x200/r,200x150/l");
1137 EXPECT_EQ("249,50", env
->last_mouse_location().ToString());
1139 // The native location is now outside, so move to the center
1140 // of closest display.
1141 UpdateDisplay("300x200/r,100x50/l");
1142 EXPECT_EQ("225,50", env
->last_mouse_location().ToString());
1144 // Make sure just zooming will not change native location.
1145 UpdateDisplay("600x400*2,400x300");
1147 // Test on 1st display.
1148 generator1
.MoveMouseToInHost(200, 300);
1149 EXPECT_EQ("100,150", env
->last_mouse_location().ToString());
1150 UpdateDisplay("600x400*2@1.5,400x300");
1151 EXPECT_EQ("150,225", env
->last_mouse_location().ToString());
1153 // Test on 2nd display.
1154 UpdateDisplay("600x400,400x300*2");
1155 generator2
.MoveMouseToInHost(200, 250);
1156 EXPECT_EQ("700,125", env
->last_mouse_location().ToString());
1157 UpdateDisplay("600x400,400x300*2@1.5");
1158 EXPECT_EQ("750,187", env
->last_mouse_location().ToString());
1160 // The native location is now outside, so move to the
1161 // center of closest display.
1162 UpdateDisplay("600x400,400x200*2@1.5");
1163 EXPECT_EQ("750,75", env
->last_mouse_location().ToString());
1166 class TestDisplayObserver
: public gfx::DisplayObserver
{
1168 TestDisplayObserver() : changed_(false) {}
1169 ~TestDisplayObserver() override
{}
1171 // gfx::DisplayObserver overrides:
1172 void OnDisplayMetricsChanged(const gfx::Display
&, uint32_t) override
{}
1173 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
1174 // Mirror window should already be delete before restoring
1175 // the external display.
1176 EXPECT_FALSE(test_api
.GetHost());
1179 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
1180 // Mirror window should not be created until the external display
1182 EXPECT_FALSE(test_api
.GetHost());
1186 bool changed_and_reset() {
1187 bool changed
= changed_
;
1193 test::MirrorWindowTestApi test_api
;
1196 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver
);
1199 TEST_F(DisplayManagerTest
, SoftwareMirroring
) {
1200 if (!SupportsMultipleDisplays())
1203 UpdateDisplay("300x400,400x500");
1205 test::MirrorWindowTestApi test_api
;
1206 EXPECT_EQ(NULL
, test_api
.GetHost());
1208 TestDisplayObserver display_observer
;
1209 Shell::GetScreen()->AddObserver(&display_observer
);
1211 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1212 display_manager
->SetMultiDisplayMode(DisplayManager::MIRRORING
);
1213 display_manager
->UpdateDisplays();
1214 RunAllPendingInMessageLoop();
1215 EXPECT_TRUE(display_observer
.changed_and_reset());
1216 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1217 EXPECT_EQ("0,0 300x400",
1218 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1219 EXPECT_EQ("400x500", test_api
.GetHost()->GetBounds().size().ToString());
1220 EXPECT_EQ("300x400",
1221 test_api
.GetHost()->window()->bounds().size().ToString());
1222 EXPECT_TRUE(display_manager
->IsInMirrorMode());
1224 display_manager
->SetMirrorMode(false);
1225 EXPECT_TRUE(display_observer
.changed_and_reset());
1226 EXPECT_EQ(NULL
, test_api
.GetHost());
1227 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1228 EXPECT_FALSE(display_manager
->IsInMirrorMode());
1230 // Make sure the mirror window has the pixel size of the
1232 display_manager
->SetMirrorMode(true);
1233 EXPECT_TRUE(display_observer
.changed_and_reset());
1235 UpdateDisplay("300x400@0.5,400x500");
1236 EXPECT_FALSE(display_observer
.changed_and_reset());
1237 EXPECT_EQ("300x400",
1238 test_api
.GetHost()->window()->bounds().size().ToString());
1240 UpdateDisplay("310x410*2,400x500");
1241 EXPECT_FALSE(display_observer
.changed_and_reset());
1242 EXPECT_EQ("310x410",
1243 test_api
.GetHost()->window()->bounds().size().ToString());
1245 UpdateDisplay("320x420/r,400x500");
1246 EXPECT_FALSE(display_observer
.changed_and_reset());
1247 EXPECT_EQ("320x420",
1248 test_api
.GetHost()->window()->bounds().size().ToString());
1250 UpdateDisplay("330x440/r,400x500");
1251 EXPECT_FALSE(display_observer
.changed_and_reset());
1252 EXPECT_EQ("330x440",
1253 test_api
.GetHost()->window()->bounds().size().ToString());
1255 // Overscan insets are ignored.
1256 UpdateDisplay("400x600/o,600x800/o");
1257 EXPECT_FALSE(display_observer
.changed_and_reset());
1258 EXPECT_EQ("400x600",
1259 test_api
.GetHost()->window()->bounds().size().ToString());
1261 Shell::GetScreen()->RemoveObserver(&display_observer
);
1264 TEST_F(DisplayManagerTest
, SingleDisplayToSoftwareMirroring
) {
1265 if (!SupportsMultipleDisplays())
1267 UpdateDisplay("600x400");
1269 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1270 display_manager
->SetMultiDisplayMode(DisplayManager::MIRRORING
);
1271 UpdateDisplay("600x400,600x400");
1273 EXPECT_TRUE(display_manager
->IsInMirrorMode());
1274 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1275 DisplayController
* display_controller
=
1276 ash::Shell::GetInstance()->display_controller();
1277 EXPECT_TRUE(display_controller
->mirror_window_controller()->GetWindow());
1279 UpdateDisplay("600x400");
1280 EXPECT_FALSE(display_manager
->IsInMirrorMode());
1281 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1282 EXPECT_FALSE(display_controller
->mirror_window_controller()->GetWindow());
1285 #if defined(OS_CHROMEOS)
1286 // Make sure this does not cause any crashes. See http://crbug.com/412910
1287 // This test is limited to OS_CHROMEOS because CursorCompositingEnabled is only
1289 TEST_F(DisplayManagerTest
, SoftwareMirroringWithCompositingCursor
) {
1290 if (!SupportsMultipleDisplays())
1293 UpdateDisplay("300x400,400x500");
1295 test::MirrorWindowTestApi test_api
;
1296 EXPECT_EQ(NULL
, test_api
.GetHost());
1298 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1299 DisplayInfo secondary_info
= display_manager
->GetDisplayInfo(
1300 ScreenUtil::GetSecondaryDisplay().id());
1302 display_manager
->SetSoftwareMirroring(true);
1303 display_manager
->UpdateDisplays();
1305 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1306 EXPECT_FALSE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1308 Shell::GetInstance()->SetCursorCompositingEnabled(true);
1310 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1312 // Removes the first display and keeps the second one.
1313 display_manager
->SetSoftwareMirroring(false);
1314 std::vector
<DisplayInfo
> new_info_list
;
1315 new_info_list
.push_back(secondary_info
);
1316 display_manager
->OnNativeDisplaysChanged(new_info_list
);
1318 root_windows
= Shell::GetAllRootWindows();
1319 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1321 Shell::GetInstance()->SetCursorCompositingEnabled(false);
1323 #endif // OS_CHROMEOS
1325 TEST_F(DisplayManagerTest
, MirroredLayout
) {
1326 if (!SupportsMultipleDisplays())
1329 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1330 UpdateDisplay("500x500,400x400");
1331 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1332 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1333 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1335 UpdateDisplay("1+0-500x500,1+0-500x500");
1336 EXPECT_TRUE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1337 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1338 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1340 UpdateDisplay("500x500,500x500");
1341 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1342 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1343 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1346 TEST_F(DisplayManagerTest
, InvertLayout
) {
1347 EXPECT_EQ("left, 0",
1348 DisplayLayout(DisplayLayout::RIGHT
, 0).Invert().ToString());
1349 EXPECT_EQ("left, -100",
1350 DisplayLayout(DisplayLayout::RIGHT
, 100).Invert().ToString());
1351 EXPECT_EQ("left, 50",
1352 DisplayLayout(DisplayLayout::RIGHT
, -50).Invert().ToString());
1354 EXPECT_EQ("right, 0",
1355 DisplayLayout(DisplayLayout::LEFT
, 0).Invert().ToString());
1356 EXPECT_EQ("right, -90",
1357 DisplayLayout(DisplayLayout::LEFT
, 90).Invert().ToString());
1358 EXPECT_EQ("right, 60",
1359 DisplayLayout(DisplayLayout::LEFT
, -60).Invert().ToString());
1361 EXPECT_EQ("bottom, 0",
1362 DisplayLayout(DisplayLayout::TOP
, 0).Invert().ToString());
1363 EXPECT_EQ("bottom, -80",
1364 DisplayLayout(DisplayLayout::TOP
, 80).Invert().ToString());
1365 EXPECT_EQ("bottom, 70",
1366 DisplayLayout(DisplayLayout::TOP
, -70).Invert().ToString());
1369 DisplayLayout(DisplayLayout::BOTTOM
, 0).Invert().ToString());
1370 EXPECT_EQ("top, -70",
1371 DisplayLayout(DisplayLayout::BOTTOM
, 70).Invert().ToString());
1372 EXPECT_EQ("top, 80",
1373 DisplayLayout(DisplayLayout::BOTTOM
, -80).Invert().ToString());
1376 TEST_F(DisplayManagerTest
, NotifyPrimaryChange
) {
1377 if (!SupportsMultipleDisplays())
1379 UpdateDisplay("500x500,500x500");
1380 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1382 UpdateDisplay("500x500");
1383 EXPECT_FALSE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1384 EXPECT_FALSE(changed_metrics() &
1385 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1386 EXPECT_TRUE(changed_metrics() &
1387 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1389 UpdateDisplay("500x500,500x500");
1390 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1392 UpdateDisplay("500x400");
1393 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1394 EXPECT_TRUE(changed_metrics() &
1395 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1396 EXPECT_TRUE(changed_metrics() &
1397 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1400 TEST_F(DisplayManagerTest
, NotifyPrimaryChangeUndock
) {
1401 if (!SupportsMultipleDisplays())
1403 // Assume the default display is an external display, and
1404 // emulates undocking by switching to another display.
1405 DisplayInfo another_display_info
=
1406 CreateDisplayInfo(1, gfx::Rect(0, 0, 1280, 800));
1407 std::vector
<DisplayInfo
> info_list
;
1408 info_list
.push_back(another_display_info
);
1410 display_manager()->OnNativeDisplaysChanged(info_list
);
1411 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1412 EXPECT_TRUE(changed_metrics() &
1413 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1414 EXPECT_TRUE(changed_metrics() &
1415 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1419 // TODO(scottmg): RootWindow doesn't get resized on Windows
1420 // Ash. http://crbug.com/247916.
1421 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1423 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1426 TEST_F(DisplayManagerTest
, MAYBE_UpdateDisplayWithHostOrigin
) {
1427 UpdateDisplay("100x200,300x400");
1428 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1429 aura::Window::Windows root_windows
=
1430 Shell::GetInstance()->GetAllRootWindows();
1431 ASSERT_EQ(2U, root_windows
.size());
1432 aura::WindowTreeHost
* host0
= root_windows
[0]->GetHost();
1433 aura::WindowTreeHost
* host1
= root_windows
[1]->GetHost();
1435 EXPECT_EQ("1,1", host0
->GetBounds().origin().ToString());
1436 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1437 // UpdateDisplay set the origin if it's not set.
1438 EXPECT_NE("1,1", host1
->GetBounds().origin().ToString());
1439 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1441 UpdateDisplay("100x200,200+300-300x400");
1442 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1443 EXPECT_EQ("0,0", host0
->GetBounds().origin().ToString());
1444 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1445 EXPECT_EQ("200,300", host1
->GetBounds().origin().ToString());
1446 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1448 UpdateDisplay("400+500-200x300,300x400");
1449 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1450 EXPECT_EQ("400,500", host0
->GetBounds().origin().ToString());
1451 EXPECT_EQ("200x300", host0
->GetBounds().size().ToString());
1452 EXPECT_EQ("0,0", host1
->GetBounds().origin().ToString());
1453 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1455 UpdateDisplay("100+200-100x200,300+500-200x300");
1456 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1457 EXPECT_EQ("100,200", host0
->GetBounds().origin().ToString());
1458 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1459 EXPECT_EQ("300,500", host1
->GetBounds().origin().ToString());
1460 EXPECT_EQ("200x300", host1
->GetBounds().size().ToString());
1463 TEST_F(DisplayManagerTest
, UnifiedDesktopBasic
) {
1464 if (!SupportsMultipleDisplays())
1466 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
1468 // Don't check root window destruction in unified mode.
1469 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
1471 UpdateDisplay("300x200,400x500");
1473 // Switch to unified desktop.
1474 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
1475 display_manager()->ReconfigureDisplays();
1477 gfx::Screen
* screen
=
1478 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1479 EXPECT_EQ("700x500", screen
->GetPrimaryDisplay().size().ToString());
1481 display_manager()->SetMirrorMode(true);
1482 EXPECT_EQ("300x200", screen
->GetPrimaryDisplay().size().ToString());
1484 display_manager()->SetMirrorMode(false);
1485 EXPECT_EQ("700x500", screen
->GetPrimaryDisplay().size().ToString());
1487 // Switch to single desktop.
1488 UpdateDisplay("500x300");
1489 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1491 // Switch to unified desktop.
1492 UpdateDisplay("500x300,400x500");
1493 EXPECT_EQ("900x500", screen
->GetPrimaryDisplay().size().ToString());
1495 // Switch back to extended desktop.
1496 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::EXTENDED
);
1497 display_manager()->ReconfigureDisplays();
1498 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1499 EXPECT_EQ("400x500", ScreenUtil::GetSecondaryDisplay().size().ToString());
1502 // Updating displays again in unified desktop mode should not crash.
1503 // crbug.com/491094.
1504 TEST_F(DisplayManagerTest
, ConfigureUnifiedTwice
) {
1505 if (!SupportsMultipleDisplays())
1507 // Don't check root window destruction in unified mode.
1508 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
1510 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
1511 UpdateDisplay("300x200,400x500");
1512 // Mirror windows are created in a posted task.
1513 RunAllPendingInMessageLoop();
1515 UpdateDisplay("300x250,400x550");
1516 RunAllPendingInMessageLoop();
1519 TEST_F(DisplayManagerTest
, RotateUnifiedDesktop
) {
1520 if (!SupportsMultipleDisplays())
1522 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
1524 // Don't check root window destruction in unified mode.
1525 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
1527 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
1528 display_manager()->SetMultiDisplayMode(DisplayManager::UNIFIED
);
1529 UpdateDisplay("300x200,400x500");
1531 gfx::Screen
* screen
=
1532 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1533 const gfx::Display
& display
= screen
->GetPrimaryDisplay();
1534 EXPECT_EQ("700x500", display
.size().ToString());
1535 display_manager()->SetDisplayRotation(display
.id(), gfx::Display::ROTATE_90
,
1536 gfx::Display::ROTATION_SOURCE_ACTIVE
);
1537 EXPECT_EQ("500x700", screen
->GetPrimaryDisplay().size().ToString());
1538 display_manager()->SetDisplayRotation(display
.id(), gfx::Display::ROTATE_0
,
1539 gfx::Display::ROTATION_SOURCE_ACTIVE
);
1540 EXPECT_EQ("700x500", screen
->GetPrimaryDisplay().size().ToString());
1542 UpdateDisplay("300x200");
1543 EXPECT_EQ("300x200", screen
->GetPrimaryDisplay().size().ToString());
1546 // Makes sure the transition from unified to single won't crash
1547 // with docked wnidows.
1548 TEST_F(DisplayManagerTest
, UnifiedWithDockWindows
) {
1549 if (!SupportsMultipleDisplays())
1551 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
1553 // Don't check root window destruction in unified mode.
1554 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
1556 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
1557 display_manager()->SetMultiDisplayMode(DisplayManager::UNIFIED
);
1558 UpdateDisplay("300x200,400x500");
1560 scoped_ptr
<aura::Window
> docked(
1561 CreateTestWindowInShellWithBounds(gfx::Rect(10, 10, 50, 50)));
1562 docked
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_DOCKED
);
1563 ASSERT_TRUE(wm::GetWindowState(docked
.get())->IsDocked());
1564 EXPECT_EQ("0,0 250x453", docked
->bounds().ToString());
1565 UpdateDisplay("300x200");
1566 // Make sure the window is still docked.
1567 EXPECT_TRUE(wm::GetWindowState(docked
.get())->IsDocked());
1568 EXPECT_EQ("0,0 250x250", docked
->bounds().ToString());
1571 class ScreenShutdownTest
: public test::AshTestBase
{
1573 ScreenShutdownTest() {
1575 ~ScreenShutdownTest() override
{}
1577 void TearDown() override
{
1578 gfx::Screen
* orig_screen
=
1579 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1580 AshTestBase::TearDown();
1581 if (!SupportsMultipleDisplays())
1583 gfx::Screen
* screen
=
1584 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1585 EXPECT_NE(orig_screen
, screen
);
1586 EXPECT_EQ(2, screen
->GetNumDisplays());
1587 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1588 std::vector
<gfx::Display
> all
= screen
->GetAllDisplays();
1589 EXPECT_EQ("500x300", all
[0].size().ToString());
1590 EXPECT_EQ("800x400", all
[1].size().ToString());
1594 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest
);
1597 TEST_F(ScreenShutdownTest
, ScreenAfterShutdown
) {
1598 if (!SupportsMultipleDisplays())
1600 UpdateDisplay("500x300,800x400");
1604 #if defined(OS_CHROMEOS)
1607 // A helper class that sets the display configuration and starts ash.
1608 // This is to make sure the font configuration happens during ash
1609 // initialization process.
1610 class FontTestHelper
: public test::AshTestBase
{
1617 FontTestHelper(float scale
, DisplayType display_type
) {
1618 gfx::ClearFontRenderParamsCacheForTest();
1619 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1620 if (display_type
== INTERNAL
)
1621 command_line
->AppendSwitch(switches::kAshUseFirstDisplayAsInternal
);
1622 command_line
->AppendSwitchASCII(switches::kAshHostWindowBounds
,
1623 StringPrintf("1000x800*%f", scale
));
1627 ~FontTestHelper() override
{ TearDown(); }
1629 // test::AshTestBase:
1630 void TestBody() override
{ NOTREACHED(); }
1633 DISALLOW_COPY_AND_ASSIGN(FontTestHelper
);
1637 bool IsTextSubpixelPositioningEnabled() {
1638 gfx::FontRenderParams params
=
1639 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), NULL
);
1640 return params
.subpixel_positioning
;
1643 gfx::FontRenderParams::Hinting
GetFontHintingParams() {
1644 gfx::FontRenderParams params
=
1645 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), NULL
);
1646 return params
.hinting
;
1651 typedef testing::Test DisplayManagerFontTest
;
1653 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100Internal
) {
1654 FontTestHelper
helper(1.0f
, FontTestHelper::INTERNAL
);
1656 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1657 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1658 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1661 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125Internal
) {
1662 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1664 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1665 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1666 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1669 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200Internal
) {
1670 FontTestHelper
helper(2.0f
, FontTestHelper::INTERNAL
);
1672 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1673 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1674 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1676 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1677 Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f
);
1680 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1681 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1682 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1685 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100External
) {
1686 FontTestHelper
helper(1.0f
, FontTestHelper::EXTERNAL
);
1688 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1689 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1690 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1693 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125External
) {
1694 FontTestHelper
helper(1.25f
, FontTestHelper::EXTERNAL
);
1696 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1697 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1698 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1701 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200External
) {
1702 FontTestHelper
helper(2.0f
, FontTestHelper::EXTERNAL
);
1704 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1705 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1706 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1709 TEST_F(DisplayManagerFontTest
,
1710 TextSubpixelPositioningWithDsf125InternalWithScaling
) {
1711 DisplayInfo::SetUse125DSFForUIScaling(true);
1712 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1714 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1715 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1716 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1718 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1719 Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f
);
1722 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1723 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1724 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1726 DisplayInfo::SetUse125DSFForUIScaling(false);
1729 #endif // OS_CHROMEOS