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..470ccbea6f1db9847826b5bfe7df8796f86c6cc2 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,43 @@ 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()); |
| + |
| + if (!input.current_mode()) |
| + EXPECT_EQ(nullptr, output.current_mode()); |
| + else |
| + EXPECT_EQ(*input.current_mode(), *output.current_mode()); |
| + |
| + if (!input.native_mode()) |
| + EXPECT_EQ(nullptr, output.native_mode()); |
| + else |
| + EXPECT_EQ(*input.native_mode(), *output.native_mode()); |
| + |
| + EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); |
| +} |
| + |
| } // namespace |
| TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
| @@ -219,4 +267,156 @@ TEST_F(DisplayStructTraitsTest, DisplayLayoutTwoMirrored) { |
| CheckDisplayLayoutsEqual(*input, *output); |
| } |
| +// One display mode, current and native mode nullptr. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentAndNativeModesNull) { |
| + // 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.
|
| + 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 sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); |
| + const int64_t product_id = 19; |
| + |
| + const DisplayMode display_mode(gfx::Size(13, 11), true, 40.0f); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = nullptr; |
| + const DisplayMode* native_mode = nullptr; |
| + 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); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*input, *output); |
| +} |
| + |
| +// One display mode that is the native mode and no current mode. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentModeNull) { |
| + // 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 sys_path = base::FilePath::FromUTF8Unsafe("z/b"); |
| + const int64_t product_id = 9; |
| + |
| + const DisplayMode display_mode(gfx::Size(13, 11), true, 50.0f); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = nullptr; |
| + const DisplayMode* native_mode = modes[0].get(); |
| + 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); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*input, *output); |
| +} |
| + |
| +// Multiple display modes, both native and current mode set. |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotExternal) { |
| + // 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.
|
| + const int64_t display_id = 9834293210466051; |
| + const gfx::Point origin(0, 1760); |
| + const gfx::Size physical_size(520, 320); |
| + const gfx::Size maximum_cursor_size(4, 5); |
| + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; |
| + const bool is_aspect_preserving_scaling = false; |
| + const bool has_overscan = false; |
| + const bool has_color_correction_matrix = false; |
| + const std::string display_name("HP Z24i"); |
| + const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); |
| + const int64_t product_id = 139; |
| + |
| + const DisplayMode display_mode(gfx::Size(1024, 768), false, 60.0); |
| + const DisplayMode display_current_mode(gfx::Size(1440, 900), false, 59.89f); |
| + const DisplayMode display_native_mode(gfx::Size(1920, 1200), false, 59.89f); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + modes.push_back(display_current_mode.Clone()); |
| + modes.push_back(display_native_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = modes[1].get(); |
| + const DisplayMode* native_mode = modes[2].get(); |
| + 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); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*input, *output); |
| +} |
| + |
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotInternal) { |
| + // prepare sample input with random values |
|
kylechar
2017/02/16 14:05:42
Ditto above.
thanhph1
2017/02/16 15:21:09
Done.
|
| + const int64_t display_id = 13761487533244416; |
| + const gfx::Point origin(0, 0); |
| + const gfx::Size physical_size(270, 180); |
| + const gfx::Size maximum_cursor_size(64, 64); |
| + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; |
| + const bool is_aspect_preserving_scaling = true; |
| + const bool has_overscan = false; |
| + const bool has_color_correction_matrix = false; |
| + const std::string display_name(""); |
| + const base::FilePath sys_path; |
| + const int64_t product_id = 139; |
| + |
| + const DisplayMode display_mode(gfx::Size(2560, 1700), false, 95.96f); |
| + |
| + display::DisplaySnapshot::DisplayModeList modes; |
| + modes.push_back(display_mode.Clone()); |
| + |
| + const DisplayMode* current_mode = modes[0].get(); |
| + const DisplayMode* native_mode = modes[0].get(); |
| + 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); |
| + |
| + std::unique_ptr<DisplaySnapshotMojo> output; |
| + GetTraitsTestProxy()->EchoDisplaySnapshotMojo(input->Clone(), &output); |
| + |
| + CheckDisplaySnapShotMojoEqual(*input, *output); |
| +} |
| + |
| } // namespace display |