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 "base/command_line.h"
19 #include "base/format_macros.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/stringprintf.h"
22 #include "ui/aura/env.h"
23 #include "ui/aura/window_observer.h"
24 #include "ui/aura/window_tree_host.h"
25 #include "ui/events/test/event_generator.h"
26 #include "ui/gfx/display.h"
27 #include "ui/gfx/display_observer.h"
28 #include "ui/gfx/font_render_params.h"
29 #include "ui/gfx/screen.h"
30 #include "ui/gfx/screen_type_delegate.h"
37 using base::StringPrintf
;
41 std::string
ToDisplayName(int64 id
) {
42 return "x-" + base::Int64ToString(id
);
47 class DisplayManagerTest
: public test::AshTestBase
,
48 public gfx::DisplayObserver
,
49 public aura::WindowObserver
{
53 root_window_destroyed_(false),
54 changed_metrics_(0U) {
56 ~DisplayManagerTest() override
{}
58 void SetUp() override
{
60 Shell::GetScreen()->AddObserver(this);
61 Shell::GetPrimaryRootWindow()->AddObserver(this);
63 void TearDown() override
{
64 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
65 Shell::GetScreen()->RemoveObserver(this);
66 AshTestBase::TearDown();
69 DisplayManager
* display_manager() {
70 return Shell::GetInstance()->display_manager();
72 const vector
<gfx::Display
>& changed() const { return changed_
; }
73 const vector
<gfx::Display
>& added() const { return added_
; }
74 uint32_t changed_metrics() const { return changed_metrics_
; }
76 string
GetCountSummary() const {
77 return StringPrintf("%" PRIuS
" %" PRIuS
" %" PRIuS
,
78 changed_
.size(), added_
.size(), removed_count_
);
85 changed_metrics_
= 0U;
86 root_window_destroyed_
= false;
89 bool root_window_destroyed() const {
90 return root_window_destroyed_
;
93 const DisplayInfo
& GetDisplayInfo(const gfx::Display
& display
) {
94 return display_manager()->GetDisplayInfo(display
.id());
97 const DisplayInfo
& GetDisplayInfoAt(int index
) {
98 return GetDisplayInfo(display_manager()->GetDisplayAt(index
));
101 const gfx::Display
& GetDisplayForId(int64 id
) {
102 return display_manager()->GetDisplayForId(id
);
105 const DisplayInfo
& GetDisplayInfoForId(int64 id
) {
106 return GetDisplayInfo(display_manager()->GetDisplayForId(id
));
109 // aura::DisplayObserver overrides:
110 void OnDisplayMetricsChanged(const gfx::Display
& display
,
111 uint32_t changed_metrics
) override
{
112 changed_
.push_back(display
);
113 changed_metrics_
|= changed_metrics
;
115 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
116 added_
.push_back(new_display
);
118 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
122 // aura::WindowObserver overrides:
123 void OnWindowDestroying(aura::Window
* window
) override
{
124 // TODO(oshima): When moving between unified desktop, the
125 // primary root window can be deleted.
126 if (!display_manager()->IsInUnifiedMode()) {
127 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window
);
128 root_window_destroyed_
= true;
133 vector
<gfx::Display
> changed_
;
134 vector
<gfx::Display
> added_
;
135 size_t removed_count_
;
136 bool root_window_destroyed_
;
137 uint32_t changed_metrics_
;
139 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest
);
142 TEST_F(DisplayManagerTest
, UpdateDisplayTest
) {
143 if (!SupportsMultipleDisplays())
146 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
148 // Update primary and add seconary.
149 UpdateDisplay("100+0-500x500,0+501-400x400");
150 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
151 EXPECT_EQ("0,0 500x500",
152 display_manager()->GetDisplayAt(0).bounds().ToString());
154 EXPECT_EQ("1 1 0", GetCountSummary());
155 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
156 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
157 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
158 // Secondary display is on right.
159 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
160 EXPECT_EQ("0,501 400x400",
161 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
165 UpdateDisplay("100+0-500x500");
166 EXPECT_EQ("0 0 1", GetCountSummary());
170 UpdateDisplay("1+1-1000x600");
171 EXPECT_EQ("1 0 0", GetCountSummary());
172 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
173 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
177 UpdateDisplay("1+1-1000x600,1002+0-600x400");
178 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
179 EXPECT_EQ("0 1 0", GetCountSummary());
180 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
181 // Secondary display is on right.
182 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
183 EXPECT_EQ("1002,0 600x400",
184 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
187 // Secondary removed, primary changed.
188 UpdateDisplay("1+1-800x300");
189 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
190 EXPECT_EQ("1 0 1", GetCountSummary());
191 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
192 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
195 // # of display can go to zero when screen is off.
196 const vector
<DisplayInfo
> empty
;
197 display_manager()->OnNativeDisplaysChanged(empty
);
198 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
199 EXPECT_EQ("0 0 0", GetCountSummary());
200 EXPECT_FALSE(root_window_destroyed());
201 // Display configuration stays the same
202 EXPECT_EQ("0,0 800x300",
203 display_manager()->GetDisplayAt(0).bounds().ToString());
206 // Connect to display again
207 UpdateDisplay("100+100-500x400");
208 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
209 EXPECT_EQ("1 0 0", GetCountSummary());
210 EXPECT_FALSE(root_window_destroyed());
211 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
212 EXPECT_EQ("100,100 500x400",
213 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
216 // Go back to zero and wake up with multiple displays.
217 display_manager()->OnNativeDisplaysChanged(empty
);
218 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
219 EXPECT_FALSE(root_window_destroyed());
223 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
224 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
225 EXPECT_EQ("0,0 1000x600",
226 display_manager()->GetDisplayAt(0).bounds().ToString());
227 // Secondary display is on right.
228 EXPECT_EQ("1000,0 600x400",
229 display_manager()->GetDisplayAt(1).bounds().ToString());
230 EXPECT_EQ("1000,1000 600x400",
231 GetDisplayInfoAt(1).bounds_in_native().ToString());
234 // Changing primary will update secondary as well.
235 UpdateDisplay("0+0-800x600,1000+1000-600x400");
236 EXPECT_EQ("2 0 0", GetCountSummary());
238 EXPECT_EQ("0,0 800x600",
239 display_manager()->GetDisplayAt(0).bounds().ToString());
240 EXPECT_EQ("800,0 600x400",
241 display_manager()->GetDisplayAt(1).bounds().ToString());
244 TEST_F(DisplayManagerTest
, ScaleOnlyChange
) {
245 if (!SupportsMultipleDisplays())
247 display_manager()->ToggleDisplayScaleFactor();
248 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
249 EXPECT_TRUE(changed_metrics() &
250 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
253 // Test in emulation mode (use_fullscreen_host_window=false)
254 TEST_F(DisplayManagerTest
, EmulatorTest
) {
255 if (!SupportsMultipleDisplays())
258 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
260 display_manager()->AddRemoveDisplay();
261 // Update primary and add seconary.
262 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
263 EXPECT_EQ("0 1 0", GetCountSummary());
266 display_manager()->AddRemoveDisplay();
267 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
268 EXPECT_EQ("0 0 1", GetCountSummary());
271 display_manager()->AddRemoveDisplay();
272 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
273 EXPECT_EQ("0 1 0", GetCountSummary());
277 // Tests support for 3 displays.
278 TEST_F(DisplayManagerTest
, UpdateThreeDisplaysTest
) {
279 if (!SupportsMultipleDisplays())
282 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
284 // Test with three displays.
285 UpdateDisplay("0+0-640x480,640+0-320x200,960+0-400x300");
286 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
287 EXPECT_EQ("0,0 640x480",
288 display_manager()->GetDisplayAt(0).bounds().ToString());
289 EXPECT_EQ("640,0 320x200",
290 display_manager()->GetDisplayAt(1).bounds().ToString());
291 EXPECT_EQ("960,0 400x300",
292 display_manager()->GetDisplayAt(2).bounds().ToString());
294 EXPECT_EQ("1 2 0", GetCountSummary());
295 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
296 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
297 EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), added()[1].id());
298 EXPECT_EQ("0,0 640x480", changed()[0].bounds().ToString());
299 // Secondary and terniary displays are on right.
300 EXPECT_EQ("640,0 320x200", added()[0].bounds().ToString());
301 EXPECT_EQ("640,0 320x200",
302 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
303 EXPECT_EQ("960,0 400x300", added()[1].bounds().ToString());
304 EXPECT_EQ("960,0 400x300",
305 GetDisplayInfo(added()[1]).bounds_in_native().ToString());
309 TEST_F(DisplayManagerTest
, OverscanInsetsTest
) {
310 if (!SupportsMultipleDisplays())
313 UpdateDisplay("0+0-500x500,0+501-400x400");
315 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
316 const DisplayInfo
& display_info1
= GetDisplayInfoAt(0);
317 const DisplayInfo
& display_info2
= GetDisplayInfoAt(1);
318 display_manager()->SetOverscanInsets(
319 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
321 std::vector
<gfx::Display
> changed_displays
= changed();
322 EXPECT_EQ(1u, changed_displays
.size());
323 EXPECT_EQ(display_info2
.id(), changed_displays
[0].id());
324 EXPECT_EQ("0,0 500x500",
325 GetDisplayInfoAt(0).bounds_in_native().ToString());
326 DisplayInfo updated_display_info2
= GetDisplayInfoAt(1);
327 EXPECT_EQ("0,501 400x400",
328 updated_display_info2
.bounds_in_native().ToString());
330 updated_display_info2
.size_in_pixel().ToString());
331 EXPECT_EQ("13,12,11,10",
332 updated_display_info2
.overscan_insets_in_dip().ToString());
333 EXPECT_EQ("500,0 378x376",
334 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
336 // Make sure that SetOverscanInsets() is idempotent.
337 display_manager()->SetOverscanInsets(display_info1
.id(), gfx::Insets());
338 display_manager()->SetOverscanInsets(
339 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
340 EXPECT_EQ("0,0 500x500",
341 GetDisplayInfoAt(0).bounds_in_native().ToString());
342 updated_display_info2
= GetDisplayInfoAt(1);
343 EXPECT_EQ("0,501 400x400",
344 updated_display_info2
.bounds_in_native().ToString());
346 updated_display_info2
.size_in_pixel().ToString());
347 EXPECT_EQ("13,12,11,10",
348 updated_display_info2
.overscan_insets_in_dip().ToString());
350 display_manager()->SetOverscanInsets(
351 display_info2
.id(), gfx::Insets(10, 11, 12, 13));
352 EXPECT_EQ("0,0 500x500",
353 GetDisplayInfoAt(0).bounds_in_native().ToString());
355 GetDisplayInfoAt(1).size_in_pixel().ToString());
356 EXPECT_EQ("10,11,12,13",
357 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
359 // Recreate a new 2nd display. It won't apply the overscan inset because the
360 // new display has a different ID.
361 UpdateDisplay("0+0-500x500");
362 UpdateDisplay("0+0-500x500,0+501-400x400");
363 EXPECT_EQ("0,0 500x500",
364 GetDisplayInfoAt(0).bounds_in_native().ToString());
365 EXPECT_EQ("0,501 400x400",
366 GetDisplayInfoAt(1).bounds_in_native().ToString());
368 // Recreate the displays with the same ID. It should apply the overscan
370 UpdateDisplay("0+0-500x500");
371 std::vector
<DisplayInfo
> display_info_list
;
372 display_info_list
.push_back(display_info1
);
373 display_info_list
.push_back(display_info2
);
374 display_manager()->OnNativeDisplaysChanged(display_info_list
);
375 EXPECT_EQ("1,1 500x500",
376 GetDisplayInfoAt(0).bounds_in_native().ToString());
377 updated_display_info2
= GetDisplayInfoAt(1);
379 updated_display_info2
.size_in_pixel().ToString());
380 EXPECT_EQ("10,11,12,13",
381 updated_display_info2
.overscan_insets_in_dip().ToString());
383 // HiDPI but overscan display. The specified insets size should be doubled.
384 UpdateDisplay("0+0-500x500,0+501-400x400*2");
385 display_manager()->SetOverscanInsets(
386 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
387 EXPECT_EQ("0,0 500x500",
388 GetDisplayInfoAt(0).bounds_in_native().ToString());
389 updated_display_info2
= GetDisplayInfoAt(1);
390 EXPECT_EQ("0,501 400x400",
391 updated_display_info2
.bounds_in_native().ToString());
393 updated_display_info2
.size_in_pixel().ToString());
395 updated_display_info2
.overscan_insets_in_dip().ToString());
396 EXPECT_EQ("8,10,12,14",
397 updated_display_info2
.GetOverscanInsetsInPixel().ToString());
399 // Make sure switching primary display applies the overscan offset only once.
400 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
401 ScreenUtil::GetSecondaryDisplay());
402 EXPECT_EQ("-500,0 500x500",
403 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
404 EXPECT_EQ("0,0 500x500",
405 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
406 bounds_in_native().ToString());
407 EXPECT_EQ("0,501 400x400",
408 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
409 bounds_in_native().ToString());
410 EXPECT_EQ("0,0 188x190",
411 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
413 // Make sure just moving the overscan area should property notify observers.
414 UpdateDisplay("0+0-500x500");
415 int64 primary_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
416 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 20, 20));
417 EXPECT_EQ("0,0 480x480",
418 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
420 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(10, 10, 10, 10));
421 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
423 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
424 EXPECT_EQ("0,0 480x480",
425 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
427 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 0, 0));
428 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
430 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
431 EXPECT_EQ("0,0 500x500",
432 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
435 TEST_F(DisplayManagerTest
, ZeroOverscanInsets
) {
436 if (!SupportsMultipleDisplays())
439 // Make sure the display change events is emitted for overscan inset changes.
440 UpdateDisplay("0+0-500x500,0+501-400x400");
441 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
442 int64 display2_id
= display_manager()->GetDisplayAt(1).id();
445 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
446 EXPECT_EQ(0u, changed().size());
449 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(1, 0, 0, 0));
450 EXPECT_EQ(1u, changed().size());
451 EXPECT_EQ(display2_id
, changed()[0].id());
454 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
455 EXPECT_EQ(1u, changed().size());
456 EXPECT_EQ(display2_id
, changed()[0].id());
459 TEST_F(DisplayManagerTest
, TestDeviceScaleOnlyChange
) {
460 if (!SupportsHostWindowResize())
463 UpdateDisplay("1000x600");
464 aura::WindowTreeHost
* host
= Shell::GetPrimaryRootWindow()->GetHost();
465 EXPECT_EQ(1, host
->compositor()->device_scale_factor());
466 EXPECT_EQ("1000x600",
467 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
468 EXPECT_EQ("1 0 0", GetCountSummary());
470 UpdateDisplay("1000x600*2");
471 EXPECT_EQ(2, host
->compositor()->device_scale_factor());
472 EXPECT_EQ("2 0 0", GetCountSummary());
474 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
477 DisplayInfo
CreateDisplayInfo(int64 id
, const gfx::Rect
& bounds
) {
478 DisplayInfo
info(id
, ToDisplayName(id
), false);
479 info
.SetBounds(bounds
);
483 TEST_F(DisplayManagerTest
, TestNativeDisplaysChanged
) {
484 const int64 internal_display_id
=
485 test::DisplayManagerTestApi(display_manager()).
486 SetFirstDisplayAsInternalDisplay();
487 const int external_id
= 10;
488 const int mirror_id
= 11;
489 const int64 invalid_id
= gfx::Display::kInvalidDisplayID
;
490 const DisplayInfo internal_display_info
=
491 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
492 const DisplayInfo external_display_info
=
493 CreateDisplayInfo(external_id
, gfx::Rect(1, 1, 100, 100));
494 const DisplayInfo mirroring_display_info
=
495 CreateDisplayInfo(mirror_id
, gfx::Rect(0, 0, 500, 500));
497 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
498 EXPECT_EQ(1U, display_manager()->num_connected_displays());
499 std::string default_bounds
=
500 display_manager()->GetDisplayAt(0).bounds().ToString();
502 std::vector
<DisplayInfo
> display_info_list
;
503 // Primary disconnected.
504 display_manager()->OnNativeDisplaysChanged(display_info_list
);
505 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
506 EXPECT_EQ(default_bounds
,
507 display_manager()->GetDisplayAt(0).bounds().ToString());
508 EXPECT_EQ(1U, display_manager()->num_connected_displays());
509 EXPECT_FALSE(display_manager()->IsInMirrorMode());
511 if (!SupportsMultipleDisplays())
514 // External connected while primary was disconnected.
515 display_info_list
.push_back(external_display_info
);
516 display_manager()->OnNativeDisplaysChanged(display_info_list
);
517 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
519 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
520 EXPECT_EQ("1,1 100x100",
521 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
522 EXPECT_EQ(1U, display_manager()->num_connected_displays());
523 EXPECT_FALSE(display_manager()->IsInMirrorMode());
524 EXPECT_EQ(external_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
526 EXPECT_EQ(internal_display_id
, gfx::Display::InternalDisplayId());
528 // Primary connected, with different bounds.
529 display_info_list
.clear();
530 display_info_list
.push_back(internal_display_info
);
531 display_info_list
.push_back(external_display_info
);
532 display_manager()->OnNativeDisplaysChanged(display_info_list
);
533 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
534 EXPECT_EQ(internal_display_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
536 // This combinatino is new, so internal display becomes primary.
537 EXPECT_EQ("0,0 500x500",
538 GetDisplayForId(internal_display_id
).bounds().ToString());
539 EXPECT_EQ("1,1 100x100",
540 GetDisplayInfoForId(10).bounds_in_native().ToString());
541 EXPECT_EQ(2U, display_manager()->num_connected_displays());
542 EXPECT_FALSE(display_manager()->IsInMirrorMode());
543 EXPECT_EQ(ToDisplayName(internal_display_id
),
544 display_manager()->GetDisplayNameForId(internal_display_id
));
547 display_info_list
.clear();
548 display_manager()->OnNativeDisplaysChanged(display_info_list
);
549 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
550 EXPECT_EQ("0,0 500x500",
551 GetDisplayForId(internal_display_id
).bounds().ToString());
552 EXPECT_EQ("1,1 100x100",
553 GetDisplayInfoForId(10).bounds_in_native().ToString());
554 EXPECT_EQ(2U, display_manager()->num_connected_displays());
555 EXPECT_FALSE(display_manager()->IsInMirrorMode());
556 EXPECT_EQ(ToDisplayName(internal_display_id
),
557 display_manager()->GetDisplayNameForId(internal_display_id
));
559 // External display has disconnected then resumed.
560 display_info_list
.push_back(internal_display_info
);
561 display_manager()->OnNativeDisplaysChanged(display_info_list
);
562 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
563 EXPECT_EQ("0,0 500x500",
564 GetDisplayForId(internal_display_id
).bounds().ToString());
565 EXPECT_EQ(1U, display_manager()->num_connected_displays());
566 EXPECT_FALSE(display_manager()->IsInMirrorMode());
568 // External display was changed during suspend.
569 display_info_list
.push_back(external_display_info
);
570 display_manager()->OnNativeDisplaysChanged(display_info_list
);
571 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
572 EXPECT_EQ(2U, display_manager()->num_connected_displays());
573 EXPECT_FALSE(display_manager()->IsInMirrorMode());
576 display_info_list
.clear();
577 display_manager()->OnNativeDisplaysChanged(display_info_list
);
578 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
579 EXPECT_EQ(2U, display_manager()->num_connected_displays());
580 EXPECT_FALSE(display_manager()->IsInMirrorMode());
582 // and resume with different external display.
583 display_info_list
.push_back(internal_display_info
);
584 display_info_list
.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
585 display_manager()->OnNativeDisplaysChanged(display_info_list
);
586 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
587 EXPECT_EQ(2U, display_manager()->num_connected_displays());
588 EXPECT_FALSE(display_manager()->IsInMirrorMode());
589 EXPECT_FALSE(display_manager()->IsInMirrorMode());
592 display_info_list
.clear();
593 display_info_list
.push_back(internal_display_info
);
594 display_info_list
.push_back(mirroring_display_info
);
595 display_manager()->OnNativeDisplaysChanged(display_info_list
);
596 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
597 EXPECT_EQ("0,0 500x500",
598 GetDisplayForId(internal_display_id
).bounds().ToString());
599 EXPECT_EQ(2U, display_manager()->num_connected_displays());
600 EXPECT_EQ(11U, display_manager()->mirroring_display_id());
601 EXPECT_TRUE(display_manager()->IsInMirrorMode());
603 // Test display name.
604 EXPECT_EQ(ToDisplayName(internal_display_id
),
605 display_manager()->GetDisplayNameForId(internal_display_id
));
606 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
607 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
608 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
609 // Default name for the id that doesn't exist.
610 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
612 // and exit mirroring.
613 display_info_list
.clear();
614 display_info_list
.push_back(internal_display_info
);
615 display_info_list
.push_back(external_display_info
);
616 display_manager()->OnNativeDisplaysChanged(display_info_list
);
617 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
618 EXPECT_EQ(2U, display_manager()->num_connected_displays());
619 EXPECT_FALSE(display_manager()->IsInMirrorMode());
620 EXPECT_EQ("0,0 500x500",
621 GetDisplayForId(internal_display_id
).bounds().ToString());
622 EXPECT_EQ("500,0 100x100",
623 GetDisplayForId(10).bounds().ToString());
626 display_info_list
.clear();
627 display_info_list
.push_back(external_display_info
);
628 display_manager()->OnNativeDisplaysChanged(display_info_list
);
629 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
630 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
631 EXPECT_EQ("1,1 100x100",
632 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
633 EXPECT_EQ(1U, display_manager()->num_connected_displays());
634 EXPECT_FALSE(display_manager()->IsInMirrorMode());
636 // Switched to another display
637 display_info_list
.clear();
638 display_info_list
.push_back(internal_display_info
);
639 display_manager()->OnNativeDisplaysChanged(display_info_list
);
640 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
643 GetDisplayInfoForId(internal_display_id
).bounds_in_native().ToString());
644 EXPECT_EQ(1U, display_manager()->num_connected_displays());
645 EXPECT_FALSE(display_manager()->IsInMirrorMode());
648 // Make sure crash does not happen if add and remove happens at the same time.
649 // See: crbug.com/414394
650 TEST_F(DisplayManagerTest
, DisplayAddRemoveAtTheSameTime
) {
651 if (!SupportsMultipleDisplays())
654 UpdateDisplay("100+0-500x500,0+501-400x400");
656 const int64 primary_id
= DisplayController::GetPrimaryDisplayId();
657 const int64 secondary_id
= ScreenUtil::GetSecondaryDisplay().id();
659 DisplayInfo primary_info
= display_manager()->GetDisplayInfo(primary_id
);
660 DisplayInfo secondary_info
= display_manager()->GetDisplayInfo(secondary_id
);
662 // An id which is different from primary and secondary.
663 const int64 third_id
= primary_id
+ secondary_id
;
665 DisplayInfo third_info
=
666 CreateDisplayInfo(third_id
, gfx::Rect(0, 0, 600, 600));
668 std::vector
<DisplayInfo
> display_info_list
;
669 display_info_list
.push_back(third_info
);
670 display_info_list
.push_back(secondary_info
);
671 display_manager()->OnNativeDisplaysChanged(display_info_list
);
673 EXPECT_EQ(third_id
, DisplayController::GetPrimaryDisplayId());
674 EXPECT_EQ("600x600", GetDisplayForId(third_id
).size().ToString());
675 EXPECT_EQ(secondary_id
, ScreenUtil::GetSecondaryDisplay().id());
679 // TODO(scottmg): RootWindow doesn't get resized on Windows
680 // Ash. http://crbug.com/247916.
681 #define MAYBE_TestNativeDisplaysChangedNoInternal \
682 DISABLED_TestNativeDisplaysChangedNoInternal
684 #define MAYBE_TestNativeDisplaysChangedNoInternal \
685 TestNativeDisplaysChangedNoInternal
688 TEST_F(DisplayManagerTest
, MAYBE_TestNativeDisplaysChangedNoInternal
) {
689 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
691 // Don't change the display info if all displays are disconnected.
692 std::vector
<DisplayInfo
> display_info_list
;
693 display_manager()->OnNativeDisplaysChanged(display_info_list
);
694 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
696 // Connect another display which will become primary.
697 const DisplayInfo external_display_info
=
698 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
699 display_info_list
.push_back(external_display_info
);
700 display_manager()->OnNativeDisplaysChanged(display_info_list
);
701 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
702 EXPECT_EQ("1,1 100x100",
703 GetDisplayInfoForId(10).bounds_in_native().ToString());
704 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
705 GetBounds().size().ToString());
708 TEST_F(DisplayManagerTest
, NativeDisplaysChangedAfterPrimaryChange
) {
709 if (!SupportsMultipleDisplays())
712 const int64 internal_display_id
=
713 test::DisplayManagerTestApi(display_manager()).
714 SetFirstDisplayAsInternalDisplay();
715 const DisplayInfo native_display_info
=
716 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
717 const DisplayInfo secondary_display_info
=
718 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
720 std::vector
<DisplayInfo
> display_info_list
;
721 display_info_list
.push_back(native_display_info
);
722 display_info_list
.push_back(secondary_display_info
);
723 display_manager()->OnNativeDisplaysChanged(display_info_list
);
724 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
725 EXPECT_EQ("0,0 500x500",
726 GetDisplayForId(internal_display_id
).bounds().ToString());
727 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
729 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
730 GetDisplayForId(secondary_display_info
.id()));
731 EXPECT_EQ("-500,0 500x500",
732 GetDisplayForId(internal_display_id
).bounds().ToString());
733 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
735 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
736 // nothing changed if the exactly same displays are specified.
737 display_manager()->OnNativeDisplaysChanged(display_info_list
);
738 EXPECT_EQ("-500,0 500x500",
739 GetDisplayForId(internal_display_id
).bounds().ToString());
740 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
743 TEST_F(DisplayManagerTest
, DontRememberBestResolution
) {
744 int display_id
= 1000;
745 DisplayInfo native_display_info
=
746 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
747 std::vector
<DisplayMode
> display_modes
;
748 display_modes
.push_back(
749 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
750 display_modes
.push_back(
751 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
752 display_modes
.push_back(
753 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
755 native_display_info
.SetDisplayModes(display_modes
);
757 std::vector
<DisplayInfo
> display_info_list
;
758 display_info_list
.push_back(native_display_info
);
759 display_manager()->OnNativeDisplaysChanged(display_info_list
);
762 DisplayMode expected_mode
;
763 expected_mode
.size
= gfx::Size(1000, 500);
765 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
766 EXPECT_TRUE(expected_mode
.IsEquivalent(
767 display_manager()->GetActiveModeForDisplayId(display_id
)));
769 // Unsupported resolution.
770 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 4000));
772 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
773 EXPECT_TRUE(expected_mode
.IsEquivalent(
774 display_manager()->GetActiveModeForDisplayId(display_id
)));
776 // Supported resolution.
777 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
779 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
780 EXPECT_EQ("800x300", mode
.size
.ToString());
781 EXPECT_EQ(59.0f
, mode
.refresh_rate
);
782 EXPECT_FALSE(mode
.native
);
783 expected_mode
.size
= gfx::Size(800, 300);
784 EXPECT_TRUE(expected_mode
.IsEquivalent(
785 display_manager()->GetActiveModeForDisplayId(display_id
)));
788 display_manager()->SetDisplayResolution(display_id
, gfx::Size(1000, 500));
790 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
791 EXPECT_EQ("1000x500", mode
.size
.ToString());
792 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
793 EXPECT_TRUE(mode
.native
);
794 expected_mode
.size
= gfx::Size(1000, 500);
795 EXPECT_TRUE(expected_mode
.IsEquivalent(
796 display_manager()->GetActiveModeForDisplayId(display_id
)));
799 TEST_F(DisplayManagerTest
, ResolutionFallback
) {
800 int display_id
= 1000;
801 DisplayInfo native_display_info
=
802 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
803 std::vector
<DisplayMode
> display_modes
;
804 display_modes
.push_back(
805 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
806 display_modes
.push_back(
807 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
808 display_modes
.push_back(
809 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
811 std::vector
<DisplayMode
> copy
= display_modes
;
812 native_display_info
.SetDisplayModes(copy
);
814 std::vector
<DisplayInfo
> display_info_list
;
815 display_info_list
.push_back(native_display_info
);
816 display_manager()->OnNativeDisplaysChanged(display_info_list
);
818 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
819 DisplayInfo new_native_display_info
=
820 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 400, 500));
821 copy
= display_modes
;
822 new_native_display_info
.SetDisplayModes(copy
);
823 std::vector
<DisplayInfo
> new_display_info_list
;
824 new_display_info_list
.push_back(new_native_display_info
);
825 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
829 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
830 EXPECT_EQ("400x500", mode
.size
.ToString());
831 EXPECT_EQ(60.0f
, mode
.refresh_rate
);
832 EXPECT_FALSE(mode
.native
);
835 // Best resolution should find itself on the resolutions list.
836 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
837 DisplayInfo new_native_display_info
=
838 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
839 std::vector
<DisplayMode
> copy
= display_modes
;
840 new_native_display_info
.SetDisplayModes(copy
);
841 std::vector
<DisplayInfo
> new_display_info_list
;
842 new_display_info_list
.push_back(new_native_display_info
);
843 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
847 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
848 EXPECT_EQ("1000x500", mode
.size
.ToString());
849 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
850 EXPECT_TRUE(mode
.native
);
854 TEST_F(DisplayManagerTest
, Rotate
) {
855 if (!SupportsMultipleDisplays())
858 UpdateDisplay("100x200/r,300x400/l");
859 EXPECT_EQ("1,1 100x200",
860 GetDisplayInfoAt(0).bounds_in_native().ToString());
862 GetDisplayInfoAt(0).size_in_pixel().ToString());
864 EXPECT_EQ("1,201 300x400",
865 GetDisplayInfoAt(1).bounds_in_native().ToString());
867 GetDisplayInfoAt(1).size_in_pixel().ToString());
869 UpdateDisplay("100x200/b,300x400");
870 EXPECT_EQ("2 0 0", GetCountSummary());
873 EXPECT_EQ("1,1 100x200",
874 GetDisplayInfoAt(0).bounds_in_native().ToString());
876 GetDisplayInfoAt(0).size_in_pixel().ToString());
878 EXPECT_EQ("1,201 300x400",
879 GetDisplayInfoAt(1).bounds_in_native().ToString());
881 GetDisplayInfoAt(1).size_in_pixel().ToString());
883 // Just Rotating display will change the bounds on both display.
884 UpdateDisplay("100x200/l,300x400");
885 EXPECT_EQ("2 0 0", GetCountSummary());
888 // Updating to the same configuration should report no changes.
889 UpdateDisplay("100x200/l,300x400");
890 EXPECT_EQ("0 0 0", GetCountSummary());
893 // Rotating 180 degrees should report one change.
894 UpdateDisplay("100x200/r,300x400");
895 EXPECT_EQ("1 0 0", GetCountSummary());
898 UpdateDisplay("200x200");
899 EXPECT_EQ("1 0 1", GetCountSummary());
902 // Rotating 180 degrees should report one change.
903 UpdateDisplay("200x200/u");
904 EXPECT_EQ("1 0 0", GetCountSummary());
907 UpdateDisplay("200x200/l");
908 EXPECT_EQ("1 0 0", GetCountSummary());
911 TEST_F(DisplayManagerTest
, UIScale
) {
912 DisplayInfo::SetUse125DSFForUIScaling(false);
914 UpdateDisplay("1280x800");
915 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
916 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
917 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
918 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
919 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
920 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
921 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
922 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
923 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
925 test::DisplayManagerTestApi(display_manager())
926 .SetInternalDisplayId(display_id
);
928 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
929 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
930 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
931 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
932 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
933 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
934 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
935 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
936 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
937 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
938 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
939 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
940 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
941 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
942 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
943 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
945 UpdateDisplay("1366x768");
946 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
947 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
948 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
949 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
950 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
951 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
952 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
953 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
954 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
955 EXPECT_EQ(0.75f
, GetDisplayInfoAt(0).configured_ui_scale());
956 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
957 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
958 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
959 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
960 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
961 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
963 UpdateDisplay("1280x850*2");
964 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
965 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
966 EXPECT_EQ(1.5f
, GetDisplayInfoAt(0).configured_ui_scale());
967 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
968 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
969 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
970 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
971 display_manager()->SetDisplayUIScale(display_id
, 1.0f
);
972 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
973 gfx::Display display
= Shell::GetScreen()->GetPrimaryDisplay();
974 EXPECT_EQ(2.0f
, display
.device_scale_factor());
975 EXPECT_EQ("640x425", display
.bounds().size().ToString());
977 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
978 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
979 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
980 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
981 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
982 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
983 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
984 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
985 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
986 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
988 display_manager()->SetDisplayUIScale(display_id
, 2.0f
);
989 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).configured_ui_scale());
990 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
991 display
= Shell::GetScreen()->GetPrimaryDisplay();
992 EXPECT_EQ(1.0f
, display
.device_scale_factor());
993 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
995 // 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
997 UpdateDisplay("1280x850*1.25");
998 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
999 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
1000 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1001 display
= Shell::GetScreen()->GetPrimaryDisplay();
1002 EXPECT_EQ(1.0f
, display
.device_scale_factor());
1003 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
1006 TEST_F(DisplayManagerTest
, UIScaleWithDisplayMode
) {
1007 int display_id
= 1000;
1009 // Setup the display modes with UI-scale.
1010 DisplayInfo native_display_info
=
1011 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1280, 800));
1012 std::vector
<DisplayMode
> display_modes
;
1013 const DisplayMode
base_mode(gfx::Size(1280, 800), 60.0f
, false, false);
1014 std::vector
<DisplayMode
> mode_list
= CreateInternalDisplayModeList(base_mode
);
1015 native_display_info
.SetDisplayModes(mode_list
);
1017 std::vector
<DisplayInfo
> display_info_list
;
1018 display_info_list
.push_back(native_display_info
);
1019 display_manager()->OnNativeDisplaysChanged(display_info_list
);
1021 DisplayMode expected_mode
= base_mode
;
1022 EXPECT_TRUE(expected_mode
.IsEquivalent(
1023 display_manager()->GetActiveModeForDisplayId(display_id
)));
1025 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1026 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
1027 EXPECT_TRUE(expected_mode
.IsEquivalent(
1028 display_manager()->GetActiveModeForDisplayId(display_id
)));
1029 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1030 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1031 EXPECT_TRUE(expected_mode
.IsEquivalent(
1032 display_manager()->GetActiveModeForDisplayId(display_id
)));
1033 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1034 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1035 EXPECT_TRUE(expected_mode
.IsEquivalent(
1036 display_manager()->GetActiveModeForDisplayId(display_id
)));
1037 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1038 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1039 EXPECT_TRUE(expected_mode
.IsEquivalent(
1040 display_manager()->GetActiveModeForDisplayId(display_id
)));
1042 test::DisplayManagerTestApi(display_manager())
1043 .SetInternalDisplayId(display_id
);
1045 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1046 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1047 EXPECT_TRUE(expected_mode
.IsEquivalent(
1048 display_manager()->GetActiveModeForDisplayId(display_id
)));
1049 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1050 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1051 EXPECT_TRUE(expected_mode
.IsEquivalent(
1052 display_manager()->GetActiveModeForDisplayId(display_id
)));
1053 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1054 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1055 expected_mode
.ui_scale
= 1.125f
;
1056 EXPECT_TRUE(expected_mode
.IsEquivalent(
1057 display_manager()->GetActiveModeForDisplayId(display_id
)));
1058 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1059 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1060 expected_mode
.ui_scale
= 0.8f
;
1061 EXPECT_TRUE(expected_mode
.IsEquivalent(
1062 display_manager()->GetActiveModeForDisplayId(display_id
)));
1063 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1064 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1065 EXPECT_TRUE(expected_mode
.IsEquivalent(
1066 display_manager()->GetActiveModeForDisplayId(display_id
)));
1067 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1068 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1069 expected_mode
.ui_scale
= 0.625f
;
1070 EXPECT_TRUE(expected_mode
.IsEquivalent(
1071 display_manager()->GetActiveModeForDisplayId(display_id
)));
1072 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1073 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1074 EXPECT_TRUE(expected_mode
.IsEquivalent(
1075 display_manager()->GetActiveModeForDisplayId(display_id
)));
1076 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1077 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1078 expected_mode
.ui_scale
= 0.5f
;
1079 EXPECT_TRUE(expected_mode
.IsEquivalent(
1080 display_manager()->GetActiveModeForDisplayId(display_id
)));
1083 TEST_F(DisplayManagerTest
, Use125DSFRorUIScaling
) {
1084 DisplayInfo::SetUse125DSFForUIScaling(true);
1086 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
1087 test::DisplayManagerTestApi(display_manager())
1088 .SetInternalDisplayId(display_id
);
1090 UpdateDisplay("1920x1080*1.25");
1091 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1092 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1094 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1095 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1096 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1097 EXPECT_EQ("1536x864", GetDisplayForId(display_id
).size().ToString());
1099 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1100 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1101 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1102 EXPECT_EQ("960x540", GetDisplayForId(display_id
).size().ToString());
1104 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1105 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1106 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1107 EXPECT_EQ("2400x1350", GetDisplayForId(display_id
).size().ToString());
1109 DisplayInfo::SetUse125DSFForUIScaling(false);
1113 // TODO(scottmg): RootWindow doesn't get resized on Windows
1114 // Ash. http://crbug.com/247916.
1115 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
1117 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
1120 TEST_F(DisplayManagerTest
, MAYBE_UpdateMouseCursorAfterRotateZoom
) {
1121 // Make sure just rotating will not change native location.
1122 UpdateDisplay("300x200,200x150");
1123 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1124 aura::Env
* env
= aura::Env::GetInstance();
1126 ui::test::EventGenerator
generator1(root_windows
[0]);
1127 ui::test::EventGenerator
generator2(root_windows
[1]);
1129 // Test on 1st display.
1130 generator1
.MoveMouseToInHost(150, 50);
1131 EXPECT_EQ("150,50", env
->last_mouse_location().ToString());
1132 UpdateDisplay("300x200/r,200x150");
1133 EXPECT_EQ("50,149", env
->last_mouse_location().ToString());
1135 // Test on 2nd display.
1136 generator2
.MoveMouseToInHost(50, 100);
1137 EXPECT_EQ("250,100", env
->last_mouse_location().ToString());
1138 UpdateDisplay("300x200/r,200x150/l");
1139 EXPECT_EQ("249,50", env
->last_mouse_location().ToString());
1141 // The native location is now outside, so move to the center
1142 // of closest display.
1143 UpdateDisplay("300x200/r,100x50/l");
1144 EXPECT_EQ("225,50", env
->last_mouse_location().ToString());
1146 // Make sure just zooming will not change native location.
1147 UpdateDisplay("600x400*2,400x300");
1149 // Test on 1st display.
1150 generator1
.MoveMouseToInHost(200, 300);
1151 EXPECT_EQ("100,150", env
->last_mouse_location().ToString());
1152 UpdateDisplay("600x400*2@1.5,400x300");
1153 EXPECT_EQ("150,225", env
->last_mouse_location().ToString());
1155 // Test on 2nd display.
1156 UpdateDisplay("600x400,400x300*2");
1157 generator2
.MoveMouseToInHost(200, 250);
1158 EXPECT_EQ("700,125", env
->last_mouse_location().ToString());
1159 UpdateDisplay("600x400,400x300*2@1.5");
1160 EXPECT_EQ("750,187", env
->last_mouse_location().ToString());
1162 // The native location is now outside, so move to the
1163 // center of closest display.
1164 UpdateDisplay("600x400,400x200*2@1.5");
1165 EXPECT_EQ("750,75", env
->last_mouse_location().ToString());
1168 class TestDisplayObserver
: public gfx::DisplayObserver
{
1170 TestDisplayObserver() : changed_(false) {}
1171 ~TestDisplayObserver() override
{}
1173 // gfx::DisplayObserver overrides:
1174 void OnDisplayMetricsChanged(const gfx::Display
&, uint32_t) override
{}
1175 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
1176 // Mirror window should already be delete before restoring
1177 // the external display.
1178 EXPECT_FALSE(test_api
.GetHost());
1181 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
1182 // Mirror window should not be created until the external display
1184 EXPECT_FALSE(test_api
.GetHost());
1188 bool changed_and_reset() {
1189 bool changed
= changed_
;
1195 test::MirrorWindowTestApi test_api
;
1198 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver
);
1201 TEST_F(DisplayManagerTest
, SoftwareMirroring
) {
1202 if (!SupportsMultipleDisplays())
1205 UpdateDisplay("300x400,400x500");
1207 test::MirrorWindowTestApi test_api
;
1208 EXPECT_EQ(NULL
, test_api
.GetHost());
1210 TestDisplayObserver display_observer
;
1211 Shell::GetScreen()->AddObserver(&display_observer
);
1213 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1214 display_manager
->SetMultiDisplayMode(DisplayManager::MIRRORING
);
1215 display_manager
->UpdateDisplays();
1216 RunAllPendingInMessageLoop();
1217 EXPECT_TRUE(display_observer
.changed_and_reset());
1218 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1219 EXPECT_EQ("0,0 300x400",
1220 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1221 EXPECT_EQ("400x500", test_api
.GetHost()->GetBounds().size().ToString());
1222 EXPECT_EQ("300x400",
1223 test_api
.GetHost()->window()->bounds().size().ToString());
1224 EXPECT_TRUE(display_manager
->IsInMirrorMode());
1226 display_manager
->SetMirrorMode(false);
1227 EXPECT_TRUE(display_observer
.changed_and_reset());
1228 EXPECT_EQ(NULL
, test_api
.GetHost());
1229 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1230 EXPECT_FALSE(display_manager
->IsInMirrorMode());
1232 // Make sure the mirror window has the pixel size of the
1234 display_manager
->SetMirrorMode(true);
1235 EXPECT_TRUE(display_observer
.changed_and_reset());
1237 UpdateDisplay("300x400@0.5,400x500");
1238 EXPECT_FALSE(display_observer
.changed_and_reset());
1239 EXPECT_EQ("300x400",
1240 test_api
.GetHost()->window()->bounds().size().ToString());
1242 UpdateDisplay("310x410*2,400x500");
1243 EXPECT_FALSE(display_observer
.changed_and_reset());
1244 EXPECT_EQ("310x410",
1245 test_api
.GetHost()->window()->bounds().size().ToString());
1247 UpdateDisplay("320x420/r,400x500");
1248 EXPECT_FALSE(display_observer
.changed_and_reset());
1249 EXPECT_EQ("320x420",
1250 test_api
.GetHost()->window()->bounds().size().ToString());
1252 UpdateDisplay("330x440/r,400x500");
1253 EXPECT_FALSE(display_observer
.changed_and_reset());
1254 EXPECT_EQ("330x440",
1255 test_api
.GetHost()->window()->bounds().size().ToString());
1257 // Overscan insets are ignored.
1258 UpdateDisplay("400x600/o,600x800/o");
1259 EXPECT_FALSE(display_observer
.changed_and_reset());
1260 EXPECT_EQ("400x600",
1261 test_api
.GetHost()->window()->bounds().size().ToString());
1263 Shell::GetScreen()->RemoveObserver(&display_observer
);
1266 TEST_F(DisplayManagerTest
, SingleDisplayToSoftwareMirroring
) {
1267 if (!SupportsMultipleDisplays())
1269 UpdateDisplay("600x400");
1271 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1272 display_manager
->SetMultiDisplayMode(DisplayManager::MIRRORING
);
1273 UpdateDisplay("600x400,600x400");
1275 EXPECT_TRUE(display_manager
->IsInMirrorMode());
1276 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1277 DisplayController
* display_controller
=
1278 ash::Shell::GetInstance()->display_controller();
1279 EXPECT_TRUE(display_controller
->mirror_window_controller()->GetWindow());
1281 UpdateDisplay("600x400");
1282 EXPECT_FALSE(display_manager
->IsInMirrorMode());
1283 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1284 EXPECT_FALSE(display_controller
->mirror_window_controller()->GetWindow());
1287 #if defined(OS_CHROMEOS)
1288 // Make sure this does not cause any crashes. See http://crbug.com/412910
1289 // This test is limited to OS_CHROMEOS because CursorCompositingEnabled is only
1291 TEST_F(DisplayManagerTest
, SoftwareMirroringWithCompositingCursor
) {
1292 if (!SupportsMultipleDisplays())
1295 UpdateDisplay("300x400,400x500");
1297 test::MirrorWindowTestApi test_api
;
1298 EXPECT_EQ(NULL
, test_api
.GetHost());
1300 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1301 DisplayInfo secondary_info
= display_manager
->GetDisplayInfo(
1302 ScreenUtil::GetSecondaryDisplay().id());
1304 display_manager
->SetSoftwareMirroring(true);
1305 display_manager
->UpdateDisplays();
1307 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1308 EXPECT_FALSE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1310 Shell::GetInstance()->SetCursorCompositingEnabled(true);
1312 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1314 // Removes the first display and keeps the second one.
1315 display_manager
->SetSoftwareMirroring(false);
1316 std::vector
<DisplayInfo
> new_info_list
;
1317 new_info_list
.push_back(secondary_info
);
1318 display_manager
->OnNativeDisplaysChanged(new_info_list
);
1320 root_windows
= Shell::GetAllRootWindows();
1321 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1323 Shell::GetInstance()->SetCursorCompositingEnabled(false);
1325 #endif // OS_CHROMEOS
1327 TEST_F(DisplayManagerTest
, MirroredLayout
) {
1328 if (!SupportsMultipleDisplays())
1331 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1332 UpdateDisplay("500x500,400x400");
1333 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1334 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1335 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1337 UpdateDisplay("1+0-500x500,1+0-500x500");
1338 EXPECT_TRUE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1339 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1340 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1342 UpdateDisplay("500x500,500x500");
1343 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1344 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1345 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1348 TEST_F(DisplayManagerTest
, InvertLayout
) {
1349 EXPECT_EQ("left, 0",
1350 DisplayLayout(DisplayLayout::RIGHT
, 0).Invert().ToString());
1351 EXPECT_EQ("left, -100",
1352 DisplayLayout(DisplayLayout::RIGHT
, 100).Invert().ToString());
1353 EXPECT_EQ("left, 50",
1354 DisplayLayout(DisplayLayout::RIGHT
, -50).Invert().ToString());
1356 EXPECT_EQ("right, 0",
1357 DisplayLayout(DisplayLayout::LEFT
, 0).Invert().ToString());
1358 EXPECT_EQ("right, -90",
1359 DisplayLayout(DisplayLayout::LEFT
, 90).Invert().ToString());
1360 EXPECT_EQ("right, 60",
1361 DisplayLayout(DisplayLayout::LEFT
, -60).Invert().ToString());
1363 EXPECT_EQ("bottom, 0",
1364 DisplayLayout(DisplayLayout::TOP
, 0).Invert().ToString());
1365 EXPECT_EQ("bottom, -80",
1366 DisplayLayout(DisplayLayout::TOP
, 80).Invert().ToString());
1367 EXPECT_EQ("bottom, 70",
1368 DisplayLayout(DisplayLayout::TOP
, -70).Invert().ToString());
1371 DisplayLayout(DisplayLayout::BOTTOM
, 0).Invert().ToString());
1372 EXPECT_EQ("top, -70",
1373 DisplayLayout(DisplayLayout::BOTTOM
, 70).Invert().ToString());
1374 EXPECT_EQ("top, 80",
1375 DisplayLayout(DisplayLayout::BOTTOM
, -80).Invert().ToString());
1378 TEST_F(DisplayManagerTest
, NotifyPrimaryChange
) {
1379 if (!SupportsMultipleDisplays())
1381 UpdateDisplay("500x500,500x500");
1382 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1384 UpdateDisplay("500x500");
1385 EXPECT_FALSE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1386 EXPECT_FALSE(changed_metrics() &
1387 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1388 EXPECT_TRUE(changed_metrics() &
1389 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1391 UpdateDisplay("500x500,500x500");
1392 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1394 UpdateDisplay("500x400");
1395 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1396 EXPECT_TRUE(changed_metrics() &
1397 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1398 EXPECT_TRUE(changed_metrics() &
1399 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1402 TEST_F(DisplayManagerTest
, NotifyPrimaryChangeUndock
) {
1403 if (!SupportsMultipleDisplays())
1405 // Assume the default display is an external display, and
1406 // emulates undocking by switching to another display.
1407 DisplayInfo another_display_info
=
1408 CreateDisplayInfo(1, gfx::Rect(0, 0, 1280, 800));
1409 std::vector
<DisplayInfo
> info_list
;
1410 info_list
.push_back(another_display_info
);
1412 display_manager()->OnNativeDisplaysChanged(info_list
);
1413 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1414 EXPECT_TRUE(changed_metrics() &
1415 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1416 EXPECT_TRUE(changed_metrics() &
1417 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1421 // TODO(scottmg): RootWindow doesn't get resized on Windows
1422 // Ash. http://crbug.com/247916.
1423 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1425 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1428 TEST_F(DisplayManagerTest
, MAYBE_UpdateDisplayWithHostOrigin
) {
1429 UpdateDisplay("100x200,300x400");
1430 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1431 aura::Window::Windows root_windows
=
1432 Shell::GetInstance()->GetAllRootWindows();
1433 ASSERT_EQ(2U, root_windows
.size());
1434 aura::WindowTreeHost
* host0
= root_windows
[0]->GetHost();
1435 aura::WindowTreeHost
* host1
= root_windows
[1]->GetHost();
1437 EXPECT_EQ("1,1", host0
->GetBounds().origin().ToString());
1438 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1439 // UpdateDisplay set the origin if it's not set.
1440 EXPECT_NE("1,1", host1
->GetBounds().origin().ToString());
1441 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1443 UpdateDisplay("100x200,200+300-300x400");
1444 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1445 EXPECT_EQ("0,0", host0
->GetBounds().origin().ToString());
1446 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1447 EXPECT_EQ("200,300", host1
->GetBounds().origin().ToString());
1448 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1450 UpdateDisplay("400+500-200x300,300x400");
1451 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1452 EXPECT_EQ("400,500", host0
->GetBounds().origin().ToString());
1453 EXPECT_EQ("200x300", host0
->GetBounds().size().ToString());
1454 EXPECT_EQ("0,0", host1
->GetBounds().origin().ToString());
1455 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1457 UpdateDisplay("100+200-100x200,300+500-200x300");
1458 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1459 EXPECT_EQ("100,200", host0
->GetBounds().origin().ToString());
1460 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1461 EXPECT_EQ("300,500", host1
->GetBounds().origin().ToString());
1462 EXPECT_EQ("200x300", host1
->GetBounds().size().ToString());
1465 #if !defined(OS_WIN) && defined(USE_X11)
1467 TEST_F(DisplayManagerTest
, UnifiedDesktopBasic
) {
1468 display_manager()->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
1469 display_manager()->SetMultiDisplayMode(DisplayManager::UNIFIED
);
1470 UpdateDisplay("300x200,400x500");
1472 gfx::Screen
* screen
=
1473 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1474 EXPECT_EQ("700x500", screen
->GetPrimaryDisplay().size().ToString());
1476 display_manager()->SetMirrorMode(true);
1477 EXPECT_EQ("300x200", screen
->GetPrimaryDisplay().size().ToString());
1479 display_manager()->SetMirrorMode(false);
1480 EXPECT_EQ("700x500", screen
->GetPrimaryDisplay().size().ToString());
1482 // Swithc to single desktop.
1483 UpdateDisplay("500x300");
1484 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1486 // Swithc to unified desktop.
1487 UpdateDisplay("500x300,400x500");
1488 EXPECT_EQ("900x500", screen
->GetPrimaryDisplay().size().ToString());
1493 class ScreenShutdownTest
: public test::AshTestBase
{
1495 ScreenShutdownTest() {
1497 ~ScreenShutdownTest() override
{}
1499 void TearDown() override
{
1500 gfx::Screen
* orig_screen
=
1501 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1502 AshTestBase::TearDown();
1503 if (!SupportsMultipleDisplays())
1505 gfx::Screen
* screen
=
1506 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1507 EXPECT_NE(orig_screen
, screen
);
1508 EXPECT_EQ(2, screen
->GetNumDisplays());
1509 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1510 std::vector
<gfx::Display
> all
= screen
->GetAllDisplays();
1511 EXPECT_EQ("500x300", all
[0].size().ToString());
1512 EXPECT_EQ("800x400", all
[1].size().ToString());
1516 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest
);
1519 TEST_F(ScreenShutdownTest
, ScreenAfterShutdown
) {
1520 if (!SupportsMultipleDisplays())
1522 UpdateDisplay("500x300,800x400");
1526 #if defined(OS_CHROMEOS)
1529 // A helper class that sets the display configuration and starts ash.
1530 // This is to make sure the font configuration happens during ash
1531 // initialization process.
1532 class FontTestHelper
: public test::AshTestBase
{
1539 FontTestHelper(float scale
, DisplayType display_type
) {
1540 gfx::ClearFontRenderParamsCacheForTest();
1541 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1542 if (display_type
== INTERNAL
)
1543 command_line
->AppendSwitch(switches::kAshUseFirstDisplayAsInternal
);
1544 command_line
->AppendSwitchASCII(switches::kAshHostWindowBounds
,
1545 StringPrintf("1000x800*%f", scale
));
1549 ~FontTestHelper() override
{ TearDown(); }
1551 // test::AshTestBase:
1552 void TestBody() override
{ NOTREACHED(); }
1555 DISALLOW_COPY_AND_ASSIGN(FontTestHelper
);
1559 bool IsTextSubpixelPositioningEnabled() {
1560 gfx::FontRenderParams params
=
1561 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), NULL
);
1562 return params
.subpixel_positioning
;
1565 gfx::FontRenderParams::Hinting
GetFontHintingParams() {
1566 gfx::FontRenderParams params
=
1567 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), NULL
);
1568 return params
.hinting
;
1573 typedef testing::Test DisplayManagerFontTest
;
1575 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100Internal
) {
1576 FontTestHelper
helper(1.0f
, FontTestHelper::INTERNAL
);
1578 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1579 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1580 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1583 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125Internal
) {
1584 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1586 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1587 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1588 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1591 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200Internal
) {
1592 FontTestHelper
helper(2.0f
, FontTestHelper::INTERNAL
);
1594 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1595 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1596 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1598 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1599 Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f
);
1602 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1603 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1604 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1607 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100External
) {
1608 FontTestHelper
helper(1.0f
, FontTestHelper::EXTERNAL
);
1610 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1611 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1612 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1615 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125External
) {
1616 FontTestHelper
helper(1.25f
, FontTestHelper::EXTERNAL
);
1618 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1619 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1620 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1623 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200External
) {
1624 FontTestHelper
helper(2.0f
, FontTestHelper::EXTERNAL
);
1626 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1627 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1628 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1631 TEST_F(DisplayManagerFontTest
,
1632 TextSubpixelPositioningWithDsf125InternalWithScaling
) {
1633 DisplayInfo::SetUse125DSFForUIScaling(true);
1634 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1636 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1637 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1638 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1640 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1641 Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f
);
1644 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1645 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1646 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1648 DisplayInfo::SetUse125DSFForUIScaling(false);
1651 #endif // OS_CHROMEOS