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/gfx/mojo/traits_test_service.mojom.h" | 8 #include "ui/gfx/mojo/traits_test_service.mojom.h" |
| 9 #include "ui/gfx/selection_bound.h" |
9 #include "ui/gfx/transform.h" | 10 #include "ui/gfx/transform.h" |
10 | 11 |
11 namespace gfx { | 12 namespace gfx { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | 16 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { |
16 public: | 17 public: |
17 StructTraitsTest() {} | 18 StructTraitsTest() {} |
18 | 19 |
19 protected: | 20 protected: |
20 mojom::TraitsTestServicePtr GetTraitsTestProxy() { | 21 mojom::TraitsTestServicePtr GetTraitsTestProxy() { |
21 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 22 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
22 } | 23 } |
23 | 24 |
24 private: | 25 private: |
25 // TraitsTestService: | 26 // TraitsTestService: |
| 27 void EchoSelectionBound(const SelectionBound& s, |
| 28 const EchoSelectionBoundCallback& callback) override { |
| 29 callback.Run(s); |
| 30 } |
| 31 |
26 void EchoTransform(const Transform& t, | 32 void EchoTransform(const Transform& t, |
27 const EchoTransformCallback& callback) override { | 33 const EchoTransformCallback& callback) override { |
28 callback.Run(t); | 34 callback.Run(t); |
29 } | 35 } |
30 | 36 |
31 base::MessageLoop loop_; | 37 base::MessageLoop loop_; |
32 mojo::BindingSet<TraitsTestService> traits_test_bindings_; | 38 mojo::BindingSet<TraitsTestService> traits_test_bindings_; |
33 | 39 |
34 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); | 40 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); |
35 }; | 41 }; |
36 | 42 |
37 } // namespace | 43 } // namespace |
38 | 44 |
| 45 TEST_F(StructTraitsTest, SelectionBound) { |
| 46 const gfx::SelectionBound::Type type = gfx::SelectionBound::CENTER; |
| 47 const gfx::PointF edge_top(1234.5f, 5678.6f); |
| 48 const gfx::PointF edge_bottom(910112.5f, 13141516.6f); |
| 49 const bool visible = true; |
| 50 gfx::SelectionBound input; |
| 51 input.set_type(type); |
| 52 input.SetEdge(edge_top, edge_bottom); |
| 53 input.set_visible(visible); |
| 54 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 55 gfx::SelectionBound output; |
| 56 proxy->EchoSelectionBound(input, &output); |
| 57 EXPECT_EQ(type, output.type()); |
| 58 EXPECT_EQ(edge_top, output.edge_top()); |
| 59 EXPECT_EQ(edge_bottom, output.edge_bottom()); |
| 60 EXPECT_EQ(input.edge_top_rounded(), output.edge_top_rounded()); |
| 61 EXPECT_EQ(input.edge_bottom_rounded(), output.edge_bottom_rounded()); |
| 62 EXPECT_EQ(visible, output.visible()); |
| 63 } |
| 64 |
39 TEST_F(StructTraitsTest, Transform) { | 65 TEST_F(StructTraitsTest, Transform) { |
40 const float col1row1 = 1.f; | 66 const float col1row1 = 1.f; |
41 const float col2row1 = 2.f; | 67 const float col2row1 = 2.f; |
42 const float col3row1 = 3.f; | 68 const float col3row1 = 3.f; |
43 const float col4row1 = 4.f; | 69 const float col4row1 = 4.f; |
44 const float col1row2 = 5.f; | 70 const float col1row2 = 5.f; |
45 const float col2row2 = 6.f; | 71 const float col2row2 = 6.f; |
46 const float col3row2 = 7.f; | 72 const float col3row2 = 7.f; |
47 const float col4row2 = 8.f; | 73 const float col4row2 = 8.f; |
48 const float col1row3 = 9.f; | 74 const float col1row3 = 9.f; |
(...skipping 23 matching lines...) Expand all Loading... |
72 EXPECT_EQ(col2row3, output.matrix().get(2, 1)); | 98 EXPECT_EQ(col2row3, output.matrix().get(2, 1)); |
73 EXPECT_EQ(col3row3, output.matrix().get(2, 2)); | 99 EXPECT_EQ(col3row3, output.matrix().get(2, 2)); |
74 EXPECT_EQ(col4row3, output.matrix().get(2, 3)); | 100 EXPECT_EQ(col4row3, output.matrix().get(2, 3)); |
75 EXPECT_EQ(col1row4, output.matrix().get(3, 0)); | 101 EXPECT_EQ(col1row4, output.matrix().get(3, 0)); |
76 EXPECT_EQ(col2row4, output.matrix().get(3, 1)); | 102 EXPECT_EQ(col2row4, output.matrix().get(3, 1)); |
77 EXPECT_EQ(col3row4, output.matrix().get(3, 2)); | 103 EXPECT_EQ(col3row4, output.matrix().get(3, 2)); |
78 EXPECT_EQ(col4row4, output.matrix().get(3, 3)); | 104 EXPECT_EQ(col4row4, output.matrix().get(3, 3)); |
79 } | 105 } |
80 | 106 |
81 } // namespace gfx | 107 } // namespace gfx |
OLD | NEW |