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