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