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

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

Issue 2892813002: Fix off-by-one in fps_meter, fix unit test to catch this. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/fps_meter.h" 5 #include "chrome/browser/android/vr_shell/fps_meter.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace vr_shell { 10 namespace vr_shell {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 EXPECT_FALSE(meter.CanComputeFPS()); 42 EXPECT_FALSE(meter.CanComputeFPS());
43 EXPECT_FLOAT_EQ(0.0, meter.GetFPS()); 43 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
44 44
45 base::TimeTicks now = usToTicks(1); 45 base::TimeTicks now = usToTicks(1);
46 base::TimeDelta frame_time = usToDelta(16666); 46 base::TimeDelta frame_time = usToDelta(16666);
47 47
48 meter.AddFrame(now); 48 meter.AddFrame(now);
49 EXPECT_FALSE(meter.CanComputeFPS()); 49 EXPECT_FALSE(meter.CanComputeFPS());
50 EXPECT_FLOAT_EQ(0.0, meter.GetFPS()); 50 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
51 51
52 for (int i = 0; i < 5; ++i) { 52 for (size_t i = 0; i < 2 * meter.GetNumFrameTimes(); ++i) {
53 now += frame_time; 53 now += frame_time;
54 meter.AddFrame(now); 54 meter.AddFrame(now);
55 EXPECT_TRUE(meter.CanComputeFPS()); 55 EXPECT_TRUE(meter.CanComputeFPS());
56 EXPECT_NEAR(60.0, meter.GetFPS(), kTolerance); 56 EXPECT_NEAR(60.0, meter.GetFPS(), kTolerance);
57 } 57 }
58 } 58 }
59 59
60 TEST(FPSMeter, AccurateFPSWithHigherFramerate) { 60 TEST(FPSMeter, AccurateFPSWithHigherFramerate) {
61 FPSMeter meter; 61 FPSMeter meter;
62 EXPECT_FALSE(meter.CanComputeFPS()); 62 EXPECT_FALSE(meter.CanComputeFPS());
63 EXPECT_FLOAT_EQ(0.0, meter.GetFPS()); 63 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
64 64
65 base::TimeTicks now = usToTicks(1); 65 base::TimeTicks now = usToTicks(1);
66 base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 90.0); 66 base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 90.0);
67 67
68 meter.AddFrame(now); 68 meter.AddFrame(now);
69 EXPECT_FALSE(meter.CanComputeFPS()); 69 EXPECT_FALSE(meter.CanComputeFPS());
70 EXPECT_FLOAT_EQ(0.0, meter.GetFPS()); 70 EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
71 71
72 for (int i = 0; i < 5; ++i) { 72 for (int i = 0; i < 5; ++i) {
73 now += frame_time; 73 now += frame_time;
74 meter.AddFrame(now); 74 meter.AddFrame(now);
75 EXPECT_TRUE(meter.CanComputeFPS()); 75 EXPECT_TRUE(meter.CanComputeFPS());
76 EXPECT_NEAR(1.0 / frame_time.InSecondsF(), meter.GetFPS(), kTolerance); 76 EXPECT_NEAR(1.0 / frame_time.InSecondsF(), meter.GetFPS(), kTolerance);
77 } 77 }
78 } 78 }
79 79
80 } // namespace vr_shell 80 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698