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

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

Issue 2173833002: Expand the functionality of the BudgetDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final cleanup Created 4 years, 5 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/budget_service/budget_database.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37d5e34a8a2aaedd86faf9aea26a8fca2ee2c50f..3d34e06663735018885742b6c7005964a3636db7 100644
--- a/chrome/browser/budget_service/budget_database_unittest.cc
+++ b/chrome/browser/budget_service/budget_database_unittest.cc
@@ -42,11 +42,11 @@ class BudgetDatabaseTest : public ::testing::Test {
// Create two chunks and give them default values.
budget_service::BudgetChunk* budget_chunk = budget.add_budget();
- budget_chunk->set_budget_amount(kDefaultBudget1);
- budget_chunk->set_expiration_timestamp(kDefaultExpiration);
+ budget_chunk->set_amount(kDefaultBudget1);
+ budget_chunk->set_expiration(kDefaultExpiration);
budget_chunk = budget.add_budget();
- budget_chunk->set_budget_amount(kDefaultBudget2);
- budget_chunk->set_expiration_timestamp(kDefaultExpiration + 1);
+ budget_chunk->set_amount(kDefaultBudget2);
+ budget_chunk->set_expiration(kDefaultExpiration + 1);
base::RunLoop run_loop;
db_.SetValue(GURL(kTestOrigin), budget,
@@ -75,7 +75,30 @@ class BudgetDatabaseTest : public ::testing::Test {
return std::move(budget_);
}
+ void GetBudgetDetailsComplete(
+ base::Closure run_loop_closure,
+ bool success,
+ double debt,
+ const BudgetDatabase::BudgetExpectation& expectation) {
+ success_ = success;
+ debt_ = debt;
+ expectation_ = expectation;
+ run_loop_closure.Run();
+ }
+
+ void GetBudgetDetails() {
+ base::RunLoop run_loop;
+ db_.GetBudgetDetails(
+ GURL(kTestOrigin),
+ base::Bind(&BudgetDatabaseTest::GetBudgetDetailsComplete,
+ base::Unretained(this), run_loop.QuitClosure()));
+ run_loop.Run();
+ }
+
Profile* profile() { return &profile_; }
+ const BudgetDatabase::BudgetExpectation& expectation() {
+ return expectation_;
+ }
protected:
bool success_;
@@ -85,6 +108,8 @@ class BudgetDatabaseTest : public ::testing::Test {
std::unique_ptr<budget_service::Budget> budget_;
TestingProfile profile_;
BudgetDatabase db_;
+ double debt_ = 0;
+ BudgetDatabase::BudgetExpectation expectation_;
};
TEST_F(BudgetDatabaseTest, ReadAndWriteTest) {
@@ -93,9 +118,38 @@ TEST_F(BudgetDatabaseTest, ReadAndWriteTest) {
ASSERT_TRUE(success_);
EXPECT_EQ(kDefaultDebt, b->debt());
- EXPECT_EQ(kDefaultBudget1, b->budget(0).budget_amount());
- EXPECT_EQ(kDefaultBudget2, b->budget(1).budget_amount());
- EXPECT_EQ(kDefaultExpiration, b->budget(0).expiration_timestamp());
+ EXPECT_EQ(kDefaultBudget1, b->budget(0).amount());
+ EXPECT_EQ(kDefaultBudget2, b->budget(1).amount());
+ EXPECT_EQ(kDefaultExpiration, b->budget(0).expiration());
+}
+
+TEST_F(BudgetDatabaseTest, BudgetDetailsTest) {
+ ASSERT_TRUE(SetBudgetWithDefaultValues());
+ GetBudgetDetails();
+
+ // Get the expectation and validate it.
+ const auto& expected_value = expectation();
+ ASSERT_TRUE(success_);
+ ASSERT_EQ(3U, expected_value.size());
+
+ // Make sure that the correct data is returned.
+ auto iter = expected_value.begin();
+
+ // 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.0.
+ EXPECT_EQ(0, iter->second);
+
+ // The next value should be the budget after the first chunk expires.
+ iter++;
+ EXPECT_EQ(kDefaultBudget2, iter->first);
+ EXPECT_EQ(kDefaultExpiration, iter->second);
+
+ // The final value gives the budget of 0.0 after the second chunk expires.
+ iter++;
+ EXPECT_EQ(0, iter->first);
+ EXPECT_EQ(kDefaultExpiration + 1, iter->second);
}
} // namespace
« no previous file with comments | « chrome/browser/budget_service/budget_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698