| 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 e2c3979e367893914af7392798829d9b2c560690..bc3060868b8ca1f727c1060d8e79fe3b9df02051 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/display/types/gamma_ramp_rgb_entry.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| @@ -42,6 +47,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 {
|
| @@ -85,6 +96,49 @@ void CheckDisplayLayoutsEqual(const DisplayLayout& input,
|
| EXPECT_EQ(input.primary_id, output.primary_id);
|
| }
|
|
|
| +bool CompareModes(const DisplayMode& lhs, const DisplayMode& rhs) {
|
| + return lhs.size() == rhs.size() &&
|
| + lhs.is_interlaced() == rhs.is_interlaced() &&
|
| + lhs.refresh_rate() == rhs.refresh_rate();
|
| +}
|
| +
|
| +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_TRUE(CompareModes(*input.modes()[i], *output.modes()[i]));
|
| +
|
| + EXPECT_EQ(input.edid(), output.edid());
|
| +
|
| + if (!input.current_mode())
|
| + EXPECT_EQ(nullptr, output.current_mode());
|
| + else
|
| + EXPECT_TRUE(CompareModes(*input.current_mode(), *output.current_mode()));
|
| +
|
| + if (!input.native_mode())
|
| + EXPECT_EQ(nullptr, output.native_mode());
|
| + else
|
| + EXPECT_TRUE(CompareModes(*input.native_mode(), *output.native_mode()));
|
| +
|
| + EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size());
|
| +}
|
| +
|
| } // namespace
|
|
|
| TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) {
|
| @@ -237,4 +291,156 @@ TEST_F(DisplayStructTraitsTest, BasicGammaRampRGBEntry) {
|
| EXPECT_EQ(input.b, output.b);
|
| }
|
|
|
| -} // namespace display
|
| +// One display mode, current and native mode nullptr.
|
| +TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentAndNativeModesNull) {
|
| + // 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 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 from external display.
|
| + 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.0f);
|
| + 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 from Pixel's internal display.
|
| + 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
|
|
|