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

Unified Diff: remoting/base/rate_counter_unittest.cc

Issue 2561173004: Cleanup RateCounter (Closed)
Patch Set: Created 4 years 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 | « remoting/base/rate_counter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/rate_counter_unittest.cc
diff --git a/remoting/base/rate_counter_unittest.cc b/remoting/base/rate_counter_unittest.cc
index 91b91c511ad06e9778cc5dc2a24a794d52e7f5fe..8d4188ec98db686fefd3442eb7bce2f3c815bcd1 100644
--- a/remoting/base/rate_counter_unittest.cc
+++ b/remoting/base/rate_counter_unittest.cc
@@ -6,6 +6,7 @@
#include <stdint.h>
#include "base/macros.h"
+#include "base/test/simple_test_tick_clock.h"
#include "remoting/base/rate_counter.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -18,10 +19,11 @@ TEST(RateCounterTest, OneSecondWindow) {
RateCounter rate_counter(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(0, rate_counter.Rate());
- base::Time now = base::Time::Now();
+ base::SimpleTestTickClock tick_clock;
+ rate_counter.set_tick_clock_for_tests(&tick_clock);
+
for (size_t i = 0; i < arraysize(kTestValues); ++i) {
- now += base::TimeDelta::FromSeconds(1);
- rate_counter.SetCurrentTimeForTest(now);
+ tick_clock.Advance(base::TimeDelta::FromSeconds(1));
rate_counter.Record(kTestValues[i]);
EXPECT_EQ(static_cast<double>(kTestValues[i]), rate_counter.Rate());
}
@@ -32,7 +34,8 @@ TEST(RateCounterTest, OneSecondWindowAllSamples) {
RateCounter rate_counter(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(0, rate_counter.Rate());
- rate_counter.SetCurrentTimeForTest(base::Time::Now());
+ base::SimpleTestTickClock tick_clock;
+ rate_counter.set_tick_clock_for_tests(&tick_clock);
double expected = 0.0;
for (size_t i = 0; i < arraysize(kTestValues); ++i) {
@@ -50,10 +53,11 @@ TEST(RateCounterTest, TwoSecondWindow) {
RateCounter rate_counter(base::TimeDelta::FromSeconds(2));
EXPECT_EQ(0, rate_counter.Rate());
- base::Time now = base::Time::Now();
+ base::SimpleTestTickClock tick_clock;
+ rate_counter.set_tick_clock_for_tests(&tick_clock);
+
for (size_t i = 0; i < arraysize(kTestValues); ++i) {
- now += base::TimeDelta::FromSeconds(1);
- rate_counter.SetCurrentTimeForTest(now);
+ tick_clock.Advance(base::TimeDelta::FromSeconds(1));
rate_counter.Record(kTestValues[i]);
double expected = kTestValues[i];
if (i > 0)
@@ -71,11 +75,12 @@ TEST(RateCounterTest, LongWindow) {
RateCounter rate_counter(base::TimeDelta::FromSeconds(kWindowSeconds));
EXPECT_EQ(0, rate_counter.Rate());
+ base::SimpleTestTickClock tick_clock;
+ rate_counter.set_tick_clock_for_tests(&tick_clock);
+
double expected = 0.0;
- base::Time now = base::Time::Now();
for (size_t i = 0; i < arraysize(kTestValues); ++i) {
- now += base::TimeDelta::FromSeconds(1);
- rate_counter.SetCurrentTimeForTest(now);
+ tick_clock.Advance(base::TimeDelta::FromSeconds(1));
rate_counter.Record(kTestValues[i]);
if (i != 0)
expected += kTestValues[i];
« no previous file with comments | « remoting/base/rate_counter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698