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

Side by Side Diff: ui/events/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
« no previous file with comments | « ui/events/mojo/latency_info_struct_traits.cc ('k') | ui/events/mojo/traits_test_service.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/cpp/bindings/binding_set.h" 6 #include "mojo/public/cpp/bindings/binding_set.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/keycodes/dom/dom_code.h" 9 #include "ui/events/keycodes/dom/dom_code.h"
10 #include "ui/events/mojo/event.mojom.h" 10 #include "ui/events/mojo/event.mojom.h"
11 #include "ui/events/mojo/event_struct_traits.h" 11 #include "ui/events/mojo/event_struct_traits.h"
12 #include "ui/events/mojo/latency_info_struct_traits.h"
13 #include "ui/events/mojo/traits_test_service.mojom.h"
14 12
15 namespace ui { 13 namespace ui {
16 14
17 namespace { 15 namespace {
18 16
19 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { 17 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
20 public: 18 public:
21 StructTraitsTest() {} 19 StructTraitsTest() {}
22 20
23 protected: 21 protected:
24 mojom::TraitsTestServicePtr GetTraitsTestProxy() { 22 mojom::TraitsTestServicePtr GetTraitsTestProxy() {
25 return traits_test_bindings_.CreateInterfacePtrAndBind(this); 23 return traits_test_bindings_.CreateInterfacePtrAndBind(this);
26 } 24 }
27 25
28 private: 26 private:
29 // TraitsTestService: 27 // TraitsTestService:
30 void EchoEvent(std::unique_ptr<ui::Event> e, 28 void EchoEvent(std::unique_ptr<ui::Event> e,
31 const EchoEventCallback& callback) override { 29 const EchoEventCallback& callback) override {
32 callback.Run(std::move(e)); 30 callback.Run(std::move(e));
33 } 31 }
34 32
35 void EchoLatencyComponent(
36 const LatencyInfo::LatencyComponent& l,
37 const EchoLatencyComponentCallback& callback) override {
38 callback.Run(l);
39 }
40
41 void EchoLatencyComponentId(
42 const std::pair<LatencyComponentType, int64_t>& id,
43 const EchoLatencyComponentIdCallback& callback) override {
44 callback.Run(id);
45 }
46
47 void EchoLatencyInfo(const LatencyInfo& info,
48 const EchoLatencyInfoCallback& callback) override {
49 callback.Run(info);
50 }
51
52 base::MessageLoop loop_; 33 base::MessageLoop loop_;
53 mojo::BindingSet<TraitsTestService> traits_test_bindings_; 34 mojo::BindingSet<TraitsTestService> traits_test_bindings_;
54 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); 35 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest);
55 }; 36 };
56 37
57 } // namespace 38 } // namespace
58 39
59 TEST_F(StructTraitsTest, LatencyComponent) {
60 const int64_t sequence_number = 13371337;
61 const base::TimeTicks event_time = base::TimeTicks::Now();
62 const uint32_t event_count = 1234;
63 LatencyInfo::LatencyComponent input;
64 input.sequence_number = sequence_number;
65 input.event_time = event_time;
66 input.event_count = event_count;
67 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
68 LatencyInfo::LatencyComponent output;
69 proxy->EchoLatencyComponent(input, &output);
70 EXPECT_EQ(sequence_number, output.sequence_number);
71 EXPECT_EQ(event_time, output.event_time);
72 EXPECT_EQ(event_count, output.event_count);
73 }
74
75 TEST_F(StructTraitsTest, LatencyComponentId) {
76 const LatencyComponentType type =
77 INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
78 const int64_t id = 1337;
79 std::pair<LatencyComponentType, int64_t> input(type, id);
80 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
81 std::pair<LatencyComponentType, int64_t> output;
82 proxy->EchoLatencyComponentId(input, &output);
83 EXPECT_EQ(type, output.first);
84 EXPECT_EQ(id, output.second);
85 }
86
87 TEST_F(StructTraitsTest, LatencyInfo) {
88 LatencyInfo latency;
89 ASSERT_FALSE(latency.terminated());
90 ASSERT_EQ(0u, latency.input_coordinates_size());
91 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0);
92 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100);
93 latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
94 1234, 0);
95 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(100, 200)));
96 EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(101, 201)));
97 // Up to 2 InputCoordinate is allowed.
98 EXPECT_FALSE(latency.AddInputCoordinate(gfx::PointF(102, 202)));
99
100 EXPECT_EQ(100, latency.trace_id());
101 EXPECT_TRUE(latency.terminated());
102 EXPECT_EQ(2u, latency.input_coordinates_size());
103
104 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
105 LatencyInfo output;
106 proxy->EchoLatencyInfo(latency, &output);
107
108 EXPECT_EQ(latency.trace_id(), output.trace_id());
109 EXPECT_EQ(latency.terminated(), output.terminated());
110 EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size());
111 for (size_t i = 0; i < latency.input_coordinates_size(); i++) {
112 EXPECT_EQ(latency.input_coordinates()[i].x(),
113 output.input_coordinates()[i].x());
114 EXPECT_EQ(latency.input_coordinates()[i].y(),
115 output.input_coordinates()[i].y());
116 }
117
118 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234,
119 nullptr));
120
121 LatencyInfo::LatencyComponent rwh_comp;
122 EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234,
123 &rwh_comp));
124 EXPECT_EQ(100, rwh_comp.sequence_number);
125 EXPECT_EQ(1u, rwh_comp.event_count);
126
127 EXPECT_TRUE(output.FindLatency(
128 INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr));
129 }
130
131 TEST_F(StructTraitsTest, KeyEvent) { 40 TEST_F(StructTraitsTest, KeyEvent) {
132 KeyEvent kTestData[] = { 41 KeyEvent kTestData[] = {
133 {ET_KEY_PRESSED, VKEY_RETURN, EF_CONTROL_DOWN}, 42 {ET_KEY_PRESSED, VKEY_RETURN, EF_CONTROL_DOWN},
134 {ET_KEY_PRESSED, VKEY_MENU, EF_ALT_DOWN}, 43 {ET_KEY_PRESSED, VKEY_MENU, EF_ALT_DOWN},
135 {ET_KEY_RELEASED, VKEY_SHIFT, EF_SHIFT_DOWN}, 44 {ET_KEY_RELEASED, VKEY_SHIFT, EF_SHIFT_DOWN},
136 {ET_KEY_RELEASED, VKEY_MENU, EF_ALT_DOWN}, 45 {ET_KEY_RELEASED, VKEY_MENU, EF_ALT_DOWN},
137 {ET_KEY_PRESSED, VKEY_A, ui::DomCode::US_A, EF_NONE}, 46 {ET_KEY_PRESSED, VKEY_A, ui::DomCode::US_A, EF_NONE},
138 {ET_KEY_PRESSED, VKEY_B, ui::DomCode::US_B, 47 {ET_KEY_PRESSED, VKEY_B, ui::DomCode::US_B,
139 EF_CONTROL_DOWN | EF_ALT_DOWN}, 48 EF_CONTROL_DOWN | EF_ALT_DOWN},
140 {'\x12', VKEY_2, EF_CONTROL_DOWN}, 49 {'\x12', VKEY_2, EF_CONTROL_DOWN},
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 std::unique_ptr<Event> event_ptr = Event::Clone(key_event); 179 std::unique_ptr<Event> event_ptr = Event::Clone(key_event);
271 std::unique_ptr<Event> deserialized; 180 std::unique_ptr<Event> deserialized;
272 ASSERT_TRUE(mojom::Event::Deserialize(mojom::Event::Serialize(&event_ptr), 181 ASSERT_TRUE(mojom::Event::Deserialize(mojom::Event::Serialize(&event_ptr),
273 &deserialized)); 182 &deserialized));
274 ASSERT_TRUE(deserialized->IsKeyEvent()); 183 ASSERT_TRUE(deserialized->IsKeyEvent());
275 ASSERT_TRUE(deserialized->AsKeyEvent()->properties()); 184 ASSERT_TRUE(deserialized->AsKeyEvent()->properties());
276 EXPECT_EQ(properties, *(deserialized->AsKeyEvent()->properties())); 185 EXPECT_EQ(properties, *(deserialized->AsKeyEvent()->properties()));
277 } 186 }
278 187
279 } // namespace ui 188 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/mojo/latency_info_struct_traits.cc ('k') | ui/events/mojo/traits_test_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698