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 if (!input.current_mode()) | |
| 117 EXPECT_EQ(nullptr, output.current_mode()); | |
| 118 else | |
| 119 EXPECT_EQ(*input.current_mode(), *output.current_mode()); | |
| 120 | |
| 121 if (!input.native_mode()) | |
| 122 EXPECT_EQ(nullptr, output.native_mode()); | |
| 123 else | |
| 124 EXPECT_EQ(*input.native_mode(), *output.native_mode()); | |
| 125 | |
| 126 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); | |
| 127 } | |
| 128 | |
| 81 } // namespace | 129 } // namespace |
| 82 | 130 |
| 83 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { | 131 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| 84 Display input(5); | 132 Display input(5); |
| 85 | 133 |
| 86 Display output; | 134 Display output; |
| 87 GetTraitsTestProxy()->EchoDisplay(input, &output); | 135 GetTraitsTestProxy()->EchoDisplay(input, &output); |
| 88 | 136 |
| 89 CheckDisplaysEqual(input, output); | 137 CheckDisplaysEqual(input, output); |
| 90 } | 138 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 input->primary_id = kDisplayId2; | 260 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; | 261 input->mirrored = true; |
| 214 input->default_unified = true; | 262 input->default_unified = true; |
| 215 | 263 |
| 216 std::unique_ptr<DisplayLayout> output; | 264 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); | 265 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 | 266 |
| 219 CheckDisplayLayoutsEqual(*input, *output); | 267 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } | 268 } |
| 221 | 269 |
| 270 // One display mode, current and native mode nullptr. | |
| 271 TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentAndNativeModesNull) { | |
| 272 // prepare sample input with random values | |
|
kylechar
2017/02/16 14:05:42
Please make the comments a proper sentence (eg cap
thanhph1
2017/02/16 15:21:09
Done.
| |
| 273 const int64_t display_id = 7; | |
| 274 const gfx::Point origin(1, 2); | |
| 275 const gfx::Size physical_size(5, 9); | |
| 276 const gfx::Size maximum_cursor_size(3, 5); | |
| 277 const DisplayConnectionType type = | |
| 278 display::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; | |
| 279 const bool is_aspect_preserving_scaling = true; | |
| 280 const bool has_overscan = true; | |
| 281 const bool has_color_correction_matrix = true; | |
| 282 const std::string display_name("whatever display_name"); | |
| 283 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); | |
| 284 const int64_t product_id = 19; | |
| 285 | |
| 286 const DisplayMode display_mode(gfx::Size(13, 11), true, 40.0f); | |
| 287 | |
| 288 display::DisplaySnapshot::DisplayModeList modes; | |
| 289 modes.push_back(display_mode.Clone()); | |
| 290 | |
| 291 const DisplayMode* current_mode = nullptr; | |
| 292 const DisplayMode* native_mode = nullptr; | |
| 293 const std::vector<uint8_t> edid = {1}; | |
| 294 | |
| 295 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 296 base::MakeUnique<DisplaySnapshotMojo>( | |
| 297 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 298 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 299 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 300 maximum_cursor_size); | |
| 301 | |
| 302 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 303 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 304 | |
| 305 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 306 } | |
| 307 | |
| 308 // One display mode that is the native mode and no current mode. | |
| 309 TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentModeNull) { | |
| 310 // prepare sample input with random values | |
| 311 const int64_t display_id = 6; | |
| 312 const gfx::Point origin(11, 32); | |
| 313 const gfx::Size physical_size(55, 49); | |
| 314 const gfx::Size maximum_cursor_size(13, 95); | |
| 315 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_VGA; | |
| 316 const bool is_aspect_preserving_scaling = true; | |
| 317 const bool has_overscan = true; | |
| 318 const bool has_color_correction_matrix = true; | |
| 319 const std::string display_name("whatever display_name"); | |
| 320 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("z/b"); | |
| 321 const int64_t product_id = 9; | |
| 322 | |
| 323 const DisplayMode display_mode(gfx::Size(13, 11), true, 50.0f); | |
| 324 | |
| 325 display::DisplaySnapshot::DisplayModeList modes; | |
| 326 modes.push_back(display_mode.Clone()); | |
| 327 | |
| 328 const DisplayMode* current_mode = nullptr; | |
| 329 const DisplayMode* native_mode = modes[0].get(); | |
| 330 const std::vector<uint8_t> edid = {1}; | |
| 331 | |
| 332 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 333 base::MakeUnique<DisplaySnapshotMojo>( | |
| 334 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 335 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 336 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 337 maximum_cursor_size); | |
| 338 | |
| 339 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 340 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 341 | |
| 342 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 343 } | |
| 344 | |
| 345 // Multiple display modes, both native and current mode set. | |
| 346 TEST_F(DisplayStructTraitsTest, DisplaySnapshotExternal) { | |
| 347 // prepare sample input with random values | |
|
kylechar
2017/02/16 14:05:42
These aren't random values, please fix the comment
thanhph1
2017/02/16 15:21:09
Done.
| |
| 348 const int64_t display_id = 9834293210466051; | |
| 349 const gfx::Point origin(0, 1760); | |
| 350 const gfx::Size physical_size(520, 320); | |
| 351 const gfx::Size maximum_cursor_size(4, 5); | |
| 352 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; | |
| 353 const bool is_aspect_preserving_scaling = false; | |
| 354 const bool has_overscan = false; | |
| 355 const bool has_color_correction_matrix = false; | |
| 356 const std::string display_name("HP Z24i"); | |
| 357 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); | |
| 358 const int64_t product_id = 139; | |
| 359 | |
| 360 const DisplayMode display_mode(gfx::Size(1024, 768), false, 60.0); | |
| 361 const DisplayMode display_current_mode(gfx::Size(1440, 900), false, 59.89f); | |
| 362 const DisplayMode display_native_mode(gfx::Size(1920, 1200), false, 59.89f); | |
| 363 | |
| 364 display::DisplaySnapshot::DisplayModeList modes; | |
| 365 modes.push_back(display_mode.Clone()); | |
| 366 modes.push_back(display_current_mode.Clone()); | |
| 367 modes.push_back(display_native_mode.Clone()); | |
| 368 | |
| 369 const DisplayMode* current_mode = modes[1].get(); | |
| 370 const DisplayMode* native_mode = modes[2].get(); | |
| 371 const std::vector<uint8_t> edid = {2, 3, 4, 5}; | |
| 372 | |
| 373 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 374 base::MakeUnique<DisplaySnapshotMojo>( | |
| 375 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 376 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 377 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 378 maximum_cursor_size); | |
| 379 | |
| 380 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 381 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 382 | |
| 383 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 384 } | |
| 385 | |
| 386 TEST_F(DisplayStructTraitsTest, DisplaySnapshotInternal) { | |
| 387 // prepare sample input with random values | |
|
kylechar
2017/02/16 14:05:42
Ditto above.
thanhph1
2017/02/16 15:21:09
Done.
| |
| 388 const int64_t display_id = 13761487533244416; | |
| 389 const gfx::Point origin(0, 0); | |
| 390 const gfx::Size physical_size(270, 180); | |
| 391 const gfx::Size maximum_cursor_size(64, 64); | |
| 392 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; | |
| 393 const bool is_aspect_preserving_scaling = true; | |
| 394 const bool has_overscan = false; | |
| 395 const bool has_color_correction_matrix = false; | |
| 396 const std::string display_name(""); | |
| 397 const base::FilePath sys_path; | |
| 398 const int64_t product_id = 139; | |
| 399 | |
| 400 const DisplayMode display_mode(gfx::Size(2560, 1700), false, 95.96f); | |
| 401 | |
| 402 display::DisplaySnapshot::DisplayModeList modes; | |
| 403 modes.push_back(display_mode.Clone()); | |
| 404 | |
| 405 const DisplayMode* current_mode = modes[0].get(); | |
| 406 const DisplayMode* native_mode = modes[0].get(); | |
| 407 const std::vector<uint8_t> edid = {2, 3}; | |
| 408 | |
| 409 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 410 base::MakeUnique<DisplaySnapshotMojo>( | |
| 411 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 412 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 413 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 414 maximum_cursor_size); | |
| 415 | |
| 416 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 417 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 418 | |
| 419 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 420 } | |
| 421 | |
| 222 } // namespace display | 422 } // namespace display |
| OLD | NEW |