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/screen_util.h"
13 #include "ash/shell.h"
14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/display_manager_test_api.h"
16 #include "ash/test/mirror_window_test_api.h"
17 #include "base/command_line.h"
18 #include "base/format_macros.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h"
21 #include "ui/aura/env.h"
22 #include "ui/aura/window_observer.h"
23 #include "ui/aura/window_tree_host.h"
24 #include "ui/events/test/event_generator.h"
25 #include "ui/gfx/display.h"
26 #include "ui/gfx/display_observer.h"
27 #include "ui/gfx/font_render_params.h"
28 #include "ui/gfx/screen.h"
29 #include "ui/gfx/screen_type_delegate.h"
36 using base::StringPrintf
;
40 std::string
ToDisplayName(int64 id
) {
41 return "x-" + base::Int64ToString(id
);
46 class DisplayManagerTest
: public test::AshTestBase
,
47 public gfx::DisplayObserver
,
48 public aura::WindowObserver
{
52 root_window_destroyed_(false),
53 changed_metrics_(0U) {
55 ~DisplayManagerTest() override
{}
57 void SetUp() override
{
59 Shell::GetScreen()->AddObserver(this);
60 Shell::GetPrimaryRootWindow()->AddObserver(this);
62 void TearDown() override
{
63 Shell::GetPrimaryRootWindow()->RemoveObserver(this);
64 Shell::GetScreen()->RemoveObserver(this);
65 AshTestBase::TearDown();
68 DisplayManager
* display_manager() {
69 return Shell::GetInstance()->display_manager();
71 const vector
<gfx::Display
>& changed() const { return changed_
; }
72 const vector
<gfx::Display
>& added() const { return added_
; }
73 uint32_t changed_metrics() const { return changed_metrics_
; }
75 string
GetCountSummary() const {
76 return StringPrintf("%" PRIuS
" %" PRIuS
" %" PRIuS
,
77 changed_
.size(), added_
.size(), removed_count_
);
84 changed_metrics_
= 0U;
85 root_window_destroyed_
= false;
88 bool root_window_destroyed() const {
89 return root_window_destroyed_
;
92 const DisplayInfo
& GetDisplayInfo(const gfx::Display
& display
) {
93 return display_manager()->GetDisplayInfo(display
.id());
96 const DisplayInfo
& GetDisplayInfoAt(int index
) {
97 return GetDisplayInfo(display_manager()->GetDisplayAt(index
));
100 const gfx::Display
& GetDisplayForId(int64 id
) {
101 return display_manager()->GetDisplayForId(id
);
104 const DisplayInfo
& GetDisplayInfoForId(int64 id
) {
105 return GetDisplayInfo(display_manager()->GetDisplayForId(id
));
108 // aura::DisplayObserver overrides:
109 void OnDisplayMetricsChanged(const gfx::Display
& display
,
110 uint32_t changed_metrics
) override
{
111 changed_
.push_back(display
);
112 changed_metrics_
|= changed_metrics
;
114 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
115 added_
.push_back(new_display
);
117 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
121 // aura::WindowObserver overrides:
122 void OnWindowDestroying(aura::Window
* window
) override
{
123 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window
);
124 root_window_destroyed_
= true;
128 vector
<gfx::Display
> changed_
;
129 vector
<gfx::Display
> added_
;
130 size_t removed_count_
;
131 bool root_window_destroyed_
;
132 uint32_t changed_metrics_
;
134 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest
);
137 TEST_F(DisplayManagerTest
, UpdateDisplayTest
) {
138 if (!SupportsMultipleDisplays())
141 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
143 // Update primary and add seconary.
144 UpdateDisplay("100+0-500x500,0+501-400x400");
145 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
146 EXPECT_EQ("0,0 500x500",
147 display_manager()->GetDisplayAt(0).bounds().ToString());
149 EXPECT_EQ("1 1 0", GetCountSummary());
150 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
151 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
152 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
153 // Secondary display is on right.
154 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
155 EXPECT_EQ("0,501 400x400",
156 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
160 UpdateDisplay("100+0-500x500");
161 EXPECT_EQ("0 0 1", GetCountSummary());
165 UpdateDisplay("1+1-1000x600");
166 EXPECT_EQ("1 0 0", GetCountSummary());
167 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
168 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
172 UpdateDisplay("1+1-1000x600,1002+0-600x400");
173 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
174 EXPECT_EQ("0 1 0", GetCountSummary());
175 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
176 // Secondary display is on right.
177 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
178 EXPECT_EQ("1002,0 600x400",
179 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
182 // Secondary removed, primary changed.
183 UpdateDisplay("1+1-800x300");
184 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
185 EXPECT_EQ("1 0 1", GetCountSummary());
186 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
187 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
190 // # of display can go to zero when screen is off.
191 const vector
<DisplayInfo
> empty
;
192 display_manager()->OnNativeDisplaysChanged(empty
);
193 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
194 EXPECT_EQ("0 0 0", GetCountSummary());
195 EXPECT_FALSE(root_window_destroyed());
196 // Display configuration stays the same
197 EXPECT_EQ("0,0 800x300",
198 display_manager()->GetDisplayAt(0).bounds().ToString());
201 // Connect to display again
202 UpdateDisplay("100+100-500x400");
203 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
204 EXPECT_EQ("1 0 0", GetCountSummary());
205 EXPECT_FALSE(root_window_destroyed());
206 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
207 EXPECT_EQ("100,100 500x400",
208 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
211 // Go back to zero and wake up with multiple displays.
212 display_manager()->OnNativeDisplaysChanged(empty
);
213 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
214 EXPECT_FALSE(root_window_destroyed());
218 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
219 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
220 EXPECT_EQ("0,0 1000x600",
221 display_manager()->GetDisplayAt(0).bounds().ToString());
222 // Secondary display is on right.
223 EXPECT_EQ("1000,0 600x400",
224 display_manager()->GetDisplayAt(1).bounds().ToString());
225 EXPECT_EQ("1000,1000 600x400",
226 GetDisplayInfoAt(1).bounds_in_native().ToString());
229 // Changing primary will update secondary as well.
230 UpdateDisplay("0+0-800x600,1000+1000-600x400");
231 EXPECT_EQ("2 0 0", GetCountSummary());
233 EXPECT_EQ("0,0 800x600",
234 display_manager()->GetDisplayAt(0).bounds().ToString());
235 EXPECT_EQ("800,0 600x400",
236 display_manager()->GetDisplayAt(1).bounds().ToString());
239 TEST_F(DisplayManagerTest
, ScaleOnlyChange
) {
240 if (!SupportsMultipleDisplays())
242 display_manager()->ToggleDisplayScaleFactor();
243 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
244 EXPECT_TRUE(changed_metrics() &
245 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
248 // Test in emulation mode (use_fullscreen_host_window=false)
249 TEST_F(DisplayManagerTest
, EmulatorTest
) {
250 if (!SupportsMultipleDisplays())
253 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
255 display_manager()->AddRemoveDisplay();
256 // Update primary and add seconary.
257 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
258 EXPECT_EQ("0 1 0", GetCountSummary());
261 display_manager()->AddRemoveDisplay();
262 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
263 EXPECT_EQ("0 0 1", GetCountSummary());
266 display_manager()->AddRemoveDisplay();
267 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
268 EXPECT_EQ("0 1 0", GetCountSummary());
272 // Tests support for 3 displays.
273 TEST_F(DisplayManagerTest
, UpdateThreeDisplaysTest
) {
274 if (!SupportsMultipleDisplays())
277 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
279 // Test with three displays.
280 UpdateDisplay("0+0-640x480,640+0-320x200,960+0-400x300");
281 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
282 EXPECT_EQ("0,0 640x480",
283 display_manager()->GetDisplayAt(0).bounds().ToString());
284 EXPECT_EQ("640,0 320x200",
285 display_manager()->GetDisplayAt(1).bounds().ToString());
286 EXPECT_EQ("960,0 400x300",
287 display_manager()->GetDisplayAt(2).bounds().ToString());
289 EXPECT_EQ("1 2 0", GetCountSummary());
290 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
291 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
292 EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), added()[1].id());
293 EXPECT_EQ("0,0 640x480", changed()[0].bounds().ToString());
294 // Secondary and terniary displays are on right.
295 EXPECT_EQ("640,0 320x200", added()[0].bounds().ToString());
296 EXPECT_EQ("640,0 320x200",
297 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
298 EXPECT_EQ("960,0 400x300", added()[1].bounds().ToString());
299 EXPECT_EQ("960,0 400x300",
300 GetDisplayInfo(added()[1]).bounds_in_native().ToString());
304 TEST_F(DisplayManagerTest
, OverscanInsetsTest
) {
305 if (!SupportsMultipleDisplays())
308 UpdateDisplay("0+0-500x500,0+501-400x400");
310 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
311 const DisplayInfo
& display_info1
= GetDisplayInfoAt(0);
312 const DisplayInfo
& display_info2
= GetDisplayInfoAt(1);
313 display_manager()->SetOverscanInsets(
314 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
316 std::vector
<gfx::Display
> changed_displays
= changed();
317 EXPECT_EQ(1u, changed_displays
.size());
318 EXPECT_EQ(display_info2
.id(), changed_displays
[0].id());
319 EXPECT_EQ("0,0 500x500",
320 GetDisplayInfoAt(0).bounds_in_native().ToString());
321 DisplayInfo updated_display_info2
= GetDisplayInfoAt(1);
322 EXPECT_EQ("0,501 400x400",
323 updated_display_info2
.bounds_in_native().ToString());
325 updated_display_info2
.size_in_pixel().ToString());
326 EXPECT_EQ("13,12,11,10",
327 updated_display_info2
.overscan_insets_in_dip().ToString());
328 EXPECT_EQ("500,0 378x376",
329 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
331 // Make sure that SetOverscanInsets() is idempotent.
332 display_manager()->SetOverscanInsets(display_info1
.id(), gfx::Insets());
333 display_manager()->SetOverscanInsets(
334 display_info2
.id(), gfx::Insets(13, 12, 11, 10));
335 EXPECT_EQ("0,0 500x500",
336 GetDisplayInfoAt(0).bounds_in_native().ToString());
337 updated_display_info2
= GetDisplayInfoAt(1);
338 EXPECT_EQ("0,501 400x400",
339 updated_display_info2
.bounds_in_native().ToString());
341 updated_display_info2
.size_in_pixel().ToString());
342 EXPECT_EQ("13,12,11,10",
343 updated_display_info2
.overscan_insets_in_dip().ToString());
345 display_manager()->SetOverscanInsets(
346 display_info2
.id(), gfx::Insets(10, 11, 12, 13));
347 EXPECT_EQ("0,0 500x500",
348 GetDisplayInfoAt(0).bounds_in_native().ToString());
350 GetDisplayInfoAt(1).size_in_pixel().ToString());
351 EXPECT_EQ("10,11,12,13",
352 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
354 // Recreate a new 2nd display. It won't apply the overscan inset because the
355 // new display has a different ID.
356 UpdateDisplay("0+0-500x500");
357 UpdateDisplay("0+0-500x500,0+501-400x400");
358 EXPECT_EQ("0,0 500x500",
359 GetDisplayInfoAt(0).bounds_in_native().ToString());
360 EXPECT_EQ("0,501 400x400",
361 GetDisplayInfoAt(1).bounds_in_native().ToString());
363 // Recreate the displays with the same ID. It should apply the overscan
365 UpdateDisplay("0+0-500x500");
366 std::vector
<DisplayInfo
> display_info_list
;
367 display_info_list
.push_back(display_info1
);
368 display_info_list
.push_back(display_info2
);
369 display_manager()->OnNativeDisplaysChanged(display_info_list
);
370 EXPECT_EQ("1,1 500x500",
371 GetDisplayInfoAt(0).bounds_in_native().ToString());
372 updated_display_info2
= GetDisplayInfoAt(1);
374 updated_display_info2
.size_in_pixel().ToString());
375 EXPECT_EQ("10,11,12,13",
376 updated_display_info2
.overscan_insets_in_dip().ToString());
378 // HiDPI but overscan display. The specified insets size should be doubled.
379 UpdateDisplay("0+0-500x500,0+501-400x400*2");
380 display_manager()->SetOverscanInsets(
381 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
382 EXPECT_EQ("0,0 500x500",
383 GetDisplayInfoAt(0).bounds_in_native().ToString());
384 updated_display_info2
= GetDisplayInfoAt(1);
385 EXPECT_EQ("0,501 400x400",
386 updated_display_info2
.bounds_in_native().ToString());
388 updated_display_info2
.size_in_pixel().ToString());
390 updated_display_info2
.overscan_insets_in_dip().ToString());
391 EXPECT_EQ("8,10,12,14",
392 updated_display_info2
.GetOverscanInsetsInPixel().ToString());
394 // Make sure switching primary display applies the overscan offset only once.
395 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
396 ScreenUtil::GetSecondaryDisplay());
397 EXPECT_EQ("-500,0 500x500",
398 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
399 EXPECT_EQ("0,0 500x500",
400 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
401 bounds_in_native().ToString());
402 EXPECT_EQ("0,501 400x400",
403 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
404 bounds_in_native().ToString());
405 EXPECT_EQ("0,0 188x190",
406 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
408 // Make sure just moving the overscan area should property notify observers.
409 UpdateDisplay("0+0-500x500");
410 int64 primary_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
411 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 20, 20));
412 EXPECT_EQ("0,0 480x480",
413 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
415 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(10, 10, 10, 10));
416 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
418 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
419 EXPECT_EQ("0,0 480x480",
420 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
422 display_manager()->SetOverscanInsets(primary_id
, gfx::Insets(0, 0, 0, 0));
423 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
425 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
426 EXPECT_EQ("0,0 500x500",
427 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
430 TEST_F(DisplayManagerTest
, ZeroOverscanInsets
) {
431 if (!SupportsMultipleDisplays())
434 // Make sure the display change events is emitted for overscan inset changes.
435 UpdateDisplay("0+0-500x500,0+501-400x400");
436 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
437 int64 display2_id
= display_manager()->GetDisplayAt(1).id();
440 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
441 EXPECT_EQ(0u, changed().size());
444 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(1, 0, 0, 0));
445 EXPECT_EQ(1u, changed().size());
446 EXPECT_EQ(display2_id
, changed()[0].id());
449 display_manager()->SetOverscanInsets(display2_id
, gfx::Insets(0, 0, 0, 0));
450 EXPECT_EQ(1u, changed().size());
451 EXPECT_EQ(display2_id
, changed()[0].id());
454 TEST_F(DisplayManagerTest
, TestDeviceScaleOnlyChange
) {
455 if (!SupportsHostWindowResize())
458 UpdateDisplay("1000x600");
459 aura::WindowTreeHost
* host
= Shell::GetPrimaryRootWindow()->GetHost();
460 EXPECT_EQ(1, host
->compositor()->device_scale_factor());
461 EXPECT_EQ("1000x600",
462 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
463 EXPECT_EQ("1 0 0", GetCountSummary());
465 UpdateDisplay("1000x600*2");
466 EXPECT_EQ(2, host
->compositor()->device_scale_factor());
467 EXPECT_EQ("2 0 0", GetCountSummary());
469 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
472 DisplayInfo
CreateDisplayInfo(int64 id
, const gfx::Rect
& bounds
) {
473 DisplayInfo
info(id
, ToDisplayName(id
), false);
474 info
.SetBounds(bounds
);
478 TEST_F(DisplayManagerTest
, TestNativeDisplaysChanged
) {
479 const int64 internal_display_id
=
480 test::DisplayManagerTestApi(display_manager()).
481 SetFirstDisplayAsInternalDisplay();
482 const int external_id
= 10;
483 const int mirror_id
= 11;
484 const int64 invalid_id
= gfx::Display::kInvalidDisplayID
;
485 const DisplayInfo internal_display_info
=
486 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
487 const DisplayInfo external_display_info
=
488 CreateDisplayInfo(external_id
, gfx::Rect(1, 1, 100, 100));
489 const DisplayInfo mirrored_display_info
=
490 CreateDisplayInfo(mirror_id
, gfx::Rect(0, 0, 500, 500));
492 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
493 EXPECT_EQ(1U, display_manager()->num_connected_displays());
494 std::string default_bounds
=
495 display_manager()->GetDisplayAt(0).bounds().ToString();
497 std::vector
<DisplayInfo
> display_info_list
;
498 // Primary disconnected.
499 display_manager()->OnNativeDisplaysChanged(display_info_list
);
500 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
501 EXPECT_EQ(default_bounds
,
502 display_manager()->GetDisplayAt(0).bounds().ToString());
503 EXPECT_EQ(1U, display_manager()->num_connected_displays());
504 EXPECT_FALSE(display_manager()->IsMirrored());
506 if (!SupportsMultipleDisplays())
509 // External connected while primary was disconnected.
510 display_info_list
.push_back(external_display_info
);
511 display_manager()->OnNativeDisplaysChanged(display_info_list
);
512 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
514 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
515 EXPECT_EQ("1,1 100x100",
516 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
517 EXPECT_EQ(1U, display_manager()->num_connected_displays());
518 EXPECT_FALSE(display_manager()->IsMirrored());
519 EXPECT_EQ(external_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
521 EXPECT_EQ(internal_display_id
, gfx::Display::InternalDisplayId());
523 // Primary connected, with different bounds.
524 display_info_list
.clear();
525 display_info_list
.push_back(internal_display_info
);
526 display_info_list
.push_back(external_display_info
);
527 display_manager()->OnNativeDisplaysChanged(display_info_list
);
528 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
529 EXPECT_EQ(internal_display_id
, Shell::GetScreen()->GetPrimaryDisplay().id());
531 // This combinatino is new, so internal display becomes primary.
532 EXPECT_EQ("0,0 500x500",
533 GetDisplayForId(internal_display_id
).bounds().ToString());
534 EXPECT_EQ("1,1 100x100",
535 GetDisplayInfoForId(10).bounds_in_native().ToString());
536 EXPECT_EQ(2U, display_manager()->num_connected_displays());
537 EXPECT_FALSE(display_manager()->IsMirrored());
538 EXPECT_EQ(ToDisplayName(internal_display_id
),
539 display_manager()->GetDisplayNameForId(internal_display_id
));
542 display_info_list
.clear();
543 display_manager()->OnNativeDisplaysChanged(display_info_list
);
544 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
545 EXPECT_EQ("0,0 500x500",
546 GetDisplayForId(internal_display_id
).bounds().ToString());
547 EXPECT_EQ("1,1 100x100",
548 GetDisplayInfoForId(10).bounds_in_native().ToString());
549 EXPECT_EQ(2U, display_manager()->num_connected_displays());
550 EXPECT_FALSE(display_manager()->IsMirrored());
551 EXPECT_EQ(ToDisplayName(internal_display_id
),
552 display_manager()->GetDisplayNameForId(internal_display_id
));
554 // External display has disconnected then resumed.
555 display_info_list
.push_back(internal_display_info
);
556 display_manager()->OnNativeDisplaysChanged(display_info_list
);
557 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
558 EXPECT_EQ("0,0 500x500",
559 GetDisplayForId(internal_display_id
).bounds().ToString());
560 EXPECT_EQ(1U, display_manager()->num_connected_displays());
561 EXPECT_FALSE(display_manager()->IsMirrored());
563 // External display was changed during suspend.
564 display_info_list
.push_back(external_display_info
);
565 display_manager()->OnNativeDisplaysChanged(display_info_list
);
566 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
567 EXPECT_EQ(2U, display_manager()->num_connected_displays());
568 EXPECT_FALSE(display_manager()->IsMirrored());
571 display_info_list
.clear();
572 display_manager()->OnNativeDisplaysChanged(display_info_list
);
573 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
574 EXPECT_EQ(2U, display_manager()->num_connected_displays());
575 EXPECT_FALSE(display_manager()->IsMirrored());
577 // and resume with different external display.
578 display_info_list
.push_back(internal_display_info
);
579 display_info_list
.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
580 display_manager()->OnNativeDisplaysChanged(display_info_list
);
581 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
582 EXPECT_EQ(2U, display_manager()->num_connected_displays());
583 EXPECT_FALSE(display_manager()->IsMirrored());
584 EXPECT_FALSE(display_manager()->IsMirrored());
587 display_info_list
.clear();
588 display_info_list
.push_back(internal_display_info
);
589 display_info_list
.push_back(mirrored_display_info
);
590 display_manager()->OnNativeDisplaysChanged(display_info_list
);
591 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
592 EXPECT_EQ("0,0 500x500",
593 GetDisplayForId(internal_display_id
).bounds().ToString());
594 EXPECT_EQ(2U, display_manager()->num_connected_displays());
595 EXPECT_EQ(11U, display_manager()->mirrored_display_id());
596 EXPECT_TRUE(display_manager()->IsMirrored());
598 // Test display name.
599 EXPECT_EQ(ToDisplayName(internal_display_id
),
600 display_manager()->GetDisplayNameForId(internal_display_id
));
601 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
602 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
603 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
604 // Default name for the id that doesn't exist.
605 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
607 // and exit mirroring.
608 display_info_list
.clear();
609 display_info_list
.push_back(internal_display_info
);
610 display_info_list
.push_back(external_display_info
);
611 display_manager()->OnNativeDisplaysChanged(display_info_list
);
612 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
613 EXPECT_EQ(2U, display_manager()->num_connected_displays());
614 EXPECT_FALSE(display_manager()->IsMirrored());
615 EXPECT_EQ("0,0 500x500",
616 GetDisplayForId(internal_display_id
).bounds().ToString());
617 EXPECT_EQ("500,0 100x100",
618 GetDisplayForId(10).bounds().ToString());
621 display_info_list
.clear();
622 display_info_list
.push_back(external_display_info
);
623 display_manager()->OnNativeDisplaysChanged(display_info_list
);
624 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
625 EXPECT_EQ(invalid_id
, GetDisplayForId(internal_display_id
).id());
626 EXPECT_EQ("1,1 100x100",
627 GetDisplayInfoForId(external_id
).bounds_in_native().ToString());
628 EXPECT_EQ(1U, display_manager()->num_connected_displays());
629 EXPECT_FALSE(display_manager()->IsMirrored());
631 // Switched to another display
632 display_info_list
.clear();
633 display_info_list
.push_back(internal_display_info
);
634 display_manager()->OnNativeDisplaysChanged(display_info_list
);
635 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
638 GetDisplayInfoForId(internal_display_id
).bounds_in_native().ToString());
639 EXPECT_EQ(1U, display_manager()->num_connected_displays());
640 EXPECT_FALSE(display_manager()->IsMirrored());
643 // Make sure crash does not happen if add and remove happens at the same time.
644 // See: crbug.com/414394
645 TEST_F(DisplayManagerTest
, DisplayAddRemoveAtTheSameTime
) {
646 if (!SupportsMultipleDisplays())
649 UpdateDisplay("100+0-500x500,0+501-400x400");
651 const int64 primary_id
= DisplayController::GetPrimaryDisplayId();
652 const int64 secondary_id
= ScreenUtil::GetSecondaryDisplay().id();
654 DisplayInfo primary_info
= display_manager()->GetDisplayInfo(primary_id
);
655 DisplayInfo secondary_info
= display_manager()->GetDisplayInfo(secondary_id
);
657 // An id which is different from primary and secondary.
658 const int64 third_id
= primary_id
+ secondary_id
;
660 DisplayInfo third_info
=
661 CreateDisplayInfo(third_id
, gfx::Rect(0, 0, 600, 600));
663 std::vector
<DisplayInfo
> display_info_list
;
664 display_info_list
.push_back(third_info
);
665 display_info_list
.push_back(secondary_info
);
666 display_manager()->OnNativeDisplaysChanged(display_info_list
);
668 EXPECT_EQ(third_id
, DisplayController::GetPrimaryDisplayId());
669 EXPECT_EQ("600x600", GetDisplayForId(third_id
).size().ToString());
670 EXPECT_EQ(secondary_id
, ScreenUtil::GetSecondaryDisplay().id());
674 // TODO(scottmg): RootWindow doesn't get resized on Windows
675 // Ash. http://crbug.com/247916.
676 #define MAYBE_TestNativeDisplaysChangedNoInternal \
677 DISABLED_TestNativeDisplaysChangedNoInternal
679 #define MAYBE_TestNativeDisplaysChangedNoInternal \
680 TestNativeDisplaysChangedNoInternal
683 TEST_F(DisplayManagerTest
, MAYBE_TestNativeDisplaysChangedNoInternal
) {
684 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
686 // Don't change the display info if all displays are disconnected.
687 std::vector
<DisplayInfo
> display_info_list
;
688 display_manager()->OnNativeDisplaysChanged(display_info_list
);
689 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
691 // Connect another display which will become primary.
692 const DisplayInfo external_display_info
=
693 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
694 display_info_list
.push_back(external_display_info
);
695 display_manager()->OnNativeDisplaysChanged(display_info_list
);
696 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
697 EXPECT_EQ("1,1 100x100",
698 GetDisplayInfoForId(10).bounds_in_native().ToString());
699 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
700 GetBounds().size().ToString());
704 // Tests that rely on the actual host size/location does not work on windows.
705 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays
706 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays_2ndOnLeft
708 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays
709 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLeft
712 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays
) {
713 UpdateDisplay("200x200,300x300");
714 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
716 aura::Env
* env
= aura::Env::GetInstance();
718 ui::test::EventGenerator
generator(root_windows
[0]);
720 // Set the initial position.
721 generator
.MoveMouseToInHost(350, 150);
722 EXPECT_EQ("350,150", env
->last_mouse_location().ToString());
724 // A mouse pointer will stay in the 2nd display.
725 UpdateDisplay("300x300,200x200");
726 EXPECT_EQ("450,50", env
->last_mouse_location().ToString());
728 // A mouse pointer will be outside of displays and move to the
729 // center of 2nd display.
730 UpdateDisplay("300x300,100x100");
731 EXPECT_EQ("350,50", env
->last_mouse_location().ToString());
733 // 2nd display was disconnected, and the cursor is
734 // now in the 1st display.
735 UpdateDisplay("400x400");
736 EXPECT_EQ("50,350", env
->last_mouse_location().ToString());
738 // 1st display's resolution has changed, and the mouse pointer is
739 // now outside. Move the mouse pointer to the center of 1st display.
740 UpdateDisplay("300x300");
741 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
743 // Move the mouse pointer to the bottom of 1st display.
744 generator
.MoveMouseToInHost(150, 290);
745 EXPECT_EQ("150,290", env
->last_mouse_location().ToString());
747 // The mouse pointer is now on 2nd display.
748 UpdateDisplay("300x280,200x200");
749 EXPECT_EQ("450,10", env
->last_mouse_location().ToString());
752 TEST_F(DisplayManagerTest
, MAYBE_EnsurePointerInDisplays_2ndOnLeft
) {
753 // Set the 2nd display on the left.
754 DisplayLayoutStore
* layout_store
=
755 Shell::GetInstance()->display_manager()->layout_store();
756 DisplayLayout layout
= layout_store
->default_display_layout();
757 layout
.position
= DisplayLayout::LEFT
;
758 layout_store
->SetDefaultDisplayLayout(layout
);
760 UpdateDisplay("200x200,300x300");
761 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
763 EXPECT_EQ("-300,0 300x300",
764 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
766 aura::Env
* env
= aura::Env::GetInstance();
768 // Set the initial position.
769 root_windows
[0]->MoveCursorTo(gfx::Point(-150, 250));
770 EXPECT_EQ("-150,250", env
->last_mouse_location().ToString());
772 // A mouse pointer will stay in 2nd display.
773 UpdateDisplay("300x300,200x300");
774 EXPECT_EQ("-50,150", env
->last_mouse_location().ToString());
776 // A mouse pointer will be outside of displays and move to the
777 // center of 2nd display.
778 UpdateDisplay("300x300,200x100");
779 EXPECT_EQ("-100,50", env
->last_mouse_location().ToString());
781 // 2nd display was disconnected. Mouse pointer should move to
783 UpdateDisplay("300x300");
784 EXPECT_EQ("150,150", env
->last_mouse_location().ToString());
787 TEST_F(DisplayManagerTest
, NativeDisplaysChangedAfterPrimaryChange
) {
788 if (!SupportsMultipleDisplays())
791 const int64 internal_display_id
=
792 test::DisplayManagerTestApi(display_manager()).
793 SetFirstDisplayAsInternalDisplay();
794 const DisplayInfo native_display_info
=
795 CreateDisplayInfo(internal_display_id
, gfx::Rect(0, 0, 500, 500));
796 const DisplayInfo secondary_display_info
=
797 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
799 std::vector
<DisplayInfo
> display_info_list
;
800 display_info_list
.push_back(native_display_info
);
801 display_info_list
.push_back(secondary_display_info
);
802 display_manager()->OnNativeDisplaysChanged(display_info_list
);
803 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
804 EXPECT_EQ("0,0 500x500",
805 GetDisplayForId(internal_display_id
).bounds().ToString());
806 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
808 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
809 GetDisplayForId(secondary_display_info
.id()));
810 EXPECT_EQ("-500,0 500x500",
811 GetDisplayForId(internal_display_id
).bounds().ToString());
812 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
814 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
815 // nothing changed if the exactly same displays are specified.
816 display_manager()->OnNativeDisplaysChanged(display_info_list
);
817 EXPECT_EQ("-500,0 500x500",
818 GetDisplayForId(internal_display_id
).bounds().ToString());
819 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
822 TEST_F(DisplayManagerTest
, DontRememberBestResolution
) {
823 int display_id
= 1000;
824 DisplayInfo native_display_info
=
825 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
826 std::vector
<DisplayMode
> display_modes
;
827 display_modes
.push_back(
828 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
829 display_modes
.push_back(
830 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
831 display_modes
.push_back(
832 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
834 native_display_info
.SetDisplayModes(display_modes
);
836 std::vector
<DisplayInfo
> display_info_list
;
837 display_info_list
.push_back(native_display_info
);
838 display_manager()->OnNativeDisplaysChanged(display_info_list
);
841 DisplayMode expected_mode
;
842 expected_mode
.size
= gfx::Size(1000, 500);
844 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
845 EXPECT_TRUE(expected_mode
.IsEquivalent(
846 display_manager()->GetActiveModeForDisplayId(display_id
)));
848 // Unsupported resolution.
849 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 4000));
851 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
852 EXPECT_TRUE(expected_mode
.IsEquivalent(
853 display_manager()->GetActiveModeForDisplayId(display_id
)));
855 // Supported resolution.
856 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
858 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
859 EXPECT_EQ("800x300", mode
.size
.ToString());
860 EXPECT_EQ(59.0f
, mode
.refresh_rate
);
861 EXPECT_FALSE(mode
.native
);
862 expected_mode
.size
= gfx::Size(800, 300);
863 EXPECT_TRUE(expected_mode
.IsEquivalent(
864 display_manager()->GetActiveModeForDisplayId(display_id
)));
867 display_manager()->SetDisplayResolution(display_id
, gfx::Size(1000, 500));
869 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
870 EXPECT_EQ("1000x500", mode
.size
.ToString());
871 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
872 EXPECT_TRUE(mode
.native
);
873 expected_mode
.size
= gfx::Size(1000, 500);
874 EXPECT_TRUE(expected_mode
.IsEquivalent(
875 display_manager()->GetActiveModeForDisplayId(display_id
)));
878 TEST_F(DisplayManagerTest
, ResolutionFallback
) {
879 int display_id
= 1000;
880 DisplayInfo native_display_info
=
881 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
882 std::vector
<DisplayMode
> display_modes
;
883 display_modes
.push_back(
884 DisplayMode(gfx::Size(1000, 500), 58.0f
, false, true));
885 display_modes
.push_back(
886 DisplayMode(gfx::Size(800, 300), 59.0f
, false, false));
887 display_modes
.push_back(
888 DisplayMode(gfx::Size(400, 500), 60.0f
, false, false));
890 std::vector
<DisplayMode
> copy
= display_modes
;
891 native_display_info
.SetDisplayModes(copy
);
893 std::vector
<DisplayInfo
> display_info_list
;
894 display_info_list
.push_back(native_display_info
);
895 display_manager()->OnNativeDisplaysChanged(display_info_list
);
897 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
898 DisplayInfo new_native_display_info
=
899 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 400, 500));
900 copy
= display_modes
;
901 new_native_display_info
.SetDisplayModes(copy
);
902 std::vector
<DisplayInfo
> new_display_info_list
;
903 new_display_info_list
.push_back(new_native_display_info
);
904 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
908 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
909 EXPECT_EQ("400x500", mode
.size
.ToString());
910 EXPECT_EQ(60.0f
, mode
.refresh_rate
);
911 EXPECT_FALSE(mode
.native
);
914 // Best resolution should find itself on the resolutions list.
915 display_manager()->SetDisplayResolution(display_id
, gfx::Size(800, 300));
916 DisplayInfo new_native_display_info
=
917 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1000, 500));
918 std::vector
<DisplayMode
> copy
= display_modes
;
919 new_native_display_info
.SetDisplayModes(copy
);
920 std::vector
<DisplayInfo
> new_display_info_list
;
921 new_display_info_list
.push_back(new_native_display_info
);
922 display_manager()->OnNativeDisplaysChanged(new_display_info_list
);
926 display_manager()->GetSelectedModeForDisplayId(display_id
, &mode
));
927 EXPECT_EQ("1000x500", mode
.size
.ToString());
928 EXPECT_EQ(58.0f
, mode
.refresh_rate
);
929 EXPECT_TRUE(mode
.native
);
933 TEST_F(DisplayManagerTest
, Rotate
) {
934 if (!SupportsMultipleDisplays())
937 UpdateDisplay("100x200/r,300x400/l");
938 EXPECT_EQ("1,1 100x200",
939 GetDisplayInfoAt(0).bounds_in_native().ToString());
941 GetDisplayInfoAt(0).size_in_pixel().ToString());
943 EXPECT_EQ("1,201 300x400",
944 GetDisplayInfoAt(1).bounds_in_native().ToString());
946 GetDisplayInfoAt(1).size_in_pixel().ToString());
948 UpdateDisplay("100x200/b,300x400");
949 EXPECT_EQ("2 0 0", GetCountSummary());
952 EXPECT_EQ("1,1 100x200",
953 GetDisplayInfoAt(0).bounds_in_native().ToString());
955 GetDisplayInfoAt(0).size_in_pixel().ToString());
957 EXPECT_EQ("1,201 300x400",
958 GetDisplayInfoAt(1).bounds_in_native().ToString());
960 GetDisplayInfoAt(1).size_in_pixel().ToString());
962 // Just Rotating display will change the bounds on both display.
963 UpdateDisplay("100x200/l,300x400");
964 EXPECT_EQ("2 0 0", GetCountSummary());
967 // Updating to the same configuration should report no changes.
968 UpdateDisplay("100x200/l,300x400");
969 EXPECT_EQ("0 0 0", GetCountSummary());
972 // Rotating 180 degrees should report one change.
973 UpdateDisplay("100x200/r,300x400");
974 EXPECT_EQ("1 0 0", GetCountSummary());
977 UpdateDisplay("200x200");
978 EXPECT_EQ("1 0 1", GetCountSummary());
981 // Rotating 180 degrees should report one change.
982 UpdateDisplay("200x200/u");
983 EXPECT_EQ("1 0 0", GetCountSummary());
986 UpdateDisplay("200x200/l");
987 EXPECT_EQ("1 0 0", GetCountSummary());
990 TEST_F(DisplayManagerTest
, UIScale
) {
991 DisplayInfo::SetUse125DSFForUIScaling(false);
993 UpdateDisplay("1280x800");
994 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
995 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
996 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
997 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
998 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
999 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1000 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1001 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1002 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1004 test::DisplayManagerTestApi(display_manager())
1005 .SetInternalDisplayId(display_id
);
1007 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1008 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1009 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1010 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1011 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1012 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1013 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1014 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1015 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1016 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1017 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1018 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1019 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1020 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1021 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1022 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1024 UpdateDisplay("1366x768");
1025 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1026 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1027 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1028 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1029 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1030 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1031 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1032 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1033 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1034 EXPECT_EQ(0.75f
, GetDisplayInfoAt(0).configured_ui_scale());
1035 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1036 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
1037 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1038 EXPECT_EQ(0.6f
, GetDisplayInfoAt(0).configured_ui_scale());
1039 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1040 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1042 UpdateDisplay("1280x850*2");
1043 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1044 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1045 EXPECT_EQ(1.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1046 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1047 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
1048 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1049 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1050 display_manager()->SetDisplayUIScale(display_id
, 1.0f
);
1051 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1052 gfx::Display display
= Shell::GetScreen()->GetPrimaryDisplay();
1053 EXPECT_EQ(2.0f
, display
.device_scale_factor());
1054 EXPECT_EQ("640x425", display
.bounds().size().ToString());
1056 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1057 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1058 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1059 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1060 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1061 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1062 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1063 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1064 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1065 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1067 display_manager()->SetDisplayUIScale(display_id
, 2.0f
);
1068 EXPECT_EQ(2.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1069 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1070 display
= Shell::GetScreen()->GetPrimaryDisplay();
1071 EXPECT_EQ(1.0f
, display
.device_scale_factor());
1072 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
1074 // 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
1076 UpdateDisplay("1280x850*1.25");
1077 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1078 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).configured_ui_scale());
1079 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1080 display
= Shell::GetScreen()->GetPrimaryDisplay();
1081 EXPECT_EQ(1.0f
, display
.device_scale_factor());
1082 EXPECT_EQ("1280x850", display
.bounds().size().ToString());
1085 TEST_F(DisplayManagerTest
, UIScaleWithDisplayMode
) {
1086 int display_id
= 1000;
1088 // Setup the display modes with UI-scale.
1089 DisplayInfo native_display_info
=
1090 CreateDisplayInfo(display_id
, gfx::Rect(0, 0, 1280, 800));
1091 std::vector
<DisplayMode
> display_modes
;
1092 const DisplayMode
base_mode(gfx::Size(1280, 800), 60.0f
, false, false);
1093 std::vector
<DisplayMode
> mode_list
= CreateInternalDisplayModeList(base_mode
);
1094 native_display_info
.SetDisplayModes(mode_list
);
1096 std::vector
<DisplayInfo
> display_info_list
;
1097 display_info_list
.push_back(native_display_info
);
1098 display_manager()->OnNativeDisplaysChanged(display_info_list
);
1100 DisplayMode expected_mode
= base_mode
;
1101 EXPECT_TRUE(expected_mode
.IsEquivalent(
1102 display_manager()->GetActiveModeForDisplayId(display_id
)));
1104 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1105 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
1106 EXPECT_TRUE(expected_mode
.IsEquivalent(
1107 display_manager()->GetActiveModeForDisplayId(display_id
)));
1108 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1109 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1110 EXPECT_TRUE(expected_mode
.IsEquivalent(
1111 display_manager()->GetActiveModeForDisplayId(display_id
)));
1112 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1113 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1114 EXPECT_TRUE(expected_mode
.IsEquivalent(
1115 display_manager()->GetActiveModeForDisplayId(display_id
)));
1116 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1117 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1118 EXPECT_TRUE(expected_mode
.IsEquivalent(
1119 display_manager()->GetActiveModeForDisplayId(display_id
)));
1121 test::DisplayManagerTestApi(display_manager())
1122 .SetInternalDisplayId(display_id
);
1124 display_manager()->SetDisplayUIScale(display_id
, 1.5f
);
1125 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1126 EXPECT_TRUE(expected_mode
.IsEquivalent(
1127 display_manager()->GetActiveModeForDisplayId(display_id
)));
1128 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1129 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).configured_ui_scale());
1130 EXPECT_TRUE(expected_mode
.IsEquivalent(
1131 display_manager()->GetActiveModeForDisplayId(display_id
)));
1132 display_manager()->SetDisplayUIScale(display_id
, 1.125f
);
1133 EXPECT_EQ(1.125f
, GetDisplayInfoAt(0).configured_ui_scale());
1134 expected_mode
.ui_scale
= 1.125f
;
1135 EXPECT_TRUE(expected_mode
.IsEquivalent(
1136 display_manager()->GetActiveModeForDisplayId(display_id
)));
1137 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1138 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1139 expected_mode
.ui_scale
= 0.8f
;
1140 EXPECT_TRUE(expected_mode
.IsEquivalent(
1141 display_manager()->GetActiveModeForDisplayId(display_id
)));
1142 display_manager()->SetDisplayUIScale(display_id
, 0.75f
);
1143 EXPECT_EQ(0.8f
, GetDisplayInfoAt(0).configured_ui_scale());
1144 EXPECT_TRUE(expected_mode
.IsEquivalent(
1145 display_manager()->GetActiveModeForDisplayId(display_id
)));
1146 display_manager()->SetDisplayUIScale(display_id
, 0.625f
);
1147 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1148 expected_mode
.ui_scale
= 0.625f
;
1149 EXPECT_TRUE(expected_mode
.IsEquivalent(
1150 display_manager()->GetActiveModeForDisplayId(display_id
)));
1151 display_manager()->SetDisplayUIScale(display_id
, 0.6f
);
1152 EXPECT_EQ(0.625f
, GetDisplayInfoAt(0).configured_ui_scale());
1153 EXPECT_TRUE(expected_mode
.IsEquivalent(
1154 display_manager()->GetActiveModeForDisplayId(display_id
)));
1155 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1156 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).configured_ui_scale());
1157 expected_mode
.ui_scale
= 0.5f
;
1158 EXPECT_TRUE(expected_mode
.IsEquivalent(
1159 display_manager()->GetActiveModeForDisplayId(display_id
)));
1162 TEST_F(DisplayManagerTest
, Use125DSFRorUIScaling
) {
1163 DisplayInfo::SetUse125DSFForUIScaling(true);
1165 int64 display_id
= Shell::GetScreen()->GetPrimaryDisplay().id();
1166 test::DisplayManagerTestApi(display_manager())
1167 .SetInternalDisplayId(display_id
);
1169 UpdateDisplay("1920x1080*1.25");
1170 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1171 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1173 display_manager()->SetDisplayUIScale(display_id
, 0.8f
);
1174 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1175 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1176 EXPECT_EQ("1536x864", GetDisplayForId(display_id
).size().ToString());
1178 display_manager()->SetDisplayUIScale(display_id
, 0.5f
);
1179 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1180 EXPECT_EQ(0.5f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1181 EXPECT_EQ("960x540", GetDisplayForId(display_id
).size().ToString());
1183 display_manager()->SetDisplayUIScale(display_id
, 1.25f
);
1184 EXPECT_EQ(1.0f
, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1185 EXPECT_EQ(1.25f
, GetDisplayInfoAt(0).GetEffectiveUIScale());
1186 EXPECT_EQ("2400x1350", GetDisplayForId(display_id
).size().ToString());
1188 DisplayInfo::SetUse125DSFForUIScaling(false);
1192 // TODO(scottmg): RootWindow doesn't get resized on Windows
1193 // Ash. http://crbug.com/247916.
1194 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
1196 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
1199 TEST_F(DisplayManagerTest
, MAYBE_UpdateMouseCursorAfterRotateZoom
) {
1200 // Make sure just rotating will not change native location.
1201 UpdateDisplay("300x200,200x150");
1202 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1203 aura::Env
* env
= aura::Env::GetInstance();
1205 ui::test::EventGenerator
generator1(root_windows
[0]);
1206 ui::test::EventGenerator
generator2(root_windows
[1]);
1208 // Test on 1st display.
1209 generator1
.MoveMouseToInHost(150, 50);
1210 EXPECT_EQ("150,50", env
->last_mouse_location().ToString());
1211 UpdateDisplay("300x200/r,200x150");
1212 EXPECT_EQ("50,149", env
->last_mouse_location().ToString());
1214 // Test on 2nd display.
1215 generator2
.MoveMouseToInHost(50, 100);
1216 EXPECT_EQ("250,100", env
->last_mouse_location().ToString());
1217 UpdateDisplay("300x200/r,200x150/l");
1218 EXPECT_EQ("249,50", env
->last_mouse_location().ToString());
1220 // The native location is now outside, so move to the center
1221 // of closest display.
1222 UpdateDisplay("300x200/r,100x50/l");
1223 EXPECT_EQ("225,50", env
->last_mouse_location().ToString());
1225 // Make sure just zooming will not change native location.
1226 UpdateDisplay("600x400*2,400x300");
1228 // Test on 1st display.
1229 generator1
.MoveMouseToInHost(200, 300);
1230 EXPECT_EQ("100,150", env
->last_mouse_location().ToString());
1231 UpdateDisplay("600x400*2@1.5,400x300");
1232 EXPECT_EQ("150,225", env
->last_mouse_location().ToString());
1234 // Test on 2nd display.
1235 UpdateDisplay("600x400,400x300*2");
1236 generator2
.MoveMouseToInHost(200, 250);
1237 EXPECT_EQ("700,125", env
->last_mouse_location().ToString());
1238 UpdateDisplay("600x400,400x300*2@1.5");
1239 EXPECT_EQ("750,187", env
->last_mouse_location().ToString());
1241 // The native location is now outside, so move to the
1242 // center of closest display.
1243 UpdateDisplay("600x400,400x200*2@1.5");
1244 EXPECT_EQ("750,75", env
->last_mouse_location().ToString());
1247 class TestDisplayObserver
: public gfx::DisplayObserver
{
1249 TestDisplayObserver() : changed_(false) {}
1250 ~TestDisplayObserver() override
{}
1252 // gfx::DisplayObserver overrides:
1253 void OnDisplayMetricsChanged(const gfx::Display
&, uint32_t) override
{}
1254 void OnDisplayAdded(const gfx::Display
& new_display
) override
{
1255 // Mirror window should already be delete before restoring
1256 // the external display.
1257 EXPECT_FALSE(test_api
.GetHost());
1260 void OnDisplayRemoved(const gfx::Display
& old_display
) override
{
1261 // Mirror window should not be created until the external display
1263 EXPECT_FALSE(test_api
.GetHost());
1267 bool changed_and_reset() {
1268 bool changed
= changed_
;
1274 test::MirrorWindowTestApi test_api
;
1277 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver
);
1280 TEST_F(DisplayManagerTest
, SoftwareMirroring
) {
1281 if (!SupportsMultipleDisplays())
1284 UpdateDisplay("300x400,400x500");
1286 test::MirrorWindowTestApi test_api
;
1287 EXPECT_EQ(NULL
, test_api
.GetHost());
1289 TestDisplayObserver display_observer
;
1290 Shell::GetScreen()->AddObserver(&display_observer
);
1292 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1293 display_manager
->SetSecondDisplayMode(DisplayManager::MIRRORING
);
1294 display_manager
->UpdateDisplays();
1295 RunAllPendingInMessageLoop();
1296 EXPECT_TRUE(display_observer
.changed_and_reset());
1297 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1298 EXPECT_EQ("0,0 300x400",
1299 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1300 EXPECT_EQ("400x500", test_api
.GetHost()->GetBounds().size().ToString());
1301 EXPECT_EQ("300x400",
1302 test_api
.GetHost()->window()->bounds().size().ToString());
1303 EXPECT_TRUE(display_manager
->IsMirrored());
1305 display_manager
->SetMirrorMode(false);
1306 EXPECT_TRUE(display_observer
.changed_and_reset());
1307 EXPECT_EQ(NULL
, test_api
.GetHost());
1308 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1309 EXPECT_FALSE(display_manager
->IsMirrored());
1311 // Make sure the mirror window has the pixel size of the
1313 display_manager
->SetMirrorMode(true);
1314 EXPECT_TRUE(display_observer
.changed_and_reset());
1316 UpdateDisplay("300x400@0.5,400x500");
1317 EXPECT_FALSE(display_observer
.changed_and_reset());
1318 EXPECT_EQ("300x400",
1319 test_api
.GetHost()->window()->bounds().size().ToString());
1321 UpdateDisplay("310x410*2,400x500");
1322 EXPECT_FALSE(display_observer
.changed_and_reset());
1323 EXPECT_EQ("310x410",
1324 test_api
.GetHost()->window()->bounds().size().ToString());
1326 UpdateDisplay("320x420/r,400x500");
1327 EXPECT_FALSE(display_observer
.changed_and_reset());
1328 EXPECT_EQ("320x420",
1329 test_api
.GetHost()->window()->bounds().size().ToString());
1331 UpdateDisplay("330x440/r,400x500");
1332 EXPECT_FALSE(display_observer
.changed_and_reset());
1333 EXPECT_EQ("330x440",
1334 test_api
.GetHost()->window()->bounds().size().ToString());
1336 // Overscan insets are ignored.
1337 UpdateDisplay("400x600/o,600x800/o");
1338 EXPECT_FALSE(display_observer
.changed_and_reset());
1339 EXPECT_EQ("400x600",
1340 test_api
.GetHost()->window()->bounds().size().ToString());
1342 Shell::GetScreen()->RemoveObserver(&display_observer
);
1345 #if defined(OS_CHROMEOS)
1346 // Make sure this does not cause any crashes. See http://crbug.com/412910
1347 // This test is limited to OS_CHROMEOS because CursorCompositingEnabled is only
1349 TEST_F(DisplayManagerTest
, SoftwareMirroringWithCompositingCursor
) {
1350 if (!SupportsMultipleDisplays())
1353 UpdateDisplay("300x400,400x500");
1355 test::MirrorWindowTestApi test_api
;
1356 EXPECT_EQ(NULL
, test_api
.GetHost());
1358 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1359 DisplayInfo secondary_info
= display_manager
->GetDisplayInfo(
1360 ScreenUtil::GetSecondaryDisplay().id());
1362 display_manager
->SetSoftwareMirroring(true);
1363 display_manager
->UpdateDisplays();
1365 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1366 EXPECT_FALSE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1368 Shell::GetInstance()->SetCursorCompositingEnabled(true);
1370 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1372 // Removes the first display and keeps the second one.
1373 display_manager
->SetSoftwareMirroring(false);
1374 std::vector
<DisplayInfo
> new_info_list
;
1375 new_info_list
.push_back(secondary_info
);
1376 display_manager
->OnNativeDisplaysChanged(new_info_list
);
1378 root_windows
= Shell::GetAllRootWindows();
1379 EXPECT_TRUE(root_windows
[0]->Contains(test_api
.GetCursorWindow()));
1381 Shell::GetInstance()->SetCursorCompositingEnabled(false);
1383 #endif // OS_CHROMEOS
1385 TEST_F(DisplayManagerTest
, MirroredLayout
) {
1386 if (!SupportsMultipleDisplays())
1389 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1390 UpdateDisplay("500x500,400x400");
1391 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1392 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1393 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1395 UpdateDisplay("1+0-500x500,1+0-500x500");
1396 EXPECT_TRUE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1397 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1398 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1400 UpdateDisplay("500x500,500x500");
1401 EXPECT_FALSE(display_manager
->GetCurrentDisplayLayout().mirrored
);
1402 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1403 EXPECT_EQ(2U, display_manager
->num_connected_displays());
1406 TEST_F(DisplayManagerTest
, InvertLayout
) {
1407 EXPECT_EQ("left, 0",
1408 DisplayLayout(DisplayLayout::RIGHT
, 0).Invert().ToString());
1409 EXPECT_EQ("left, -100",
1410 DisplayLayout(DisplayLayout::RIGHT
, 100).Invert().ToString());
1411 EXPECT_EQ("left, 50",
1412 DisplayLayout(DisplayLayout::RIGHT
, -50).Invert().ToString());
1414 EXPECT_EQ("right, 0",
1415 DisplayLayout(DisplayLayout::LEFT
, 0).Invert().ToString());
1416 EXPECT_EQ("right, -90",
1417 DisplayLayout(DisplayLayout::LEFT
, 90).Invert().ToString());
1418 EXPECT_EQ("right, 60",
1419 DisplayLayout(DisplayLayout::LEFT
, -60).Invert().ToString());
1421 EXPECT_EQ("bottom, 0",
1422 DisplayLayout(DisplayLayout::TOP
, 0).Invert().ToString());
1423 EXPECT_EQ("bottom, -80",
1424 DisplayLayout(DisplayLayout::TOP
, 80).Invert().ToString());
1425 EXPECT_EQ("bottom, 70",
1426 DisplayLayout(DisplayLayout::TOP
, -70).Invert().ToString());
1429 DisplayLayout(DisplayLayout::BOTTOM
, 0).Invert().ToString());
1430 EXPECT_EQ("top, -70",
1431 DisplayLayout(DisplayLayout::BOTTOM
, 70).Invert().ToString());
1432 EXPECT_EQ("top, 80",
1433 DisplayLayout(DisplayLayout::BOTTOM
, -80).Invert().ToString());
1436 TEST_F(DisplayManagerTest
, NotifyPrimaryChange
) {
1437 if (!SupportsMultipleDisplays())
1439 UpdateDisplay("500x500,500x500");
1440 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1442 UpdateDisplay("500x500");
1443 EXPECT_FALSE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1444 EXPECT_FALSE(changed_metrics() &
1445 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1446 EXPECT_TRUE(changed_metrics() &
1447 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1449 UpdateDisplay("500x500,500x500");
1450 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1452 UpdateDisplay("500x400");
1453 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1454 EXPECT_TRUE(changed_metrics() &
1455 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1456 EXPECT_TRUE(changed_metrics() &
1457 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1460 TEST_F(DisplayManagerTest
, NotifyPrimaryChangeUndock
) {
1461 if (!SupportsMultipleDisplays())
1463 // Assume the default display is an external display, and
1464 // emulates undocking by switching to another display.
1465 DisplayInfo another_display_info
=
1466 CreateDisplayInfo(1, gfx::Rect(0, 0, 1280, 800));
1467 std::vector
<DisplayInfo
> info_list
;
1468 info_list
.push_back(another_display_info
);
1470 display_manager()->OnNativeDisplaysChanged(info_list
);
1471 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS
);
1472 EXPECT_TRUE(changed_metrics() &
1473 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA
);
1474 EXPECT_TRUE(changed_metrics() &
1475 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY
);
1479 // TODO(scottmg): RootWindow doesn't get resized on Windows
1480 // Ash. http://crbug.com/247916.
1481 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1483 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1486 TEST_F(DisplayManagerTest
, MAYBE_UpdateDisplayWithHostOrigin
) {
1487 UpdateDisplay("100x200,300x400");
1488 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1489 aura::Window::Windows root_windows
=
1490 Shell::GetInstance()->GetAllRootWindows();
1491 ASSERT_EQ(2U, root_windows
.size());
1492 aura::WindowTreeHost
* host0
= root_windows
[0]->GetHost();
1493 aura::WindowTreeHost
* host1
= root_windows
[1]->GetHost();
1495 EXPECT_EQ("1,1", host0
->GetBounds().origin().ToString());
1496 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1497 // UpdateDisplay set the origin if it's not set.
1498 EXPECT_NE("1,1", host1
->GetBounds().origin().ToString());
1499 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1501 UpdateDisplay("100x200,200+300-300x400");
1502 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1503 EXPECT_EQ("0,0", host0
->GetBounds().origin().ToString());
1504 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1505 EXPECT_EQ("200,300", host1
->GetBounds().origin().ToString());
1506 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1508 UpdateDisplay("400+500-200x300,300x400");
1509 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1510 EXPECT_EQ("400,500", host0
->GetBounds().origin().ToString());
1511 EXPECT_EQ("200x300", host0
->GetBounds().size().ToString());
1512 EXPECT_EQ("0,0", host1
->GetBounds().origin().ToString());
1513 EXPECT_EQ("300x400", host1
->GetBounds().size().ToString());
1515 UpdateDisplay("100+200-100x200,300+500-200x300");
1516 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1517 EXPECT_EQ("100,200", host0
->GetBounds().origin().ToString());
1518 EXPECT_EQ("100x200", host0
->GetBounds().size().ToString());
1519 EXPECT_EQ("300,500", host1
->GetBounds().origin().ToString());
1520 EXPECT_EQ("200x300", host1
->GetBounds().size().ToString());
1523 class ScreenShutdownTest
: public test::AshTestBase
{
1525 ScreenShutdownTest() {
1527 ~ScreenShutdownTest() override
{}
1529 void TearDown() override
{
1530 gfx::Screen
* orig_screen
=
1531 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1532 AshTestBase::TearDown();
1533 if (!SupportsMultipleDisplays())
1535 gfx::Screen
* screen
=
1536 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
);
1537 EXPECT_NE(orig_screen
, screen
);
1538 EXPECT_EQ(2, screen
->GetNumDisplays());
1539 EXPECT_EQ("500x300", screen
->GetPrimaryDisplay().size().ToString());
1540 std::vector
<gfx::Display
> all
= screen
->GetAllDisplays();
1541 EXPECT_EQ("500x300", all
[0].size().ToString());
1542 EXPECT_EQ("800x400", all
[1].size().ToString());
1546 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest
);
1549 TEST_F(ScreenShutdownTest
, ScreenAfterShutdown
) {
1550 if (!SupportsMultipleDisplays())
1552 UpdateDisplay("500x300,800x400");
1556 #if defined(OS_CHROMEOS)
1559 // A helper class that sets the display configuration and starts ash.
1560 // This is to make sure the font configuration happens during ash
1561 // initialization process.
1562 class FontTestHelper
: public test::AshTestBase
{
1569 FontTestHelper(float scale
, DisplayType display_type
) {
1570 gfx::ClearFontRenderParamsCacheForTest();
1571 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
1572 if (display_type
== INTERNAL
)
1573 command_line
->AppendSwitch(switches::kAshUseFirstDisplayAsInternal
);
1574 command_line
->AppendSwitchASCII(switches::kAshHostWindowBounds
,
1575 StringPrintf("1000x800*%f", scale
));
1579 ~FontTestHelper() override
{ TearDown(); }
1581 // test::AshTestBase:
1582 void TestBody() override
{ NOTREACHED(); }
1585 DISALLOW_COPY_AND_ASSIGN(FontTestHelper
);
1589 bool IsTextSubpixelPositioningEnabled() {
1590 gfx::FontRenderParams params
=
1591 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(false), NULL
);
1592 return params
.subpixel_positioning
;
1595 gfx::FontRenderParams::Hinting
GetFontHintingParams() {
1596 gfx::FontRenderParams params
=
1597 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(false), NULL
);
1598 return params
.hinting
;
1603 typedef testing::Test DisplayManagerFontTest
;
1605 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100Internal
) {
1606 FontTestHelper
helper(1.0f
, FontTestHelper::INTERNAL
);
1608 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1609 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1610 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1613 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125Internal
) {
1614 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1616 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1617 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1618 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1621 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200Internal
) {
1622 FontTestHelper
helper(2.0f
, FontTestHelper::INTERNAL
);
1624 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1625 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1626 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1628 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1629 Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f
);
1632 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1633 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1634 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1637 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf100External
) {
1638 FontTestHelper
helper(1.0f
, FontTestHelper::EXTERNAL
);
1640 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1641 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1642 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1645 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf125External
) {
1646 FontTestHelper
helper(1.25f
, FontTestHelper::EXTERNAL
);
1648 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1649 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1650 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1653 TEST_F(DisplayManagerFontTest
, TextSubpixelPositioningWithDsf200External
) {
1654 FontTestHelper
helper(2.0f
, FontTestHelper::EXTERNAL
);
1656 2.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1657 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1658 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1661 TEST_F(DisplayManagerFontTest
,
1662 TextSubpixelPositioningWithDsf125InternalWithScaling
) {
1663 DisplayInfo::SetUse125DSFForUIScaling(true);
1664 FontTestHelper
helper(1.25f
, FontTestHelper::INTERNAL
);
1666 1.0f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1667 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1668 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1670 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1671 Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f
);
1674 1.25f
, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1675 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1676 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE
, GetFontHintingParams());
1678 DisplayInfo::SetUse125DSFForUIScaling(false);
1681 #endif // OS_CHROMEOS