| 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 <memory> |
| 6 |
| 7 #include "base/macros.h" |
| 5 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/display/display.h" | 11 #include "ui/display/display.h" |
| 9 #include "ui/display/display_layout.h" | 12 #include "ui/display/display_layout.h" |
| 13 #include "ui/display/display_snapshot_mojo.h" |
| 10 #include "ui/display/mojo/display_struct_traits_test.mojom.h" | 14 #include "ui/display/mojo/display_struct_traits_test.mojom.h" |
| 15 #include "ui/display/types/display_constants.h" |
| 11 #include "ui/display/types/display_mode.h" | 16 #include "ui/display/types/display_mode.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 14 | 19 |
| 15 namespace display { | 20 namespace display { |
| 16 namespace { | 21 namespace { |
| 17 | 22 |
| 18 constexpr int64_t kDisplayId1 = 123; | 23 constexpr int64_t kDisplayId1 = 123; |
| 19 constexpr int64_t kDisplayId2 = 456; | 24 constexpr int64_t kDisplayId2 = 456; |
| 20 constexpr int64_t kDisplayId3 = 789; | 25 constexpr int64_t kDisplayId3 = 789; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 void EchoDisplay(const Display& in, | 39 void EchoDisplay(const Display& in, |
| 35 const EchoDisplayCallback& callback) override { | 40 const EchoDisplayCallback& callback) override { |
| 36 callback.Run(in); | 41 callback.Run(in); |
| 37 } | 42 } |
| 38 | 43 |
| 39 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, | 44 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, |
| 40 const EchoDisplayModeCallback& callback) override { | 45 const EchoDisplayModeCallback& callback) override { |
| 41 callback.Run(std::move(in)); | 46 callback.Run(std::move(in)); |
| 42 } | 47 } |
| 43 | 48 |
| 49 void EchoDisplaySnapshotMojo( |
| 50 std::unique_ptr<DisplaySnapshotMojo> in, |
| 51 const EchoDisplaySnapshotMojoCallback& callback) override { |
| 52 callback.Run(std::move(in)); |
| 53 } |
| 54 |
| 44 void EchoDisplayPlacement( | 55 void EchoDisplayPlacement( |
| 45 const DisplayPlacement& in, | 56 const DisplayPlacement& in, |
| 46 const EchoDisplayPlacementCallback& callback) override { | 57 const EchoDisplayPlacementCallback& callback) override { |
| 47 callback.Run(in); | 58 callback.Run(in); |
| 48 } | 59 } |
| 49 | 60 |
| 50 void EchoDisplayLayout(std::unique_ptr<display::DisplayLayout> in, | 61 void EchoDisplayLayout(std::unique_ptr<display::DisplayLayout> in, |
| 51 const EchoDisplayLayoutCallback& callback) override { | 62 const EchoDisplayLayoutCallback& callback) override { |
| 52 callback.Run(std::move(in)); | 63 callback.Run(std::move(in)); |
| 53 } | 64 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 | 82 |
| 72 void CheckDisplayLayoutsEqual(const DisplayLayout& input, | 83 void CheckDisplayLayoutsEqual(const DisplayLayout& input, |
| 73 const DisplayLayout& output) { | 84 const DisplayLayout& output) { |
| 74 EXPECT_NE(&input, &output); // Make sure they aren't the same object. | 85 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
| 75 EXPECT_EQ(input.placement_list, output.placement_list); | 86 EXPECT_EQ(input.placement_list, output.placement_list); |
| 76 EXPECT_EQ(input.mirrored, output.mirrored); | 87 EXPECT_EQ(input.mirrored, output.mirrored); |
| 77 EXPECT_EQ(input.default_unified, output.default_unified); | 88 EXPECT_EQ(input.default_unified, output.default_unified); |
| 78 EXPECT_EQ(input.primary_id, output.primary_id); | 89 EXPECT_EQ(input.primary_id, output.primary_id); |
| 79 } | 90 } |
| 80 | 91 |
| 92 bool CompareModes(const DisplayMode& lhs, const DisplayMode& rhs) { |
| 93 return lhs.size() == rhs.size() && |
| 94 lhs.is_interlaced() == rhs.is_interlaced() && |
| 95 lhs.refresh_rate() == rhs.refresh_rate(); |
| 96 } |
| 97 |
| 98 void CheckDisplaySnapShotMojoEqual(const DisplaySnapshotMojo& input, |
| 99 const DisplaySnapshotMojo& output) { |
| 100 // We want to test each component individually to make sure each data member |
| 101 // was correctly serialized and deserialized. |
| 102 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
| 103 EXPECT_EQ(input.display_id(), output.display_id()); |
| 104 EXPECT_EQ(input.origin(), output.origin()); |
| 105 EXPECT_EQ(input.physical_size(), output.physical_size()); |
| 106 EXPECT_EQ(input.type(), output.type()); |
| 107 EXPECT_EQ(input.is_aspect_preserving_scaling(), |
| 108 output.is_aspect_preserving_scaling()); |
| 109 EXPECT_EQ(input.has_overscan(), output.has_overscan()); |
| 110 EXPECT_EQ(input.has_color_correction_matrix(), |
| 111 output.has_color_correction_matrix()); |
| 112 EXPECT_EQ(input.display_name(), output.display_name()); |
| 113 EXPECT_EQ(input.sys_path(), output.sys_path()); |
| 114 EXPECT_EQ(input.product_id(), output.product_id()); |
| 115 EXPECT_EQ(input.modes().size(), output.modes().size()); |
| 116 |
| 117 for (size_t i = 0; i < input.modes().size(); i++) |
| 118 EXPECT_TRUE(CompareModes(*input.modes()[i], *output.modes()[i])); |
| 119 |
| 120 EXPECT_EQ(input.edid(), output.edid()); |
| 121 |
| 122 if (!input.current_mode()) |
| 123 EXPECT_EQ(nullptr, output.current_mode()); |
| 124 else |
| 125 EXPECT_TRUE(CompareModes(*input.current_mode(), *output.current_mode())); |
| 126 |
| 127 if (!input.native_mode()) |
| 128 EXPECT_EQ(nullptr, output.native_mode()); |
| 129 else |
| 130 EXPECT_TRUE(CompareModes(*input.native_mode(), *output.native_mode())); |
| 131 |
| 132 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); |
| 133 } |
| 134 |
| 81 } // namespace | 135 } // namespace |
| 82 | 136 |
| 83 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { | 137 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| 84 Display input(5); | 138 Display input(5); |
| 85 | 139 |
| 86 Display output; | 140 Display output; |
| 87 GetTraitsTestProxy()->EchoDisplay(input, &output); | 141 GetTraitsTestProxy()->EchoDisplay(input, &output); |
| 88 | 142 |
| 89 CheckDisplaysEqual(input, output); | 143 CheckDisplaysEqual(input, output); |
| 90 } | 144 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 input->primary_id = kDisplayId2; | 266 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; | 267 input->mirrored = true; |
| 214 input->default_unified = true; | 268 input->default_unified = true; |
| 215 | 269 |
| 216 std::unique_ptr<DisplayLayout> output; | 270 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); | 271 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 | 272 |
| 219 CheckDisplayLayoutsEqual(*input, *output); | 273 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } | 274 } |
| 221 | 275 |
| 276 // One display mode, current and native mode nullptr. |
| 277 TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentAndNativeModesNull) { |
| 278 // Prepare sample input with random values. |
| 279 const int64_t display_id = 7; |
| 280 const gfx::Point origin(1, 2); |
| 281 const gfx::Size physical_size(5, 9); |
| 282 const gfx::Size maximum_cursor_size(3, 5); |
| 283 const DisplayConnectionType type = |
| 284 display::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; |
| 285 const bool is_aspect_preserving_scaling = true; |
| 286 const bool has_overscan = true; |
| 287 const bool has_color_correction_matrix = true; |
| 288 const std::string display_name("whatever display_name"); |
| 289 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); |
| 290 const int64_t product_id = 19; |
| 291 |
| 292 const DisplayMode display_mode(gfx::Size(13, 11), true, 40.0f); |
| 293 |
| 294 display::DisplaySnapshot::DisplayModeList modes; |
| 295 modes.push_back(display_mode.Clone()); |
| 296 |
| 297 const DisplayMode* current_mode = nullptr; |
| 298 const DisplayMode* native_mode = nullptr; |
| 299 const std::vector<uint8_t> edid = {1}; |
| 300 |
| 301 std::unique_ptr<DisplaySnapshotMojo> input = |
| 302 base::MakeUnique<DisplaySnapshotMojo>( |
| 303 display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| 304 has_overscan, has_color_correction_matrix, display_name, sys_path, |
| 305 product_id, std::move(modes), edid, current_mode, native_mode, |
| 306 maximum_cursor_size); |
| 307 |
| 308 std::unique_ptr<DisplaySnapshotMojo> output; |
| 309 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| 310 |
| 311 CheckDisplaySnapShotMojoEqual(*input, *output); |
| 312 } |
| 313 |
| 314 // One display mode that is the native mode and no current mode. |
| 315 TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentModeNull) { |
| 316 // Prepare sample input with random values. |
| 317 const int64_t display_id = 6; |
| 318 const gfx::Point origin(11, 32); |
| 319 const gfx::Size physical_size(55, 49); |
| 320 const gfx::Size maximum_cursor_size(13, 95); |
| 321 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_VGA; |
| 322 const bool is_aspect_preserving_scaling = true; |
| 323 const bool has_overscan = true; |
| 324 const bool has_color_correction_matrix = true; |
| 325 const std::string display_name("whatever display_name"); |
| 326 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("z/b"); |
| 327 const int64_t product_id = 9; |
| 328 |
| 329 const DisplayMode display_mode(gfx::Size(13, 11), true, 50.0f); |
| 330 |
| 331 display::DisplaySnapshot::DisplayModeList modes; |
| 332 modes.push_back(display_mode.Clone()); |
| 333 |
| 334 const DisplayMode* current_mode = nullptr; |
| 335 const DisplayMode* native_mode = modes[0].get(); |
| 336 const std::vector<uint8_t> edid = {1}; |
| 337 |
| 338 std::unique_ptr<DisplaySnapshotMojo> input = |
| 339 base::MakeUnique<DisplaySnapshotMojo>( |
| 340 display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| 341 has_overscan, has_color_correction_matrix, display_name, sys_path, |
| 342 product_id, std::move(modes), edid, current_mode, native_mode, |
| 343 maximum_cursor_size); |
| 344 |
| 345 std::unique_ptr<DisplaySnapshotMojo> output; |
| 346 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| 347 |
| 348 CheckDisplaySnapShotMojoEqual(*input, *output); |
| 349 } |
| 350 |
| 351 // Multiple display modes, both native and current mode set. |
| 352 TEST_F(DisplayStructTraitsTest, DisplaySnapshotExternal) { |
| 353 // Prepare sample input from external display. |
| 354 const int64_t display_id = 9834293210466051; |
| 355 const gfx::Point origin(0, 1760); |
| 356 const gfx::Size physical_size(520, 320); |
| 357 const gfx::Size maximum_cursor_size(4, 5); |
| 358 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; |
| 359 const bool is_aspect_preserving_scaling = false; |
| 360 const bool has_overscan = false; |
| 361 const bool has_color_correction_matrix = false; |
| 362 const std::string display_name("HP Z24i"); |
| 363 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); |
| 364 const int64_t product_id = 139; |
| 365 |
| 366 const DisplayMode display_mode(gfx::Size(1024, 768), false, 60.0f); |
| 367 const DisplayMode display_current_mode(gfx::Size(1440, 900), false, 59.89f); |
| 368 const DisplayMode display_native_mode(gfx::Size(1920, 1200), false, 59.89f); |
| 369 |
| 370 display::DisplaySnapshot::DisplayModeList modes; |
| 371 modes.push_back(display_mode.Clone()); |
| 372 modes.push_back(display_current_mode.Clone()); |
| 373 modes.push_back(display_native_mode.Clone()); |
| 374 |
| 375 const DisplayMode* current_mode = modes[1].get(); |
| 376 const DisplayMode* native_mode = modes[2].get(); |
| 377 const std::vector<uint8_t> edid = {2, 3, 4, 5}; |
| 378 |
| 379 std::unique_ptr<DisplaySnapshotMojo> input = |
| 380 base::MakeUnique<DisplaySnapshotMojo>( |
| 381 display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| 382 has_overscan, has_color_correction_matrix, display_name, sys_path, |
| 383 product_id, std::move(modes), edid, current_mode, native_mode, |
| 384 maximum_cursor_size); |
| 385 |
| 386 std::unique_ptr<DisplaySnapshotMojo> output; |
| 387 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| 388 |
| 389 CheckDisplaySnapShotMojoEqual(*input, *output); |
| 390 } |
| 391 |
| 392 TEST_F(DisplayStructTraitsTest, DisplaySnapshotInternal) { |
| 393 // Prepare sample input from Pixel's internal display. |
| 394 const int64_t display_id = 13761487533244416; |
| 395 const gfx::Point origin(0, 0); |
| 396 const gfx::Size physical_size(270, 180); |
| 397 const gfx::Size maximum_cursor_size(64, 64); |
| 398 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; |
| 399 const bool is_aspect_preserving_scaling = true; |
| 400 const bool has_overscan = false; |
| 401 const bool has_color_correction_matrix = false; |
| 402 const std::string display_name(""); |
| 403 const base::FilePath sys_path; |
| 404 const int64_t product_id = 139; |
| 405 |
| 406 const DisplayMode display_mode(gfx::Size(2560, 1700), false, 95.96f); |
| 407 |
| 408 display::DisplaySnapshot::DisplayModeList modes; |
| 409 modes.push_back(display_mode.Clone()); |
| 410 |
| 411 const DisplayMode* current_mode = modes[0].get(); |
| 412 const DisplayMode* native_mode = modes[0].get(); |
| 413 const std::vector<uint8_t> edid = {2, 3}; |
| 414 |
| 415 std::unique_ptr<DisplaySnapshotMojo> input = |
| 416 base::MakeUnique<DisplaySnapshotMojo>( |
| 417 display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| 418 has_overscan, has_color_correction_matrix, display_name, sys_path, |
| 419 product_id, std::move(modes), edid, current_mode, native_mode, |
| 420 maximum_cursor_size); |
| 421 |
| 422 std::unique_ptr<DisplaySnapshotMojo> output; |
| 423 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| 424 |
| 425 CheckDisplaySnapShotMojoEqual(*input, *output); |
| 426 } |
| 427 |
| 222 } // namespace display | 428 } // namespace display |
| OLD | NEW |