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" | |
| 14 #include "ui/display/mojo/display_mode_struct_traits.h" | |
|
kylechar
2017/02/13 22:01:24
You shouldn't need to include the StructTraits I d
thanhph1
2017/02/14 20:20:54
I remove display_mode_struct_traits.h. display_str
| |
| 10 #include "ui/display/mojo/display_struct_traits_test.mojom.h" | 15 #include "ui/display/mojo/display_struct_traits_test.mojom.h" |
| 16 #include "ui/display/types/display_constants.h" | |
| 11 #include "ui/display/types/display_mode.h" | 17 #include "ui/display/types/display_mode.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 14 | 20 |
| 15 namespace display { | 21 namespace display { |
| 16 namespace { | 22 namespace { |
| 17 | 23 |
| 18 constexpr int64_t kDisplayId1 = 123; | 24 constexpr int64_t kDisplayId1 = 123; |
| 19 constexpr int64_t kDisplayId2 = 456; | 25 constexpr int64_t kDisplayId2 = 456; |
| 20 constexpr int64_t kDisplayId3 = 789; | 26 constexpr int64_t kDisplayId3 = 789; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 34 void EchoDisplay(const Display& in, | 40 void EchoDisplay(const Display& in, |
| 35 const EchoDisplayCallback& callback) override { | 41 const EchoDisplayCallback& callback) override { |
| 36 callback.Run(in); | 42 callback.Run(in); |
| 37 } | 43 } |
| 38 | 44 |
| 39 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, | 45 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, |
| 40 const EchoDisplayModeCallback& callback) override { | 46 const EchoDisplayModeCallback& callback) override { |
| 41 callback.Run(std::move(in)); | 47 callback.Run(std::move(in)); |
| 42 } | 48 } |
| 43 | 49 |
| 50 void EchoDisplaySnapshotMojo( | |
| 51 std::unique_ptr<DisplaySnapshotMojo> in, | |
| 52 const EchoDisplaySnapshotMojoCallback& callback) override { | |
| 53 callback.Run(std::move(in)); | |
| 54 } | |
| 55 | |
| 44 void EchoDisplayPlacement( | 56 void EchoDisplayPlacement( |
| 45 const DisplayPlacement& in, | 57 const DisplayPlacement& in, |
| 46 const EchoDisplayPlacementCallback& callback) override { | 58 const EchoDisplayPlacementCallback& callback) override { |
| 47 callback.Run(in); | 59 callback.Run(in); |
| 48 } | 60 } |
| 49 | 61 |
| 50 void EchoDisplayLayout(std::unique_ptr<display::DisplayLayout> in, | 62 void EchoDisplayLayout(std::unique_ptr<display::DisplayLayout> in, |
| 51 const EchoDisplayLayoutCallback& callback) override { | 63 const EchoDisplayLayoutCallback& callback) override { |
| 52 callback.Run(std::move(in)); | 64 callback.Run(std::move(in)); |
| 53 } | 65 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); | 113 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); |
| 102 input.set_maximum_cursor_size(maximum_cursor_size); | 114 input.set_maximum_cursor_size(maximum_cursor_size); |
| 103 | 115 |
| 104 Display output; | 116 Display output; |
| 105 GetTraitsTestProxy()->EchoDisplay(input, &output); | 117 GetTraitsTestProxy()->EchoDisplay(input, &output); |
| 106 | 118 |
| 107 CheckDisplaysEqual(input, output); | 119 CheckDisplaysEqual(input, output); |
| 108 } | 120 } |
| 109 | 121 |
| 110 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { | 122 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { |
| 123 // Prepare sample input with random values | |
|
kylechar
2017/02/13 22:01:24
Undo this change?
thanhph1
2017/02/14 20:20:53
Done.
| |
| 111 std::unique_ptr<DisplayMode> input = | 124 std::unique_ptr<DisplayMode> input = |
| 112 base::MakeUnique<DisplayMode>(gfx::Size(1024, 768), true, 61.0); | 125 base::MakeUnique<DisplayMode>(gfx::Size(1024, 768), true, 61.0); |
| 113 | 126 |
| 114 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 127 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 115 std::unique_ptr<DisplayMode> output; | 128 std::unique_ptr<DisplayMode> output; |
| 116 | |
|
kylechar
2017/02/13 22:01:24
Undo this change?
| |
| 117 proxy->EchoDisplayMode(input->Clone(), &output); | 129 proxy->EchoDisplayMode(input->Clone(), &output); |
| 118 | 130 |
| 119 // We want to test each component individually to make sure each data member | 131 // We want to test each component individually to make sure each data member |
| 120 // was correctly serialized and deserialized. | 132 // was correctly serialized and deserialized. |
| 121 EXPECT_EQ(input->size(), output->size()); | 133 EXPECT_EQ(input->size(), output->size()); |
| 122 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); | 134 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); |
| 123 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); | 135 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); |
| 124 } | 136 } |
| 125 | 137 |
| 126 TEST_F(DisplayStructTraitsTest, DisplayPlacementFlushAtTop) { | 138 TEST_F(DisplayStructTraitsTest, DisplayPlacementFlushAtTop) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 input->primary_id = kDisplayId2; | 224 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; | 225 input->mirrored = true; |
| 214 input->default_unified = true; | 226 input->default_unified = true; |
| 215 | 227 |
| 216 std::unique_ptr<DisplayLayout> output; | 228 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); | 229 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 | 230 |
| 219 CheckDisplayLayoutsEqual(*input, *output); | 231 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } | 232 } |
| 221 | 233 |
| 234 TEST_F(DisplayStructTraitsTest, DefaultDisplaySnapshotMojo) { | |
|
kylechar
2017/02/13 22:01:24
This test is pretty massive and doesn't hit all th
thanhph1
2017/02/14 20:20:53
Thanks! I added helper function CheckDisplaySnapSh
| |
| 235 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
| 236 | |
| 237 // prepare sample input with random values | |
| 238 const int64_t display_id = 7; | |
| 239 const gfx::Point origin(3, 12); | |
| 240 const gfx::Size physical_size(15, 29); | |
| 241 const gfx::Size maximum_cursor_size(30, 35); | |
| 242 const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; | |
| 243 const bool is_aspect_preserving_scaling = true; | |
| 244 const bool has_overscan = true; | |
| 245 const bool has_color_correction_matrix = true; | |
| 246 const std::string display_name("whatever display_name"); | |
| 247 const base::FilePath::StringType string_type_path = | |
| 248 FILE_PATH_LITERAL("a/b/c"); | |
| 249 const base::FilePath::StringPieceType string_piece_path(string_type_path); | |
| 250 const base::FilePath sys_path(string_piece_path); | |
| 251 const int64_t product_id = 19; | |
| 252 | |
| 253 const DisplayMode display_mode_1(gfx::Size(11, 12), true, 111.0); | |
| 254 const DisplayMode display_current_mode(gfx::Size(22, 23), true, 222.0); | |
| 255 const DisplayMode display_native_mode(gfx::Size(33, 34), true, 333.0); | |
| 256 const DisplayMode display_mode_2(gfx::Size(44, 45), true, 444.0); | |
| 257 | |
| 258 display::DisplaySnapshot::DisplayModeList modes(4); | |
| 259 modes.push_back(display_mode_1.Clone()); | |
| 260 modes.push_back(display_current_mode.Clone()); | |
| 261 modes.push_back(display_native_mode.Clone()); | |
| 262 modes.push_back(display_mode_2.Clone()); | |
| 263 | |
| 264 const DisplayMode* current_mode = modes[1].get(); | |
| 265 const DisplayMode* native_mode = modes[2].get(); | |
| 266 | |
| 267 display::DisplaySnapshot::DisplayModeList expected_modes(4); | |
| 268 expected_modes.push_back(display_mode_1.Clone()); | |
| 269 expected_modes.push_back(display_current_mode.Clone()); | |
| 270 expected_modes.push_back(display_native_mode.Clone()); | |
| 271 expected_modes.push_back(display_mode_2.Clone()); | |
| 272 | |
| 273 const std::vector<uint8_t> edid = {2, 3, 4, 5}; | |
| 274 | |
| 275 std::unique_ptr<DisplaySnapshotMojo> input = | |
| 276 base::MakeUnique<DisplaySnapshotMojo>( | |
| 277 display_id, origin, physical_size, type, is_aspect_preserving_scaling, | |
| 278 has_overscan, has_color_correction_matrix, display_name, sys_path, | |
| 279 product_id, std::move(modes), edid, current_mode, true, native_mode, | |
| 280 true, maximum_cursor_size); | |
| 281 | |
| 282 std::unique_ptr<DisplaySnapshotMojo> output; | |
| 283 proxy->EchoDisplaySnapshotMojo(std::move(input), &output); | |
| 284 | |
| 285 // We want to test each component individually to make sure each data member | |
| 286 // was correctly serialized and deserialized. | |
| 287 EXPECT_EQ(display_id, output->display_id()); | |
| 288 EXPECT_EQ(origin, output->origin()); | |
| 289 EXPECT_EQ(physical_size, output->physical_size()); | |
| 290 EXPECT_EQ(type, output->type()); | |
| 291 EXPECT_EQ(is_aspect_preserving_scaling, | |
| 292 output->is_aspect_preserving_scaling()); | |
| 293 EXPECT_EQ(has_overscan, output->has_overscan()); | |
| 294 EXPECT_EQ(has_color_correction_matrix, output->has_color_correction_matrix()); | |
| 295 EXPECT_EQ(display_name, output->display_name()); | |
| 296 EXPECT_EQ(sys_path, output->sys_path()); | |
| 297 EXPECT_EQ(product_id, output->product_id()); | |
| 298 EXPECT_EQ(4, (int)output->modes().size()); | |
|
kylechar
2017/02/13 22:01:24
You shouldn't downcast unless you absolutely need
thanhph1
2017/02/14 20:20:53
Thanks, changed to EXPECT_EQ(input.modes().size(),
| |
| 299 | |
| 300 for (int i = 0; i < (int)expected_modes.size(); i++) | |
| 301 EXPECT_EQ(*expected_modes[i].get(), *output->modes()[i].get()); | |
|
kylechar
2017/02/13 22:01:24
unique_ptr defines *, so no need to call .get() fi
thanhph1
2017/02/14 20:20:53
Nice, done!
| |
| 302 | |
| 303 EXPECT_EQ(edid, output->edid()); | |
| 304 EXPECT_EQ(display_current_mode, *output->current_mode()); | |
| 305 EXPECT_EQ(true, output->current_mode_exist()); | |
| 306 EXPECT_EQ(display_native_mode, *output->native_mode()); | |
| 307 EXPECT_EQ(true, output->native_mode_exist()); | |
| 308 EXPECT_EQ(maximum_cursor_size, output->maximum_cursor_size()); | |
| 309 } | |
| 310 | |
| 222 } // namespace display | 311 } // namespace display |
| OLD | NEW |