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

Unified 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: dcheck is on 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/fps_meter_unittest.cc
diff --git a/chrome/browser/android/vr_shell/fps_meter_unittest.cc b/chrome/browser/android/vr_shell/fps_meter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5a9c0695defb6f7d441859fc7a2dcee386be2a5
--- /dev/null
+++ b/chrome/browser/android/vr_shell/fps_meter_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/fps_meter.h"
+
+#include "base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace vr_shell {
+
+namespace {
+
+static constexpr double kTolerance = 0.01;
+
+base::TimeTicks usToTicks(uint64_t us) {
+ return base::TimeTicks::FromInternalValue(us);
+}
+
+base::TimeDelta usToDelta(uint64_t us) {
+ return base::TimeDelta::FromInternalValue(us);
+}
+
+} // namespace
+
+TEST(FPSMeter, GetFPSWithTooFewFrames) {
+ FPSMeter meter;
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ meter.AddFrame(usToTicks(16000));
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ meter.AddFrame(usToTicks(32000));
+ EXPECT_TRUE(meter.CanComputeFPS());
+ EXPECT_LT(0.0, meter.GetFPS());
+}
+
+TEST(FPSMeter, AccurateFPSWithManyFrames) {
+ FPSMeter meter;
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ base::TimeTicks now = usToTicks(1);
+ base::TimeDelta frame_time = usToDelta(16666);
+
+ meter.AddFrame(now);
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ for (int i = 0; i < 5; ++i) {
+ now += frame_time;
+ meter.AddFrame(now);
+ EXPECT_TRUE(meter.CanComputeFPS());
+ EXPECT_NEAR(60.0, meter.GetFPS(), kTolerance);
+ }
+}
+
+TEST(FPSMeter, AccurateFPSWithHigherFramerate) {
+ FPSMeter meter;
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ base::TimeTicks now = usToTicks(1);
+ base::TimeDelta frame_time = base::TimeDelta::FromSecondsD(1.0 / 90.0);
+
+ meter.AddFrame(now);
+ EXPECT_FALSE(meter.CanComputeFPS());
+ EXPECT_FLOAT_EQ(0.0, meter.GetFPS());
+
+ for (int i = 0; i < 5; ++i) {
+ now += frame_time;
+ meter.AddFrame(now);
+ EXPECT_TRUE(meter.CanComputeFPS());
+ EXPECT_NEAR(1.0 / frame_time.InSecondsF(), meter.GetFPS(), kTolerance);
+ }
+}
+
+} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698