cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ui / events / ipc / latency_info_param_traits_unittest.cc
blobd5dc6b85c02a7e36f314b79cc919562656e6a858
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
3 // found in the LICENSE file.
5 #include "ipc/ipc_message_macros.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/ipc/latency_info_param_traits.h"
8 #include "ui/events/ipc/latency_info_param_traits_macros.h"
10 namespace ui {
12 TEST(LatencyInfoParamTraitsTest, Basic) {
13 LatencyInfo latency;
14 ASSERT_FALSE(latency.terminated());
15 ASSERT_EQ(0u, latency.input_coordinates_size());
16 ASSERT_EQ(0u, latency.coalesced_events_size());
17 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0);
18 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100);
19 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
20 1234, 0);
21 EXPECT_TRUE(latency.AddInputCoordinate(
22 LatencyInfo::InputCoordinate(100, 200)));
23 EXPECT_TRUE(latency.AddInputCoordinate(
24 LatencyInfo::InputCoordinate(101, 201)));
25 // Up to 2 InputCoordinate is allowed.
26 EXPECT_FALSE(latency.AddInputCoordinate(
27 LatencyInfo::InputCoordinate(102, 202)));
29 EXPECT_TRUE(latency.AddCoalescedEventTimestamp(10.0));
30 EXPECT_TRUE(latency.AddCoalescedEventTimestamp(20.0));
31 // Up to 2 coalesced events is allowed.
32 EXPECT_FALSE(latency.AddCoalescedEventTimestamp(30.0));
34 EXPECT_EQ(100, latency.trace_id());
35 EXPECT_TRUE(latency.terminated());
36 EXPECT_EQ(2u, latency.input_coordinates_size());
37 EXPECT_EQ(2u, latency.coalesced_events_size());
39 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
40 IPC::WriteParam(&msg, latency);
41 base::PickleIterator iter(msg);
42 LatencyInfo output;
43 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
45 EXPECT_EQ(latency.trace_id(), output.trace_id());
46 EXPECT_EQ(latency.terminated(), output.terminated());
47 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size());
48 for (size_t i = 0; i < latency.input_coordinates_size(); i++) {
49 EXPECT_EQ(latency.input_coordinates()[i].x,
50 output.input_coordinates()[i].x);
51 EXPECT_EQ(latency.input_coordinates()[i].y,
52 output.input_coordinates()[i].y);
54 EXPECT_EQ(latency.coalesced_events_size(), output.coalesced_events_size());
55 for (size_t i = 0; i < latency.coalesced_events_size(); i++) {
56 EXPECT_EQ(latency.timestamps_of_coalesced_events()[i],
57 output.timestamps_of_coalesced_events()[i]);
60 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
61 1234,
62 nullptr));
64 LatencyInfo::LatencyComponent rwh_comp;
65 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
66 1234,
67 &rwh_comp));
68 EXPECT_EQ(100, rwh_comp.sequence_number);
69 EXPECT_EQ(1u, rwh_comp.event_count);
71 EXPECT_TRUE(output.FindLatency(
72 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr));
75 TEST(LatencyInfoParamTraitsTest, InvalidData) {
76 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
77 IPC::WriteParam(&msg, std::string());
78 ui::LatencyInfo::LatencyMap components;
79 IPC::WriteParam(&msg, components);
80 IPC::WriteParam(&msg, static_cast<uint32>(2));
81 IPC::WriteParam(&msg, ui::LatencyInfo::InputCoordinate());
82 IPC::WriteParam(&msg, ui::LatencyInfo::InputCoordinate());
83 // coalesced_events_size is 2 but only one event timestamp is written.
84 IPC::WriteParam(&msg, static_cast<uint32>(2));
85 IPC::WriteParam(&msg, static_cast<double>(10.0));
86 IPC::WriteParam(&msg, static_cast<int64>(1234));
87 IPC::WriteParam(&msg, true);
89 base::PickleIterator iter(msg);
90 LatencyInfo output;
91 EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output));
94 } // namespace ui