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