| 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/events/mojo/traits_test_service.mojom.h" | 8 #include "ui/events/mojo/traits_test_service.mojom.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | 14 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { |
| 15 public: | 15 public: |
| 16 StructTraitsTest() {} | 16 StructTraitsTest() {} |
| 17 | 17 |
| 18 protected: | 18 protected: |
| 19 mojom::TraitsTestServicePtr GetTraitsTestProxy() { | 19 mojom::TraitsTestServicePtr GetTraitsTestProxy() { |
| 20 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 20 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
| 21 } | 21 } |
| 22 | 22 |
| 23 private: | 23 private: |
| 24 // TraitsTestService: | 24 // TraitsTestService: |
| 25 void EchoInputCoordinate( |
| 26 const LatencyInfo::InputCoordinate& i, |
| 27 const EchoInputCoordinateCallback& callback) override { |
| 28 callback.Run(i); |
| 29 } |
| 30 |
| 25 void EchoLatencyComponent( | 31 void EchoLatencyComponent( |
| 26 const LatencyInfo::LatencyComponent& l, | 32 const LatencyInfo::LatencyComponent& l, |
| 27 const EchoLatencyComponentCallback& callback) override { | 33 const EchoLatencyComponentCallback& callback) override { |
| 28 callback.Run(l); | 34 callback.Run(l); |
| 29 } | 35 } |
| 30 | 36 |
| 31 void EchoLatencyComponentId( | 37 void EchoLatencyComponentId( |
| 32 const std::pair<LatencyComponentType, int64_t>& id, | 38 const std::pair<LatencyComponentType, int64_t>& id, |
| 33 const EchoLatencyComponentIdCallback& callback) override { | 39 const EchoLatencyComponentIdCallback& callback) override { |
| 34 callback.Run(id); | 40 callback.Run(id); |
| 35 } | 41 } |
| 36 | 42 |
| 37 void EchoLatencyInfo(const LatencyInfo& info, | 43 void EchoLatencyInfo(const LatencyInfo& info, |
| 38 const EchoLatencyInfoCallback& callback) override { | 44 const EchoLatencyInfoCallback& callback) override { |
| 39 callback.Run(info); | 45 callback.Run(info); |
| 40 } | 46 } |
| 41 | 47 |
| 42 base::MessageLoop loop_; | 48 base::MessageLoop loop_; |
| 43 mojo::BindingSet<TraitsTestService> traits_test_bindings_; | 49 mojo::BindingSet<TraitsTestService> traits_test_bindings_; |
| 44 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); | 50 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); |
| 45 }; | 51 }; |
| 46 | 52 |
| 47 } // namespace | 53 } // namespace |
| 48 | 54 |
| 55 TEST_F(StructTraitsTest, InputCoordinate) { |
| 56 const float x = 1337.5f; |
| 57 const float y = 7331.6f; |
| 58 LatencyInfo::InputCoordinate input(x, y); |
| 59 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 60 LatencyInfo::InputCoordinate output; |
| 61 proxy->EchoInputCoordinate(input, &output); |
| 62 EXPECT_EQ(x, output.x); |
| 63 EXPECT_EQ(y, output.y); |
| 64 } |
| 65 |
| 49 TEST_F(StructTraitsTest, LatencyComponent) { | 66 TEST_F(StructTraitsTest, LatencyComponent) { |
| 50 const int64_t sequence_number = 13371337; | 67 const int64_t sequence_number = 13371337; |
| 51 const base::TimeTicks event_time = base::TimeTicks::Now(); | 68 const base::TimeTicks event_time = base::TimeTicks::Now(); |
| 52 const uint32_t event_count = 1234; | 69 const uint32_t event_count = 1234; |
| 53 LatencyInfo::LatencyComponent input; | 70 LatencyInfo::LatencyComponent input; |
| 54 input.sequence_number = sequence_number; | 71 input.sequence_number = sequence_number; |
| 55 input.event_time = event_time; | 72 input.event_time = event_time; |
| 56 input.event_count = event_count; | 73 input.event_count = event_count; |
| 57 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 74 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 58 LatencyInfo::LatencyComponent output; | 75 LatencyInfo::LatencyComponent output; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 } | 92 } |
| 76 | 93 |
| 77 TEST_F(StructTraitsTest, LatencyInfo) { | 94 TEST_F(StructTraitsTest, LatencyInfo) { |
| 78 LatencyInfo latency; | 95 LatencyInfo latency; |
| 79 ASSERT_FALSE(latency.terminated()); | 96 ASSERT_FALSE(latency.terminated()); |
| 80 ASSERT_EQ(0u, latency.input_coordinates_size()); | 97 ASSERT_EQ(0u, latency.input_coordinates_size()); |
| 81 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); | 98 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); |
| 82 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); | 99 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); |
| 83 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, | 100 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, |
| 84 1234, 0); | 101 1234, 0); |
| 85 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(100, 200))); | 102 EXPECT_TRUE( |
| 86 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(101, 201))); | 103 latency.AddInputCoordinate(LatencyInfo::InputCoordinate(100, 200))); |
| 104 EXPECT_TRUE( |
| 105 latency.AddInputCoordinate(LatencyInfo::InputCoordinate(101, 201))); |
| 87 // Up to 2 InputCoordinate is allowed. | 106 // Up to 2 InputCoordinate is allowed. |
| 88 EXPECT_FALSE(latency.AddInputCoordinate(gfx::PointF(102, 202))); | 107 EXPECT_FALSE( |
| 108 latency.AddInputCoordinate(LatencyInfo::InputCoordinate(102, 202))); |
| 89 | 109 |
| 90 EXPECT_EQ(100, latency.trace_id()); | 110 EXPECT_EQ(100, latency.trace_id()); |
| 91 EXPECT_TRUE(latency.terminated()); | 111 EXPECT_TRUE(latency.terminated()); |
| 92 EXPECT_EQ(2u, latency.input_coordinates_size()); | 112 EXPECT_EQ(2u, latency.input_coordinates_size()); |
| 93 | 113 |
| 94 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 114 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 95 LatencyInfo output; | 115 LatencyInfo output; |
| 96 proxy->EchoLatencyInfo(latency, &output); | 116 proxy->EchoLatencyInfo(latency, &output); |
| 97 | 117 |
| 98 EXPECT_EQ(latency.trace_id(), output.trace_id()); | 118 EXPECT_EQ(latency.trace_id(), output.trace_id()); |
| 99 EXPECT_EQ(latency.terminated(), output.terminated()); | 119 EXPECT_EQ(latency.terminated(), output.terminated()); |
| 100 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size()); | 120 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size()); |
| 101 for (size_t i = 0; i < latency.input_coordinates_size(); i++) { | 121 for (size_t i = 0; i < latency.input_coordinates_size(); i++) { |
| 102 EXPECT_EQ(latency.input_coordinates()[i].x(), | 122 EXPECT_EQ(latency.input_coordinates()[i].x, |
| 103 output.input_coordinates()[i].x()); | 123 output.input_coordinates()[i].x); |
| 104 EXPECT_EQ(latency.input_coordinates()[i].y(), | 124 EXPECT_EQ(latency.input_coordinates()[i].y, |
| 105 output.input_coordinates()[i].y()); | 125 output.input_coordinates()[i].y); |
| 106 } | 126 } |
| 107 | 127 |
| 108 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, | 128 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, |
| 109 nullptr)); | 129 nullptr)); |
| 110 | 130 |
| 111 LatencyInfo::LatencyComponent rwh_comp; | 131 LatencyInfo::LatencyComponent rwh_comp; |
| 112 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, | 132 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, |
| 113 &rwh_comp)); | 133 &rwh_comp)); |
| 114 EXPECT_EQ(100, rwh_comp.sequence_number); | 134 EXPECT_EQ(100, rwh_comp.sequence_number); |
| 115 EXPECT_EQ(1u, rwh_comp.event_count); | 135 EXPECT_EQ(1u, rwh_comp.event_count); |
| 116 | 136 |
| 117 EXPECT_TRUE(output.FindLatency( | 137 EXPECT_TRUE(output.FindLatency( |
| 118 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); | 138 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); |
| 119 } | 139 } |
| 120 | 140 |
| 121 } // namespace ui | 141 } // namespace ui |
| OLD | NEW |