| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 db_.SpendBudget(origin(), amount, | 53 db_.SpendBudget(origin(), amount, |
| 54 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete, | 54 base::Bind(&BudgetDatabaseTest::WriteBudgetComplete, |
| 55 base::Unretained(this), run_loop.QuitClosure())); | 55 base::Unretained(this), run_loop.QuitClosure())); |
| 56 run_loop.Run(); | 56 run_loop.Run(); |
| 57 return success_; | 57 return success_; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void GetBudgetDetailsComplete( | 60 void GetBudgetDetailsComplete( |
| 61 base::Closure run_loop_closure, | 61 base::Closure run_loop_closure, |
| 62 blink::mojom::BudgetServiceErrorType error, | 62 blink::mojom::BudgetServiceErrorType error, |
| 63 mojo::Array<blink::mojom::BudgetStatePtr> predictions) { | 63 std::vector<blink::mojom::BudgetStatePtr> predictions) { |
| 64 success_ = (error == blink::mojom::BudgetServiceErrorType::NONE); | 64 success_ = (error == blink::mojom::BudgetServiceErrorType::NONE); |
| 65 prediction_.Swap(&predictions); | 65 prediction_.swap(predictions); |
| 66 run_loop_closure.Run(); | 66 run_loop_closure.Run(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Get the full set of budget predictions for the origin. | 69 // Get the full set of budget predictions for the origin. |
| 70 void GetBudgetDetails() { | 70 void GetBudgetDetails() { |
| 71 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
| 72 db_.GetBudgetDetails( | 72 db_.GetBudgetDetails( |
| 73 origin(), base::Bind(&BudgetDatabaseTest::GetBudgetDetailsComplete, | 73 origin(), base::Bind(&BudgetDatabaseTest::GetBudgetDetailsComplete, |
| 74 base::Unretained(this), run_loop.QuitClosure())); | 74 base::Unretained(this), run_loop.QuitClosure())); |
| 75 run_loop.Run(); | 75 run_loop.Run(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 void SetSiteEngagementScore(double score) { | 88 void SetSiteEngagementScore(double score) { |
| 89 SiteEngagementService* service = SiteEngagementService::Get(&profile_); | 89 SiteEngagementService* service = SiteEngagementService::Get(&profile_); |
| 90 service->ResetScoreForURL(GURL(kTestOrigin), score); | 90 service->ResetScoreForURL(GURL(kTestOrigin), score); |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } | 94 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } |
| 95 bool success_; | 95 bool success_; |
| 96 mojo::Array<blink::mojom::BudgetStatePtr> prediction_; | 96 std::vector<blink::mojom::BudgetStatePtr> prediction_; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 content::TestBrowserThreadBundle thread_bundle_; | 99 content::TestBrowserThreadBundle thread_bundle_; |
| 100 std::unique_ptr<budget_service::Budget> budget_; | 100 std::unique_ptr<budget_service::Budget> budget_; |
| 101 TestingProfile profile_; | 101 TestingProfile profile_; |
| 102 BudgetDatabase db_; | 102 BudgetDatabase db_; |
| 103 base::HistogramTester histogram_tester_; | 103 base::HistogramTester histogram_tester_; |
| 104 const url::Origin origin_; | 104 const url::Origin origin_; |
| 105 }; | 105 }; |
| 106 | 106 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 306 |
| 307 std::vector<base::Bucket> low_budget_buckets = | 307 std::vector<base::Bucket> low_budget_buckets = |
| 308 GetHistogramTester()->GetAllSamples( | 308 GetHistogramTester()->GetAllSamples( |
| 309 "PushMessaging.SESForLowBudgetOrigin"); | 309 "PushMessaging.SESForLowBudgetOrigin"); |
| 310 ASSERT_EQ(2U, low_budget_buckets.size()); | 310 ASSERT_EQ(2U, low_budget_buckets.size()); |
| 311 EXPECT_EQ(engagement, low_budget_buckets[0].min); | 311 EXPECT_EQ(engagement, low_budget_buckets[0].min); |
| 312 EXPECT_EQ(1, low_budget_buckets[0].count); | 312 EXPECT_EQ(1, low_budget_buckets[0].count); |
| 313 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min); | 313 EXPECT_EQ(engagement * 2, low_budget_buckets[1].min); |
| 314 EXPECT_EQ(1, low_budget_buckets[1].count); | 314 EXPECT_EQ(1, low_budget_buckets[1].count); |
| 315 } | 315 } |
| OLD | NEW |