Chromium Code Reviews| Index: ui/display/mojo/display_struct_traits_unittest.cc |
| diff --git a/ui/display/mojo/display_struct_traits_unittest.cc b/ui/display/mojo/display_struct_traits_unittest.cc |
| index e087e68d63e240e979ba24140c472ba8a62b6b45..bb825b571edfa33480c0a1f0f2d467c269af3090 100644 |
| --- a/ui/display/mojo/display_struct_traits_unittest.cc |
| +++ b/ui/display/mojo/display_struct_traits_unittest.cc |
| @@ -2,12 +2,17 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| #include "base/message_loop/message_loop.h" |
| #include "mojo/public/cpp/bindings/binding_set.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/display/display.h" |
| #include "ui/display/display_layout.h" |
| +#include "ui/display/display_snapshot_mojo.h" |
| #include "ui/display/mojo/display_struct_traits_test.mojom.h" |
| +#include "ui/display/types/display_constants.h" |
| #include "ui/display/types/display_mode.h" |
| #include "ui/gfx/geometry/rect.h" |
| #include "ui/gfx/geometry/size.h" |
| @@ -41,6 +46,12 @@ class DisplayStructTraitsTest : public testing::Test, |
| callback.Run(std::move(in)); |
| } |
| + void EchoDisplaySnapshotMojo( |
| + std::unique_ptr<DisplaySnapshotMojo> in, |
| + const EchoDisplaySnapshotMojoCallback& callback) override { |
| + callback.Run(std::move(in)); |
| + } |
| + |
| void EchoDisplayPlacement( |
| const DisplayPlacement& in, |
| const EchoDisplayPlacementCallback& callback) override { |
| @@ -78,6 +89,40 @@ void CheckDisplayLayoutsEqual(const DisplayLayout& input, |
| EXPECT_EQ(input.primary_id, output.primary_id); |
| } |
| +void CheckDisplaySnapShotMojoEqual(const DisplaySnapshotMojo& input, |
| + const DisplaySnapshotMojo& output) { |
| + // We want to test each component individually to make sure each data member |
| + // was correctly serialized and deserialized. |
| + EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
| + EXPECT_EQ(input.display_id(), output.display_id()); |
| + EXPECT_EQ(input.origin(), output.origin()); |
| + EXPECT_EQ(input.physical_size(), output.physical_size()); |
| + EXPECT_EQ(input.type(), output.type()); |
| + EXPECT_EQ(input.is_aspect_preserving_scaling(), |
| + output.is_aspect_preserving_scaling()); |
| + EXPECT_EQ(input.has_overscan(), output.has_overscan()); |
| + EXPECT_EQ(input.has_color_correction_matrix(), |
| + output.has_color_correction_matrix()); |
| + EXPECT_EQ(input.display_name(), output.display_name()); |
| + EXPECT_EQ(input.sys_path(), output.sys_path()); |
| + EXPECT_EQ(input.product_id(), output.product_id()); |
| + EXPECT_EQ(input.modes().size(), output.modes().size()); |
| + |
| + for (size_t i = 0; i < input.modes().size(); i++) |
| + EXPECT_EQ(*input.modes()[i], *output.modes()[i]); |
| + |
| + EXPECT_EQ(input.edid(), output.edid()); |
| + |
| + 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.
|
| + (nullptr == input.current_mode()) || |
| + *input.current_mode() == *output.current_mode()); |
| + EXPECT_EQ(true, ((nullptr == output.native_mode()) && |
| + (nullptr == input.native_mode())) || |
| + (*input.native_mode() == *output.native_mode())); |
| + |
| + EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); |
| +} |
| + |
| } // namespace |
| TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| @@ -219,4 +264,238 @@ TEST_F(DisplayStructTraitsTest, DisplayLayoutTwoMirrored) { |
| CheckDisplayLayoutsEqual(*input, *output); |
| } |
| +// One display mode, current and native mode nullptr. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoNullBothIndexPointer) { |
| + 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.
|
| + |
| + // prepare sample input with random values |
| + const int64_t display_id = 7; |
| + const gfx::Point origin(1, 2); |
| + const gfx::Size physical_size(5, 9); |
| + const gfx::Size maximum_cursor_size(3, 5); |
| + const DisplayConnectionType type = |
| + display::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; |
| + const bool is_aspect_preserving_scaling = true; |
| + const bool has_overscan = true; |
| + const bool has_color_correction_matrix = true; |
| + const std::string display_name("whatever display_name"); |
| + const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("a/cb"); |
| + const base::FilePath::StringPieceType string_piece_path(string_type_path); |
| + 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.
|
| + const int64_t product_id = 19; |
| + |
| + const DisplayMode display_mode(gfx::Size(13, 11), true, 1211.0); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = nullptr; |
| + const DisplayMode* native_mode = nullptr; |
| + |
| + display::DisplaySnapshot::DisplayModeList expected_modes; |
| + expected_modes.push_back(display_mode.Clone()); |
| + |
| + const std::vector<uint8_t> edid = {1}; |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(modes), edid, current_mode, native_mode, |
| + maximum_cursor_size); |
| + |
| + const DisplayMode* expected_current_mode = nullptr; |
| + const DisplayMode* expected_native_mode = nullptr; |
| + |
| + // Similar object as |input|. |expected_input| is used for later comparison. |
| + 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
|
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(expected_modes), edid, expected_current_mode, |
| + expected_native_mode, maximum_cursor_size); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + proxy->EchoDisplaySnapshotMojo(std::move(input), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*expected_input, *output); |
| +} |
| + |
| +// One display mode that is the native mode and no current mode. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoNullOneIndexPointer) { |
| + mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| + |
| + // prepare sample input with random values |
| + const int64_t display_id = 6; |
| + const gfx::Point origin(11, 32); |
| + const gfx::Size physical_size(55, 49); |
| + const gfx::Size maximum_cursor_size(13, 95); |
| + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_VGA; |
| + const bool is_aspect_preserving_scaling = true; |
| + const bool has_overscan = true; |
| + const bool has_color_correction_matrix = true; |
| + const std::string display_name("whatever display_name"); |
| + const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("z/b"); |
| + const base::FilePath::StringPieceType string_piece_path(string_type_path); |
| + const base::FilePath sys_path(string_piece_path); |
| + const int64_t product_id = 9; |
| + |
| + const DisplayMode display_mode_1(gfx::Size(13, 11), true, 1211.0); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode_1.Clone()); |
| + |
| + const DisplayMode* current_mode = modes[0].get(); |
| + const DisplayMode* native_mode = nullptr; |
| + |
| + display::DisplaySnapshot::DisplayModeList expected_modes; |
| + expected_modes.push_back(display_mode_1.Clone()); |
| + |
| + const std::vector<uint8_t> edid = {1}; |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(modes), edid, current_mode, native_mode, |
| + maximum_cursor_size); |
| + |
| + const DisplayMode* expected_current_mode = expected_modes[0].get(); |
| + const DisplayMode* expected_native_mode = nullptr; |
| + |
| + // Similar object as |input|. |expected_input| is used for later comparison. |
| + std::unique_ptr<DisplaySnapshotMojo> expected_input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(expected_modes), edid, expected_current_mode, |
| + expected_native_mode, maximum_cursor_size); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + proxy->EchoDisplaySnapshotMojo(std::move(input), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*expected_input, *output); |
| +} |
| + |
| +// Multiple display modes, both native and current mode set. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoDefault) { |
| + mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| + |
| + // prepare sample input with random values |
| + const int64_t display_id = 73; |
| + const gfx::Point origin(33, 126); |
| + const gfx::Size physical_size(152, 294); |
| + const gfx::Size maximum_cursor_size(320, 353); |
| + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; |
| + const bool is_aspect_preserving_scaling = true; |
| + const bool has_overscan = true; |
| + const bool has_color_correction_matrix = true; |
| + const std::string display_name("whatever display_name"); |
| + const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("a/cb"); |
| + const base::FilePath::StringPieceType string_piece_path(string_type_path); |
| + const base::FilePath sys_path(string_piece_path); |
| + const int64_t product_id = 139; |
| + |
| + const DisplayMode display_mode_1(gfx::Size(11, 12), true, 111.0); |
| + const DisplayMode display_current_mode(gfx::Size(22, 23), true, 222.0); |
| + const DisplayMode display_native_mode(gfx::Size(33, 34), true, 333.0); |
| + const DisplayMode display_mode_2(gfx::Size(44, 45), true, 444.0); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode_1.Clone()); |
| + modes.push_back(display_current_mode.Clone()); |
| + modes.push_back(display_native_mode.Clone()); |
| + modes.push_back(display_mode_2.Clone()); |
| + |
| + const DisplayMode* current_mode = modes[1].get(); |
| + const DisplayMode* native_mode = modes[2].get(); |
| + |
| + display::DisplaySnapshot::DisplayModeList expected_modes; |
| + expected_modes.push_back(display_mode_1.Clone()); |
| + expected_modes.push_back(display_current_mode.Clone()); |
| + expected_modes.push_back(display_native_mode.Clone()); |
| + expected_modes.push_back(display_mode_2.Clone()); |
| + |
| + const std::vector<uint8_t> edid = {2, 3, 4, 5}; |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(modes), edid, current_mode, native_mode, |
| + maximum_cursor_size); |
| + |
| + const DisplayMode* expected_current_mode = expected_modes[1].get(); |
| + const DisplayMode* expected_native_mode = expected_modes[2].get(); |
| + |
| + // Similar object as |input|. |expected_input| is used for later comparison. |
| + std::unique_ptr<DisplaySnapshotMojo> expected_input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(expected_modes), edid, expected_current_mode, |
| + expected_native_mode, maximum_cursor_size); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + proxy->EchoDisplaySnapshotMojo(std::move(input), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*expected_input, *output); |
| +} |
| + |
| +// Tests for both internal display and external display. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotMojoInternalDisplay) { |
| + mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| + |
| + // prepare sample input with random values |
| + const int64_t display_id = 17; |
| + const gfx::Point origin(31, 2); |
| + const gfx::Size physical_size(215, 219); |
| + const gfx::Size maximum_cursor_size(330, 351); |
| + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; |
| + const bool is_aspect_preserving_scaling = true; |
| + const bool has_overscan = true; |
| + const bool has_color_correction_matrix = true; |
| + const std::string display_name("display_name"); |
| + const base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("c/a"); |
| + const base::FilePath::StringPieceType string_piece_path(string_type_path); |
| + const base::FilePath sys_path(string_piece_path); |
| + const int64_t product_id = 139; |
| + |
| + const DisplayMode display_mode(gfx::Size(11, 12), true, 111.0); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = modes[0].get(); |
| + const DisplayMode* native_mode = modes[0].get(); |
| + |
| + display::DisplaySnapshot::DisplayModeList expected_modes; |
| + expected_modes.push_back(display_mode.Clone()); |
| + |
| + const std::vector<uint8_t> edid = {2, 3}; |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(modes), edid, current_mode, native_mode, |
| + maximum_cursor_size); |
| + |
| + const DisplayMode* expected_current_mode = expected_modes[0].get(); |
| + const DisplayMode* expected_native_mode = expected_modes[0].get(); |
| + |
| + // Similar object as |input|. |expected_input| is used for later comparison. |
| + std::unique_ptr<DisplaySnapshotMojo> expected_input = |
| + base::MakeUnique<DisplaySnapshotMojo>( |
| + display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| + has_overscan, has_color_correction_matrix, display_name, sys_path, |
| + product_id, std::move(expected_modes), edid, expected_current_mode, |
| + expected_native_mode, maximum_cursor_size); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + proxy->EchoDisplaySnapshotMojo(std::move(input), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*expected_input, *output); |
| +} |
| + |
| } // namespace display |