Flutter Engine
The Flutter Engine
stopwatch_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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
5#include "flutter/flow/stopwatch.h"
7#include "gmock/gmock.h" // IWYU pragma: keep
8#include "gtest/gtest.h"
9
10using testing::Return;
11
12namespace flutter {
13namespace testing {
14
16 public:
17 fml::Milliseconds GetFrameBudget() const override { return budget_; }
18
19 void SetFrameBudget(fml::Milliseconds budget) { budget_ = budget; }
20
21 private:
22 fml::Milliseconds budget_;
23};
24
25TEST(Instrumentation, GetDefaultFrameBudgetTest) {
26 fml::Milliseconds frame_budget_60fps = fml::RefreshRateToFrameBudget(60);
27 // The default constructor sets the frame_budget to 16.6667 (60 fps).
29 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
30 EXPECT_EQ(frame_budget_60fps, actual_frame_budget);
31}
32
33TEST(Instrumentation, GetOneShotFrameBudgetTest) {
34 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
35 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
36 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
37 EXPECT_EQ(frame_budget_90fps, actual_frame_budget);
38}
39
40TEST(Instrumentation, GetFrameBudgetFromUpdaterTest) {
42 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
43 updater.SetFrameBudget(frame_budget_90fps);
44
45 Stopwatch stopwatch(updater);
46 fml::Milliseconds actual_frame_budget = stopwatch.GetFrameBudget();
47 EXPECT_EQ(frame_budget_90fps, actual_frame_budget);
48}
49
50TEST(Instrumentation, GetLapByIndexTest) {
51 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
52 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
54 EXPECT_EQ(stopwatch.GetLap(1), fml::TimeDelta::FromMilliseconds(10));
55}
56
57TEST(Instrumentation, GetCurrentSampleTest) {
58 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
59 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
60 stopwatch.Start();
61 stopwatch.Stop();
62 EXPECT_EQ(stopwatch.GetCurrentSample(), size_t(1));
63}
64
65TEST(Instrumentation, GetLapsCount) {
66 fml::Milliseconds frame_budget_90fps = fml::RefreshRateToFrameBudget(90);
67 FixedRefreshRateStopwatch stopwatch(frame_budget_90fps);
69 EXPECT_EQ(stopwatch.GetLapsCount(), size_t(120));
70}
71
72} // namespace testing
73} // namespace flutter
Used for fixed refresh rate cases.
Definition: stopwatch.h:77
The refresh rate interface for Stopwatch.
Definition: stopwatch.h:20
const fml::TimeDelta & GetLap(size_t index) const
Definition: stopwatch.cc:45
fml::Milliseconds GetFrameBudget() const
All places which want to get frame_budget should call this function.
Definition: stopwatch.cc:88
size_t GetLapsCount() const
Return a reference to all the laps.
Definition: stopwatch.cc:49
size_t GetCurrentSample() const
Definition: stopwatch.cc:53
void SetLapTime(const fml::TimeDelta &delta)
Definition: stopwatch.cc:36
fml::Milliseconds GetFrameBudget() const override
void SetFrameBudget(fml::Milliseconds budget)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46
TEST(DisplayListComplexity, EmptyDisplayList)
std::chrono::duration< double, std::milli > Milliseconds
Definition: time_delta.h:18
Milliseconds RefreshRateToFrameBudget(T refresh_rate)
Definition: time_delta.h:24