Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / events / latency_info_unittest.cc
1 // Copyright 2013 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 "ui/events/latency_info.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace ui {
10
11 TEST(LatencyInfoTest, AddTwoSeparateEvent) {
12   LatencyInfo info;
13   info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
14                                      0,
15                                      1,
16                                      base::TimeTicks::FromInternalValue(100),
17                                      1);
18   info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
19                                      1,
20                                      5,
21                                      base::TimeTicks::FromInternalValue(1000),
22                                      2);
23
24   EXPECT_EQ(info.latency_components.size(), 2u);
25   LatencyInfo::LatencyComponent component;
26   EXPECT_FALSE(
27       info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
28   EXPECT_FALSE(
29       info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1, &component));
30   EXPECT_TRUE(
31       info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, &component));
32   EXPECT_EQ(component.sequence_number, 1);
33   EXPECT_EQ(component.event_count, 1u);
34   EXPECT_EQ(component.event_time.ToInternalValue(), 100);
35   EXPECT_TRUE(
36       info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
37   EXPECT_EQ(component.sequence_number, 5);
38   EXPECT_EQ(component.event_count, 2u);
39   EXPECT_EQ(component.event_time.ToInternalValue(), 1000);
40 }
41
42 TEST(LatencyInfoTest, AddTwoSameEvent) {
43   LatencyInfo info;
44   info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
45                                      0,
46                                      30,
47                                      base::TimeTicks::FromInternalValue(100),
48                                      2);
49   info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
50                                      0,
51                                      13,
52                                      base::TimeTicks::FromInternalValue(200),
53                                      3);
54
55   EXPECT_EQ(info.latency_components.size(), 1u);
56   LatencyInfo::LatencyComponent component;
57   EXPECT_FALSE(
58       info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
59   EXPECT_FALSE(
60       info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
61   EXPECT_TRUE(
62       info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, &component));
63   EXPECT_EQ(component.sequence_number, 30);
64   EXPECT_EQ(component.event_count, 5u);
65   EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
66 }
67
68 TEST(LatencyInfoTest, ClearEvents) {
69   LatencyInfo info;
70   info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
71                                      0,
72                                      30,
73                                      base::TimeTicks::FromInternalValue(100),
74                                      2);
75
76   EXPECT_EQ(info.latency_components.size(), 1u);
77   info.Clear();
78   EXPECT_EQ(info.latency_components.size(), 0u);
79 }
80
81 }  // namespace ui