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

Unified Diff: chrome/browser/budget_service/budget_database_unittest.cc

Issue 2199763002: Add in expiring budget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@budget_database
Patch Set: Converted to base::Time return and other code review changes Created 4 years, 4 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
Index: chrome/browser/budget_service/budget_database_unittest.cc
diff --git a/chrome/browser/budget_service/budget_database_unittest.cc b/chrome/browser/budget_service/budget_database_unittest.cc
index f10a2ba9217a73978ed2a924b29be9426fdfa798..f4cb523dcf618e81800ef79f89027a759013108b 100644
--- a/chrome/browser/budget_service/budget_database_unittest.cc
+++ b/chrome/browser/budget_service/budget_database_unittest.cc
@@ -101,6 +101,7 @@ TEST_F(BudgetDatabaseTest, ReadAndWriteTest) {
base::SimpleTestClock* clock = SetClockForTesting();
base::TimeDelta expiration(
base::TimeDelta::FromHours(kDefaultExpirationInHours));
+ base::Time starting_time = clock->Now();
base::Time expiration_time = clock->Now() + expiration;
// Add two budget chunks with different expirations (default expiration and
@@ -122,18 +123,38 @@ TEST_F(BudgetDatabaseTest, ReadAndWriteTest) {
// First value should be [total_budget, now]
EXPECT_EQ(kDefaultBudget1 + kDefaultBudget2, iter->first);
- // TODO(harkness): This will be "now" in the final version. For now, it's
- // just 0.
- EXPECT_EQ(0, iter->second);
+ EXPECT_EQ(clock->Now(), iter->second);
// The next value should be the budget after the first chunk expires.
iter++;
EXPECT_EQ(kDefaultBudget2, iter->first);
- EXPECT_EQ(expiration_time.ToInternalValue(), iter->second);
+ EXPECT_EQ(expiration_time, iter->second);
// The final value gives the budget of 0.0 after the second chunk expires.
expiration_time += base::TimeDelta::FromDays(1);
iter++;
EXPECT_EQ(0, iter->first);
- EXPECT_EQ(expiration_time.ToInternalValue(), iter->second);
+ EXPECT_EQ(expiration_time, iter->second);
+
+ // Advance the time until the first chunk of budget should be expired.
+ clock->SetNow(starting_time +
+ base::TimeDelta::FromHours(kDefaultExpirationInHours));
+
+ // Get the new budget and check that kDefaultBudget1 has been removed.
+ GetBudgetDetails();
+ iter = expectation().begin();
+ ASSERT_EQ(2U, expectation().size());
+ EXPECT_EQ(kDefaultBudget2, iter->first);
+ iter++;
+ EXPECT_EQ(0, iter->first);
+
+ // Advace the time until both chunks of budget should be expired.
+ clock->SetNow(starting_time +
+ base::TimeDelta::FromHours(kDefaultExpirationInHours) +
+ base::TimeDelta::FromDays(1));
+
+ GetBudgetDetails();
+ iter = expectation().begin();
+ ASSERT_EQ(1U, expectation().size());
+ EXPECT_EQ(0, iter->first);
}

Powered by Google App Engine
This is Rietveld 408576698