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

Unified Diff: ui/latency/mojo/struct_traits_unittest.cc

Issue 2783973002: Moving LatencyInfo into a separate component. (Closed)
Patch Set: Rebase again Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/latency/mojo/struct_traits_unittest.cc
diff --git a/ui/latency/mojo/struct_traits_unittest.cc b/ui/latency/mojo/struct_traits_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b9a930f2a400ffd00e98603479f341e8c538efac
--- /dev/null
+++ b/ui/latency/mojo/struct_traits_unittest.cc
@@ -0,0 +1,122 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/message_loop/message_loop.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/mojo/latency_info_struct_traits.h"
+#include "ui/events/mojo/traits_test_service.mojom.h"
+
+namespace ui {
+
+namespace {
+
+class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
+ public:
+ StructTraitsTest() {}
+
+ protected:
+ mojom::TraitsTestServicePtr GetTraitsTestProxy() {
+ return traits_test_bindings_.CreateInterfacePtrAndBind(this);
+ }
+
+ private:
+ // TraitsTestService:
+ void EchoLatencyComponent(
+ const LatencyInfo::LatencyComponent& l,
+ const EchoLatencyComponentCallback& callback) override {
+ callback.Run(l);
+ }
+
+ void EchoLatencyComponentId(
+ const std::pair<LatencyComponentType, int64_t>& id,
+ const EchoLatencyComponentIdCallback& callback) override {
+ callback.Run(id);
+ }
+
+ void EchoLatencyInfo(const LatencyInfo& info,
+ const EchoLatencyInfoCallback& callback) override {
+ callback.Run(info);
+ }
+
+ base::MessageLoop loop_;
+ mojo::BindingSet<TraitsTestService> traits_test_bindings_;
+ DISALLOW_COPY_AND_ASSIGN(StructTraitsTest);
+};
+
+} // namespace
+
+TEST_F(StructTraitsTest, LatencyComponent) {
+ const int64_t sequence_number = 13371337;
+ const base::TimeTicks event_time = base::TimeTicks::Now();
+ const uint32_t event_count = 1234;
+ LatencyInfo::LatencyComponent input;
+ input.sequence_number = sequence_number;
+ input.event_time = event_time;
+ input.event_count = event_count;
+ mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
+ LatencyInfo::LatencyComponent output;
+ proxy->EchoLatencyComponent(input, &output);
+ EXPECT_EQ(sequence_number, output.sequence_number);
+ EXPECT_EQ(event_time, output.event_time);
+ EXPECT_EQ(event_count, output.event_count);
+}
+
+TEST_F(StructTraitsTest, LatencyComponentId) {
+ const LatencyComponentType type =
+ INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT;
+ const int64_t id = 1337;
+ std::pair<LatencyComponentType, int64_t> input(type, id);
+ mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
+ std::pair<LatencyComponentType, int64_t> output;
+ proxy->EchoLatencyComponentId(input, &output);
+ EXPECT_EQ(type, output.first);
+ EXPECT_EQ(id, output.second);
+}
+
+TEST_F(StructTraitsTest, LatencyInfo) {
+ LatencyInfo latency;
+ ASSERT_FALSE(latency.terminated());
+ ASSERT_EQ(0u, latency.input_coordinates_size());
+ latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0);
+ latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100);
+ latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
+ 1234, 0);
+ EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(100, 200)));
+ EXPECT_TRUE(latency.AddInputCoordinate(gfx::PointF(101, 201)));
+ // Up to 2 InputCoordinate is allowed.
+ EXPECT_FALSE(latency.AddInputCoordinate(gfx::PointF(102, 202)));
+
+ EXPECT_EQ(100, latency.trace_id());
+ EXPECT_TRUE(latency.terminated());
+ EXPECT_EQ(2u, latency.input_coordinates_size());
+
+ mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
+ LatencyInfo output;
+ proxy->EchoLatencyInfo(latency, &output);
+
+ EXPECT_EQ(latency.trace_id(), output.trace_id());
+ EXPECT_EQ(latency.terminated(), output.terminated());
+ EXPECT_EQ(latency.input_coordinates_size(), output.input_coordinates_size());
+ for (size_t i = 0; i < latency.input_coordinates_size(); i++) {
+ EXPECT_EQ(latency.input_coordinates()[i].x(),
+ output.input_coordinates()[i].x());
+ EXPECT_EQ(latency.input_coordinates()[i].y(),
+ output.input_coordinates()[i].y());
+ }
+
+ EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234,
+ nullptr));
+
+ LatencyInfo::LatencyComponent rwh_comp;
+ EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234,
+ &rwh_comp));
+ EXPECT_EQ(100, rwh_comp.sequence_number);
+ EXPECT_EQ(1u, rwh_comp.event_count);
+
+ EXPECT_TRUE(output.FindLatency(
+ INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr));
+}
+
+} // namespace ui
« 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