mojom_traits_unittest.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <utility>
  5. #include "base/test/task_environment.h"
  6. #include "mojo/public/cpp/bindings/receiver_set.h"
  7. #include "mojo/public/cpp/bindings/remote.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. #include "ui/latency/mojom/latency_info_mojom_traits.h"
  10. #include "ui/latency/mojom/traits_test_service.mojom.h"
  11. namespace ui {
  12. namespace {
  13. class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
  14. public:
  15. StructTraitsTest() {}
  16. StructTraitsTest(const StructTraitsTest&) = delete;
  17. StructTraitsTest& operator=(const StructTraitsTest&) = delete;
  18. protected:
  19. mojo::Remote<mojom::TraitsTestService> GetTraitsTestRemote() {
  20. mojo::Remote<mojom::TraitsTestService> remote;
  21. traits_test_receivers_.Add(this, remote.BindNewPipeAndPassReceiver());
  22. return remote;
  23. }
  24. private:
  25. // TraitsTestService:
  26. void EchoLatencyInfo(const LatencyInfo& info,
  27. EchoLatencyInfoCallback callback) override {
  28. std::move(callback).Run(info);
  29. }
  30. base::test::TaskEnvironment task_environment_;
  31. mojo::ReceiverSet<TraitsTestService> traits_test_receivers_;
  32. };
  33. } // namespace
  34. TEST_F(StructTraitsTest, LatencyInfo) {
  35. LatencyInfo latency;
  36. latency.set_trace_id(5);
  37. latency.set_ukm_source_id(10);
  38. ASSERT_FALSE(latency.terminated());
  39. latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
  40. latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT);
  41. latency.AddLatencyNumber(INPUT_EVENT_LATENCY_FRAME_SWAP_COMPONENT);
  42. EXPECT_EQ(5, latency.trace_id());
  43. EXPECT_EQ(10, latency.ukm_source_id());
  44. EXPECT_TRUE(latency.terminated());
  45. latency.set_source_event_type(ui::SourceEventType::TOUCH);
  46. mojo::Remote<mojom::TraitsTestService> remote = GetTraitsTestRemote();
  47. LatencyInfo output;
  48. remote->EchoLatencyInfo(latency, &output);
  49. EXPECT_EQ(latency.trace_id(), output.trace_id());
  50. EXPECT_EQ(latency.ukm_source_id(), output.ukm_source_id());
  51. EXPECT_EQ(latency.terminated(), output.terminated());
  52. EXPECT_EQ(latency.source_event_type(), output.source_event_type());
  53. EXPECT_TRUE(
  54. output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, nullptr));
  55. }
  56. } // namespace ui