display_layout_unittest.cc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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
  3. // found in the LICENSE file.
  4. #include "ui/display/display.h"
  5. #include <tuple>
  6. #include <vector>
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "ui/display/display_layout.h"
  9. #include "ui/display/display_layout_builder.h"
  10. namespace display {
  11. using Position = DisplayPlacement::Position;
  12. TEST(DisplayLayoutTest, Empty) {
  13. Displays display_list;
  14. std::vector<int64_t> updated_ids;
  15. DisplayLayout display_layout;
  16. display_layout.ApplyToDisplayList(&display_list, &updated_ids, 0);
  17. EXPECT_EQ(0u, updated_ids.size());
  18. EXPECT_EQ(0u, display_list.size());
  19. }
  20. TEST(DisplayLayoutTest, SingleDisplayNoPlacements) {
  21. Displays display_list;
  22. display_list.emplace_back(0, gfx::Rect(0, 0, 800, 600));
  23. std::vector<int64_t> updated_ids;
  24. DisplayLayout display_layout;
  25. display_layout.ApplyToDisplayList(&display_list, &updated_ids, 0);
  26. EXPECT_EQ(0u, updated_ids.size());
  27. ASSERT_EQ(1u, display_list.size());
  28. EXPECT_EQ(gfx::Rect(0, 0, 800, 600), display_list[0].bounds());
  29. }
  30. TEST(DisplayLayoutTest, SingleDisplayNonRelevantPlacement) {
  31. Displays display_list;
  32. display_list.emplace_back(0, gfx::Rect(0, 0, 800, 600));
  33. std::vector<int64_t> updated_ids;
  34. DisplayLayoutBuilder builder(20);
  35. builder.AddDisplayPlacement(20, 40, DisplayPlacement::Position::LEFT, 150);
  36. std::unique_ptr<DisplayLayout> display_layout(builder.Build());
  37. display_layout->ApplyToDisplayList(&display_list, &updated_ids, 0);
  38. EXPECT_EQ(0u, updated_ids.size());
  39. ASSERT_EQ(1u, display_list.size());
  40. EXPECT_EQ(gfx::Rect(0, 0, 800, 600), display_list[0].bounds());
  41. }
  42. TEST(DisplayLayoutTest, SwapPrimaryDisplay) {
  43. std::unique_ptr<DisplayLayout> layout =
  44. DisplayLayoutBuilder(123)
  45. .AddDisplayPlacement(456, 123, Position::LEFT, 150)
  46. .Build();
  47. // Initial layout will be 123 <-- 456
  48. EXPECT_EQ(123, layout->primary_id);
  49. EXPECT_EQ(456, layout->placement_list[0].display_id);
  50. EXPECT_EQ(123, layout->placement_list[0].parent_display_id);
  51. EXPECT_EQ(Position::LEFT, layout->placement_list[0].position);
  52. EXPECT_EQ(150, layout->placement_list[0].offset);
  53. // Swap layout to 123 --> 456.
  54. layout->SwapPrimaryDisplay(456);
  55. EXPECT_EQ(456, layout->primary_id);
  56. EXPECT_EQ(123, layout->placement_list[0].display_id);
  57. EXPECT_EQ(456, layout->placement_list[0].parent_display_id);
  58. EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position);
  59. EXPECT_EQ(-150, layout->placement_list[0].offset);
  60. // Swap layout back to 123 <-- 456.
  61. layout->SwapPrimaryDisplay(123);
  62. EXPECT_EQ(123, layout->primary_id);
  63. EXPECT_EQ(456, layout->placement_list[0].display_id);
  64. EXPECT_EQ(123, layout->placement_list[0].parent_display_id);
  65. EXPECT_EQ(Position::LEFT, layout->placement_list[0].position);
  66. EXPECT_EQ(150, layout->placement_list[0].offset);
  67. }
  68. TEST(DisplayLayoutTest, SwapPrimaryDisplayThreeDisplays) {
  69. std::unique_ptr<DisplayLayout> layout =
  70. DisplayLayoutBuilder(456)
  71. .AddDisplayPlacement(123, 456, Position::LEFT, 0)
  72. .AddDisplayPlacement(789, 456, Position::RIGHT, 0)
  73. .Build();
  74. // Note: Placement order is determined by least significant 8 bits of IDs.
  75. // Initial layout will be 123 (0x7B) --> 456 (0x1C8) <-- 789 (0x315).
  76. EXPECT_EQ(456, layout->primary_id);
  77. EXPECT_EQ(789, layout->placement_list[0].display_id);
  78. EXPECT_EQ(456, layout->placement_list[0].parent_display_id);
  79. EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position);
  80. EXPECT_EQ(123, layout->placement_list[1].display_id);
  81. EXPECT_EQ(456, layout->placement_list[1].parent_display_id);
  82. EXPECT_EQ(Position::LEFT, layout->placement_list[1].position);
  83. // Swap layout to 123 --> 456 --> 789.
  84. layout->SwapPrimaryDisplay(789);
  85. EXPECT_EQ(789, layout->primary_id);
  86. EXPECT_EQ(123, layout->placement_list[0].display_id);
  87. EXPECT_EQ(456, layout->placement_list[0].parent_display_id);
  88. EXPECT_EQ(Position::LEFT, layout->placement_list[0].position);
  89. EXPECT_EQ(456, layout->placement_list[1].display_id);
  90. EXPECT_EQ(789, layout->placement_list[1].parent_display_id);
  91. EXPECT_EQ(Position::LEFT, layout->placement_list[1].position);
  92. // Swap layout to 123 <-- 456 <-- 789.
  93. layout->SwapPrimaryDisplay(123);
  94. EXPECT_EQ(123, layout->primary_id);
  95. EXPECT_EQ(789, layout->placement_list[0].display_id);
  96. EXPECT_EQ(456, layout->placement_list[0].parent_display_id);
  97. EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position);
  98. EXPECT_EQ(456, layout->placement_list[1].display_id);
  99. EXPECT_EQ(123, layout->placement_list[1].parent_display_id);
  100. EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position);
  101. }
  102. // Makes sure that only the least significant 8 bits of the display IDs in the
  103. // placement lists are used to validate their sort order.
  104. TEST(DisplayLayoutTest, PlacementSortOrder) {
  105. // Sorted placement lists by full IDs, but not sorted by the least significant
  106. // 8 bits of the IDs.
  107. std::unique_ptr<DisplayLayout> layout(new DisplayLayout);
  108. layout->primary_id = 456;
  109. layout->placement_list.emplace_back(0x0405, 456, Position::LEFT, 0,
  110. DisplayPlacement::TOP_LEFT);
  111. layout->placement_list.emplace_back(0x0506, 0x0405, Position::RIGHT, 0,
  112. DisplayPlacement::TOP_LEFT);
  113. layout->placement_list.emplace_back(0x0604, 0x0506, Position::RIGHT, 0,
  114. DisplayPlacement::TOP_LEFT);
  115. EXPECT_FALSE(DisplayLayout::Validate({456, 0x0405, 0x0506, 0x0604}, *layout));
  116. // Full IDs not sorted, but least significant 8 bits of the IDs are sorted.
  117. layout->placement_list.clear();
  118. layout->placement_list.emplace_back(0x0504, 456, Position::LEFT, 0,
  119. DisplayPlacement::TOP_LEFT);
  120. layout->placement_list.emplace_back(0x0605, 0x0504, Position::RIGHT, 0,
  121. DisplayPlacement::TOP_LEFT);
  122. layout->placement_list.emplace_back(0x0406, 0x0605, Position::RIGHT, 0,
  123. DisplayPlacement::TOP_LEFT);
  124. EXPECT_TRUE(DisplayLayout::Validate({456, 0x0504, 0x0605, 0x0406}, *layout));
  125. }
  126. namespace {
  127. class TwoDisplays
  128. : public testing::TestWithParam<std::tuple<
  129. // Primary Display Bounds
  130. gfx::Rect,
  131. // Secondary Display Bounds
  132. gfx::Rect,
  133. // Secondary Layout Position
  134. DisplayPlacement::Position,
  135. // Secondary Layout Offset
  136. int,
  137. // Minimum Offset Overlap
  138. int,
  139. // Expected Primary Display Bounds
  140. gfx::Rect,
  141. // Expected Secondary Display Bounds
  142. gfx::Rect>> {
  143. public:
  144. TwoDisplays() = default;
  145. TwoDisplays(const TwoDisplays&) = delete;
  146. TwoDisplays& operator=(const TwoDisplays&) = delete;
  147. };
  148. } // namespace
  149. TEST_P(TwoDisplays, Placement) {
  150. gfx::Rect primary_display_bounds = std::get<0>(GetParam());
  151. gfx::Rect secondary_display_bounds = std::get<1>(GetParam());
  152. DisplayPlacement::Position position = std::get<2>(GetParam());
  153. int offset = std::get<3>(GetParam());
  154. int minimum_offset_overlap = std::get<4>(GetParam());
  155. gfx::Rect expected_primary_display_bounds = std::get<5>(GetParam());
  156. gfx::Rect expected_secondary_display_bounds = std::get<6>(GetParam());
  157. Displays display_list;
  158. display_list.emplace_back(0, primary_display_bounds);
  159. display_list.emplace_back(1, secondary_display_bounds);
  160. std::vector<int64_t> updated_ids;
  161. DisplayLayoutBuilder builder(0);
  162. builder.AddDisplayPlacement(1, 0, position, offset);
  163. std::unique_ptr<DisplayLayout> display_layout(builder.Build());
  164. display_layout->ApplyToDisplayList(
  165. &display_list, &updated_ids, minimum_offset_overlap);
  166. ASSERT_EQ(1u, updated_ids.size());
  167. EXPECT_EQ(1u, updated_ids[0]);
  168. ASSERT_EQ(2u, display_list.size());
  169. EXPECT_EQ(expected_primary_display_bounds, display_list[0].bounds());
  170. EXPECT_EQ(expected_secondary_display_bounds, display_list[1].bounds());
  171. }
  172. INSTANTIATE_TEST_SUITE_P(
  173. DisplayLayoutTestZero,
  174. TwoDisplays,
  175. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  176. gfx::Rect(0, 0, 1024, 768),
  177. DisplayPlacement::Position::LEFT,
  178. 0,
  179. 0,
  180. gfx::Rect(0, 0, 800, 600),
  181. gfx::Rect(-1024, 0, 1024, 768)),
  182. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  183. gfx::Rect(0, 0, 1024, 768),
  184. DisplayPlacement::Position::TOP,
  185. 0,
  186. 0,
  187. gfx::Rect(0, 0, 800, 600),
  188. gfx::Rect(0, -768, 1024, 768)),
  189. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  190. gfx::Rect(0, 0, 1024, 768),
  191. DisplayPlacement::Position::RIGHT,
  192. 0,
  193. 0,
  194. gfx::Rect(0, 0, 800, 600),
  195. gfx::Rect(800, 0, 1024, 768)),
  196. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  197. gfx::Rect(0, 0, 1024, 768),
  198. DisplayPlacement::Position::BOTTOM,
  199. 0,
  200. 0,
  201. gfx::Rect(0, 0, 800, 600),
  202. gfx::Rect(0, 600, 1024, 768))));
  203. INSTANTIATE_TEST_SUITE_P(
  204. DisplayLayoutTestOffset,
  205. TwoDisplays,
  206. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  207. gfx::Rect(0, 0, 1024, 768),
  208. DisplayPlacement::Position::LEFT,
  209. 37,
  210. 0,
  211. gfx::Rect(0, 0, 800, 600),
  212. gfx::Rect(-1024, 37, 1024, 768)),
  213. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  214. gfx::Rect(0, 0, 1024, 768),
  215. DisplayPlacement::Position::TOP,
  216. 37,
  217. 0,
  218. gfx::Rect(0, 0, 800, 600),
  219. gfx::Rect(37, -768, 1024, 768)),
  220. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  221. gfx::Rect(0, 0, 1024, 768),
  222. DisplayPlacement::Position::RIGHT,
  223. 37,
  224. 0,
  225. gfx::Rect(0, 0, 800, 600),
  226. gfx::Rect(800, 37, 1024, 768)),
  227. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  228. gfx::Rect(0, 0, 1024, 768),
  229. DisplayPlacement::Position::BOTTOM,
  230. 37,
  231. 0,
  232. gfx::Rect(0, 0, 800, 600),
  233. gfx::Rect(37, 600, 1024, 768))));
  234. INSTANTIATE_TEST_SUITE_P(DisplayLayoutTestCorner,
  235. TwoDisplays,
  236. testing::Values(
  237. // Top-Left
  238. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  239. gfx::Rect(0, 0, 30, 60),
  240. DisplayPlacement::Position::LEFT,
  241. -60,
  242. 0,
  243. gfx::Rect(0, 0, 20, 40),
  244. gfx::Rect(-30, -60, 30, 60)),
  245. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  246. gfx::Rect(0, 0, 30, 60),
  247. DisplayPlacement::Position::TOP,
  248. -30,
  249. 0,
  250. gfx::Rect(0, 0, 20, 40),
  251. gfx::Rect(-30, -60, 30, 60)),
  252. // Top-Right
  253. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  254. gfx::Rect(0, 0, 30, 60),
  255. DisplayPlacement::Position::RIGHT,
  256. -60,
  257. 0,
  258. gfx::Rect(0, 0, 20, 40),
  259. gfx::Rect(20, -60, 30, 60)),
  260. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  261. gfx::Rect(0, 0, 30, 60),
  262. DisplayPlacement::Position::TOP,
  263. 20,
  264. 0,
  265. gfx::Rect(0, 0, 20, 40),
  266. gfx::Rect(20, -60, 30, 60)),
  267. // Bottom-Right
  268. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  269. gfx::Rect(0, 0, 30, 60),
  270. DisplayPlacement::Position::RIGHT,
  271. 40,
  272. 0,
  273. gfx::Rect(0, 0, 20, 40),
  274. gfx::Rect(20, 40, 30, 60)),
  275. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  276. gfx::Rect(0, 0, 30, 60),
  277. DisplayPlacement::Position::BOTTOM,
  278. 20,
  279. 0,
  280. gfx::Rect(0, 0, 20, 40),
  281. gfx::Rect(20, 40, 30, 60)),
  282. // Bottom-Left
  283. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  284. gfx::Rect(0, 0, 30, 60),
  285. DisplayPlacement::Position::LEFT,
  286. 40,
  287. 0,
  288. gfx::Rect(0, 0, 20, 40),
  289. gfx::Rect(-30, 40, 30, 60)),
  290. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  291. gfx::Rect(0, 0, 30, 60),
  292. DisplayPlacement::Position::BOTTOM,
  293. -30,
  294. 0,
  295. gfx::Rect(0, 0, 20, 40),
  296. gfx::Rect(-30, 40, 30, 60))));
  297. INSTANTIATE_TEST_SUITE_P(
  298. DisplayLayoutTestZeroMinimumOverlap,
  299. TwoDisplays,
  300. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  301. gfx::Rect(0, 0, 1024, 768),
  302. DisplayPlacement::Position::LEFT,
  303. 0,
  304. 14,
  305. gfx::Rect(0, 0, 800, 600),
  306. gfx::Rect(-1024, 0, 1024, 768)),
  307. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  308. gfx::Rect(0, 0, 1024, 768),
  309. DisplayPlacement::Position::TOP,
  310. 0,
  311. 14,
  312. gfx::Rect(0, 0, 800, 600),
  313. gfx::Rect(0, -768, 1024, 768)),
  314. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  315. gfx::Rect(0, 0, 1024, 768),
  316. DisplayPlacement::Position::RIGHT,
  317. 0,
  318. 14,
  319. gfx::Rect(0, 0, 800, 600),
  320. gfx::Rect(800, 0, 1024, 768)),
  321. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  322. gfx::Rect(0, 0, 1024, 768),
  323. DisplayPlacement::Position::BOTTOM,
  324. 0,
  325. 14,
  326. gfx::Rect(0, 0, 800, 600),
  327. gfx::Rect(0, 600, 1024, 768))));
  328. INSTANTIATE_TEST_SUITE_P(
  329. DisplayLayoutTestOffsetMinimumOverlap,
  330. TwoDisplays,
  331. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  332. gfx::Rect(0, 0, 1024, 768),
  333. DisplayPlacement::Position::LEFT,
  334. 37,
  335. 14,
  336. gfx::Rect(0, 0, 800, 600),
  337. gfx::Rect(-1024, 37, 1024, 768)),
  338. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  339. gfx::Rect(0, 0, 1024, 768),
  340. DisplayPlacement::Position::TOP,
  341. 37,
  342. 14,
  343. gfx::Rect(0, 0, 800, 600),
  344. gfx::Rect(37, -768, 1024, 768)),
  345. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  346. gfx::Rect(0, 0, 1024, 768),
  347. DisplayPlacement::Position::RIGHT,
  348. 37,
  349. 14,
  350. gfx::Rect(0, 0, 800, 600),
  351. gfx::Rect(800, 37, 1024, 768)),
  352. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  353. gfx::Rect(0, 0, 1024, 768),
  354. DisplayPlacement::Position::BOTTOM,
  355. 37,
  356. 14,
  357. gfx::Rect(0, 0, 800, 600),
  358. gfx::Rect(37, 600, 1024, 768))));
  359. INSTANTIATE_TEST_SUITE_P(DisplayLayoutTestMinimumOverlap,
  360. TwoDisplays,
  361. testing::Values(
  362. // Top-Left
  363. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  364. gfx::Rect(0, 0, 30, 60),
  365. DisplayPlacement::Position::LEFT,
  366. -60,
  367. 14,
  368. gfx::Rect(0, 0, 20, 40),
  369. gfx::Rect(-30, -46, 30, 60)),
  370. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  371. gfx::Rect(0, 0, 30, 60),
  372. DisplayPlacement::Position::TOP,
  373. -30,
  374. 14,
  375. gfx::Rect(0, 0, 20, 40),
  376. gfx::Rect(-16, -60, 30, 60)),
  377. // Top-Right
  378. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  379. gfx::Rect(0, 0, 30, 60),
  380. DisplayPlacement::Position::RIGHT,
  381. -60,
  382. 14,
  383. gfx::Rect(0, 0, 20, 40),
  384. gfx::Rect(20, -46, 30, 60)),
  385. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  386. gfx::Rect(0, 0, 30, 60),
  387. DisplayPlacement::Position::TOP,
  388. 20,
  389. 14,
  390. gfx::Rect(0, 0, 20, 40),
  391. gfx::Rect(6, -60, 30, 60)),
  392. // Bottom-Right
  393. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  394. gfx::Rect(0, 0, 30, 60),
  395. DisplayPlacement::Position::RIGHT,
  396. 40,
  397. 14,
  398. gfx::Rect(0, 0, 20, 40),
  399. gfx::Rect(20, 26, 30, 60)),
  400. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  401. gfx::Rect(0, 0, 30, 60),
  402. DisplayPlacement::Position::BOTTOM,
  403. 20,
  404. 14,
  405. gfx::Rect(0, 0, 20, 40),
  406. gfx::Rect(6, 40, 30, 60)),
  407. // Bottom-Left
  408. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  409. gfx::Rect(0, 0, 30, 60),
  410. DisplayPlacement::Position::LEFT,
  411. 40,
  412. 14,
  413. gfx::Rect(0, 0, 20, 40),
  414. gfx::Rect(-30, 26, 30, 60)),
  415. std::make_tuple(gfx::Rect(0, 0, 20, 40),
  416. gfx::Rect(0, 0, 30, 60),
  417. DisplayPlacement::Position::BOTTOM,
  418. -30,
  419. 14,
  420. gfx::Rect(0, 0, 20, 40),
  421. gfx::Rect(-16, 40, 30, 60))));
  422. // Display Layout
  423. // [1] [4]
  424. // [0][3] [6]
  425. // [2] [5]
  426. TEST(DisplayLayoutTest, MultipleDisplays) {
  427. Displays display_list;
  428. display_list.emplace_back(0, gfx::Rect(0, 0, 100, 100));
  429. display_list.emplace_back(1, gfx::Rect(0, 0, 100, 100));
  430. display_list.emplace_back(2, gfx::Rect(0, 0, 100, 100));
  431. display_list.emplace_back(3, gfx::Rect(0, 0, 100, 100));
  432. display_list.emplace_back(4, gfx::Rect(0, 0, 100, 100));
  433. display_list.emplace_back(5, gfx::Rect(0, 0, 100, 100));
  434. display_list.emplace_back(6, gfx::Rect(0, 0, 100, 100));
  435. std::vector<int64_t> updated_ids;
  436. DisplayLayoutBuilder builder(0);
  437. builder.AddDisplayPlacement(1, 0, DisplayPlacement::Position::TOP, 50);
  438. builder.AddDisplayPlacement(2, 0, DisplayPlacement::Position::LEFT, 100);
  439. builder.AddDisplayPlacement(3, 0, DisplayPlacement::Position::RIGHT, 0);
  440. builder.AddDisplayPlacement(4, 3, DisplayPlacement::Position::RIGHT, -100);
  441. builder.AddDisplayPlacement(5, 3, DisplayPlacement::Position::BOTTOM, -50);
  442. builder.AddDisplayPlacement(6, 4, DisplayPlacement::Position::BOTTOM, 100);
  443. std::unique_ptr<DisplayLayout> display_layout(builder.Build());
  444. display_layout->ApplyToDisplayList(&display_list, &updated_ids, 0);
  445. ASSERT_EQ(6u, updated_ids.size());
  446. std::sort(updated_ids.begin(), updated_ids.end());
  447. EXPECT_EQ(1u, updated_ids[0]);
  448. EXPECT_EQ(2u, updated_ids[1]);
  449. EXPECT_EQ(3u, updated_ids[2]);
  450. EXPECT_EQ(4u, updated_ids[3]);
  451. EXPECT_EQ(5u, updated_ids[4]);
  452. EXPECT_EQ(6u, updated_ids[5]);
  453. EXPECT_EQ(gfx::Rect(0, 0, 100, 100), display_list[0].bounds());
  454. EXPECT_EQ(gfx::Rect(50, -100, 100, 100), display_list[1].bounds());
  455. EXPECT_EQ(gfx::Rect(-100, 100, 100, 100), display_list[2].bounds());
  456. EXPECT_EQ(gfx::Rect(100, 0, 100, 100), display_list[3].bounds());
  457. EXPECT_EQ(gfx::Rect(200, -100, 100, 100), display_list[4].bounds());
  458. EXPECT_EQ(gfx::Rect(50, 100, 100, 100), display_list[5].bounds());
  459. EXPECT_EQ(gfx::Rect(300, 0, 100, 100), display_list[6].bounds());
  460. }
  461. namespace {
  462. class TwoDisplaysBottomRightReference
  463. : public testing::TestWithParam<std::tuple<
  464. // Primary Display Bounds
  465. gfx::Rect,
  466. // Secondary Display Bounds
  467. gfx::Rect,
  468. // Secondary Layout Position
  469. DisplayPlacement::Position,
  470. // Secondary Layout Offset
  471. int,
  472. // Minimum Offset Overlap
  473. int,
  474. // Expected Primary Display Bounds
  475. gfx::Rect,
  476. // Expected Secondary Display Bounds
  477. gfx::Rect>> {
  478. public:
  479. TwoDisplaysBottomRightReference() = default;
  480. TwoDisplaysBottomRightReference(const TwoDisplaysBottomRightReference&) =
  481. delete;
  482. TwoDisplaysBottomRightReference& operator=(
  483. const TwoDisplaysBottomRightReference&) = delete;
  484. };
  485. } // namespace
  486. TEST_P(TwoDisplaysBottomRightReference, Placement) {
  487. gfx::Rect primary_display_bounds = std::get<0>(GetParam());
  488. gfx::Rect secondary_display_bounds = std::get<1>(GetParam());
  489. DisplayPlacement::Position position = std::get<2>(GetParam());
  490. int offset = std::get<3>(GetParam());
  491. int minimum_offset_overlap = std::get<4>(GetParam());
  492. gfx::Rect expected_primary_display_bounds = std::get<5>(GetParam());
  493. gfx::Rect expected_secondary_display_bounds = std::get<6>(GetParam());
  494. Displays display_list;
  495. display_list.emplace_back(0, primary_display_bounds);
  496. display_list.emplace_back(1, secondary_display_bounds);
  497. std::vector<int64_t> updated_ids;
  498. DisplayLayoutBuilder builder(0);
  499. DisplayPlacement placement;
  500. placement.display_id = 1;
  501. placement.parent_display_id = 0;
  502. placement.position = position;
  503. placement.offset = offset;
  504. placement.offset_reference = DisplayPlacement::OffsetReference::BOTTOM_RIGHT;
  505. builder.AddDisplayPlacement(placement);
  506. std::unique_ptr<DisplayLayout> display_layout(builder.Build());
  507. display_layout->ApplyToDisplayList(
  508. &display_list, &updated_ids, minimum_offset_overlap);
  509. ASSERT_EQ(1u, updated_ids.size());
  510. EXPECT_EQ(1u, updated_ids[0]);
  511. ASSERT_EQ(2u, display_list.size());
  512. EXPECT_EQ(expected_primary_display_bounds, display_list[0].bounds());
  513. EXPECT_EQ(expected_secondary_display_bounds, display_list[1].bounds());
  514. }
  515. INSTANTIATE_TEST_SUITE_P(
  516. DisplayLayoutTestZero,
  517. TwoDisplaysBottomRightReference,
  518. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  519. gfx::Rect(0, 0, 1024, 768),
  520. DisplayPlacement::Position::LEFT,
  521. 0,
  522. 0,
  523. gfx::Rect(0, 0, 800, 600),
  524. gfx::Rect(-1024, -168, 1024, 768)),
  525. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  526. gfx::Rect(0, 0, 1024, 768),
  527. DisplayPlacement::Position::TOP,
  528. 0,
  529. 0,
  530. gfx::Rect(0, 0, 800, 600),
  531. gfx::Rect(-224, -768, 1024, 768)),
  532. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  533. gfx::Rect(0, 0, 1024, 768),
  534. DisplayPlacement::Position::RIGHT,
  535. 0,
  536. 0,
  537. gfx::Rect(0, 0, 800, 600),
  538. gfx::Rect(800, -168, 1024, 768)),
  539. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  540. gfx::Rect(0, 0, 1024, 768),
  541. DisplayPlacement::Position::BOTTOM,
  542. 0,
  543. 0,
  544. gfx::Rect(0, 0, 800, 600),
  545. gfx::Rect(-224, 600, 1024, 768))));
  546. INSTANTIATE_TEST_SUITE_P(
  547. DisplayLayoutTestOffset,
  548. TwoDisplaysBottomRightReference,
  549. testing::Values(std::make_tuple(gfx::Rect(0, 0, 800, 600),
  550. gfx::Rect(0, 0, 1024, 768),
  551. DisplayPlacement::Position::LEFT,
  552. 7,
  553. 0,
  554. gfx::Rect(0, 0, 800, 600),
  555. gfx::Rect(-1024, -175, 1024, 768)),
  556. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  557. gfx::Rect(0, 0, 1024, 768),
  558. DisplayPlacement::Position::TOP,
  559. 7,
  560. 0,
  561. gfx::Rect(0, 0, 800, 600),
  562. gfx::Rect(-231, -768, 1024, 768)),
  563. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  564. gfx::Rect(0, 0, 1024, 768),
  565. DisplayPlacement::Position::RIGHT,
  566. 7,
  567. 0,
  568. gfx::Rect(0, 0, 800, 600),
  569. gfx::Rect(800, -175, 1024, 768)),
  570. std::make_tuple(gfx::Rect(0, 0, 800, 600),
  571. gfx::Rect(0, 0, 1024, 768),
  572. DisplayPlacement::Position::BOTTOM,
  573. 7,
  574. 0,
  575. gfx::Rect(0, 0, 800, 600),
  576. gfx::Rect(-231, 600, 1024, 768))));
  577. } // namespace display