| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class BudgetDatabaseTest : public ::testing::Test { | 34 class BudgetDatabaseTest : public ::testing::Test { |
| 35 public: | 35 public: |
| 36 BudgetDatabaseTest() | 36 BudgetDatabaseTest() |
| 37 : success_(false), | 37 : success_(false), |
| 38 db_(&profile_, | 38 db_(&profile_, |
| 39 profile_.GetPath().Append(FILE_PATH_LITERAL("BudgetDatabase")), | 39 profile_.GetPath().Append(FILE_PATH_LITERAL("BudgetDatabase")), |
| 40 base::ThreadTaskRunnerHandle::Get()), | 40 base::ThreadTaskRunnerHandle::Get()), |
| 41 origin_(url::Origin(GURL(kTestOrigin))) {} | 41 origin_(url::Origin(GURL(kTestOrigin))) {} |
| 42 | 42 |
| 43 void WriteBudgetComplete(base::Closure run_loop_closure, bool success) { | 43 void WriteBudgetComplete(base::Closure run_loop_closure, |
| 44 success_ = success; | 44 blink::mojom::BudgetServiceErrorType error, |
| 45 bool success) { |
| 46 success_ = (error == blink::mojom::BudgetServiceErrorType::NONE) && success; |
| 45 run_loop_closure.Run(); | 47 run_loop_closure.Run(); |
| 46 } | 48 } |
| 47 | 49 |
| 48 // Spend budget for the origin. | 50 // Spend budget for the origin. |
| 49 bool SpendBudget(double amount) { | 51 bool SpendBudget(double amount) { |
| 50 base::RunLoop run_loop; | 52 base::RunLoop run_loop; |
| 51 db_.SpendBudget(origin(), amount, | 53 db_.SpendBudget(origin(), amount, |
| 52 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete, | 54 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete, |
| 53 base::Unretained(this), run_loop.QuitClosure())); | 55 base::Unretained(this), run_loop.QuitClosure())); |
| 54 run_loop.Run(); | 56 run_loop.Run(); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 305 |
| 304 std::vector<base::Bucket> low_budget_buckets = | 306 std::vector<base::Bucket> low_budget_buckets = |
| 305 GetHistogramTester()->GetAllSamples( | 307 GetHistogramTester()->GetAllSamples( |
| 306 "PushMessaging.SESForLowBudgetOrigin"); | 308 "PushMessaging.SESForLowBudgetOrigin"); |
| 307 ASSERT_EQ(2U, low_budget_buckets.size()); | 309 ASSERT_EQ(2U, low_budget_buckets.size()); |
| 308 EXPECT_EQ(engagement, low_budget_buckets[0].min); | 310 EXPECT_EQ(engagement, low_budget_buckets[0].min); |
| 309 EXPECT_EQ(1, low_budget_buckets[0].count); | 311 EXPECT_EQ(1, low_budget_buckets[0].count); |
| 310 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min); | 312 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min); |
| 311 EXPECT_EQ(1, low_budget_buckets[1].count); | 313 EXPECT_EQ(1, low_budget_buckets[1].count); |
| 312 } | 314 } |
| OLD | NEW |