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/mojo/display_struct_traits_test.mojom.h" | 9 #include "ui/display/mojo/display_struct_traits_test.mojom.h" |
| 10 #include "ui/display/types/display_mode.h" |
10 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
11 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
12 | 13 |
13 namespace display { | 14 namespace display { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class DisplayStructTraitsTest : public testing::Test, | 18 class DisplayStructTraitsTest : public testing::Test, |
18 public mojom::DisplayStructTraitsTest { | 19 public mojom::DisplayStructTraitsTest { |
19 public: | 20 public: |
20 DisplayStructTraitsTest() {} | 21 DisplayStructTraitsTest() {} |
21 | 22 |
22 protected: | 23 protected: |
23 mojom::DisplayStructTraitsTestPtr GetTraitsTestProxy() { | 24 mojom::DisplayStructTraitsTestPtr GetTraitsTestProxy() { |
24 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 25 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
25 } | 26 } |
26 | 27 |
27 private: | 28 private: |
28 // mojom::DisplayStructTraitsTest: | 29 // mojom::DisplayStructTraitsTest: |
29 void EchoDisplay(const Display& in, | 30 void EchoDisplay(const Display& in, |
30 const EchoDisplayCallback& callback) override { | 31 const EchoDisplayCallback& callback) override { |
31 callback.Run(in); | 32 callback.Run(in); |
32 } | 33 } |
33 | 34 |
| 35 void EchoDisplayMode(std::unique_ptr<DisplayMode> in, |
| 36 const EchoDisplayModeCallback& callback) override { |
| 37 callback.Run(std::move(in)); |
| 38 } |
| 39 |
34 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. | 40 base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. |
35 mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; | 41 mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; |
36 | 42 |
37 DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTest); | 43 DISALLOW_COPY_AND_ASSIGN(DisplayStructTraitsTest); |
38 }; | 44 }; |
39 | 45 |
40 void CheckDisplaysEqual(const Display& input, const Display& output) { | 46 void CheckDisplaysEqual(const Display& input, const Display& output) { |
41 EXPECT_NE(&input, &output); // Make sure they aren't the same object. | 47 EXPECT_NE(&input, &output); // Make sure they aren't the same object. |
42 EXPECT_EQ(input.id(), output.id()); | 48 EXPECT_EQ(input.id(), output.id()); |
43 EXPECT_EQ(input.bounds(), output.bounds()); | 49 EXPECT_EQ(input.bounds(), output.bounds()); |
(...skipping 28 matching lines...) Expand all Loading... |
72 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); | 78 input.set_touch_support(Display::TOUCH_SUPPORT_AVAILABLE); |
73 input.set_maximum_cursor_size(maximum_cursor_size); | 79 input.set_maximum_cursor_size(maximum_cursor_size); |
74 | 80 |
75 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); | 81 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
76 Display output; | 82 Display output; |
77 proxy->EchoDisplay(input, &output); | 83 proxy->EchoDisplay(input, &output); |
78 | 84 |
79 CheckDisplaysEqual(input, output); | 85 CheckDisplaysEqual(input, output); |
80 } | 86 } |
81 | 87 |
| 88 TEST_F(DisplayStructTraitsTest, DefaultDisplayMode) { |
| 89 // Prepare sample input with random values |
| 90 |
| 91 std::unique_ptr<DisplayMode> input = |
| 92 base::MakeUnique<DisplayMode>(gfx::Size(15, 29), true, 61.0); |
| 93 |
| 94 mojom::DisplayStructTraitsTestPtr proxy = GetTraitsTestProxy(); |
| 95 std::unique_ptr<DisplayMode> output; |
| 96 |
| 97 proxy->EchoDisplayMode(input->Clone(), &output); |
| 98 |
| 99 // We want to test each component individually to make sure each data member |
| 100 // was correctly serialized and deserialized. |
| 101 EXPECT_EQ(input->size(), output->size()); |
| 102 EXPECT_EQ(input->is_interlaced(), output->is_interlaced()); |
| 103 EXPECT_EQ(input->refresh_rate(), output->refresh_rate()); |
| 104 } |
| 105 |
82 } // namespace display | 106 } // namespace display |
OLD | NEW |