Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / browser / download / rate_estimator_unittest.cc
blobcb3a14fd5dd0cec276569cf9190e3cd9c93d785a
1 // Copyright 2013 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.
5 #include "content/browser/download/rate_estimator.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using base::TimeDelta;
11 namespace content {
13 TEST(RateEstimatorTest, RateEstimator) {
14 base::TimeTicks now;
15 RateEstimator estimator(TimeDelta::FromSeconds(1), 10u, now);
16 EXPECT_EQ(0u, estimator.GetCountPerSecond(now));
18 estimator.Increment(50u, now);
19 EXPECT_EQ(50u, estimator.GetCountPerSecond(now));
21 now += TimeDelta::FromMilliseconds(800);
22 estimator.Increment(50, now);
23 EXPECT_EQ(100u, estimator.GetCountPerSecond(now));
25 // Advance time.
26 now += TimeDelta::FromSeconds(3);
27 EXPECT_EQ(25u, estimator.GetCountPerSecond(now));
28 estimator.Increment(60, now);
29 EXPECT_EQ(40u, estimator.GetCountPerSecond(now));
31 // Advance time again.
32 now += TimeDelta::FromSeconds(4);
33 EXPECT_EQ(20u, estimator.GetCountPerSecond(now));
35 // Advance time to the end.
36 now += TimeDelta::FromSeconds(2);
37 EXPECT_EQ(16u, estimator.GetCountPerSecond(now));
38 estimator.Increment(100, now);
39 EXPECT_EQ(26u, estimator.GetCountPerSecond(now));
41 // Now wrap around to the start.
42 now += TimeDelta::FromSeconds(1);
43 EXPECT_EQ(16u, estimator.GetCountPerSecond(now));
44 estimator.Increment(100, now);
45 EXPECT_EQ(26u, estimator.GetCountPerSecond(now));
47 // Advance far into the future.
48 now += TimeDelta::FromSeconds(40);
49 EXPECT_EQ(0u, estimator.GetCountPerSecond(now));
50 estimator.Increment(100, now);
51 EXPECT_EQ(100u, estimator.GetCountPerSecond(now));
53 // Pretend that there is timeticks wrap around.
54 now = base::TimeTicks();
55 EXPECT_EQ(0u, estimator.GetCountPerSecond(now));
58 } // namespace content