Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: ash/display/display_manager_unittest.cc

Issue 2573673003: Detect and fix overlapping displays (Closed)
Patch Set: Extract Reparent Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/display/manager/display_manager.h" 5 #include "ui/display/manager/display_manager.h"
6 6
7 #include "ash/accelerators/accelerator_commands_aura.h" 7 #include "ash/accelerators/accelerator_commands_aura.h"
8 #include "ash/common/ash_switches.h" 8 #include "ash/common/ash_switches.h"
9 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 list, builder.Build()); 355 list, builder.Build());
356 356
357 UpdateDisplay("640x480,320x200,400x300"); 357 UpdateDisplay("640x480,320x200,400x300");
358 358
359 EXPECT_EQ(3U, display_manager()->GetNumDisplays()); 359 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
360 360
361 EXPECT_EQ("0,0 640x480", 361 EXPECT_EQ("0,0 640x480",
362 display_manager()->GetDisplayAt(0).bounds().ToString()); 362 display_manager()->GetDisplayAt(0).bounds().ToString());
363 EXPECT_EQ("-320,10 320x200", 363 EXPECT_EQ("-320,10 320x200",
364 display_manager()->GetDisplayAt(1).bounds().ToString()); 364 display_manager()->GetDisplayAt(1).bounds().ToString());
365 EXPECT_EQ("-310,-290 400x300", 365
366 // The above layout causes an overlap between [P] and [2], making [2]'s
367 // bounds be "-310,-290 400x300" if the overlap is not fixed. The overlap
368 // must be detected and fixed and [2] is shifted up to remove the overlap.
369 EXPECT_EQ("-310,-300 400x300",
366 display_manager()->GetDisplayAt(2).bounds().ToString()); 370 display_manager()->GetDisplayAt(2).bounds().ToString());
367 } 371 }
368 { 372 {
369 // Layout: [1] 373 // Layout: [1]
370 // [P][2] 374 // [P][2]
371 display::DisplayLayoutBuilder builder(primary_id); 375 display::DisplayLayoutBuilder builder(primary_id);
372 builder.AddDisplayPlacement(list[1], primary_id, 376 builder.AddDisplayPlacement(list[1], primary_id,
373 display::DisplayPlacement::TOP, 10); 377 display::DisplayPlacement::TOP, 10);
374 builder.AddDisplayPlacement(list[2], primary_id, 378 builder.AddDisplayPlacement(list[2], primary_id,
375 display::DisplayPlacement::RIGHT, 10); 379 display::DisplayPlacement::RIGHT, 10);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 display_manager()->GetDisplayAt(4).bounds().ToString()); 448 display_manager()->GetDisplayAt(4).bounds().ToString());
445 // 3rd is the left of 4th. 449 // 3rd is the left of 4th.
446 EXPECT_EQ("-290,480 300x200", 450 EXPECT_EQ("-290,480 300x200",
447 display_manager()->GetDisplayAt(3).bounds().ToString()); 451 display_manager()->GetDisplayAt(3).bounds().ToString());
448 // 1st is the bottom of 3rd. 452 // 1st is the bottom of 3rd.
449 EXPECT_EQ("-280,680 320x200", 453 EXPECT_EQ("-280,680 320x200",
450 display_manager()->GetDisplayAt(1).bounds().ToString()); 454 display_manager()->GetDisplayAt(1).bounds().ToString());
451 } 455 }
452 } 456 }
453 457
458 // Makes sure that layouts with overlapped displays are detected and fixed when
459 // applied.
460 TEST_P(DisplayManagerTest, NoOverlappedDisplays) {
461 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
462 {
463 // Layout with multiple overlaps and special cases:
464 //
465 // +-----+
466 // +----+-+6 |
467 // | 5 | | |
468 // +----+----+ | |
469 // | 7 | | | |
470 // +----+----+-+---+---+-+---------+
471 // | | P | | 2 |
472 // +------+ | | +----------+
473 // | | | | 3 |
474 // | | | | |
475 // +--+----+-+-+-+-----+--+ |
476 // | 1 | | 4 | | |
477 // | | | +--+-------+
478 // | | | |
479 // +--------+ +--------+
480
481 display::DisplayIdList list = display::test::CreateDisplayIdListN(
482 8, primary_id, primary_id + 1, primary_id + 2, primary_id + 3,
483 primary_id + 4, primary_id + 5, primary_id + 6, primary_id + 7);
484 display::DisplayLayoutBuilder builder(primary_id);
485 builder.AddDisplayPlacement(list[1], primary_id,
486 display::DisplayPlacement::BOTTOM, 50);
487 builder.AddDisplayPlacement(list[2], list[1],
488 display::DisplayPlacement::TOP, 300);
489 builder.AddDisplayPlacement(list[3], list[2],
490 display::DisplayPlacement::RIGHT, 30);
491 builder.AddDisplayPlacement(list[4], list[2],
492 display::DisplayPlacement::BOTTOM, 400);
493 builder.AddDisplayPlacement(list[5], primary_id,
494 display::DisplayPlacement::LEFT, -300);
495 builder.AddDisplayPlacement(list[6], primary_id,
496 display::DisplayPlacement::TOP, -250);
497 builder.AddDisplayPlacement(list[7], list[6],
498 display::DisplayPlacement::LEFT, 250);
499 display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
500 list, builder.Build());
501
502 UpdateDisplay(
503 "480x400,480x400,480x400,480x400,480x400,480x400,480x400,530x150");
504
505 // The resulting layout after overlaps had been removed:
506 //
507 //
508 // +---------+
509 // | 7 +-----+
510 // +-+-------+ 6 |
511 // | 5 | |
512 // | | |
513 // | | |
514 // | |-+---+----+---------+
515 // | | | P | 2 |
516 // +-------+ | | +----------+
517 // | | | 3 |
518 // | | | |
519 // +--+-----+-+-------+ |
520 // | 1 | | |
521 // | | +----+---+------+
522 // | | | 4 |
523 // +-------+ | |
524 // | |
525 // +--------+
526
527 EXPECT_EQ(8U, display_manager()->GetNumDisplays());
528
529 EXPECT_EQ("0,0 480x400",
530 display_manager()->GetDisplayAt(0).bounds().ToString());
531 EXPECT_EQ("50,400 480x400",
532 display_manager()->GetDisplayAt(1).bounds().ToString());
533 EXPECT_EQ("480,0 480x400",
534 display_manager()->GetDisplayAt(2).bounds().ToString());
535 EXPECT_EQ("960,30 480x400",
536 display_manager()->GetDisplayAt(3).bounds().ToString());
537 EXPECT_EQ("730,430 480x400",
538 display_manager()->GetDisplayAt(4).bounds().ToString());
539 EXPECT_EQ("-730,-300 480x400",
540 display_manager()->GetDisplayAt(5).bounds().ToString());
541 EXPECT_EQ("-250,-400 480x400",
542 display_manager()->GetDisplayAt(6).bounds().ToString());
543 EXPECT_EQ("-780,-450 530x150",
544 display_manager()->GetDisplayAt(7).bounds().ToString());
545
546 // Expect that the displays have been reparented correctly, such that a
547 // child is always touching its parent.
548 display::DisplayLayoutBuilder expected_layout_builder(primary_id);
549 expected_layout_builder.AddDisplayPlacement(
550 list[1], primary_id, display::DisplayPlacement::BOTTOM, 50);
551 expected_layout_builder.AddDisplayPlacement(
552 list[2], list[1], display::DisplayPlacement::TOP, 430);
553 expected_layout_builder.AddDisplayPlacement(
554 list[3], list[2], display::DisplayPlacement::RIGHT, 30);
555 // [4] became a child of [3] instead of [2] as they no longer touch.
556 expected_layout_builder.AddDisplayPlacement(
557 list[4], list[3], display::DisplayPlacement::BOTTOM, -230);
558 // [5] became a child of [6] instead of [P] as they no longer touch.
559 expected_layout_builder.AddDisplayPlacement(
560 list[5], list[6], display::DisplayPlacement::LEFT, 100);
561 expected_layout_builder.AddDisplayPlacement(
562 list[6], primary_id, display::DisplayPlacement::TOP, -250);
563 expected_layout_builder.AddDisplayPlacement(
564 list[7], list[6], display::DisplayPlacement::LEFT, -50);
565
566 const display::DisplayLayout& layout =
567 display_manager()->GetCurrentResolvedDisplayLayout();
568
569 EXPECT_TRUE(
570 layout.HasSamePlacementList(*(expected_layout_builder.Build())));
571 }
572
573 {
574 // The following is a special case where a child display is closer to the
575 // origin than its parent. Test that we can handle it successfully without
576 // introducing a circular dependency.
577 //
578 // +---------+
579 // | P | +---------+
580 // | | | 3 |
581 // | | | |
582 // | | | |
583 // +------+--+----+ |
584 // | 1 | | 2 +---------+
585 // | | | |
586 // | | | |
587 // | | | |
588 // +------+--+----+
589 //
590
591 display::DisplayIdList list = display::test::CreateDisplayIdListN(
592 4, primary_id, primary_id + 1, primary_id + 2, primary_id + 3);
593 display::DisplayLayoutBuilder builder(primary_id);
594 builder.AddDisplayPlacement(list[1], primary_id,
595 display::DisplayPlacement::BOTTOM, 0);
596 builder.AddDisplayPlacement(list[2], primary_id,
597 display::DisplayPlacement::BOTTOM, 464);
598 builder.AddDisplayPlacement(list[3], list[2],
599 display::DisplayPlacement::RIGHT, -700);
600 display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
601 list, builder.Build());
602 UpdateDisplay("696x800,696x800,300x800,696x800");
603
604 // The expected layout should be:
605 //
606 // +---------+
607 // | P | +---------+
608 // | | | 3 |
609 // | | | |
610 // | | | |
611 // +---------+-------+ |
612 // | 1 | 2 +---------+
613 // | | |
614 // | | |
615 // | | |
616 // +---------+-------+
617 //
618 //
619
620 EXPECT_EQ(4U, display_manager()->GetNumDisplays());
621 EXPECT_EQ("0,0 696x800",
622 display_manager()->GetDisplayAt(0).bounds().ToString());
623 EXPECT_EQ("0,800 696x800",
624 display_manager()->GetDisplayAt(1).bounds().ToString());
625 EXPECT_EQ("696,800 300x800",
626 display_manager()->GetDisplayAt(2).bounds().ToString());
627 EXPECT_EQ("996,100 696x800",
628 display_manager()->GetDisplayAt(3).bounds().ToString());
629
630 // This case if not handled correctly might lead to a cyclic dependency.
631 // Make sure this doesn't happen.
632 display::DisplayLayoutBuilder expected_layout_builder(primary_id);
633 expected_layout_builder.AddDisplayPlacement(
634 list[1], primary_id, display::DisplayPlacement::BOTTOM, 0);
635 expected_layout_builder.AddDisplayPlacement(
636 list[2], primary_id, display::DisplayPlacement::BOTTOM, 696);
637 expected_layout_builder.AddDisplayPlacement(
638 list[3], list[2], display::DisplayPlacement::RIGHT, -700);
639
640 const display::DisplayLayout& layout =
641 display_manager()->GetCurrentResolvedDisplayLayout();
642 EXPECT_TRUE(
643 layout.HasSamePlacementList(*(expected_layout_builder.Build())));
644 }
645
646 {
647 // The following is a layout with an overlap to the left of the primary
648 // display.
649 //
650 // +---------+---------+
651 // | 1 | P |
652 // | | |
653 // +---------+ |
654 // | | |
655 // +---------+---------+
656 // | 2 |
657 // | |
658 // +---------+
659
660 display::DisplayIdList list = display::test::CreateDisplayIdListN(
661 3, primary_id, primary_id + 1, primary_id + 2);
662 display::DisplayLayoutBuilder builder(primary_id);
663 builder.AddDisplayPlacement(list[1], primary_id,
664 display::DisplayPlacement::LEFT, 0);
665 builder.AddDisplayPlacement(list[2], primary_id,
666 display::DisplayPlacement::LEFT, 250);
667 display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
668 list, builder.Build());
669 UpdateDisplay("696x500,696x500,696x500");
670
671 // The expected layout should be:
672 //
673 // +---------+---------+
674 // | 1 | P |
675 // | | |
676 // | | |
677 // | | |
678 // +---------+---------+
679 // | 2 |
680 // | |
681 // | |
682 // | |
683 // +---------+
684
685 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
686 EXPECT_EQ("0,0 696x500",
687 display_manager()->GetDisplayAt(0).bounds().ToString());
688 EXPECT_EQ("-696,0 696x500",
689 display_manager()->GetDisplayAt(1).bounds().ToString());
690 EXPECT_EQ("-696,500 696x500",
691 display_manager()->GetDisplayAt(2).bounds().ToString());
692 }
693
694 {
695 // The following is a layout with an overlap occuring above the primary
696 // display.
697 //
698 // +------+--+------+
699 // | 2 | | 1 |
700 // | | | |
701 // | | | |
702 // | | | |
703 // +------+--+------+
704 // | P |
705 // | |
706 // | |
707 // | |
708 // +---------+
709 //
710
711 display::DisplayIdList list = display::test::CreateDisplayIdListN(
712 3, primary_id, primary_id + 1, primary_id + 2);
713 display::DisplayLayoutBuilder builder(primary_id);
714 builder.AddDisplayPlacement(list[1], primary_id,
715 display::DisplayPlacement::TOP, 0);
716 builder.AddDisplayPlacement(list[2], primary_id,
717 display::DisplayPlacement::TOP, -348);
718 display_manager()->layout_store()->RegisterLayoutForDisplayIdList(
719 list, builder.Build());
720 UpdateDisplay("696x500,696x500,696x500");
721
722 // The expected layout should be:
723 //
724 // +---------+---------+
725 // | 2 | 1 |
726 // | | |
727 // | | |
728 // | | |
729 // +---------+---------+
730 // | P |
731 // | |
732 // | |
733 // | |
734 // +---------+
735 //
736
737 EXPECT_EQ(3U, display_manager()->GetNumDisplays());
738 EXPECT_EQ("0,0 696x500",
739 display_manager()->GetDisplayAt(0).bounds().ToString());
740 EXPECT_EQ("0,-500 696x500",
741 display_manager()->GetDisplayAt(1).bounds().ToString());
742 EXPECT_EQ("-696,-500 696x500",
743 display_manager()->GetDisplayAt(2).bounds().ToString());
744 }
oshima 2017/01/31 16:55:43 can you also add the scenario like this [1][2][3
afakhry 2017/01/31 19:19:32 Done.
745 }
746
454 TEST_P(DisplayManagerTest, NoMirrorInThreeDisplays) { 747 TEST_P(DisplayManagerTest, NoMirrorInThreeDisplays) {
455 UpdateDisplay("640x480,320x200,400x300"); 748 UpdateDisplay("640x480,320x200,400x300");
456 ash::Shell::GetInstance()->display_configuration_controller()->SetMirrorMode( 749 ash::Shell::GetInstance()->display_configuration_controller()->SetMirrorMode(
457 true, true); 750 true, true);
458 EXPECT_FALSE(display_manager()->IsInMirrorMode()); 751 EXPECT_FALSE(display_manager()->IsInMirrorMode());
459 EXPECT_EQ(3u, display_manager()->GetNumDisplays()); 752 EXPECT_EQ(3u, display_manager()->GetNumDisplays());
460 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED), 753 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED),
461 GetDisplayErrorNotificationMessageForTest()); 754 GetDisplayErrorNotificationMessageForTest());
462 } 755 }
463 756
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 display::DisplayIdList list = display::test::CreateDisplayIdList2(id1, id2); 2730 display::DisplayIdList list = display::test::CreateDisplayIdList2(id1, id2);
2438 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout)); 2731 layout_store->RegisterLayoutForDisplayIdList(list, std::move(old_layout));
2439 const display::DisplayLayout& stored = 2732 const display::DisplayLayout& stored =
2440 layout_store->GetRegisteredDisplayLayout(list); 2733 layout_store->GetRegisteredDisplayLayout(list);
2441 2734
2442 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); 2735 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id);
2443 EXPECT_EQ(id2, stored.placement_list[0].display_id); 2736 EXPECT_EQ(id2, stored.placement_list[0].display_id);
2444 } 2737 }
2445 2738
2446 } // namespace ash 2739 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698