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

Side by Side Diff: chrome/browser/android/vr_shell/fps_meter_unittest.cc

Issue 2804943003: [vr] Add a frame rate counter for the vr UI (Closed)
Patch Set: () Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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
5 #include "chrome/browser/android/vr_shell/fps_meter.h"
6
7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace vr_shell {
11
12 namespace {
13
14 static constexpr double kTolerance = 0.01;
15
16 base::TimeTicks usToTicks(uint64_t us) {
17 return base::TimeTicks::FromInternalValue(us);
18 }
19
20 base::TimeDelta usToDelta(uint64_t us) {
21 return base::TimeDelta::FromInternalValue(us);
22 }
23
24 } // namespace
25
26 TEST(FPSMeter, GetFPSWithTooFewFrames) {
27 FPSMeter meter;
28 EXPECT_FALSE(meter.CanComputeFPS());
29 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
30
31 meter.AddFrame(usToTicks(16000));
32 EXPECT_FALSE(meter.CanComputeFPS());
33 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
34
35 meter.AddFrame(usToTicks(32000));
36 EXPECT_TRUE(meter.CanComputeFPS());
37 EXPECT_LT(0.0, meter.GetFPS());
38 }
39
40 TEST(FPSMeter, AccurateFPSWithManyFrames) {
41 FPSMeter meter;
42 EXPECT_FALSE(meter.CanComputeFPS());
43 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
44
45 base::TimeTicks now = usToTicks(1);
46 base::TimeDelta frame_time = usToDelta(16666);
47
48 meter.AddFrame(now);
49 EXPECT_FALSE(meter.CanComputeFPS());
50 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
51
52 for (int i = 0; i < 5; ++i) {
53 now += frame_time;
54 meter.AddFrame(now);
55 EXPECT_TRUE(meter.CanComputeFPS());
56 EXPECT_NEAR(60.0, meter.GetFPS(), kTolerance);
57 }
58 }
59
60 TEST(FPSMeter, AccurateFPSWithHigherFramerate) {
61 FPSMeter meter;
62 EXPECT_FALSE(meter.CanComputeFPS());
63 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
64
65 base::TimeTicks now = usToTicks(1);
66 base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 90.0);
67
68 meter.AddFrame(now);
69 EXPECT_FALSE(meter.CanComputeFPS());
70 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
71
72 for (int i = 0; i < 5; ++i) {
73 now += frame_time;
74 meter.AddFrame(now);
75 EXPECT_TRUE(meter.CanComputeFPS());
76 EXPECT_NEAR(1.0 / frame_time.InSecondsF(), meter.GetFPS(), kTolerance);
77 }
78 }
79
80 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698