Chromium Code Reviews| 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 void CheckDisplaySnapShotMojoEqual(const DisplaySnapshotMojo& input, | |
| 93 const DisplaySnapshotMojo& output) { | |
| 94 // We want to test each component individually to make sure each data member | |
| 95 // was correctly serialized and deserialized. | |
| 96 EXPECT_NE(&input, &output); // Make sure they aren't the same object. | |
| 97 EXPECT_EQ(input.display_id(), output.display_id()); | |
| 98 EXPECT_EQ(input.origin(), output.origin()); | |
| 99 EXPECT_EQ(input.physical_size(), output.physical_size()); | |
| 100 EXPECT_EQ(input.type(), output.type()); | |
| 101 EXPECT_EQ(input.is_aspect_preserving_scaling(), | |
| 102 output.is_aspect_preserving_scaling()); | |
| 103 EXPECT_EQ(input.has_overscan(), output.has_overscan()); | |
| 104 EXPECT_EQ(input.has_color_correction_matrix(), | |
| 105 output.has_color_correction_matrix()); | |
| 106 EXPECT_EQ(input.display_name(), output.display_name()); | |
| 107 EXPECT_EQ(input.sys_path(), output.sys_path()); | |
| 108 EXPECT_EQ(input.product_id(), output.product_id()); | |
| 109 EXPECT_EQ(input.modes().size(), output.modes().size()); | |
| 110 | |
| 111 for (size_t i = 0; i < input.modes().size(); i++) | |
| 112 EXPECT_EQ(*input.modes()[i], *output.modes()[i]); | |
| 113 | |
| 114 EXPECT_EQ(input.edid(), output.edid()); | |
| 115 | |
| 116 EXPECT_EQ(true, (nullptr == output.current_mode()) && | |
|
kylechar
2017/02/14 21:35:28
So in general if you want to expect something is t
thanhph1
2017/02/15 15:37:56
Done.
| |
| 117 (nullptr == input.current_mode()) || | |
| 118 *input.current_mode() == *output.current_mode()); | |
| 119 EXPECT_EQ(true, ((nullptr == output.native_mode()) && | |
| 120 (nullptr == input.native_mode())) || | |
| 121 (*input.native_mode() == *output.native_mode())); | |
| 122 | |
| 123 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); | |
| 124 } | |
| 125 | |
| 81 } // namespace | 126 } // namespace |
| 82 | 127 |
| 83 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { | 128 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| 84 Display input(5); | 129 Display input(5); |
| 85 | 130 |
| 86 Display output; | 131 Display output; |
| 87 GetTraitsTestProxy()->EchoDisplay(input, &output); | 132 GetTraitsTestProxy()->EchoDisplay(input, &output); |
| 88 | 133 |
| 89 CheckDisplaysEqual(input, output); | 134 CheckDisplaysEqual(input, output); |
| 90 } | 135 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 input->primary_id = kDisplayId2; | 257 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; | 258 input->mirrored = true; |
| 214 input->default_unified = true; | 259 input->default_unified = true; |
| 215 | 260 |
| 216 std::unique_ptr<DisplayLayout> output; | 261 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); | 262 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 | 263 |
| 219 CheckDisplayLayoutsEqual(*input, *output); | 264 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } | 265 } |
| 221 | 266 |
| 267 // One display mode, current and native mode nullptr. | |
| 268 TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoNullBothIndexPointer) { | |
| 269 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
|
kylechar
2017/02/14 21:35:28
You should create this near where you use it. Alth
thanhph1
2017/02/15 15:37:56
Done.
| |
| 270 | |
| 271 // prepare sample input with random values | |
| 272 const int64_t display_id = 7; | |
| 273 const gfx::Point origin(1, 2); | |
| 274 const gfx::Size physical_size(5, 9); | |
| 275 const gfx::Size maximum_cursor_size(3, 5); | |
| 276 const DisplayConnectionType type = | |
| 277 display::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; | |
| 278 const bool is_aspect_preserving_scaling = true; | |
| 279 const bool has_overscan = true; | |
| 280 const bool has_color_correction_matrix = true; | |
| 281 const std::string display_name("whatever display_name"); | |
| 282 const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("a/cb"); | |
| 283 const base::FilePath::StringPieceType string_piece_path(string_type_path); | |
| 284 const base::FilePath sys_path(string_piece_path); | |
|
kylechar
2017/02/14 21:35:28
Are you just trying to create a FilePath object wi
thanhph1
2017/02/15 15:37:56
Done.
| |
| 285 const int64_t product_id = 19; | |
| 286 | |
| 287 const DisplayMode display_mode(gfx::Size(13, 11), true, 1211.0); | |
| 288 | |
| 289 display::DisplaySnapshot::DisplayModeList modes; | |
| 290 modes.push_back(display_mode.Clone()); | |
| 291 | |
| 292 const DisplayMode* current_mode = nullptr; | |
| 293 const DisplayMode* native_mode = nullptr; | |
| 294 | |
| 295 display::DisplaySnapshot::DisplayModeList expected_modes; | |
| 296 expected_modes.push_back(display_mode.Clone()); | |
| 297 | |
| 298 const std::vector<uint8_t> edid = {1}; | |
| 299 | |
| 300 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 301 base::MakeUnique<DisplaySnapshotMojo>( | |
| 302 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 303 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 304 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 305 maximum_cursor_size); | |
| 306 | |
| 307 const DisplayMode* expected_current_mode = nullptr; | |
| 308 const DisplayMode* expected_native_mode = nullptr; | |
| 309 | |
| 310 // Similar object as |input|. |expected_input| is used for later comparison. | |
| 311 std::unique_ptr<DisplaySnapshotMojo> expected_input = | |
|
kylechar
2017/02/14 21:35:28
I'm not a big fan of this.
thanhph1
2017/02/15 15:37:56
I added a Clone() for DisplaySnapshotMojo and able
| |
| 312 base::MakeUnique<DisplaySnapshotMojo>( | |
| 313 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 314 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 315 product_id, std::move(expected_modes), edid, expected_current_mode, | |
| 316 expected_native_mode, maximum_cursor_size); | |
| 317 | |
| 318 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 319 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); | |
| 320 | |
| 321 CheckDisplaySnapShotMojoEqual(*expected_input, *output); | |
| 322 } | |
| 323 | |
| 324 // One display mode that is the native mode and no current mode. | |
| 325 TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoNullOneIndexPointer) { | |
| 326 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
| 327 | |
| 328 // prepare sample input with random values | |
| 329 const int64_t display_id = 6; | |
| 330 const gfx::Point origin(11, 32); | |
| 331 const gfx::Size physical_size(55, 49); | |
| 332 const gfx::Size maximum_cursor_size(13, 95); | |
| 333 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_VGA; | |
| 334 const bool is_aspect_preserving_scaling = true; | |
| 335 const bool has_overscan = true; | |
| 336 const bool has_color_correction_matrix = true; | |
| 337 const std::string display_name("whatever display_name"); | |
| 338 const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("z/b"); | |
| 339 const base::FilePath::StringPieceType string_piece_path(string_type_path); | |
| 340 const base::FilePath sys_path(string_piece_path); | |
| 341 const int64_t product_id = 9; | |
| 342 | |
| 343 const DisplayMode display_mode_1(gfx::Size(13, 11), true, 1211.0); | |
| 344 | |
| 345 display::DisplaySnapshot::DisplayModeList modes; | |
| 346 modes.push_back(display_mode_1.Clone()); | |
| 347 | |
| 348 const DisplayMode* current_mode = modes[0].get(); | |
| 349 const DisplayMode* native_mode = nullptr; | |
| 350 | |
| 351 display::DisplaySnapshot::DisplayModeList expected_modes; | |
| 352 expected_modes.push_back(display_mode_1.Clone()); | |
| 353 | |
| 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 const DisplayMode* expected_current_mode = expected_modes[0].get(); | |
| 364 const DisplayMode* expected_native_mode = nullptr; | |
| 365 | |
| 366 // Similar object as |input|. |expected_input| is used for later comparison. | |
| 367 std::unique_ptr<DisplaySnapshotMojo> expected_input = | |
| 368 base::MakeUnique<DisplaySnapshotMojo>( | |
| 369 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 370 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 371 product_id, std::move(expected_modes), edid, expected_current_mode, | |
| 372 expected_native_mode, maximum_cursor_size); | |
| 373 | |
| 374 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 375 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); | |
| 376 | |
| 377 CheckDisplaySnapShotMojoEqual(*expected_input, *output); | |
| 378 } | |
| 379 | |
| 380 // Multiple display modes, both native and current mode set. | |
| 381 TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoDefault) { | |
| 382 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
| 383 | |
| 384 // prepare sample input with random values | |
| 385 const int64_t display_id = 73; | |
| 386 const gfx::Point origin(33, 126); | |
| 387 const gfx::Size physical_size(152, 294); | |
| 388 const gfx::Size maximum_cursor_size(320, 353); | |
| 389 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; | |
| 390 const bool is_aspect_preserving_scaling = true; | |
| 391 const bool has_overscan = true; | |
| 392 const bool has_color_correction_matrix = true; | |
| 393 const std::string display_name("whatever display_name"); | |
| 394 const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("a/cb"); | |
| 395 const base::FilePath::StringPieceType string_piece_path(string_type_path); | |
| 396 const base::FilePath sys_path(string_piece_path); | |
| 397 const int64_t product_id = 139; | |
| 398 | |
| 399 const DisplayMode display_mode_1(gfx::Size(11, 12), true, 111.0); | |
| 400 const DisplayMode display_current_mode(gfx::Size(22, 23), true, 222.0); | |
| 401 const DisplayMode display_native_mode(gfx::Size(33, 34), true, 333.0); | |
| 402 const DisplayMode display_mode_2(gfx::Size(44, 45), true, 444.0); | |
| 403 | |
| 404 display::DisplaySnapshot::DisplayModeList modes; | |
| 405 modes.push_back(display_mode_1.Clone()); | |
| 406 modes.push_back(display_current_mode.Clone()); | |
| 407 modes.push_back(display_native_mode.Clone()); | |
| 408 modes.push_back(display_mode_2.Clone()); | |
| 409 | |
| 410 const DisplayMode* current_mode = modes[1].get(); | |
| 411 const DisplayMode* native_mode = modes[2].get(); | |
| 412 | |
| 413 display::DisplaySnapshot::DisplayModeList expected_modes; | |
| 414 expected_modes.push_back(display_mode_1.Clone()); | |
| 415 expected_modes.push_back(display_current_mode.Clone()); | |
| 416 expected_modes.push_back(display_native_mode.Clone()); | |
| 417 expected_modes.push_back(display_mode_2.Clone()); | |
| 418 | |
| 419 const std::vector<uint8_t> edid = {2, 3, 4, 5}; | |
| 420 | |
| 421 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 422 base::MakeUnique<DisplaySnapshotMojo>( | |
| 423 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 424 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 425 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 426 maximum_cursor_size); | |
| 427 | |
| 428 const DisplayMode* expected_current_mode = expected_modes[1].get(); | |
| 429 const DisplayMode* expected_native_mode = expected_modes[2].get(); | |
| 430 | |
| 431 // Similar object as |input|. |expected_input| is used for later comparison. | |
| 432 std::unique_ptr<DisplaySnapshotMojo> expected_input = | |
| 433 base::MakeUnique<DisplaySnapshotMojo>( | |
| 434 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 435 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 436 product_id, std::move(expected_modes), edid, expected_current_mode, | |
| 437 expected_native_mode, maximum_cursor_size); | |
| 438 | |
| 439 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 440 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); | |
| 441 | |
| 442 CheckDisplaySnapShotMojoEqual(*expected_input, *output); | |
| 443 } | |
| 444 | |
| 445 // Tests for both internal display and external display. | |
| 446 TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoInternalDisplay) { | |
| 447 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
| 448 | |
| 449 // prepare sample input with random values | |
| 450 const int64_t display_id = 17; | |
| 451 const gfx::Point origin(31, 2); | |
| 452 const gfx::Size physical_size(215, 219); | |
| 453 const gfx::Size maximum_cursor_size(330, 351); | |
| 454 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; | |
| 455 const bool is_aspect_preserving_scaling = true; | |
| 456 const bool has_overscan = true; | |
| 457 const bool has_color_correction_matrix = true; | |
| 458 const std::string display_name("display_name"); | |
| 459 const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("c/a"); | |
| 460 const base::FilePath::StringPieceType string_piece_path(string_type_path); | |
| 461 const base::FilePath sys_path(string_piece_path); | |
| 462 const int64_t product_id = 139; | |
| 463 | |
| 464 const DisplayMode display_mode(gfx::Size(11, 12), true, 111.0); | |
| 465 | |
| 466 display::DisplaySnapshot::DisplayModeList modes; | |
| 467 modes.push_back(display_mode.Clone()); | |
| 468 | |
| 469 const DisplayMode* current_mode = modes[0].get(); | |
| 470 const DisplayMode* native_mode = modes[0].get(); | |
| 471 | |
| 472 display::DisplaySnapshot::DisplayModeList expected_modes; | |
| 473 expected_modes.push_back(display_mode.Clone()); | |
| 474 | |
| 475 const std::vector<uint8_t> edid = {2, 3}; | |
| 476 | |
| 477 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 478 base::MakeUnique<DisplaySnapshotMojo>( | |
| 479 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 480 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 481 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 482 maximum_cursor_size); | |
| 483 | |
| 484 const DisplayMode* expected_current_mode = expected_modes[0].get(); | |
| 485 const DisplayMode* expected_native_mode = expected_modes[0].get(); | |
| 486 | |
| 487 // Similar object as |input|. |expected_input| is used for later comparison. | |
| 488 std::unique_ptr<DisplaySnapshotMojo> expected_input = | |
| 489 base::MakeUnique<DisplaySnapshotMojo>( | |
| 490 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 491 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 492 product_id, std::move(expected_modes), edid, expected_current_mode, | |
| 493 expected_native_mode, maximum_cursor_size); | |
| 494 | |
| 495 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 496 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); | |
| 497 | |
| 498 CheckDisplaySnapShotMojoEqual(*expected_input, *output); | |
| 499 } | |
| 500 | |
| 222 } // namespace display | 501 } // namespace display |
| OLD | NEW |