Commit 62713891 authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Use mock time in CompositorFrameReportingControllerTest

Currently, the test uses base::TimeTicks::Now() for timings which makes
it hard to verify timing expectations. This CL changes the test to use a
mock time that can be advanced on demand. This unblocks adding more
tests.

Bug: 1054009,1057193
Change-Id: I68448ac591d86d26246459cddd64f36d42bd82f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2159413Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761020}
parent 7b9b6a4e
...@@ -80,7 +80,7 @@ class CompositorFrameReportingControllerTest : public testing::Test { ...@@ -80,7 +80,7 @@ class CompositorFrameReportingControllerTest : public testing::Test {
if (!reporting_controller_ if (!reporting_controller_
.reporters()[CompositorFrameReportingController::PipelineStage:: .reporters()[CompositorFrameReportingController::PipelineStage::
kBeginMainFrame]) { kBeginMainFrame]) {
begin_main_start_ = base::TimeTicks::Now(); begin_main_start_ = AdvanceNowByMs(10);
SimulateBeginMainFrame(); SimulateBeginMainFrame();
} }
CHECK( CHECK(
...@@ -121,18 +121,15 @@ class CompositorFrameReportingControllerTest : public testing::Test { ...@@ -121,18 +121,15 @@ class CompositorFrameReportingControllerTest : public testing::Test {
++next_token_; ++next_token_;
SimulateSubmitCompositorFrame(*next_token_, {}); SimulateSubmitCompositorFrame(*next_token_, {});
viz::FrameTimingDetails details = {}; viz::FrameTimingDetails details = {};
details.presentation_feedback.timestamp = base::TimeTicks::Now(); details.presentation_feedback.timestamp = AdvanceNowByMs(10);
reporting_controller_.DidPresentCompositorFrame(*next_token_, details); reporting_controller_.DidPresentCompositorFrame(*next_token_, details);
} }
viz::BeginFrameArgs SimulateBeginFrameArgs( viz::BeginFrameArgs SimulateBeginFrameArgs(viz::BeginFrameId frame_id) {
viz::BeginFrameId frame_id,
base::TimeTicks frame_time = base::TimeTicks::Now(),
base::TimeDelta interval = base::TimeDelta::FromMilliseconds(16)) {
args_ = viz::BeginFrameArgs(); args_ = viz::BeginFrameArgs();
args_.frame_id = frame_id; args_.frame_id = frame_id;
args_.frame_time = frame_time; args_.frame_time = AdvanceNowByMs(10);
args_.interval = interval; args_.interval = base::TimeDelta::FromMilliseconds(16);
return args_; return args_;
} }
...@@ -141,6 +138,11 @@ class CompositorFrameReportingControllerTest : public testing::Test { ...@@ -141,6 +138,11 @@ class CompositorFrameReportingControllerTest : public testing::Test {
args_.frame_id = current_id_; args_.frame_id = current_id_;
} }
base::TimeTicks AdvanceNowByMs(int64_t advance_ms) {
now_ += base::TimeDelta::FromMicroseconds(advance_ms);
return now_;
}
protected: protected:
TestCompositorFrameReportingController reporting_controller_; TestCompositorFrameReportingController reporting_controller_;
viz::BeginFrameArgs args_; viz::BeginFrameArgs args_;
...@@ -148,6 +150,9 @@ class CompositorFrameReportingControllerTest : public testing::Test { ...@@ -148,6 +150,9 @@ class CompositorFrameReportingControllerTest : public testing::Test {
viz::BeginFrameId last_activated_id_; viz::BeginFrameId last_activated_id_;
base::TimeTicks begin_main_start_; base::TimeTicks begin_main_start_;
viz::FrameTokenGenerator next_token_; viz::FrameTokenGenerator next_token_;
private:
base::TimeTicks now_ = base::TimeTicks::Now();
}; };
TEST_F(CompositorFrameReportingControllerTest, ActiveReporterCounts) { TEST_F(CompositorFrameReportingControllerTest, ActiveReporterCounts) {
...@@ -816,7 +821,7 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -816,7 +821,7 @@ TEST_F(CompositorFrameReportingControllerTest,
EventLatencyForPresentedFrameReported) { EventLatencyForPresentedFrameReported) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
const base::TimeTicks event_time = base::TimeTicks::Now(); const base::TimeTicks event_time = AdvanceNowByMs(10);
std::vector<EventMetrics> events_metrics = { std::vector<EventMetrics> events_metrics = {
{ui::ET_TOUCH_PRESSED, event_time, base::nullopt}, {ui::ET_TOUCH_PRESSED, event_time, base::nullopt},
{ui::ET_TOUCH_MOVED, event_time, base::nullopt}, {ui::ET_TOUCH_MOVED, event_time, base::nullopt},
...@@ -830,13 +835,13 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -830,13 +835,13 @@ TEST_F(CompositorFrameReportingControllerTest,
SimulateSubmitCompositorFrame(*next_token_, {std::move(events_metrics), {}}); SimulateSubmitCompositorFrame(*next_token_, {std::move(events_metrics), {}});
// Present the submitted compositor frame to the user. // Present the submitted compositor frame to the user.
const base::TimeTicks presentation_time = base::TimeTicks::Now(); const base::TimeTicks presentation_time = AdvanceNowByMs(10);
viz::FrameTimingDetails details; viz::FrameTimingDetails details;
details.presentation_feedback.timestamp = presentation_time; details.presentation_feedback.timestamp = presentation_time;
reporting_controller_.DidPresentCompositorFrame(*next_token_, details); reporting_controller_.DidPresentCompositorFrame(*next_token_, details);
// Verify that EventLatency histograms are recorded. // Verify that EventLatency histograms are recorded.
const int latency_ms = (presentation_time - event_time).InMicroseconds(); const int64_t latency_ms = (presentation_time - event_time).InMicroseconds();
histogram_tester.ExpectTotalCount("EventLatency.TouchPressed.TotalLatency", histogram_tester.ExpectTotalCount("EventLatency.TouchPressed.TotalLatency",
1); 1);
histogram_tester.ExpectTotalCount("EventLatency.TouchMoved.TotalLatency", 2); histogram_tester.ExpectTotalCount("EventLatency.TouchMoved.TotalLatency", 2);
...@@ -852,7 +857,7 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -852,7 +857,7 @@ TEST_F(CompositorFrameReportingControllerTest,
EventLatencyScrollForPresentedFrameReported) { EventLatencyScrollForPresentedFrameReported) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
const base::TimeTicks event_time = base::TimeTicks::Now(); const base::TimeTicks event_time = AdvanceNowByMs(10);
std::vector<EventMetrics> events_metrics = { std::vector<EventMetrics> events_metrics = {
{ui::ET_GESTURE_SCROLL_BEGIN, event_time, ScrollInputType::kWheel}, {ui::ET_GESTURE_SCROLL_BEGIN, event_time, ScrollInputType::kWheel},
{ui::ET_GESTURE_SCROLL_UPDATE, event_time, ScrollInputType::kWheel}, {ui::ET_GESTURE_SCROLL_UPDATE, event_time, ScrollInputType::kWheel},
...@@ -866,13 +871,13 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -866,13 +871,13 @@ TEST_F(CompositorFrameReportingControllerTest,
SimulateSubmitCompositorFrame(*next_token_, {std::move(events_metrics), {}}); SimulateSubmitCompositorFrame(*next_token_, {std::move(events_metrics), {}});
// Present the submitted compositor frame to the user. // Present the submitted compositor frame to the user.
const base::TimeTicks presentation_time = base::TimeTicks::Now(); const base::TimeTicks presentation_time = AdvanceNowByMs(10);
viz::FrameTimingDetails details; viz::FrameTimingDetails details;
details.presentation_feedback.timestamp = presentation_time; details.presentation_feedback.timestamp = presentation_time;
reporting_controller_.DidPresentCompositorFrame(*next_token_, details); reporting_controller_.DidPresentCompositorFrame(*next_token_, details);
// Verify that EventLatency histograms are recorded. // Verify that EventLatency histograms are recorded.
const int latency_ms = (presentation_time - event_time).InMicroseconds(); const int64_t latency_ms = (presentation_time - event_time).InMicroseconds();
histogram_tester.ExpectTotalCount( histogram_tester.ExpectTotalCount(
"EventLatency.GestureScrollBegin.Wheel.TotalLatency", 1); "EventLatency.GestureScrollBegin.Wheel.TotalLatency", 1);
histogram_tester.ExpectTotalCount( histogram_tester.ExpectTotalCount(
...@@ -889,7 +894,7 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -889,7 +894,7 @@ TEST_F(CompositorFrameReportingControllerTest,
EventLatencyForDidNotPresentFrameNotReported) { EventLatencyForDidNotPresentFrameNotReported) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
const base::TimeTicks event_time = base::TimeTicks::Now(); const base::TimeTicks event_time = AdvanceNowByMs(10);
std::vector<EventMetrics> events_metrics = { std::vector<EventMetrics> events_metrics = {
{ui::ET_TOUCH_PRESSED, event_time, base::nullopt}, {ui::ET_TOUCH_PRESSED, event_time, base::nullopt},
{ui::ET_TOUCH_MOVED, event_time, base::nullopt}, {ui::ET_TOUCH_MOVED, event_time, base::nullopt},
...@@ -909,7 +914,7 @@ TEST_F(CompositorFrameReportingControllerTest, ...@@ -909,7 +914,7 @@ TEST_F(CompositorFrameReportingControllerTest,
// Present the second compositor frame to the uesr, dropping the first one. // Present the second compositor frame to the uesr, dropping the first one.
viz::FrameTimingDetails details; viz::FrameTimingDetails details;
details.presentation_feedback.timestamp = base::TimeTicks::Now(); details.presentation_feedback.timestamp = AdvanceNowByMs(10);
reporting_controller_.DidPresentCompositorFrame(*next_token_, details); reporting_controller_.DidPresentCompositorFrame(*next_token_, details);
// Verify that no EventLatency histogram is recorded. // Verify that no EventLatency histogram is recorded.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment