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