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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "mojo/public/cpp/bindings/binding_set.h" | 6 #include "mojo/public/cpp/bindings/binding_set.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/display/display.h" | 8 #include "ui/display/display.h" |
| 9 #include "ui/display/display_layout.h" |
9 #include "ui/display/mojo/display_struct_traits_test.mojom.h" | 10 #include "ui/display/mojo/display_struct_traits_test.mojom.h" |
10 #include "ui/display/types/display_mode.h" | 11 #include "ui/display/types/display_mode.h" |
11 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
13 | 14 |
14 namespace display { | 15 namespace display { |
| 16 namespace { |
15 | 17 |
16 namespace { | 18 constexpr int64_t kDisplayId1 = 123; |
| 19 constexpr int64_t kDisplayId2 = 456; |
| 20 constexpr int64_t kDisplayId3 = 789; |
17 | 21 |
18 class DisplayStructTraitsTest : public testing::Test, | 22 class DisplayStructTraitsTest : public testing::Test, |
19 public mojom::DisplayStructTraitsTest { | 23 public mojom::DisplayStructTraitsTest { |
20 public: | 24 public: |
21 DisplayStructTraitsTest() {} | 25 DisplayStructTraitsTest() {} |
22 | 26 |
23 protected: | 27 protected: |
24 mojom::DisplayStructTraitsTestPtr GetTraitsTestProxy() { | 28 mojom::DisplayStructTraitsTestPtr GetTraitsTestProxy() { |
25 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 29 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
26 } | 30 } |
27 | 31 |
28 private: | 32 private: |
29 // mojom::DisplayStructTraitsTest: | 33 // mojom::DisplayStructTraitsTest: |
30 void EchoDisplay(const Display& in, | 34 void EchoDisplay(const Display& in, |
31 const EchoDisplayCallback& callback) override { | 35 const EchoDisplayCallback& callback) override { |
32 callback.Run(in); | 36 callback.Run(in); |
33 } | 37 } |
34 | 38 |
35 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, | 39 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, |
36 const EchoDisplayModeCallback& callback) override { | 40 const EchoDisplayModeCallback& callback) override { |
37 callback.Run(std::move(in)); | 41 callback.Run(std::move(in)); |
38 } | 42 } |
39 | 43 |
| 44 void EchoDisplayPlacement( |
| 45 const DisplayPlacement& in, |
| 46 const EchoDisplayPlacementCallback& callback) override { |
| 47 callback.Run(in); |
| 48 } |
| 49 |
| 50 void EchoDisplayLayout(std::unique_ptr<display::DisplayLayout> in, |
| 51 const EchoDisplayLayoutCallback& callback) override { |
| 52 callback.Run(std::move(in)); |
| 53 } |
| 54 |
40 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. | 55 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. |
41 mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; | 56 mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; |
42 | 57 |
43 DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTest); | 58 DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTest); |
44 }; | 59 }; |
45 | 60 |
46 void CheckDisplaysEqual(const Display& input, const Display& output) { | 61 void CheckDisplaysEqual(const Display& input, const Display& output) { |
47 EXPECT_NE(&input, &output); // Make sure they aren't the same object. | 62 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
48 EXPECT_EQ(input.id(), output.id()); | 63 EXPECT_EQ(input.id(), output.id()); |
49 EXPECT_EQ(input.bounds(), output.bounds()); | 64 EXPECT_EQ(input.bounds(), output.bounds()); |
50 EXPECT_EQ(input.work_area(), output.work_area()); | 65 EXPECT_EQ(input.work_area(), output.work_area()); |
51 EXPECT_EQ(input.device_scale_factor(), output.device_scale_factor()); | 66 EXPECT_EQ(input.device_scale_factor(), output.device_scale_factor()); |
52 EXPECT_EQ(input.rotation(), output.rotation()); | 67 EXPECT_EQ(input.rotation(), output.rotation()); |
53 EXPECT_EQ(input.touch_support(), output.touch_support()); | 68 EXPECT_EQ(input.touch_support(), output.touch_support()); |
54 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); | 69 EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); |
55 } | 70 } |
56 | 71 |
| 72 void CheckDisplayLayoutsEqual(const DisplayLayout& input, |
| 73 const DisplayLayout& output) { |
| 74 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
| 75 EXPECT_EQ(input.placement_list, output.placement_list); |
| 76 EXPECT_EQ(input.mirrored, output.mirrored); |
| 77 EXPECT_EQ(input.default_unified, output.default_unified); |
| 78 EXPECT_EQ(input.primary_id, output.primary_id); |
| 79 } |
| 80 |
57 } // namespace | 81 } // namespace |
58 | 82 |
59 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { | 83 TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { |
60 Display input(5); | 84 Display input(5); |
61 | 85 |
62 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
63 Display output; | 86 Display output; |
64 proxy->EchoDisplay(input, &output); | 87 GetTraitsTestProxy()->EchoDisplay(input, &output); |
65 | 88 |
66 CheckDisplaysEqual(input, output); | 89 CheckDisplaysEqual(input, output); |
67 } | 90 } |
68 | 91 |
69 TEST_F(DisplayStructTraitsTest, SetAllDisplayValues) { | 92 TEST_F(DisplayStructTraitsTest, SetAllDisplayValues) { |
70 const gfx::Rect bounds(100, 200, 500, 600); | 93 const gfx::Rect bounds(100, 200, 500, 600); |
71 const gfx::Rect work_area(150, 250, 400, 500); | 94 const gfx::Rect work_area(150, 250, 400, 500); |
72 const gfx::Size maximum_cursor_size(64, 64); | 95 const gfx::Size maximum_cursor_size(64, 64); |
73 | 96 |
74 Display input(246345234, bounds); | 97 Display input(246345234, bounds); |
75 input.set_work_area(work_area); | 98 input.set_work_area(work_area); |
76 input.set_device_scale_factor(2.0f); | 99 input.set_device_scale_factor(2.0f); |
77 input.set_rotation(Display::ROTATE_270); | 100 input.set_rotation(Display::ROTATE_270); |
78 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); | 101 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); |
79 input.set_maximum_cursor_size(maximum_cursor_size); | 102 input.set_maximum_cursor_size(maximum_cursor_size); |
80 | 103 |
81 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | |
82 Display output; | 104 Display output; |
83 proxy->EchoDisplay(input, &output); | 105 GetTraitsTestProxy()->EchoDisplay(input, &output); |
84 | 106 |
85 CheckDisplaysEqual(input, output); | 107 CheckDisplaysEqual(input, output); |
86 } | 108 } |
87 | 109 |
88 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { | 110 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { |
89 // Prepare sample input with random values | |
90 | |
91 std::unique_ptr<DisplayMode> input = | 111 std::unique_ptr<DisplayMode> input = |
92 base::MakeUnique<DisplayMode>(gfx::Size(15, 29), true, 61.0); | 112 base::MakeUnique<DisplayMode>(gfx::Size(1024, 768), true, 61.0); |
93 | 113 |
94 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 114 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
95 std::unique_ptr<DisplayMode> output; | 115 std::unique_ptr<DisplayMode> output; |
96 | 116 |
97 proxy->EchoDisplayMode(input->Clone(), &output); | 117 proxy->EchoDisplayMode(input->Clone(), &output); |
98 | 118 |
99 // We want to test each component individually to make sure each data member | 119 // We want to test each component individually to make sure each data member |
100 // was correctly serialized and deserialized. | 120 // was correctly serialized and deserialized. |
101 EXPECT_EQ(input->size(), output->size()); | 121 EXPECT_EQ(input->size(), output->size()); |
102 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); | 122 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); |
103 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); | 123 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); |
104 } | 124 } |
105 | 125 |
| 126 TEST_F(DisplayStructTraitsTest, DisplayPlacementFlushAtTop) { |
| 127 DisplayPlacement input; |
| 128 input.display_id = kDisplayId1; |
| 129 input.parent_display_id = kDisplayId2; |
| 130 input.position = DisplayPlacement::TOP; |
| 131 input.offset = 0; |
| 132 input.offset_reference = DisplayPlacement::TOP_LEFT; |
| 133 |
| 134 DisplayPlacement output; |
| 135 GetTraitsTestProxy()->EchoDisplayPlacement(input, &output); |
| 136 |
| 137 EXPECT_EQ(input, output); |
| 138 } |
| 139 |
| 140 TEST_F(DisplayStructTraitsTest, DisplayPlacementWithOffset) { |
| 141 DisplayPlacement input; |
| 142 input.display_id = kDisplayId1; |
| 143 input.parent_display_id = kDisplayId2; |
| 144 input.position = DisplayPlacement::BOTTOM; |
| 145 input.offset = -100; |
| 146 input.offset_reference = DisplayPlacement::BOTTOM_RIGHT; |
| 147 |
| 148 DisplayPlacement output; |
| 149 GetTraitsTestProxy()->EchoDisplayPlacement(input, &output); |
| 150 |
| 151 EXPECT_EQ(input, output); |
| 152 } |
| 153 |
| 154 TEST_F(DisplayStructTraitsTest, DisplayLayoutTwoExtended) { |
| 155 DisplayPlacement placement; |
| 156 placement.display_id = kDisplayId1; |
| 157 placement.parent_display_id = kDisplayId2; |
| 158 placement.position = DisplayPlacement::RIGHT; |
| 159 placement.offset = 0; |
| 160 placement.offset_reference = DisplayPlacement::TOP_LEFT; |
| 161 |
| 162 auto input = base::MakeUnique<DisplayLayout>(); |
| 163 input->placement_list.push_back(placement); |
| 164 input->primary_id = kDisplayId2; |
| 165 input->mirrored = false; |
| 166 input->default_unified = true; |
| 167 |
| 168 std::unique_ptr<DisplayLayout> output; |
| 169 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 170 |
| 171 CheckDisplayLayoutsEqual(*input, *output); |
| 172 } |
| 173 |
| 174 TEST_F(DisplayStructTraitsTest, DisplayLayoutThreeExtended) { |
| 175 DisplayPlacement placement1; |
| 176 placement1.display_id = kDisplayId2; |
| 177 placement1.parent_display_id = kDisplayId1; |
| 178 placement1.position = DisplayPlacement::LEFT; |
| 179 placement1.offset = 0; |
| 180 placement1.offset_reference = DisplayPlacement::TOP_LEFT; |
| 181 |
| 182 DisplayPlacement placement2; |
| 183 placement2.display_id = kDisplayId3; |
| 184 placement2.parent_display_id = kDisplayId1; |
| 185 placement2.position = DisplayPlacement::RIGHT; |
| 186 placement2.offset = -100; |
| 187 placement2.offset_reference = DisplayPlacement::BOTTOM_RIGHT; |
| 188 |
| 189 auto input = base::MakeUnique<DisplayLayout>(); |
| 190 input->placement_list.push_back(placement1); |
| 191 input->placement_list.push_back(placement2); |
| 192 input->primary_id = kDisplayId1; |
| 193 input->mirrored = false; |
| 194 input->default_unified = false; |
| 195 |
| 196 std::unique_ptr<DisplayLayout> output; |
| 197 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 198 |
| 199 CheckDisplayLayoutsEqual(*input, *output); |
| 200 } |
| 201 |
| 202 TEST_F(DisplayStructTraitsTest, DisplayLayoutTwoMirrored) { |
| 203 DisplayPlacement placement; |
| 204 placement.display_id = kDisplayId1; |
| 205 placement.parent_display_id = kDisplayId2; |
| 206 placement.position = DisplayPlacement::RIGHT; |
| 207 placement.offset = 0; |
| 208 placement.offset_reference = DisplayPlacement::TOP_LEFT; |
| 209 |
| 210 auto input = base::MakeUnique<DisplayLayout>(); |
| 211 input->placement_list.push_back(placement); |
| 212 input->primary_id = kDisplayId2; |
| 213 input->mirrored = true; |
| 214 input->default_unified = true; |
| 215 |
| 216 std::unique_ptr<DisplayLayout> output; |
| 217 GetTraitsTestProxy()->EchoDisplayLayout(input->Copy(), &output); |
| 218 |
| 219 CheckDisplayLayoutsEqual(*input, *output); |
| 220 } |
| 221 |
106 } // namespace display | 222 } // namespace display |
OLD | NEW |