Port Android relocation packer to chromium build
[chromium-blink-merge.git] / ash / display / display_manager_unittest.cc
blobfe240c6f6b510c9bc38102ff2b1ef72c3450495c
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"
32 namespace ash {
34 using std::vector;
35 using std::string;
37 using base::StringPrintf;
39 namespace {
41 std::string ToDisplayName(int64 id) {
42 return "x-" + base::Int64ToString(id);
45 } // namespace
47 class DisplayManagerTest : public test::AshTestBase,
48 public gfx::DisplayObserver,
49 public aura::WindowObserver {
50 public:
51 DisplayManagerTest()
52 : removed_count_(0U),
53 root_window_destroyed_(false),
54 changed_metrics_(0U) {
56 ~DisplayManagerTest() override {}
58 void SetUp() override {
59 AshTestBase::SetUp();
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_);
81 void reset() {
82 changed_.clear();
83 added_.clear();
84 removed_count_ = 0U;
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 {
119 ++removed_count_;
122 // aura::WindowObserver overrides:
123 void OnWindowDestroying(aura::Window* window) override {
124 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window);
125 root_window_destroyed_ = true;
128 private:
129 vector<gfx::Display> changed_;
130 vector<gfx::Display> added_;
131 size_t removed_count_;
132 bool root_window_destroyed_;
133 uint32_t changed_metrics_;
135 DISALLOW_COPY_AND_ASSIGN(DisplayManagerTest);
138 TEST_F(DisplayManagerTest, UpdateDisplayTest) {
139 if (!SupportsMultipleDisplays())
140 return;
142 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
144 // Update primary and add seconary.
145 UpdateDisplay("100+0-500x500,0+501-400x400");
146 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
147 EXPECT_EQ("0,0 500x500",
148 display_manager()->GetDisplayAt(0).bounds().ToString());
150 EXPECT_EQ("1 1 0", GetCountSummary());
151 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
152 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
153 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
154 // Secondary display is on right.
155 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString());
156 EXPECT_EQ("0,501 400x400",
157 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
158 reset();
160 // Delete secondary.
161 UpdateDisplay("100+0-500x500");
162 EXPECT_EQ("0 0 1", GetCountSummary());
163 reset();
165 // Change primary.
166 UpdateDisplay("1+1-1000x600");
167 EXPECT_EQ("1 0 0", GetCountSummary());
168 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
169 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
170 reset();
172 // Add secondary.
173 UpdateDisplay("1+1-1000x600,1002+0-600x400");
174 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
175 EXPECT_EQ("0 1 0", GetCountSummary());
176 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
177 // Secondary display is on right.
178 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString());
179 EXPECT_EQ("1002,0 600x400",
180 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
181 reset();
183 // Secondary removed, primary changed.
184 UpdateDisplay("1+1-800x300");
185 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
186 EXPECT_EQ("1 0 1", GetCountSummary());
187 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
188 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
189 reset();
191 // # of display can go to zero when screen is off.
192 const vector<DisplayInfo> empty;
193 display_manager()->OnNativeDisplaysChanged(empty);
194 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
195 EXPECT_EQ("0 0 0", GetCountSummary());
196 EXPECT_FALSE(root_window_destroyed());
197 // Display configuration stays the same
198 EXPECT_EQ("0,0 800x300",
199 display_manager()->GetDisplayAt(0).bounds().ToString());
200 reset();
202 // Connect to display again
203 UpdateDisplay("100+100-500x400");
204 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
205 EXPECT_EQ("1 0 0", GetCountSummary());
206 EXPECT_FALSE(root_window_destroyed());
207 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
208 EXPECT_EQ("100,100 500x400",
209 GetDisplayInfo(changed()[0]).bounds_in_native().ToString());
210 reset();
212 // Go back to zero and wake up with multiple displays.
213 display_manager()->OnNativeDisplaysChanged(empty);
214 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
215 EXPECT_FALSE(root_window_destroyed());
216 reset();
218 // Add secondary.
219 UpdateDisplay("0+0-1000x600,1000+1000-600x400");
220 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
221 EXPECT_EQ("0,0 1000x600",
222 display_manager()->GetDisplayAt(0).bounds().ToString());
223 // Secondary display is on right.
224 EXPECT_EQ("1000,0 600x400",
225 display_manager()->GetDisplayAt(1).bounds().ToString());
226 EXPECT_EQ("1000,1000 600x400",
227 GetDisplayInfoAt(1).bounds_in_native().ToString());
228 reset();
230 // Changing primary will update secondary as well.
231 UpdateDisplay("0+0-800x600,1000+1000-600x400");
232 EXPECT_EQ("2 0 0", GetCountSummary());
233 reset();
234 EXPECT_EQ("0,0 800x600",
235 display_manager()->GetDisplayAt(0).bounds().ToString());
236 EXPECT_EQ("800,0 600x400",
237 display_manager()->GetDisplayAt(1).bounds().ToString());
240 TEST_F(DisplayManagerTest, ScaleOnlyChange) {
241 if (!SupportsMultipleDisplays())
242 return;
243 display_manager()->ToggleDisplayScaleFactor();
244 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
245 EXPECT_TRUE(changed_metrics() &
246 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
249 // Test in emulation mode (use_fullscreen_host_window=false)
250 TEST_F(DisplayManagerTest, EmulatorTest) {
251 if (!SupportsMultipleDisplays())
252 return;
254 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
256 display_manager()->AddRemoveDisplay();
257 // Update primary and add seconary.
258 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
259 EXPECT_EQ("0 1 0", GetCountSummary());
260 reset();
262 display_manager()->AddRemoveDisplay();
263 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
264 EXPECT_EQ("0 0 1", GetCountSummary());
265 reset();
267 display_manager()->AddRemoveDisplay();
268 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
269 EXPECT_EQ("0 1 0", GetCountSummary());
270 reset();
273 // Tests support for 3 displays.
274 TEST_F(DisplayManagerTest, UpdateThreeDisplaysTest) {
275 if (!SupportsMultipleDisplays())
276 return;
278 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
280 // Test with three displays.
281 UpdateDisplay("0+0-640x480,640+0-320x200,960+0-400x300");
282 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
283 EXPECT_EQ("0,0 640x480",
284 display_manager()->GetDisplayAt(0).bounds().ToString());
285 EXPECT_EQ("640,0 320x200",
286 display_manager()->GetDisplayAt(1).bounds().ToString());
287 EXPECT_EQ("960,0 400x300",
288 display_manager()->GetDisplayAt(2).bounds().ToString());
290 EXPECT_EQ("1 2 0", GetCountSummary());
291 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
292 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
293 EXPECT_EQ(display_manager()->GetDisplayAt(2).id(), added()[1].id());
294 EXPECT_EQ("0,0 640x480", changed()[0].bounds().ToString());
295 // Secondary and terniary displays are on right.
296 EXPECT_EQ("640,0 320x200", added()[0].bounds().ToString());
297 EXPECT_EQ("640,0 320x200",
298 GetDisplayInfo(added()[0]).bounds_in_native().ToString());
299 EXPECT_EQ("960,0 400x300", added()[1].bounds().ToString());
300 EXPECT_EQ("960,0 400x300",
301 GetDisplayInfo(added()[1]).bounds_in_native().ToString());
302 reset();
305 TEST_F(DisplayManagerTest, OverscanInsetsTest) {
306 if (!SupportsMultipleDisplays())
307 return;
309 UpdateDisplay("0+0-500x500,0+501-400x400");
310 reset();
311 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
312 const DisplayInfo& display_info1 = GetDisplayInfoAt(0);
313 const DisplayInfo& display_info2 = GetDisplayInfoAt(1);
314 display_manager()->SetOverscanInsets(
315 display_info2.id(), gfx::Insets(13, 12, 11, 10));
317 std::vector<gfx::Display> changed_displays = changed();
318 EXPECT_EQ(1u, changed_displays.size());
319 EXPECT_EQ(display_info2.id(), changed_displays[0].id());
320 EXPECT_EQ("0,0 500x500",
321 GetDisplayInfoAt(0).bounds_in_native().ToString());
322 DisplayInfo updated_display_info2 = GetDisplayInfoAt(1);
323 EXPECT_EQ("0,501 400x400",
324 updated_display_info2.bounds_in_native().ToString());
325 EXPECT_EQ("378x376",
326 updated_display_info2.size_in_pixel().ToString());
327 EXPECT_EQ("13,12,11,10",
328 updated_display_info2.overscan_insets_in_dip().ToString());
329 EXPECT_EQ("500,0 378x376",
330 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
332 // Make sure that SetOverscanInsets() is idempotent.
333 display_manager()->SetOverscanInsets(display_info1.id(), gfx::Insets());
334 display_manager()->SetOverscanInsets(
335 display_info2.id(), gfx::Insets(13, 12, 11, 10));
336 EXPECT_EQ("0,0 500x500",
337 GetDisplayInfoAt(0).bounds_in_native().ToString());
338 updated_display_info2 = GetDisplayInfoAt(1);
339 EXPECT_EQ("0,501 400x400",
340 updated_display_info2.bounds_in_native().ToString());
341 EXPECT_EQ("378x376",
342 updated_display_info2.size_in_pixel().ToString());
343 EXPECT_EQ("13,12,11,10",
344 updated_display_info2.overscan_insets_in_dip().ToString());
346 display_manager()->SetOverscanInsets(
347 display_info2.id(), gfx::Insets(10, 11, 12, 13));
348 EXPECT_EQ("0,0 500x500",
349 GetDisplayInfoAt(0).bounds_in_native().ToString());
350 EXPECT_EQ("376x378",
351 GetDisplayInfoAt(1).size_in_pixel().ToString());
352 EXPECT_EQ("10,11,12,13",
353 GetDisplayInfoAt(1).overscan_insets_in_dip().ToString());
355 // Recreate a new 2nd display. It won't apply the overscan inset because the
356 // new display has a different ID.
357 UpdateDisplay("0+0-500x500");
358 UpdateDisplay("0+0-500x500,0+501-400x400");
359 EXPECT_EQ("0,0 500x500",
360 GetDisplayInfoAt(0).bounds_in_native().ToString());
361 EXPECT_EQ("0,501 400x400",
362 GetDisplayInfoAt(1).bounds_in_native().ToString());
364 // Recreate the displays with the same ID. It should apply the overscan
365 // inset.
366 UpdateDisplay("0+0-500x500");
367 std::vector<DisplayInfo> display_info_list;
368 display_info_list.push_back(display_info1);
369 display_info_list.push_back(display_info2);
370 display_manager()->OnNativeDisplaysChanged(display_info_list);
371 EXPECT_EQ("1,1 500x500",
372 GetDisplayInfoAt(0).bounds_in_native().ToString());
373 updated_display_info2 = GetDisplayInfoAt(1);
374 EXPECT_EQ("376x378",
375 updated_display_info2.size_in_pixel().ToString());
376 EXPECT_EQ("10,11,12,13",
377 updated_display_info2.overscan_insets_in_dip().ToString());
379 // HiDPI but overscan display. The specified insets size should be doubled.
380 UpdateDisplay("0+0-500x500,0+501-400x400*2");
381 display_manager()->SetOverscanInsets(
382 display_manager()->GetDisplayAt(1).id(), gfx::Insets(4, 5, 6, 7));
383 EXPECT_EQ("0,0 500x500",
384 GetDisplayInfoAt(0).bounds_in_native().ToString());
385 updated_display_info2 = GetDisplayInfoAt(1);
386 EXPECT_EQ("0,501 400x400",
387 updated_display_info2.bounds_in_native().ToString());
388 EXPECT_EQ("376x380",
389 updated_display_info2.size_in_pixel().ToString());
390 EXPECT_EQ("4,5,6,7",
391 updated_display_info2.overscan_insets_in_dip().ToString());
392 EXPECT_EQ("8,10,12,14",
393 updated_display_info2.GetOverscanInsetsInPixel().ToString());
395 // Make sure switching primary display applies the overscan offset only once.
396 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
397 ScreenUtil::GetSecondaryDisplay());
398 EXPECT_EQ("-500,0 500x500",
399 ScreenUtil::GetSecondaryDisplay().bounds().ToString());
400 EXPECT_EQ("0,0 500x500",
401 GetDisplayInfo(ScreenUtil::GetSecondaryDisplay()).
402 bounds_in_native().ToString());
403 EXPECT_EQ("0,501 400x400",
404 GetDisplayInfo(Shell::GetScreen()->GetPrimaryDisplay()).
405 bounds_in_native().ToString());
406 EXPECT_EQ("0,0 188x190",
407 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
409 // Make sure just moving the overscan area should property notify observers.
410 UpdateDisplay("0+0-500x500");
411 int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id();
412 display_manager()->SetOverscanInsets(primary_id, gfx::Insets(0, 0, 20, 20));
413 EXPECT_EQ("0,0 480x480",
414 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
415 reset();
416 display_manager()->SetOverscanInsets(primary_id, gfx::Insets(10, 10, 10, 10));
417 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
418 EXPECT_TRUE(
419 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
420 EXPECT_EQ("0,0 480x480",
421 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
422 reset();
423 display_manager()->SetOverscanInsets(primary_id, gfx::Insets(0, 0, 0, 0));
424 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
425 EXPECT_TRUE(
426 changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
427 EXPECT_EQ("0,0 500x500",
428 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
431 TEST_F(DisplayManagerTest, ZeroOverscanInsets) {
432 if (!SupportsMultipleDisplays())
433 return;
435 // Make sure the display change events is emitted for overscan inset changes.
436 UpdateDisplay("0+0-500x500,0+501-400x400");
437 ASSERT_EQ(2u, display_manager()->GetNumDisplays());
438 int64 display2_id = display_manager()->GetDisplayAt(1).id();
440 reset();
441 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0));
442 EXPECT_EQ(0u, changed().size());
444 reset();
445 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(1, 0, 0, 0));
446 EXPECT_EQ(1u, changed().size());
447 EXPECT_EQ(display2_id, changed()[0].id());
449 reset();
450 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0));
451 EXPECT_EQ(1u, changed().size());
452 EXPECT_EQ(display2_id, changed()[0].id());
455 TEST_F(DisplayManagerTest, TestDeviceScaleOnlyChange) {
456 if (!SupportsHostWindowResize())
457 return;
459 UpdateDisplay("1000x600");
460 aura::WindowTreeHost* host = Shell::GetPrimaryRootWindow()->GetHost();
461 EXPECT_EQ(1, host->compositor()->device_scale_factor());
462 EXPECT_EQ("1000x600",
463 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
464 EXPECT_EQ("1 0 0", GetCountSummary());
466 UpdateDisplay("1000x600*2");
467 EXPECT_EQ(2, host->compositor()->device_scale_factor());
468 EXPECT_EQ("2 0 0", GetCountSummary());
469 EXPECT_EQ("500x300",
470 Shell::GetPrimaryRootWindow()->bounds().size().ToString());
473 DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) {
474 DisplayInfo info(id, ToDisplayName(id), false);
475 info.SetBounds(bounds);
476 return info;
479 TEST_F(DisplayManagerTest, TestNativeDisplaysChanged) {
480 const int64 internal_display_id =
481 test::DisplayManagerTestApi(display_manager()).
482 SetFirstDisplayAsInternalDisplay();
483 const int external_id = 10;
484 const int mirror_id = 11;
485 const int64 invalid_id = gfx::Display::kInvalidDisplayID;
486 const DisplayInfo internal_display_info =
487 CreateDisplayInfo(internal_display_id, gfx::Rect(0, 0, 500, 500));
488 const DisplayInfo external_display_info =
489 CreateDisplayInfo(external_id, gfx::Rect(1, 1, 100, 100));
490 const DisplayInfo mirrored_display_info =
491 CreateDisplayInfo(mirror_id, gfx::Rect(0, 0, 500, 500));
493 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
494 EXPECT_EQ(1U, display_manager()->num_connected_displays());
495 std::string default_bounds =
496 display_manager()->GetDisplayAt(0).bounds().ToString();
498 std::vector<DisplayInfo> display_info_list;
499 // Primary disconnected.
500 display_manager()->OnNativeDisplaysChanged(display_info_list);
501 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
502 EXPECT_EQ(default_bounds,
503 display_manager()->GetDisplayAt(0).bounds().ToString());
504 EXPECT_EQ(1U, display_manager()->num_connected_displays());
505 EXPECT_FALSE(display_manager()->IsMirrored());
507 if (!SupportsMultipleDisplays())
508 return;
510 // External connected while primary was disconnected.
511 display_info_list.push_back(external_display_info);
512 display_manager()->OnNativeDisplaysChanged(display_info_list);
513 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
515 EXPECT_EQ(invalid_id, GetDisplayForId(internal_display_id).id());
516 EXPECT_EQ("1,1 100x100",
517 GetDisplayInfoForId(external_id).bounds_in_native().ToString());
518 EXPECT_EQ(1U, display_manager()->num_connected_displays());
519 EXPECT_FALSE(display_manager()->IsMirrored());
520 EXPECT_EQ(external_id, Shell::GetScreen()->GetPrimaryDisplay().id());
522 EXPECT_EQ(internal_display_id, gfx::Display::InternalDisplayId());
524 // Primary connected, with different bounds.
525 display_info_list.clear();
526 display_info_list.push_back(internal_display_info);
527 display_info_list.push_back(external_display_info);
528 display_manager()->OnNativeDisplaysChanged(display_info_list);
529 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
530 EXPECT_EQ(internal_display_id, Shell::GetScreen()->GetPrimaryDisplay().id());
532 // This combinatino is new, so internal display becomes primary.
533 EXPECT_EQ("0,0 500x500",
534 GetDisplayForId(internal_display_id).bounds().ToString());
535 EXPECT_EQ("1,1 100x100",
536 GetDisplayInfoForId(10).bounds_in_native().ToString());
537 EXPECT_EQ(2U, display_manager()->num_connected_displays());
538 EXPECT_FALSE(display_manager()->IsMirrored());
539 EXPECT_EQ(ToDisplayName(internal_display_id),
540 display_manager()->GetDisplayNameForId(internal_display_id));
542 // Emulate suspend.
543 display_info_list.clear();
544 display_manager()->OnNativeDisplaysChanged(display_info_list);
545 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
546 EXPECT_EQ("0,0 500x500",
547 GetDisplayForId(internal_display_id).bounds().ToString());
548 EXPECT_EQ("1,1 100x100",
549 GetDisplayInfoForId(10).bounds_in_native().ToString());
550 EXPECT_EQ(2U, display_manager()->num_connected_displays());
551 EXPECT_FALSE(display_manager()->IsMirrored());
552 EXPECT_EQ(ToDisplayName(internal_display_id),
553 display_manager()->GetDisplayNameForId(internal_display_id));
555 // External display has disconnected then resumed.
556 display_info_list.push_back(internal_display_info);
557 display_manager()->OnNativeDisplaysChanged(display_info_list);
558 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
559 EXPECT_EQ("0,0 500x500",
560 GetDisplayForId(internal_display_id).bounds().ToString());
561 EXPECT_EQ(1U, display_manager()->num_connected_displays());
562 EXPECT_FALSE(display_manager()->IsMirrored());
564 // External display was changed during suspend.
565 display_info_list.push_back(external_display_info);
566 display_manager()->OnNativeDisplaysChanged(display_info_list);
567 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
568 EXPECT_EQ(2U, display_manager()->num_connected_displays());
569 EXPECT_FALSE(display_manager()->IsMirrored());
571 // suspend...
572 display_info_list.clear();
573 display_manager()->OnNativeDisplaysChanged(display_info_list);
574 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
575 EXPECT_EQ(2U, display_manager()->num_connected_displays());
576 EXPECT_FALSE(display_manager()->IsMirrored());
578 // and resume with different external display.
579 display_info_list.push_back(internal_display_info);
580 display_info_list.push_back(CreateDisplayInfo(12, gfx::Rect(1, 1, 100, 100)));
581 display_manager()->OnNativeDisplaysChanged(display_info_list);
582 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
583 EXPECT_EQ(2U, display_manager()->num_connected_displays());
584 EXPECT_FALSE(display_manager()->IsMirrored());
585 EXPECT_FALSE(display_manager()->IsMirrored());
587 // mirrored...
588 display_info_list.clear();
589 display_info_list.push_back(internal_display_info);
590 display_info_list.push_back(mirrored_display_info);
591 display_manager()->OnNativeDisplaysChanged(display_info_list);
592 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
593 EXPECT_EQ("0,0 500x500",
594 GetDisplayForId(internal_display_id).bounds().ToString());
595 EXPECT_EQ(2U, display_manager()->num_connected_displays());
596 EXPECT_EQ(11U, display_manager()->mirrored_display_id());
597 EXPECT_TRUE(display_manager()->IsMirrored());
599 // Test display name.
600 EXPECT_EQ(ToDisplayName(internal_display_id),
601 display_manager()->GetDisplayNameForId(internal_display_id));
602 EXPECT_EQ("x-10", display_manager()->GetDisplayNameForId(10));
603 EXPECT_EQ("x-11", display_manager()->GetDisplayNameForId(11));
604 EXPECT_EQ("x-12", display_manager()->GetDisplayNameForId(12));
605 // Default name for the id that doesn't exist.
606 EXPECT_EQ("Display 100", display_manager()->GetDisplayNameForId(100));
608 // and exit mirroring.
609 display_info_list.clear();
610 display_info_list.push_back(internal_display_info);
611 display_info_list.push_back(external_display_info);
612 display_manager()->OnNativeDisplaysChanged(display_info_list);
613 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
614 EXPECT_EQ(2U, display_manager()->num_connected_displays());
615 EXPECT_FALSE(display_manager()->IsMirrored());
616 EXPECT_EQ("0,0 500x500",
617 GetDisplayForId(internal_display_id).bounds().ToString());
618 EXPECT_EQ("500,0 100x100",
619 GetDisplayForId(10).bounds().ToString());
621 // Turn off internal
622 display_info_list.clear();
623 display_info_list.push_back(external_display_info);
624 display_manager()->OnNativeDisplaysChanged(display_info_list);
625 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
626 EXPECT_EQ(invalid_id, GetDisplayForId(internal_display_id).id());
627 EXPECT_EQ("1,1 100x100",
628 GetDisplayInfoForId(external_id).bounds_in_native().ToString());
629 EXPECT_EQ(1U, display_manager()->num_connected_displays());
630 EXPECT_FALSE(display_manager()->IsMirrored());
632 // Switched to another display
633 display_info_list.clear();
634 display_info_list.push_back(internal_display_info);
635 display_manager()->OnNativeDisplaysChanged(display_info_list);
636 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
637 EXPECT_EQ(
638 "0,0 500x500",
639 GetDisplayInfoForId(internal_display_id).bounds_in_native().ToString());
640 EXPECT_EQ(1U, display_manager()->num_connected_displays());
641 EXPECT_FALSE(display_manager()->IsMirrored());
644 // Make sure crash does not happen if add and remove happens at the same time.
645 // See: crbug.com/414394
646 TEST_F(DisplayManagerTest, DisplayAddRemoveAtTheSameTime) {
647 if (!SupportsMultipleDisplays())
648 return;
650 UpdateDisplay("100+0-500x500,0+501-400x400");
652 const int64 primary_id = DisplayController::GetPrimaryDisplayId();
653 const int64 secondary_id = ScreenUtil::GetSecondaryDisplay().id();
655 DisplayInfo primary_info = display_manager()->GetDisplayInfo(primary_id);
656 DisplayInfo secondary_info = display_manager()->GetDisplayInfo(secondary_id);
658 // An id which is different from primary and secondary.
659 const int64 third_id = primary_id + secondary_id;
661 DisplayInfo third_info =
662 CreateDisplayInfo(third_id, gfx::Rect(0, 0, 600, 600));
664 std::vector<DisplayInfo> display_info_list;
665 display_info_list.push_back(third_info);
666 display_info_list.push_back(secondary_info);
667 display_manager()->OnNativeDisplaysChanged(display_info_list);
669 EXPECT_EQ(third_id, DisplayController::GetPrimaryDisplayId());
670 EXPECT_EQ("600x600", GetDisplayForId(third_id).size().ToString());
671 EXPECT_EQ(secondary_id, ScreenUtil::GetSecondaryDisplay().id());
674 #if defined(OS_WIN)
675 // TODO(scottmg): RootWindow doesn't get resized on Windows
676 // Ash. http://crbug.com/247916.
677 #define MAYBE_TestNativeDisplaysChangedNoInternal \
678 DISABLED_TestNativeDisplaysChangedNoInternal
679 #else
680 #define MAYBE_TestNativeDisplaysChangedNoInternal \
681 TestNativeDisplaysChangedNoInternal
682 #endif
684 TEST_F(DisplayManagerTest, MAYBE_TestNativeDisplaysChangedNoInternal) {
685 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
687 // Don't change the display info if all displays are disconnected.
688 std::vector<DisplayInfo> display_info_list;
689 display_manager()->OnNativeDisplaysChanged(display_info_list);
690 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
692 // Connect another display which will become primary.
693 const DisplayInfo external_display_info =
694 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
695 display_info_list.push_back(external_display_info);
696 display_manager()->OnNativeDisplaysChanged(display_info_list);
697 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
698 EXPECT_EQ("1,1 100x100",
699 GetDisplayInfoForId(10).bounds_in_native().ToString());
700 EXPECT_EQ("100x100", ash::Shell::GetPrimaryRootWindow()->GetHost()->
701 GetBounds().size().ToString());
704 TEST_F(DisplayManagerTest, NativeDisplaysChangedAfterPrimaryChange) {
705 if (!SupportsMultipleDisplays())
706 return;
708 const int64 internal_display_id =
709 test::DisplayManagerTestApi(display_manager()).
710 SetFirstDisplayAsInternalDisplay();
711 const DisplayInfo native_display_info =
712 CreateDisplayInfo(internal_display_id, gfx::Rect(0, 0, 500, 500));
713 const DisplayInfo secondary_display_info =
714 CreateDisplayInfo(10, gfx::Rect(1, 1, 100, 100));
716 std::vector<DisplayInfo> display_info_list;
717 display_info_list.push_back(native_display_info);
718 display_info_list.push_back(secondary_display_info);
719 display_manager()->OnNativeDisplaysChanged(display_info_list);
720 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
721 EXPECT_EQ("0,0 500x500",
722 GetDisplayForId(internal_display_id).bounds().ToString());
723 EXPECT_EQ("500,0 100x100", GetDisplayForId(10).bounds().ToString());
725 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay(
726 GetDisplayForId(secondary_display_info.id()));
727 EXPECT_EQ("-500,0 500x500",
728 GetDisplayForId(internal_display_id).bounds().ToString());
729 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
731 // OnNativeDisplaysChanged may change the display bounds. Here makes sure
732 // nothing changed if the exactly same displays are specified.
733 display_manager()->OnNativeDisplaysChanged(display_info_list);
734 EXPECT_EQ("-500,0 500x500",
735 GetDisplayForId(internal_display_id).bounds().ToString());
736 EXPECT_EQ("0,0 100x100", GetDisplayForId(10).bounds().ToString());
739 TEST_F(DisplayManagerTest, DontRememberBestResolution) {
740 int display_id = 1000;
741 DisplayInfo native_display_info =
742 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
743 std::vector<DisplayMode> display_modes;
744 display_modes.push_back(
745 DisplayMode(gfx::Size(1000, 500), 58.0f, false, true));
746 display_modes.push_back(
747 DisplayMode(gfx::Size(800, 300), 59.0f, false, false));
748 display_modes.push_back(
749 DisplayMode(gfx::Size(400, 500), 60.0f, false, false));
751 native_display_info.SetDisplayModes(display_modes);
753 std::vector<DisplayInfo> display_info_list;
754 display_info_list.push_back(native_display_info);
755 display_manager()->OnNativeDisplaysChanged(display_info_list);
757 DisplayMode mode;
758 DisplayMode expected_mode;
759 expected_mode.size = gfx::Size(1000, 500);
760 EXPECT_FALSE(
761 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
762 EXPECT_TRUE(expected_mode.IsEquivalent(
763 display_manager()->GetActiveModeForDisplayId(display_id)));
765 // Unsupported resolution.
766 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 4000));
767 EXPECT_FALSE(
768 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
769 EXPECT_TRUE(expected_mode.IsEquivalent(
770 display_manager()->GetActiveModeForDisplayId(display_id)));
772 // Supported resolution.
773 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
774 EXPECT_TRUE(
775 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
776 EXPECT_EQ("800x300", mode.size.ToString());
777 EXPECT_EQ(59.0f, mode.refresh_rate);
778 EXPECT_FALSE(mode.native);
779 expected_mode.size = gfx::Size(800, 300);
780 EXPECT_TRUE(expected_mode.IsEquivalent(
781 display_manager()->GetActiveModeForDisplayId(display_id)));
783 // Best resolution.
784 display_manager()->SetDisplayResolution(display_id, gfx::Size(1000, 500));
785 EXPECT_TRUE(
786 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
787 EXPECT_EQ("1000x500", mode.size.ToString());
788 EXPECT_EQ(58.0f, mode.refresh_rate);
789 EXPECT_TRUE(mode.native);
790 expected_mode.size = gfx::Size(1000, 500);
791 EXPECT_TRUE(expected_mode.IsEquivalent(
792 display_manager()->GetActiveModeForDisplayId(display_id)));
795 TEST_F(DisplayManagerTest, ResolutionFallback) {
796 int display_id = 1000;
797 DisplayInfo native_display_info =
798 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
799 std::vector<DisplayMode> display_modes;
800 display_modes.push_back(
801 DisplayMode(gfx::Size(1000, 500), 58.0f, false, true));
802 display_modes.push_back(
803 DisplayMode(gfx::Size(800, 300), 59.0f, false, false));
804 display_modes.push_back(
805 DisplayMode(gfx::Size(400, 500), 60.0f, false, false));
807 std::vector<DisplayMode> copy = display_modes;
808 native_display_info.SetDisplayModes(copy);
810 std::vector<DisplayInfo> display_info_list;
811 display_info_list.push_back(native_display_info);
812 display_manager()->OnNativeDisplaysChanged(display_info_list);
814 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
815 DisplayInfo new_native_display_info =
816 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 400, 500));
817 copy = display_modes;
818 new_native_display_info.SetDisplayModes(copy);
819 std::vector<DisplayInfo> new_display_info_list;
820 new_display_info_list.push_back(new_native_display_info);
821 display_manager()->OnNativeDisplaysChanged(new_display_info_list);
823 DisplayMode mode;
824 EXPECT_TRUE(
825 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
826 EXPECT_EQ("400x500", mode.size.ToString());
827 EXPECT_EQ(60.0f, mode.refresh_rate);
828 EXPECT_FALSE(mode.native);
831 // Best resolution should find itself on the resolutions list.
832 display_manager()->SetDisplayResolution(display_id, gfx::Size(800, 300));
833 DisplayInfo new_native_display_info =
834 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1000, 500));
835 std::vector<DisplayMode> copy = display_modes;
836 new_native_display_info.SetDisplayModes(copy);
837 std::vector<DisplayInfo> new_display_info_list;
838 new_display_info_list.push_back(new_native_display_info);
839 display_manager()->OnNativeDisplaysChanged(new_display_info_list);
841 DisplayMode mode;
842 EXPECT_TRUE(
843 display_manager()->GetSelectedModeForDisplayId(display_id, &mode));
844 EXPECT_EQ("1000x500", mode.size.ToString());
845 EXPECT_EQ(58.0f, mode.refresh_rate);
846 EXPECT_TRUE(mode.native);
850 TEST_F(DisplayManagerTest, Rotate) {
851 if (!SupportsMultipleDisplays())
852 return;
854 UpdateDisplay("100x200/r,300x400/l");
855 EXPECT_EQ("1,1 100x200",
856 GetDisplayInfoAt(0).bounds_in_native().ToString());
857 EXPECT_EQ("200x100",
858 GetDisplayInfoAt(0).size_in_pixel().ToString());
860 EXPECT_EQ("1,201 300x400",
861 GetDisplayInfoAt(1).bounds_in_native().ToString());
862 EXPECT_EQ("400x300",
863 GetDisplayInfoAt(1).size_in_pixel().ToString());
864 reset();
865 UpdateDisplay("100x200/b,300x400");
866 EXPECT_EQ("2 0 0", GetCountSummary());
867 reset();
869 EXPECT_EQ("1,1 100x200",
870 GetDisplayInfoAt(0).bounds_in_native().ToString());
871 EXPECT_EQ("100x200",
872 GetDisplayInfoAt(0).size_in_pixel().ToString());
874 EXPECT_EQ("1,201 300x400",
875 GetDisplayInfoAt(1).bounds_in_native().ToString());
876 EXPECT_EQ("300x400",
877 GetDisplayInfoAt(1).size_in_pixel().ToString());
879 // Just Rotating display will change the bounds on both display.
880 UpdateDisplay("100x200/l,300x400");
881 EXPECT_EQ("2 0 0", GetCountSummary());
882 reset();
884 // Updating to the same configuration should report no changes.
885 UpdateDisplay("100x200/l,300x400");
886 EXPECT_EQ("0 0 0", GetCountSummary());
887 reset();
889 // Rotating 180 degrees should report one change.
890 UpdateDisplay("100x200/r,300x400");
891 EXPECT_EQ("1 0 0", GetCountSummary());
892 reset();
894 UpdateDisplay("200x200");
895 EXPECT_EQ("1 0 1", GetCountSummary());
896 reset();
898 // Rotating 180 degrees should report one change.
899 UpdateDisplay("200x200/u");
900 EXPECT_EQ("1 0 0", GetCountSummary());
901 reset();
903 UpdateDisplay("200x200/l");
904 EXPECT_EQ("1 0 0", GetCountSummary());
907 TEST_F(DisplayManagerTest, UIScale) {
908 DisplayInfo::SetUse125DSFForUIScaling(false);
910 UpdateDisplay("1280x800");
911 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
912 display_manager()->SetDisplayUIScale(display_id, 1.125f);
913 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
914 display_manager()->SetDisplayUIScale(display_id, 0.8f);
915 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
916 display_manager()->SetDisplayUIScale(display_id, 0.75f);
917 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
918 display_manager()->SetDisplayUIScale(display_id, 0.625f);
919 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
921 test::DisplayManagerTestApi(display_manager())
922 .SetInternalDisplayId(display_id);
924 display_manager()->SetDisplayUIScale(display_id, 1.5f);
925 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
926 display_manager()->SetDisplayUIScale(display_id, 1.25f);
927 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
928 display_manager()->SetDisplayUIScale(display_id, 1.125f);
929 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
930 display_manager()->SetDisplayUIScale(display_id, 0.8f);
931 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
932 display_manager()->SetDisplayUIScale(display_id, 0.75f);
933 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
934 display_manager()->SetDisplayUIScale(display_id, 0.625f);
935 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
936 display_manager()->SetDisplayUIScale(display_id, 0.6f);
937 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
938 display_manager()->SetDisplayUIScale(display_id, 0.5f);
939 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
941 UpdateDisplay("1366x768");
942 display_manager()->SetDisplayUIScale(display_id, 1.5f);
943 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
944 display_manager()->SetDisplayUIScale(display_id, 1.25f);
945 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
946 display_manager()->SetDisplayUIScale(display_id, 1.125f);
947 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
948 display_manager()->SetDisplayUIScale(display_id, 0.8f);
949 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
950 display_manager()->SetDisplayUIScale(display_id, 0.75f);
951 EXPECT_EQ(0.75f, GetDisplayInfoAt(0).configured_ui_scale());
952 display_manager()->SetDisplayUIScale(display_id, 0.6f);
953 EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
954 display_manager()->SetDisplayUIScale(display_id, 0.625f);
955 EXPECT_EQ(0.6f, GetDisplayInfoAt(0).configured_ui_scale());
956 display_manager()->SetDisplayUIScale(display_id, 0.5f);
957 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
959 UpdateDisplay("1280x850*2");
960 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
961 display_manager()->SetDisplayUIScale(display_id, 1.5f);
962 EXPECT_EQ(1.5f, GetDisplayInfoAt(0).configured_ui_scale());
963 display_manager()->SetDisplayUIScale(display_id, 1.25f);
964 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale());
965 display_manager()->SetDisplayUIScale(display_id, 1.125f);
966 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
967 display_manager()->SetDisplayUIScale(display_id, 1.0f);
968 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
969 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
970 EXPECT_EQ(2.0f, display.device_scale_factor());
971 EXPECT_EQ("640x425", display.bounds().size().ToString());
973 display_manager()->SetDisplayUIScale(display_id, 0.8f);
974 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
975 display_manager()->SetDisplayUIScale(display_id, 0.75f);
976 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
977 display_manager()->SetDisplayUIScale(display_id, 0.625f);
978 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
979 display_manager()->SetDisplayUIScale(display_id, 0.6f);
980 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
981 display_manager()->SetDisplayUIScale(display_id, 0.5f);
982 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
984 display_manager()->SetDisplayUIScale(display_id, 2.0f);
985 EXPECT_EQ(2.0f, GetDisplayInfoAt(0).configured_ui_scale());
986 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
987 display = Shell::GetScreen()->GetPrimaryDisplay();
988 EXPECT_EQ(1.0f, display.device_scale_factor());
989 EXPECT_EQ("1280x850", display.bounds().size().ToString());
991 // 1.25 ui scaling on 1.25 DSF device should use 1.0 DSF
992 // on screen.
993 UpdateDisplay("1280x850*1.25");
994 display_manager()->SetDisplayUIScale(display_id, 1.25f);
995 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).configured_ui_scale());
996 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
997 display = Shell::GetScreen()->GetPrimaryDisplay();
998 EXPECT_EQ(1.0f, display.device_scale_factor());
999 EXPECT_EQ("1280x850", display.bounds().size().ToString());
1002 TEST_F(DisplayManagerTest, UIScaleWithDisplayMode) {
1003 int display_id = 1000;
1005 // Setup the display modes with UI-scale.
1006 DisplayInfo native_display_info =
1007 CreateDisplayInfo(display_id, gfx::Rect(0, 0, 1280, 800));
1008 std::vector<DisplayMode> display_modes;
1009 const DisplayMode base_mode(gfx::Size(1280, 800), 60.0f, false, false);
1010 std::vector<DisplayMode> mode_list = CreateInternalDisplayModeList(base_mode);
1011 native_display_info.SetDisplayModes(mode_list);
1013 std::vector<DisplayInfo> display_info_list;
1014 display_info_list.push_back(native_display_info);
1015 display_manager()->OnNativeDisplaysChanged(display_info_list);
1017 DisplayMode expected_mode = base_mode;
1018 EXPECT_TRUE(expected_mode.IsEquivalent(
1019 display_manager()->GetActiveModeForDisplayId(display_id)));
1021 display_manager()->SetDisplayUIScale(display_id, 1.125f);
1022 EXPECT_EQ(1.0, GetDisplayInfoAt(0).configured_ui_scale());
1023 EXPECT_TRUE(expected_mode.IsEquivalent(
1024 display_manager()->GetActiveModeForDisplayId(display_id)));
1025 display_manager()->SetDisplayUIScale(display_id, 0.8f);
1026 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
1027 EXPECT_TRUE(expected_mode.IsEquivalent(
1028 display_manager()->GetActiveModeForDisplayId(display_id)));
1029 display_manager()->SetDisplayUIScale(display_id, 0.75f);
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.625f);
1034 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
1035 EXPECT_TRUE(expected_mode.IsEquivalent(
1036 display_manager()->GetActiveModeForDisplayId(display_id)));
1038 test::DisplayManagerTestApi(display_manager())
1039 .SetInternalDisplayId(display_id);
1041 display_manager()->SetDisplayUIScale(display_id, 1.5f);
1042 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).configured_ui_scale());
1043 EXPECT_TRUE(expected_mode.IsEquivalent(
1044 display_manager()->GetActiveModeForDisplayId(display_id)));
1045 display_manager()->SetDisplayUIScale(display_id, 1.25f);
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.125f);
1050 EXPECT_EQ(1.125f, GetDisplayInfoAt(0).configured_ui_scale());
1051 expected_mode.ui_scale = 1.125f;
1052 EXPECT_TRUE(expected_mode.IsEquivalent(
1053 display_manager()->GetActiveModeForDisplayId(display_id)));
1054 display_manager()->SetDisplayUIScale(display_id, 0.8f);
1055 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
1056 expected_mode.ui_scale = 0.8f;
1057 EXPECT_TRUE(expected_mode.IsEquivalent(
1058 display_manager()->GetActiveModeForDisplayId(display_id)));
1059 display_manager()->SetDisplayUIScale(display_id, 0.75f);
1060 EXPECT_EQ(0.8f, GetDisplayInfoAt(0).configured_ui_scale());
1061 EXPECT_TRUE(expected_mode.IsEquivalent(
1062 display_manager()->GetActiveModeForDisplayId(display_id)));
1063 display_manager()->SetDisplayUIScale(display_id, 0.625f);
1064 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
1065 expected_mode.ui_scale = 0.625f;
1066 EXPECT_TRUE(expected_mode.IsEquivalent(
1067 display_manager()->GetActiveModeForDisplayId(display_id)));
1068 display_manager()->SetDisplayUIScale(display_id, 0.6f);
1069 EXPECT_EQ(0.625f, GetDisplayInfoAt(0).configured_ui_scale());
1070 EXPECT_TRUE(expected_mode.IsEquivalent(
1071 display_manager()->GetActiveModeForDisplayId(display_id)));
1072 display_manager()->SetDisplayUIScale(display_id, 0.5f);
1073 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).configured_ui_scale());
1074 expected_mode.ui_scale = 0.5f;
1075 EXPECT_TRUE(expected_mode.IsEquivalent(
1076 display_manager()->GetActiveModeForDisplayId(display_id)));
1079 TEST_F(DisplayManagerTest, Use125DSFRorUIScaling) {
1080 DisplayInfo::SetUse125DSFForUIScaling(true);
1082 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
1083 test::DisplayManagerTestApi(display_manager())
1084 .SetInternalDisplayId(display_id);
1086 UpdateDisplay("1920x1080*1.25");
1087 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1088 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
1090 display_manager()->SetDisplayUIScale(display_id, 0.8f);
1091 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1092 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveUIScale());
1093 EXPECT_EQ("1536x864", GetDisplayForId(display_id).size().ToString());
1095 display_manager()->SetDisplayUIScale(display_id, 0.5f);
1096 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1097 EXPECT_EQ(0.5f, GetDisplayInfoAt(0).GetEffectiveUIScale());
1098 EXPECT_EQ("960x540", GetDisplayForId(display_id).size().ToString());
1100 display_manager()->SetDisplayUIScale(display_id, 1.25f);
1101 EXPECT_EQ(1.0f, GetDisplayInfoAt(0).GetEffectiveDeviceScaleFactor());
1102 EXPECT_EQ(1.25f, GetDisplayInfoAt(0).GetEffectiveUIScale());
1103 EXPECT_EQ("2400x1350", GetDisplayForId(display_id).size().ToString());
1105 DisplayInfo::SetUse125DSFForUIScaling(false);
1108 #if defined(OS_WIN)
1109 // TODO(scottmg): RootWindow doesn't get resized on Windows
1110 // Ash. http://crbug.com/247916.
1111 #define MAYBE_UpdateMouseCursorAfterRotateZoom DISABLED_UpdateMouseCursorAfterRotateZoom
1112 #else
1113 #define MAYBE_UpdateMouseCursorAfterRotateZoom UpdateMouseCursorAfterRotateZoom
1114 #endif
1116 TEST_F(DisplayManagerTest, MAYBE_UpdateMouseCursorAfterRotateZoom) {
1117 // Make sure just rotating will not change native location.
1118 UpdateDisplay("300x200,200x150");
1119 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1120 aura::Env* env = aura::Env::GetInstance();
1122 ui::test::EventGenerator generator1(root_windows[0]);
1123 ui::test::EventGenerator generator2(root_windows[1]);
1125 // Test on 1st display.
1126 generator1.MoveMouseToInHost(150, 50);
1127 EXPECT_EQ("150,50", env->last_mouse_location().ToString());
1128 UpdateDisplay("300x200/r,200x150");
1129 EXPECT_EQ("50,149", env->last_mouse_location().ToString());
1131 // Test on 2nd display.
1132 generator2.MoveMouseToInHost(50, 100);
1133 EXPECT_EQ("250,100", env->last_mouse_location().ToString());
1134 UpdateDisplay("300x200/r,200x150/l");
1135 EXPECT_EQ("249,50", env->last_mouse_location().ToString());
1137 // The native location is now outside, so move to the center
1138 // of closest display.
1139 UpdateDisplay("300x200/r,100x50/l");
1140 EXPECT_EQ("225,50", env->last_mouse_location().ToString());
1142 // Make sure just zooming will not change native location.
1143 UpdateDisplay("600x400*2,400x300");
1145 // Test on 1st display.
1146 generator1.MoveMouseToInHost(200, 300);
1147 EXPECT_EQ("100,150", env->last_mouse_location().ToString());
1148 UpdateDisplay("600x400*2@1.5,400x300");
1149 EXPECT_EQ("150,225", env->last_mouse_location().ToString());
1151 // Test on 2nd display.
1152 UpdateDisplay("600x400,400x300*2");
1153 generator2.MoveMouseToInHost(200, 250);
1154 EXPECT_EQ("700,125", env->last_mouse_location().ToString());
1155 UpdateDisplay("600x400,400x300*2@1.5");
1156 EXPECT_EQ("750,187", env->last_mouse_location().ToString());
1158 // The native location is now outside, so move to the
1159 // center of closest display.
1160 UpdateDisplay("600x400,400x200*2@1.5");
1161 EXPECT_EQ("750,75", env->last_mouse_location().ToString());
1164 class TestDisplayObserver : public gfx::DisplayObserver {
1165 public:
1166 TestDisplayObserver() : changed_(false) {}
1167 ~TestDisplayObserver() override {}
1169 // gfx::DisplayObserver overrides:
1170 void OnDisplayMetricsChanged(const gfx::Display&, uint32_t) override {}
1171 void OnDisplayAdded(const gfx::Display& new_display) override {
1172 // Mirror window should already be delete before restoring
1173 // the external display.
1174 EXPECT_FALSE(test_api.GetHost());
1175 changed_ = true;
1177 void OnDisplayRemoved(const gfx::Display& old_display) override {
1178 // Mirror window should not be created until the external display
1179 // is removed.
1180 EXPECT_FALSE(test_api.GetHost());
1181 changed_ = true;
1184 bool changed_and_reset() {
1185 bool changed = changed_;
1186 changed_ = false;
1187 return changed;
1190 private:
1191 test::MirrorWindowTestApi test_api;
1192 bool changed_;
1194 DISALLOW_COPY_AND_ASSIGN(TestDisplayObserver);
1197 TEST_F(DisplayManagerTest, SoftwareMirroring) {
1198 if (!SupportsMultipleDisplays())
1199 return;
1201 UpdateDisplay("300x400,400x500");
1203 test::MirrorWindowTestApi test_api;
1204 EXPECT_EQ(NULL, test_api.GetHost());
1206 TestDisplayObserver display_observer;
1207 Shell::GetScreen()->AddObserver(&display_observer);
1209 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1210 display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING);
1211 display_manager->UpdateDisplays();
1212 RunAllPendingInMessageLoop();
1213 EXPECT_TRUE(display_observer.changed_and_reset());
1214 EXPECT_EQ(1U, display_manager->GetNumDisplays());
1215 EXPECT_EQ("0,0 300x400",
1216 Shell::GetScreen()->GetPrimaryDisplay().bounds().ToString());
1217 EXPECT_EQ("400x500", test_api.GetHost()->GetBounds().size().ToString());
1218 EXPECT_EQ("300x400",
1219 test_api.GetHost()->window()->bounds().size().ToString());
1220 EXPECT_TRUE(display_manager->IsMirrored());
1222 display_manager->SetMirrorMode(false);
1223 EXPECT_TRUE(display_observer.changed_and_reset());
1224 EXPECT_EQ(NULL, test_api.GetHost());
1225 EXPECT_EQ(2U, display_manager->GetNumDisplays());
1226 EXPECT_FALSE(display_manager->IsMirrored());
1228 // Make sure the mirror window has the pixel size of the
1229 // source display.
1230 display_manager->SetMirrorMode(true);
1231 EXPECT_TRUE(display_observer.changed_and_reset());
1233 UpdateDisplay("300x400@0.5,400x500");
1234 EXPECT_FALSE(display_observer.changed_and_reset());
1235 EXPECT_EQ("300x400",
1236 test_api.GetHost()->window()->bounds().size().ToString());
1238 UpdateDisplay("310x410*2,400x500");
1239 EXPECT_FALSE(display_observer.changed_and_reset());
1240 EXPECT_EQ("310x410",
1241 test_api.GetHost()->window()->bounds().size().ToString());
1243 UpdateDisplay("320x420/r,400x500");
1244 EXPECT_FALSE(display_observer.changed_and_reset());
1245 EXPECT_EQ("320x420",
1246 test_api.GetHost()->window()->bounds().size().ToString());
1248 UpdateDisplay("330x440/r,400x500");
1249 EXPECT_FALSE(display_observer.changed_and_reset());
1250 EXPECT_EQ("330x440",
1251 test_api.GetHost()->window()->bounds().size().ToString());
1253 // Overscan insets are ignored.
1254 UpdateDisplay("400x600/o,600x800/o");
1255 EXPECT_FALSE(display_observer.changed_and_reset());
1256 EXPECT_EQ("400x600",
1257 test_api.GetHost()->window()->bounds().size().ToString());
1259 Shell::GetScreen()->RemoveObserver(&display_observer);
1262 TEST_F(DisplayManagerTest, SingleDisplayToSoftwareMirroring) {
1263 if (!SupportsMultipleDisplays())
1264 return;
1265 UpdateDisplay("600x400");
1267 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1268 display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING);
1269 UpdateDisplay("600x400,600x400");
1271 EXPECT_TRUE(display_manager->IsMirrored());
1272 EXPECT_EQ(1U, display_manager->GetNumDisplays());
1273 DisplayController* display_controller =
1274 ash::Shell::GetInstance()->display_controller();
1275 EXPECT_TRUE(display_controller->mirror_window_controller()->GetWindow());
1277 UpdateDisplay("600x400");
1278 EXPECT_FALSE(display_manager->IsMirrored());
1279 EXPECT_EQ(1U, display_manager->GetNumDisplays());
1280 EXPECT_FALSE(display_controller->mirror_window_controller()->GetWindow());
1283 #if defined(OS_CHROMEOS)
1284 // Make sure this does not cause any crashes. See http://crbug.com/412910
1285 // This test is limited to OS_CHROMEOS because CursorCompositingEnabled is only
1286 // for ChromeOS.
1287 TEST_F(DisplayManagerTest, SoftwareMirroringWithCompositingCursor) {
1288 if (!SupportsMultipleDisplays())
1289 return;
1291 UpdateDisplay("300x400,400x500");
1293 test::MirrorWindowTestApi test_api;
1294 EXPECT_EQ(NULL, test_api.GetHost());
1296 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1297 DisplayInfo secondary_info = display_manager->GetDisplayInfo(
1298 ScreenUtil::GetSecondaryDisplay().id());
1300 display_manager->SetSoftwareMirroring(true);
1301 display_manager->UpdateDisplays();
1303 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1304 EXPECT_FALSE(root_windows[0]->Contains(test_api.GetCursorWindow()));
1306 Shell::GetInstance()->SetCursorCompositingEnabled(true);
1308 EXPECT_TRUE(root_windows[0]->Contains(test_api.GetCursorWindow()));
1310 // Removes the first display and keeps the second one.
1311 display_manager->SetSoftwareMirroring(false);
1312 std::vector<DisplayInfo> new_info_list;
1313 new_info_list.push_back(secondary_info);
1314 display_manager->OnNativeDisplaysChanged(new_info_list);
1316 root_windows = Shell::GetAllRootWindows();
1317 EXPECT_TRUE(root_windows[0]->Contains(test_api.GetCursorWindow()));
1319 Shell::GetInstance()->SetCursorCompositingEnabled(false);
1321 #endif // OS_CHROMEOS
1323 TEST_F(DisplayManagerTest, MirroredLayout) {
1324 if (!SupportsMultipleDisplays())
1325 return;
1327 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1328 UpdateDisplay("500x500,400x400");
1329 EXPECT_FALSE(display_manager->GetCurrentDisplayLayout().mirrored);
1330 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1331 EXPECT_EQ(2U, display_manager->num_connected_displays());
1333 UpdateDisplay("1+0-500x500,1+0-500x500");
1334 EXPECT_TRUE(display_manager->GetCurrentDisplayLayout().mirrored);
1335 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
1336 EXPECT_EQ(2U, display_manager->num_connected_displays());
1338 UpdateDisplay("500x500,500x500");
1339 EXPECT_FALSE(display_manager->GetCurrentDisplayLayout().mirrored);
1340 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1341 EXPECT_EQ(2U, display_manager->num_connected_displays());
1344 TEST_F(DisplayManagerTest, InvertLayout) {
1345 EXPECT_EQ("left, 0",
1346 DisplayLayout(DisplayLayout::RIGHT, 0).Invert().ToString());
1347 EXPECT_EQ("left, -100",
1348 DisplayLayout(DisplayLayout::RIGHT, 100).Invert().ToString());
1349 EXPECT_EQ("left, 50",
1350 DisplayLayout(DisplayLayout::RIGHT, -50).Invert().ToString());
1352 EXPECT_EQ("right, 0",
1353 DisplayLayout(DisplayLayout::LEFT, 0).Invert().ToString());
1354 EXPECT_EQ("right, -90",
1355 DisplayLayout(DisplayLayout::LEFT, 90).Invert().ToString());
1356 EXPECT_EQ("right, 60",
1357 DisplayLayout(DisplayLayout::LEFT, -60).Invert().ToString());
1359 EXPECT_EQ("bottom, 0",
1360 DisplayLayout(DisplayLayout::TOP, 0).Invert().ToString());
1361 EXPECT_EQ("bottom, -80",
1362 DisplayLayout(DisplayLayout::TOP, 80).Invert().ToString());
1363 EXPECT_EQ("bottom, 70",
1364 DisplayLayout(DisplayLayout::TOP, -70).Invert().ToString());
1366 EXPECT_EQ("top, 0",
1367 DisplayLayout(DisplayLayout::BOTTOM, 0).Invert().ToString());
1368 EXPECT_EQ("top, -70",
1369 DisplayLayout(DisplayLayout::BOTTOM, 70).Invert().ToString());
1370 EXPECT_EQ("top, 80",
1371 DisplayLayout(DisplayLayout::BOTTOM, -80).Invert().ToString());
1374 TEST_F(DisplayManagerTest, NotifyPrimaryChange) {
1375 if (!SupportsMultipleDisplays())
1376 return;
1377 UpdateDisplay("500x500,500x500");
1378 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1379 reset();
1380 UpdateDisplay("500x500");
1381 EXPECT_FALSE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
1382 EXPECT_FALSE(changed_metrics() &
1383 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
1384 EXPECT_TRUE(changed_metrics() &
1385 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY);
1387 UpdateDisplay("500x500,500x500");
1388 ash::Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1389 reset();
1390 UpdateDisplay("500x400");
1391 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
1392 EXPECT_TRUE(changed_metrics() &
1393 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
1394 EXPECT_TRUE(changed_metrics() &
1395 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY);
1398 TEST_F(DisplayManagerTest, NotifyPrimaryChangeUndock) {
1399 if (!SupportsMultipleDisplays())
1400 return;
1401 // Assume the default display is an external display, and
1402 // emulates undocking by switching to another display.
1403 DisplayInfo another_display_info =
1404 CreateDisplayInfo(1, gfx::Rect(0, 0, 1280, 800));
1405 std::vector<DisplayInfo> info_list;
1406 info_list.push_back(another_display_info);
1407 reset();
1408 display_manager()->OnNativeDisplaysChanged(info_list);
1409 EXPECT_TRUE(changed_metrics() & gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
1410 EXPECT_TRUE(changed_metrics() &
1411 gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
1412 EXPECT_TRUE(changed_metrics() &
1413 gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY);
1416 #if defined(OS_WIN)
1417 // TODO(scottmg): RootWindow doesn't get resized on Windows
1418 // Ash. http://crbug.com/247916.
1419 #define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin
1420 #else
1421 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin
1422 #endif
1424 TEST_F(DisplayManagerTest, MAYBE_UpdateDisplayWithHostOrigin) {
1425 UpdateDisplay("100x200,300x400");
1426 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1427 aura::Window::Windows root_windows =
1428 Shell::GetInstance()->GetAllRootWindows();
1429 ASSERT_EQ(2U, root_windows.size());
1430 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
1431 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
1433 EXPECT_EQ("1,1", host0->GetBounds().origin().ToString());
1434 EXPECT_EQ("100x200", host0->GetBounds().size().ToString());
1435 // UpdateDisplay set the origin if it's not set.
1436 EXPECT_NE("1,1", host1->GetBounds().origin().ToString());
1437 EXPECT_EQ("300x400", host1->GetBounds().size().ToString());
1439 UpdateDisplay("100x200,200+300-300x400");
1440 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1441 EXPECT_EQ("0,0", host0->GetBounds().origin().ToString());
1442 EXPECT_EQ("100x200", host0->GetBounds().size().ToString());
1443 EXPECT_EQ("200,300", host1->GetBounds().origin().ToString());
1444 EXPECT_EQ("300x400", host1->GetBounds().size().ToString());
1446 UpdateDisplay("400+500-200x300,300x400");
1447 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1448 EXPECT_EQ("400,500", host0->GetBounds().origin().ToString());
1449 EXPECT_EQ("200x300", host0->GetBounds().size().ToString());
1450 EXPECT_EQ("0,0", host1->GetBounds().origin().ToString());
1451 EXPECT_EQ("300x400", host1->GetBounds().size().ToString());
1453 UpdateDisplay("100+200-100x200,300+500-200x300");
1454 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
1455 EXPECT_EQ("100,200", host0->GetBounds().origin().ToString());
1456 EXPECT_EQ("100x200", host0->GetBounds().size().ToString());
1457 EXPECT_EQ("300,500", host1->GetBounds().origin().ToString());
1458 EXPECT_EQ("200x300", host1->GetBounds().size().ToString());
1461 class ScreenShutdownTest : public test::AshTestBase {
1462 public:
1463 ScreenShutdownTest() {
1465 ~ScreenShutdownTest() override {}
1467 void TearDown() override {
1468 gfx::Screen* orig_screen =
1469 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
1470 AshTestBase::TearDown();
1471 if (!SupportsMultipleDisplays())
1472 return;
1473 gfx::Screen* screen =
1474 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
1475 EXPECT_NE(orig_screen, screen);
1476 EXPECT_EQ(2, screen->GetNumDisplays());
1477 EXPECT_EQ("500x300", screen->GetPrimaryDisplay().size().ToString());
1478 std::vector<gfx::Display> all = screen->GetAllDisplays();
1479 EXPECT_EQ("500x300", all[0].size().ToString());
1480 EXPECT_EQ("800x400", all[1].size().ToString());
1483 private:
1484 DISALLOW_COPY_AND_ASSIGN(ScreenShutdownTest);
1487 TEST_F(ScreenShutdownTest, ScreenAfterShutdown) {
1488 if (!SupportsMultipleDisplays())
1489 return;
1490 UpdateDisplay("500x300,800x400");
1494 #if defined(OS_CHROMEOS)
1495 namespace {
1497 // A helper class that sets the display configuration and starts ash.
1498 // This is to make sure the font configuration happens during ash
1499 // initialization process.
1500 class FontTestHelper : public test::AshTestBase {
1501 public:
1502 enum DisplayType {
1503 INTERNAL,
1504 EXTERNAL
1507 FontTestHelper(float scale, DisplayType display_type) {
1508 gfx::ClearFontRenderParamsCacheForTest();
1509 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1510 if (display_type == INTERNAL)
1511 command_line->AppendSwitch(switches::kAshUseFirstDisplayAsInternal);
1512 command_line->AppendSwitchASCII(switches::kAshHostWindowBounds,
1513 StringPrintf("1000x800*%f", scale));
1514 SetUp();
1517 ~FontTestHelper() override { TearDown(); }
1519 // test::AshTestBase:
1520 void TestBody() override { NOTREACHED(); }
1522 private:
1523 DISALLOW_COPY_AND_ASSIGN(FontTestHelper);
1527 bool IsTextSubpixelPositioningEnabled() {
1528 gfx::FontRenderParams params =
1529 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(false), NULL);
1530 return params.subpixel_positioning;
1533 gfx::FontRenderParams::Hinting GetFontHintingParams() {
1534 gfx::FontRenderParams params =
1535 gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(false), NULL);
1536 return params.hinting;
1539 } // namespace
1541 typedef testing::Test DisplayManagerFontTest;
1543 TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100Internal) {
1544 FontTestHelper helper(1.0f, FontTestHelper::INTERNAL);
1545 ASSERT_DOUBLE_EQ(
1546 1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1547 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1548 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1551 TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf125Internal) {
1552 FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
1553 ASSERT_DOUBLE_EQ(
1554 1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1555 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1556 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1559 TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf200Internal) {
1560 FontTestHelper helper(2.0f, FontTestHelper::INTERNAL);
1561 ASSERT_DOUBLE_EQ(
1562 2.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1563 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1564 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1566 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1567 Shell::GetScreen()->GetPrimaryDisplay().id(), 2.0f);
1569 ASSERT_DOUBLE_EQ(
1570 1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1571 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1572 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1575 TEST_F(DisplayManagerFontTest, TextSubpixelPositioningWithDsf100External) {
1576 FontTestHelper helper(1.0f, FontTestHelper::EXTERNAL);
1577 ASSERT_DOUBLE_EQ(
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, TextSubpixelPositioningWithDsf125External) {
1584 FontTestHelper helper(1.25f, FontTestHelper::EXTERNAL);
1585 ASSERT_DOUBLE_EQ(
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, TextSubpixelPositioningWithDsf200External) {
1592 FontTestHelper helper(2.0f, FontTestHelper::EXTERNAL);
1593 ASSERT_DOUBLE_EQ(
1594 2.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1595 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1596 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1599 TEST_F(DisplayManagerFontTest,
1600 TextSubpixelPositioningWithDsf125InternalWithScaling) {
1601 DisplayInfo::SetUse125DSFForUIScaling(true);
1602 FontTestHelper helper(1.25f, FontTestHelper::INTERNAL);
1603 ASSERT_DOUBLE_EQ(
1604 1.0f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1605 EXPECT_FALSE(IsTextSubpixelPositioningEnabled());
1606 EXPECT_NE(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1608 Shell::GetInstance()->display_manager()->SetDisplayUIScale(
1609 Shell::GetScreen()->GetPrimaryDisplay().id(), 0.8f);
1611 ASSERT_DOUBLE_EQ(
1612 1.25f, Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
1613 EXPECT_TRUE(IsTextSubpixelPositioningEnabled());
1614 EXPECT_EQ(gfx::FontRenderParams::HINTING_NONE, GetFontHintingParams());
1616 DisplayInfo::SetUse125DSFForUIScaling(false);
1619 #endif // OS_CHROMEOS
1621 } // namespace ash