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, DisplaySnapshotMojoNullBothIndexPointer) { | |
|
kylechar
2017/02/15 16:48:45
DisplaySnapshotCurrentAndNativeModesNull
thanhph
2017/02/16 11:48:21
Done.
| |
| 272 // prepare sample input with random values | |
| 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, 1211.0); | |
|
kylechar
2017/02/15 16:48:45
I don't think any displays have refresh rates that
thanhph
2017/02/16 11:48:21
I changed to 40.0, 50.0 & 60.0.
| |
| 287 | |
| 288 display::DisplaySnapshot::DisplayModeList modes; | |
| 289 modes.push_back(display_mode.Clone()); | |
|
kylechar
2017/02/15 16:48:45
If you think this helps with readability, leave it
thanhph
2017/02/16 11:48:21
I'll leave it as it is since it's shorter. Thanks
| |
| 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, DisplaySnapshotMojoNullOneIndexPointer) { | |
|
kylechar
2017/02/15 16:48:45
DisplaySnapshotCurrentModeNull
thanhph
2017/02/16 11:48:21
Done.
| |
| 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, 1211.0); | |
| 324 | |
| 325 display::DisplaySnapshot::DisplayModeList modes; | |
| 326 modes.push_back(display_mode.Clone()); | |
| 327 | |
| 328 const DisplayMode* current_mode = modes[0].get(); | |
|
kylechar
2017/02/15 16:48:45
The description says one native mode and no curren
thanhph
2017/02/16 11:48:21
Done, I swapped current_mode to nullptr.
| |
| 329 const DisplayMode* native_mode = nullptr; | |
| 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, DisplaySnapshotMojoDefault) { | |
|
kylechar
2017/02/15 16:48:45
What does DisplaySnapshotMojoDefault mean exactly?
thanhph
2017/02/16 11:48:21
Done.
| |
| 347 // prepare sample input with random values | |
|
kylechar
2017/02/15 16:48:45
Here is some sample data from an external monitor:
thanhph
2017/02/16 11:48:21
Thanks, I added these data in. How do you get thes
kylechar
2017/02/16 14:05:42
I have this monitor on my desk and I printed the c
| |
| 348 const int64_t display_id = 73; | |
| 349 const gfx::Point origin(33, 126); | |
| 350 const gfx::Size physical_size(152, 294); | |
| 351 const gfx::Size maximum_cursor_size(320, 353); | |
| 352 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; | |
| 353 const bool is_aspect_preserving_scaling = true; | |
| 354 const bool has_overscan = true; | |
| 355 const bool has_color_correction_matrix = true; | |
| 356 const std::string display_name("whatever display_name"); | |
| 357 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); | |
| 358 const int64_t product_id = 139; | |
| 359 | |
| 360 const DisplayMode display_mode_1(gfx::Size(11, 12), true, 111.0); | |
| 361 const DisplayMode display_current_mode(gfx::Size(22, 23), true, 222.0); | |
| 362 const DisplayMode display_native_mode(gfx::Size(33, 34), true, 333.0); | |
| 363 const DisplayMode display_mode_2(gfx::Size(44, 45), true, 444.0); | |
| 364 | |
| 365 display::DisplaySnapshot::DisplayModeList modes; | |
| 366 modes.push_back(display_mode_1.Clone()); | |
| 367 modes.push_back(display_current_mode.Clone()); | |
| 368 modes.push_back(display_native_mode.Clone()); | |
| 369 modes.push_back(display_mode_2.Clone()); | |
| 370 | |
| 371 const DisplayMode* current_mode = modes[1].get(); | |
| 372 const DisplayMode* native_mode = modes[2].get(); | |
| 373 const std::vector<uint8_t> edid = {2, 3, 4, 5}; | |
| 374 | |
| 375 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 376 base::MakeUnique<DisplaySnapshotMojo>( | |
| 377 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 378 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 379 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 380 maximum_cursor_size); | |
| 381 | |
| 382 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 383 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 384 | |
| 385 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 386 } | |
| 387 | |
| 388 // Tests for both internal display and external display. | |
|
kylechar
2017/02/15 16:48:45
This display is an internal display, as per the di
thanhph
2017/02/16 11:48:21
Removed this comment since the test name seems mea
| |
| 389 TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoInternalDisplay) { | |
|
kylechar
2017/02/15 16:48:45
DisplaySnapshotInternal maybe?
thanhph
2017/02/16 11:48:21
Done.
| |
| 390 // prepare sample input with random values | |
|
kylechar
2017/02/15 16:48:45
I'll provide you with some sample data from Pixel
thanhph
2017/02/16 11:48:21
nice, thanks!
| |
| 391 const int64_t display_id = 17; | |
| 392 const gfx::Point origin(31, 2); | |
| 393 const gfx::Size physical_size(215, 219); | |
| 394 const gfx::Size maximum_cursor_size(330, 351); | |
| 395 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; | |
| 396 const bool is_aspect_preserving_scaling = true; | |
| 397 const bool has_overscan = true; | |
| 398 const bool has_color_correction_matrix = true; | |
| 399 const std::string display_name("display_name"); | |
| 400 const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("c/a"); | |
| 401 const int64_t product_id = 139; | |
| 402 | |
| 403 const DisplayMode display_mode(gfx::Size(11, 12), true, 111.0); | |
| 404 | |
| 405 display::DisplaySnapshot::DisplayModeList modes; | |
| 406 modes.push_back(display_mode.Clone()); | |
| 407 | |
| 408 const DisplayMode* current_mode = modes[0].get(); | |
| 409 const DisplayMode* native_mode = modes[0].get(); | |
| 410 const std::vector<uint8_t> edid = {2, 3}; | |
| 411 | |
| 412 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 413 base::MakeUnique<DisplaySnapshotMojo>( | |
| 414 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 415 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 416 product_id, std::move(modes), edid, current_mode, native_mode, | |
| 417 maximum_cursor_size); | |
| 418 | |
| 419 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 420 GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); | |
| 421 | |
| 422 CheckDisplaySnapShotMojoEqual(*input, *output); | |
| 423 } | |
| 424 | |
| 222 } // namespace display | 425 } // namespace display |
| OLD | NEW |