OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "ipc/ipc_message_macros.h" | 8 #include "ipc/ipc_message_macros.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/ipc/geometry/gfx_param_traits.h" | 10 #include "ui/gfx/ipc/geometry/gfx_param_traits.h" |
11 #include "ui/latency/ipc/latency_info_param_traits.h" | 11 #include "ui/latency/ipc/latency_info_param_traits.h" |
12 #include "ui/latency/ipc/latency_info_param_traits_macros.h" | 12 #include "ui/latency/ipc/latency_info_param_traits_macros.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 TEST(LatencyInfoParamTraitsTest, Basic) { | 16 TEST(LatencyInfoParamTraitsTest, Basic) { |
17 LatencyInfo latency; | 17 LatencyInfo latency; |
18 ASSERT_FALSE(latency.terminated()); | 18 ASSERT_FALSE(latency.terminated()); |
19 ASSERT_EQ(0u, latency.input_coordinates_size()); | |
20 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); | 19 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); |
21 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); | 20 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); |
22 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, | 21 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, |
23 1234, 0); | 22 1234, 0); |
24 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(100, 200))); | |
25 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(101, 201))); | |
26 // Up to 2 InputCoordinate is allowed. | |
27 EXPECT_FALSE(latency.AddInputCoordinate(gfx::PointF(102, 202))); | |
28 | 23 |
29 EXPECT_EQ(100, latency.trace_id()); | 24 EXPECT_EQ(100, latency.trace_id()); |
30 EXPECT_TRUE(latency.terminated()); | 25 EXPECT_TRUE(latency.terminated()); |
31 EXPECT_EQ(2u, latency.input_coordinates_size()); | |
32 | 26 |
33 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 27 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
34 IPC::WriteParam(&msg, latency); | 28 IPC::WriteParam(&msg, latency); |
35 base::PickleIterator iter(msg); | 29 base::PickleIterator iter(msg); |
36 LatencyInfo output; | 30 LatencyInfo output; |
37 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 31 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
38 | 32 |
39 EXPECT_EQ(latency.trace_id(), output.trace_id()); | 33 EXPECT_EQ(latency.trace_id(), output.trace_id()); |
40 EXPECT_EQ(latency.terminated(), output.terminated()); | 34 EXPECT_EQ(latency.terminated(), output.terminated()); |
41 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size()); | |
42 for (size_t i = 0; i < latency.input_coordinates_size(); i++) { | |
43 EXPECT_EQ(latency.input_coordinates()[i].x(), | |
44 output.input_coordinates()[i].x()); | |
45 EXPECT_EQ(latency.input_coordinates()[i].y(), | |
46 output.input_coordinates()[i].y()); | |
47 } | |
48 | 35 |
49 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 36 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
50 1234, | 37 1234, |
51 nullptr)); | 38 nullptr)); |
52 | 39 |
53 LatencyInfo::LatencyComponent rwh_comp; | 40 LatencyInfo::LatencyComponent rwh_comp; |
54 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 41 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
55 1234, | 42 1234, |
56 &rwh_comp)); | 43 &rwh_comp)); |
57 EXPECT_EQ(100, rwh_comp.sequence_number); | 44 EXPECT_EQ(100, rwh_comp.sequence_number); |
58 EXPECT_EQ(1u, rwh_comp.event_count); | 45 EXPECT_EQ(1u, rwh_comp.event_count); |
59 | 46 |
60 EXPECT_TRUE(output.FindLatency( | 47 EXPECT_TRUE(output.FindLatency( |
61 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); | 48 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); |
62 } | 49 } |
63 | 50 |
64 TEST(LatencyInfoParamTraitsTest, InvalidData) { | 51 TEST(LatencyInfoParamTraitsTest, InvalidData) { |
65 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 52 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
66 IPC::WriteParam(&msg, std::string()); | 53 IPC::WriteParam(&msg, std::string()); |
67 ui::LatencyInfo::LatencyMap components; | 54 ui::LatencyInfo::LatencyMap components; |
68 IPC::WriteParam(&msg, components); | 55 IPC::WriteParam(&msg, components); |
69 // input_coordinates_size is 2 but only one InputCoordinate is written. | |
70 IPC::WriteParam(&msg, static_cast<uint32_t>(2)); | |
71 IPC::WriteParam(&msg, gfx::PointF()); | |
72 IPC::WriteParam(&msg, static_cast<int64_t>(1234)); | 56 IPC::WriteParam(&msg, static_cast<int64_t>(1234)); |
73 IPC::WriteParam(&msg, true); | 57 IPC::WriteParam(&msg, true); |
74 | 58 |
75 base::PickleIterator iter(msg); | 59 base::PickleIterator iter(msg); |
76 LatencyInfo output; | 60 LatencyInfo output; |
77 EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output)); | 61 EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output)); |
78 } | 62 } |
79 | 63 |
80 } // namespace ui | 64 } // namespace ui |
OLD | NEW |