| 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 |
| 5 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" | 8 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
| 9 #include "ui/display/display_layout.h" | 11 #include "ui/display/display_layout.h" |
| 12 #include "ui/display/mojo/display_mode_struct_traits.h" |
| 13 #include "ui/display/mojo/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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); | 112 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); |
| 102 input.set_maximum_cursor_size(maximum_cursor_size); | 113 input.set_maximum_cursor_size(maximum_cursor_size); |
| 103 | 114 |
| 104 Display output; | 115 Display output; |
| 105 GetTraitsTestProxy()->EchoDisplay(input, &output); | 116 GetTraitsTestProxy()->EchoDisplay(input, &output); |
| 106 | 117 |
| 107 CheckDisplaysEqual(input, output); | 118 CheckDisplaysEqual(input, output); |
| 108 } | 119 } |
| 109 | 120 |
| 110 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { | 121 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { |
| 122 // Prepare sample input with random values |
| 111 std::unique_ptr<DisplayMode> input = | 123 std::unique_ptr<DisplayMode> input = |
| 112 base::MakeUnique<DisplayMode>(gfx::Size(1024, 768), true, 61.0); | 124 base::MakeUnique<DisplayMode>(gfx::Size(1024, 768), true, 61.0); |
| 113 | 125 |
| 114 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 126 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 115 std::unique_ptr<DisplayMode> output; | 127 std::unique_ptr<DisplayMode> output; |
| 116 | |
| 117 proxy->EchoDisplayMode(input->Clone(), &output); | 128 proxy->EchoDisplayMode(input->Clone(), &output); |
| 118 | 129 |
| 119 // We want to test each component individually to make sure each data member | 130 // We want to test each component individually to make sure each data member |
| 120 // was correctly serialized and deserialized. | 131 // was correctly serialized and deserialized. |
| 121 EXPECT_EQ(input->size(), output->size()); | 132 EXPECT_EQ(input->size(), output->size()); |
| 122 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); | 133 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); |
| 123 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); | 134 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); |
| 124 } | 135 } |
| 125 | 136 |
| 126 TEST_F(DisplayStructTraitsTest, DisplayPlacementFlushAtTop) { | 137 TEST_F(DisplayStructTraitsTest, DisplayPlacementFlushAtTop) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 input->primary_id = kDisplayId2; | 223 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; | 224 input->mirrored = true; |
| 214 input->default_unified = true; | 225 input->default_unified = true; |
| 215 | 226 |
| 216 std::unique_ptr<DisplayLayout> output; | 227 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); | 228 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 | 229 |
| 219 CheckDisplayLayoutsEqual(*input, *output); | 230 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } | 231 } |
| 221 | 232 |
| 233 static bool compareDisplayMode(const DisplayMode& display_mode_a, |
| 234 const DisplayMode& display_mode_b) { |
| 235 if ((display_mode_a.size() != display_mode_b.size()) || |
| 236 (display_mode_a.is_interlaced() != display_mode_b.is_interlaced()) || |
| 237 (display_mode_a.refresh_rate() != display_mode_b.refresh_rate())) |
| 238 return false; |
| 239 return true; |
| 240 } |
| 241 |
| 242 TEST_F(DisplayStructTraitsTest, DefaultDisplaySnapshotMojo) { |
| 243 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 244 |
| 245 // prepare sample input with random values |
| 246 int64_t display_id = 7; |
| 247 const gfx::Point origin(3, 12); |
| 248 const gfx::Size physical_size(15, 29); |
| 249 DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; |
| 250 bool is_aspect_preserving_scaling = true; |
| 251 bool has_overscan = true; |
| 252 bool has_color_correction_matrix = true; |
| 253 std::string display_name("whatever display_name"); |
| 254 |
| 255 base::FilePath::StringType string_type_path = FILE_PATH_LITERAL("a/b/c"); |
| 256 const base::FilePath::StringPieceType string_piece_path(string_type_path); |
| 257 const base::FilePath sys_path(string_piece_path); |
| 258 |
| 259 int64_t product_id = 19; |
| 260 |
| 261 DisplayMode display_mode_1(gfx::Size(11, 12), true, 111.0); |
| 262 DisplayMode display_current_mode(gfx::Size(22, 23), true, 222.0); |
| 263 DisplayMode display_native_mode(gfx::Size(33, 34), true, 333.0); |
| 264 DisplayMode display_mode_2(gfx::Size(44, 45), true, 444.0); |
| 265 |
| 266 display::DisplaySnapshot::DisplayModeList modes; |
| 267 modes.reserve(4); |
| 268 modes.push_back(display_mode_1.Clone()); |
| 269 modes.push_back(display_current_mode.Clone()); |
| 270 modes.push_back(display_native_mode.Clone()); |
| 271 modes.push_back(display_mode_2.Clone()); |
| 272 |
| 273 const DisplayMode* current_mode = modes[1].get(); |
| 274 const DisplayMode* native_mode = modes[2].get(); |
| 275 |
| 276 display::DisplaySnapshot::DisplayModeList expected_modes; |
| 277 expected_modes.reserve(4); |
| 278 expected_modes.push_back(display_mode_1.Clone()); |
| 279 expected_modes.push_back(display_current_mode.Clone()); |
| 280 expected_modes.push_back(display_native_mode.Clone()); |
| 281 expected_modes.push_back(display_mode_2.Clone()); |
| 282 |
| 283 const std::vector<uint8_t> edid{1, 2, 4, 5}; |
| 284 std::unique_ptr<DisplaySnapshotMojo> input = |
| 285 base::MakeUnique<DisplaySnapshotMojo>( |
| 286 display_id, origin, physical_size, type, is_aspect_preserving_scaling, |
| 287 has_overscan, has_color_correction_matrix, display_name, sys_path, |
| 288 product_id, std::move(modes), edid, current_mode, native_mode); |
| 289 std::unique_ptr<DisplaySnapshotMojo> output; |
| 290 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); |
| 291 |
| 292 // We want to test each component individually to make sure each data member |
| 293 // was correctly serialized and deserialized. |
| 294 EXPECT_EQ(display_id, output->display_id()); |
| 295 EXPECT_EQ(origin, output->origin()); |
| 296 EXPECT_EQ(physical_size, output->physical_size()); |
| 297 EXPECT_EQ(type, output->type()); |
| 298 EXPECT_EQ(is_aspect_preserving_scaling, |
| 299 output->is_aspect_preserving_scaling()); |
| 300 EXPECT_EQ(has_overscan, output->has_overscan()); |
| 301 EXPECT_EQ(has_color_correction_matrix, output->has_color_correction_matrix()); |
| 302 EXPECT_EQ(display_name, output->display_name()); |
| 303 EXPECT_EQ(sys_path, output->sys_path()); |
| 304 EXPECT_EQ(product_id, output->product_id()); |
| 305 |
| 306 EXPECT_EQ(4, (int)output->modes().size()); |
| 307 for (int i = 0; i < (int)expected_modes.size(); i++) { |
| 308 EXPECT_EQ(true, compareDisplayMode(*expected_modes[i].get(), |
| 309 *output->modes()[i].get())); |
| 310 } |
| 311 EXPECT_EQ(edid, output->edid()); |
| 312 EXPECT_EQ(true, |
| 313 compareDisplayMode(display_current_mode, *output->current_mode())); |
| 314 EXPECT_EQ(true, |
| 315 compareDisplayMode(display_native_mode, *output->native_mode())); |
| 316 } |
| 317 |
| 222 } // namespace display | 318 } // namespace display |
| OLD | NEW |