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

Side by Side Diff: chrome/browser/budget_service/budget_database_unittest.cc

Issue 2326523003: Connect Mojo budget_service to BudgetManager implementation of Reserve. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/budget_service/budget_database.h" 5 #include "chrome/browser/budget_service/budget_database.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 19 matching lines...) Expand all
30 } // namespace 30 } // namespace
31 31
32 class BudgetDatabaseTest : public ::testing::Test { 32 class BudgetDatabaseTest : public ::testing::Test {
33 public: 33 public:
34 BudgetDatabaseTest() 34 BudgetDatabaseTest()
35 : success_(false), 35 : success_(false),
36 db_(&profile_, 36 db_(&profile_,
37 profile_.GetPath().Append(FILE_PATH_LITERAL("BudgetDatabase")), 37 profile_.GetPath().Append(FILE_PATH_LITERAL("BudgetDatabase")),
38 base::ThreadTaskRunnerHandle::Get()) {} 38 base::ThreadTaskRunnerHandle::Get()) {}
39 39
40 void WriteBudgetComplete(base::Closure run_loop_closure, bool success) { 40 void WriteBudgetComplete(base::Closure run_loop_closure,
41 success_ = success; 41 blink::mojom::BudgetServiceErrorType error,
42 bool success) {
43 success_ = (error == blink::mojom::BudgetServiceErrorType::NONE) && success;
42 run_loop_closure.Run(); 44 run_loop_closure.Run();
43 } 45 }
44 46
45 // Spend budget for the origin. 47 // Spend budget for the origin.
46 bool SpendBudget(const GURL& origin, double amount) { 48 bool SpendBudget(const GURL& origin, double amount) {
47 base::RunLoop run_loop; 49 base::RunLoop run_loop;
48 db_.SpendBudget(origin, amount, 50 db_.SpendBudget(origin, amount,
49 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete, 51 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete,
50 base::Unretained(this), run_loop.QuitClosure())); 52 base::Unretained(this), run_loop.QuitClosure()));
51 run_loop.Run(); 53 run_loop.Run();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 307
306 std::vector<base::Bucket> low_budget_buckets = 308 std::vector<base::Bucket> low_budget_buckets =
307 GetHistogramTester()->GetAllSamples( 309 GetHistogramTester()->GetAllSamples(
308 "PushMessaging.SESForLowBudgetOrigin"); 310 "PushMessaging.SESForLowBudgetOrigin");
309 ASSERT_EQ(2U, low_budget_buckets.size()); 311 ASSERT_EQ(2U, low_budget_buckets.size());
310 EXPECT_EQ(engagement, low_budget_buckets[0].min); 312 EXPECT_EQ(engagement, low_budget_buckets[0].min);
311 EXPECT_EQ(1, low_budget_buckets[0].count); 313 EXPECT_EQ(1, low_budget_buckets[0].count);
312 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min); 314 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min);
313 EXPECT_EQ(1, low_budget_buckets[1].count); 315 EXPECT_EQ(1, low_budget_buckets[1].count);
314 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698