Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/latency/mojo/struct_traits_unittest.cc

Issue 2783973002: Moving LatencyInfo into a separate component. (Closed)
Patch Set: Rebase again Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/message_loop/message_loop.h"
6 #include "mojo/public/cpp/bindings/binding_set.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/mojo/latency_info_struct_traits.h"
9 #include "ui/events/mojo/traits_test_service.mojom.h"
10
11 namespace ui {
12
13 namespace {
14
15 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
16 public:
17 StructTraitsTest() {}
18
19 protected:
20 mojom::TraitsTestServicePtr GetTraitsTestProxy() {
21 return traits_test_bindings_.CreateInterfacePtrAndBind(this);
22 }
23
24 private:
25 // TraitsTestService:
26 void EchoLatencyComponent(
27 const LatencyInfo::LatencyComponent& l,
28 const EchoLatencyComponentCallback& callback) override {
29 callback.Run(l);
30 }
31
32 void EchoLatencyComponentId(
33 const std::pair<LatencyComponentType, int64_t>& id,
34 const EchoLatencyComponentIdCallback& callback) override {
35 callback.Run(id);
36 }
37
38 void EchoLatencyInfo(const LatencyInfo& info,
39 const EchoLatencyInfoCallback& callback) override {
40 callback.Run(info);
41 }
42
43 base::MessageLoop loop_;
44 mojo::BindingSet<TraitsTestService> traits_test_bindings_;
45 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest);
46 };
47
48 } // namespace
49
50 TEST_F(StructTraitsTest, LatencyComponent) {
51 const int64_t sequence_number = 13371337;
52 const base::TimeTicks event_time = base::TimeTicks::Now();
53 const uint32_t event_count = 1234;
54 LatencyInfo::LatencyComponent input;
55 input.sequence_number = sequence_number;
56 input.event_time = event_time;
57 input.event_count = event_count;
58 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
59 LatencyInfo::LatencyComponent output;
60 proxy->EchoLatencyComponent(input, &output);
61 EXPECT_EQ(sequence_number, output.sequence_number);
62 EXPECT_EQ(event_time, output.event_time);
63 EXPECT_EQ(event_count, output.event_count);
64 }
65
66 TEST_F(StructTraitsTest, LatencyComponentId) {
67 const LatencyComponentType type =
68 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
69 const int64_t id = 1337;
70 std::pair<LatencyComponentType, int64_t> input(type, id);
71 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
72 std::pair<LatencyComponentType, int64_t> output;
73 proxy->EchoLatencyComponentId(input, &output);
74 EXPECT_EQ(type, output.first);
75 EXPECT_EQ(id, output.second);
76 }
77
78 TEST_F(StructTraitsTest, LatencyInfo) {
79 LatencyInfo latency;
80 ASSERT_FALSE(latency.terminated());
81 ASSERT_EQ(0u, latency.input_coordinates_size());
82 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0);
83 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100);
84 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
85 1234, 0);
86 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(100, 200)));
87 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(101, 201)));
88 // Up to 2 InputCoordinate is allowed.
89 EXPECT_FALSE(latency.AddInputCoordinate(gfx::PointF(102, 202)));
90
91 EXPECT_EQ(100, latency.trace_id());
92 EXPECT_TRUE(latency.terminated());
93 EXPECT_EQ(2u, latency.input_coordinates_size());
94
95 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
96 LatencyInfo output;
97 proxy->EchoLatencyInfo(latency, &output);
98
99 EXPECT_EQ(latency.trace_id(), output.trace_id());
100 EXPECT_EQ(latency.terminated(), output.terminated());
101 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size());
102 for (size_t i = 0; i < latency.input_coordinates_size(); i++) {
103 EXPECT_EQ(latency.input_coordinates()[i].x(),
104 output.input_coordinates()[i].x());
105 EXPECT_EQ(latency.input_coordinates()[i].y(),
106 output.input_coordinates()[i].y());
107 }
108
109 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234,
110 nullptr));
111
112 LatencyInfo::LatencyComponent rwh_comp;
113 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234,
114 &rwh_comp));
115 EXPECT_EQ(100, rwh_comp.sequence_number);
116 EXPECT_EQ(1u, rwh_comp.event_count);
117
118 EXPECT_TRUE(output.FindLatency(
119 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr));
120 }
121
122 } // namespace ui
OLDNEW
« no previous file with comments | « ui/latency/mojo/latency_info_struct_traits.cc ('k') | ui/latency/mojo/traits_test_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698