| Index: content/browser/download/rate_estimator_unittest.cc
|
| diff --git a/content/browser/download/rate_estimator_unittest.cc b/content/browser/download/rate_estimator_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ce4ca734f56ae647ebe1dcade54d3a502e2e57c2
|
| --- /dev/null
|
| +++ b/content/browser/download/rate_estimator_unittest.cc
|
| @@ -0,0 +1,56 @@
|
| +// Copyright (c) 2013 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 "content/browser/download/rate_estimator.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +TEST(RateEstimatorTest, RateEstimator) {
|
| + base::Time now;
|
| + RateEstimator estimator(base::TimeDelta::FromSeconds(1), 10u, now);
|
| + EXPECT_EQ(0u, estimator.GetBytesPerSecond(now));
|
| +
|
| + estimator.AddBytes(50u, now);
|
| + EXPECT_EQ(50u, estimator.GetBytesPerSecond(now));
|
| +
|
| + now += base::TimeDelta::FromMilliseconds(800);
|
| + estimator.AddBytes(50, now);
|
| + EXPECT_EQ(100u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Advance time.
|
| + now += base::TimeDelta::FromSeconds(3);
|
| + EXPECT_EQ(25u, estimator.GetBytesPerSecond(now));
|
| + estimator.AddBytes(60, now);
|
| + EXPECT_EQ(40u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Advance time again.
|
| + now += base::TimeDelta::FromSeconds(4);
|
| + EXPECT_EQ(20u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Advance time to the end.
|
| + now += base::TimeDelta::FromSeconds(2);
|
| + EXPECT_EQ(16u, estimator.GetBytesPerSecond(now));
|
| + estimator.AddBytes(100, now);
|
| + EXPECT_EQ(26u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Now wrap around to the start.
|
| + now += base::TimeDelta::FromSeconds(1);
|
| + EXPECT_EQ(16u, estimator.GetBytesPerSecond(now));
|
| + estimator.AddBytes(100, now);
|
| + EXPECT_EQ(26u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Advance far into the future.
|
| + now += base::TimeDelta::FromSeconds(40);
|
| + EXPECT_EQ(0u, estimator.GetBytesPerSecond(now));
|
| + estimator.AddBytes(100, now);
|
| + EXPECT_EQ(100u, estimator.GetBytesPerSecond(now));
|
| +
|
| + // Go backwards - this can happen if the user changes the clock.
|
| + now -= base::TimeDelta::FromSeconds(100);
|
| + EXPECT_EQ(0u, estimator.GetBytesPerSecond(now));
|
| +}
|
| +
|
| +} // namespace content
|
|
|