| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/display.h" | 5 #include "ui/display/display.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 EXPECT_EQ(150, layout->placement_list[0].offset); | 84 EXPECT_EQ(150, layout->placement_list[0].offset); |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST(DisplayLayoutTest, SwapPrimaryDisplayThreeDisplays) { | 87 TEST(DisplayLayoutTest, SwapPrimaryDisplayThreeDisplays) { |
| 88 std::unique_ptr<DisplayLayout> layout = | 88 std::unique_ptr<DisplayLayout> layout = |
| 89 DisplayLayoutBuilder(456) | 89 DisplayLayoutBuilder(456) |
| 90 .AddDisplayPlacement(123, 456, Position::LEFT, 0) | 90 .AddDisplayPlacement(123, 456, Position::LEFT, 0) |
| 91 .AddDisplayPlacement(789, 456, Position::RIGHT, 0) | 91 .AddDisplayPlacement(789, 456, Position::RIGHT, 0) |
| 92 .Build(); | 92 .Build(); |
| 93 | 93 |
| 94 // Initial layout will be 123 --> 456 <-- 789. | 94 // Note: Placement order is determined by least significant 8 bits of IDs. |
| 95 // Initial layout will be 123 (0x7B) --> 456 (0x1C8) <-- 789 (0x315). |
| 95 EXPECT_EQ(456, layout->primary_id); | 96 EXPECT_EQ(456, layout->primary_id); |
| 96 EXPECT_EQ(123, layout->placement_list[0].display_id); | 97 EXPECT_EQ(789, layout->placement_list[0].display_id); |
| 97 EXPECT_EQ(456, layout->placement_list[0].parent_display_id); | 98 EXPECT_EQ(456, layout->placement_list[0].parent_display_id); |
| 98 EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); | 99 EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position); |
| 99 EXPECT_EQ(789, layout->placement_list[1].display_id); | 100 EXPECT_EQ(123, layout->placement_list[1].display_id); |
| 100 EXPECT_EQ(456, layout->placement_list[1].parent_display_id); | 101 EXPECT_EQ(456, layout->placement_list[1].parent_display_id); |
| 101 EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position); | 102 EXPECT_EQ(Position::LEFT, layout->placement_list[1].position); |
| 102 | 103 |
| 103 // Swap layout to 123 --> 456 --> 789. | 104 // Swap layout to 123 --> 456 --> 789. |
| 104 layout->SwapPrimaryDisplay(789); | 105 layout->SwapPrimaryDisplay(789); |
| 105 EXPECT_EQ(789, layout->primary_id); | 106 EXPECT_EQ(789, layout->primary_id); |
| 106 EXPECT_EQ(123, layout->placement_list[0].display_id); | 107 EXPECT_EQ(123, layout->placement_list[0].display_id); |
| 107 EXPECT_EQ(456, layout->placement_list[0].parent_display_id); | 108 EXPECT_EQ(456, layout->placement_list[0].parent_display_id); |
| 108 EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); | 109 EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); |
| 109 EXPECT_EQ(456, layout->placement_list[1].display_id); | 110 EXPECT_EQ(456, layout->placement_list[1].display_id); |
| 110 EXPECT_EQ(789, layout->placement_list[1].parent_display_id); | 111 EXPECT_EQ(789, layout->placement_list[1].parent_display_id); |
| 111 EXPECT_EQ(Position::LEFT, layout->placement_list[1].position); | 112 EXPECT_EQ(Position::LEFT, layout->placement_list[1].position); |
| 112 | 113 |
| 113 // Swap layout to 123 <-- 456 <-- 789. | 114 // Swap layout to 123 <-- 456 <-- 789. |
| 114 layout->SwapPrimaryDisplay(123); | 115 layout->SwapPrimaryDisplay(123); |
| 115 EXPECT_EQ(123, layout->primary_id); | 116 EXPECT_EQ(123, layout->primary_id); |
| 116 EXPECT_EQ(456, layout->placement_list[0].display_id); | 117 EXPECT_EQ(789, layout->placement_list[0].display_id); |
| 117 EXPECT_EQ(123, layout->placement_list[0].parent_display_id); | 118 EXPECT_EQ(456, layout->placement_list[0].parent_display_id); |
| 118 EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position); | 119 EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position); |
| 119 EXPECT_EQ(789, layout->placement_list[1].display_id); | 120 EXPECT_EQ(456, layout->placement_list[1].display_id); |
| 120 EXPECT_EQ(456, layout->placement_list[1].parent_display_id); | 121 EXPECT_EQ(123, layout->placement_list[1].parent_display_id); |
| 121 EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position); | 122 EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position); |
| 122 } | 123 } |
| 123 | 124 |
| 125 // Makes sure that only the least significant 8 bits of the display IDs in the |
| 126 // placement lists are used to validate their sort order. |
| 127 TEST(DisplayLayoutTest, PlacementSortOrder) { |
| 128 // Sorted placement lists by full IDs, but not sorted by the least significant |
| 129 // 8 bits of the IDs. |
| 130 std::unique_ptr<DisplayLayout> layout(new DisplayLayout); |
| 131 layout->primary_id = 456; |
| 132 layout->placement_list.emplace_back(0x0405, 456, Position::LEFT, 0, |
| 133 DisplayPlacement::TOP_LEFT); |
| 134 layout->placement_list.emplace_back(0x0506, 0x0405, Position::RIGHT, 0, |
| 135 DisplayPlacement::TOP_LEFT); |
| 136 layout->placement_list.emplace_back(0x0604, 0x0506, Position::RIGHT, 0, |
| 137 DisplayPlacement::TOP_LEFT); |
| 138 EXPECT_FALSE(DisplayLayout::Validate({456, 0x0405, 0x0506, 0x0604}, *layout)); |
| 139 |
| 140 // Full IDs not sorted, but least significant 8 bits of the IDs are sorted. |
| 141 layout->placement_list.clear(); |
| 142 layout->placement_list.emplace_back(0x0504, 456, Position::LEFT, 0, |
| 143 DisplayPlacement::TOP_LEFT); |
| 144 layout->placement_list.emplace_back(0x0605, 0x0504, Position::RIGHT, 0, |
| 145 DisplayPlacement::TOP_LEFT); |
| 146 layout->placement_list.emplace_back(0x0406, 0x0605, Position::RIGHT, 0, |
| 147 DisplayPlacement::TOP_LEFT); |
| 148 EXPECT_TRUE(DisplayLayout::Validate({456, 0x0504, 0x0605, 0x0406}, *layout)); |
| 149 } |
| 150 |
| 124 namespace { | 151 namespace { |
| 125 | 152 |
| 126 class TwoDisplays | 153 class TwoDisplays |
| 127 : public testing::TestWithParam<std::tuple< | 154 : public testing::TestWithParam<std::tuple< |
| 128 // Primary Display Bounds | 155 // Primary Display Bounds |
| 129 gfx::Rect, | 156 gfx::Rect, |
| 130 // Secondary Display Bounds | 157 // Secondary Display Bounds |
| 131 gfx::Rect, | 158 gfx::Rect, |
| 132 // Secondary Layout Position | 159 // Secondary Layout Position |
| 133 DisplayPlacement::Position, | 160 DisplayPlacement::Position, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 std::make_tuple( | 487 std::make_tuple( |
| 461 gfx::Rect(0, 0, 800, 600), gfx::Rect(0, 0, 1024, 768), | 488 gfx::Rect(0, 0, 800, 600), gfx::Rect(0, 0, 1024, 768), |
| 462 DisplayPlacement::Position::RIGHT, 7, 0, | 489 DisplayPlacement::Position::RIGHT, 7, 0, |
| 463 gfx::Rect(0, 0, 800, 600), gfx::Rect(800, -175, 1024, 768)), | 490 gfx::Rect(0, 0, 800, 600), gfx::Rect(800, -175, 1024, 768)), |
| 464 std::make_tuple( | 491 std::make_tuple( |
| 465 gfx::Rect(0, 0, 800, 600), gfx::Rect(0, 0, 1024, 768), | 492 gfx::Rect(0, 0, 800, 600), gfx::Rect(0, 0, 1024, 768), |
| 466 DisplayPlacement::Position::BOTTOM, 7, 0, | 493 DisplayPlacement::Position::BOTTOM, 7, 0, |
| 467 gfx::Rect(0, 0, 800, 600), gfx::Rect(-231, 600, 1024, 768)))); | 494 gfx::Rect(0, 0, 800, 600), gfx::Rect(-231, 600, 1024, 768)))); |
| 468 | 495 |
| 469 } // namespace display | 496 } // namespace display |
| OLD | NEW |