latency_info_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include "ui/latency/latency_info.h"
  5. #include <stddef.h>
  6. #include "base/time/time.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace ui {
  9. namespace {
  10. // Returns a fake TimeTicks based on the given microsecond offset.
  11. base::TimeTicks ToTestTimeTicks(int64_t micros) {
  12. return base::TimeTicks() + base::Microseconds(micros);
  13. }
  14. } // namespace
  15. TEST(LatencyInfoTest, AddTwoSeparateEvent) {
  16. LatencyInfo info;
  17. info.set_trace_id(1);
  18. EXPECT_FALSE(info.began());
  19. info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
  20. ToTestTimeTicks(100));
  21. EXPECT_TRUE(info.began());
  22. info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
  23. ToTestTimeTicks(1000));
  24. EXPECT_EQ(info.latency_components().size(), 2u);
  25. base::TimeTicks timestamp;
  26. EXPECT_FALSE(info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, &timestamp));
  27. EXPECT_TRUE(
  28. info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, &timestamp));
  29. EXPECT_EQ(timestamp, ToTestTimeTicks(100));
  30. EXPECT_TRUE(
  31. info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, &timestamp));
  32. EXPECT_EQ(timestamp, ToTestTimeTicks(1000));
  33. }
  34. } // namespace ui