| 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 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); | 19 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234); |
| 20 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); | 20 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234); |
| 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); |
| 23 | 23 |
| 24 EXPECT_EQ(100, latency.trace_id()); | |
| 25 EXPECT_TRUE(latency.terminated()); | 24 EXPECT_TRUE(latency.terminated()); |
| 26 | 25 |
| 27 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 26 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 28 IPC::WriteParam(&msg, latency); | 27 IPC::WriteParam(&msg, latency); |
| 29 base::PickleIterator iter(msg); | 28 base::PickleIterator iter(msg); |
| 30 LatencyInfo output; | 29 LatencyInfo output; |
| 31 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 30 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
| 32 | 31 |
| 33 EXPECT_EQ(latency.trace_id(), output.trace_id()); | 32 EXPECT_EQ(latency.trace_id(), output.trace_id()); |
| 34 EXPECT_EQ(latency.terminated(), output.terminated()); | 33 EXPECT_EQ(latency.terminated(), output.terminated()); |
| 35 | 34 |
| 36 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 35 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 37 1234, | 36 1234, |
| 38 nullptr)); | 37 nullptr)); |
| 39 | 38 |
| 40 LatencyInfo::LatencyComponent rwh_comp; | 39 LatencyInfo::LatencyComponent rwh_comp; |
| 41 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 40 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 42 1234, | 41 1234, |
| 43 &rwh_comp)); | 42 &rwh_comp)); |
| 44 EXPECT_EQ(100, rwh_comp.sequence_number); | |
| 45 EXPECT_EQ(1u, rwh_comp.event_count); | 43 EXPECT_EQ(1u, rwh_comp.event_count); |
| 46 | 44 |
| 47 EXPECT_TRUE(output.FindLatency( | 45 EXPECT_TRUE(output.FindLatency( |
| 48 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); | 46 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); |
| 49 } | 47 } |
| 50 | 48 |
| 51 TEST(LatencyInfoParamTraitsTest, InvalidData) { | 49 TEST(LatencyInfoParamTraitsTest, InvalidData) { |
| 52 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 50 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 53 IPC::WriteParam(&msg, std::string()); | 51 IPC::WriteParam(&msg, std::string()); |
| 54 ui::LatencyInfo::LatencyMap components; | 52 ui::LatencyInfo::LatencyMap components; |
| 55 IPC::WriteParam(&msg, components); | 53 IPC::WriteParam(&msg, components); |
| 56 IPC::WriteParam(&msg, static_cast<int64_t>(1234)); | 54 IPC::WriteParam(&msg, static_cast<int64_t>(1234)); |
| 57 IPC::WriteParam(&msg, true); | 55 IPC::WriteParam(&msg, true); |
| 58 | 56 |
| 59 base::PickleIterator iter(msg); | 57 base::PickleIterator iter(msg); |
| 60 LatencyInfo output; | 58 LatencyInfo output; |
| 61 EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output)); | 59 EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output)); |
| 62 } | 60 } |
| 63 | 61 |
| 64 } // namespace ui | 62 } // namespace ui |
| OLD | NEW |