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 <stdint.h> | 5 #include <stdint.h> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/budget_service/budget_manager.h" | 10 #include "chrome/browser/budget_service/budget_manager.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 return BudgetManagerFactory::GetForProfile(&profile_); | 33 return BudgetManagerFactory::GetForProfile(&profile_); |
34 } | 34 } |
35 | 35 |
36 void SetSiteEngagementScore(const GURL& url, double score) { | 36 void SetSiteEngagementScore(const GURL& url, double score) { |
37 SiteEngagementService* service = SiteEngagementService::Get(&profile_); | 37 SiteEngagementService* service = SiteEngagementService::Get(&profile_); |
38 service->ResetScoreForURL(url, score); | 38 service->ResetScoreForURL(url, score); |
39 } | 39 } |
40 | 40 |
41 Profile* profile() { return &profile_; } | 41 Profile* profile() { return &profile_; } |
42 | 42 |
| 43 void ReserveCallback(base::Closure run_loop_closure, |
| 44 blink::mojom::BudgetServiceErrorType error, |
| 45 bool success) { |
| 46 success_ = (error == blink::mojom::BudgetServiceErrorType::NONE) && success; |
| 47 run_loop_closure.Run(); |
| 48 } |
| 49 |
43 void StatusCallback(base::Closure run_loop_closure, bool success) { | 50 void StatusCallback(base::Closure run_loop_closure, bool success) { |
44 success_ = success; | 51 success_ = success; |
45 run_loop_closure.Run(); | 52 run_loop_closure.Run(); |
46 } | 53 } |
47 | 54 |
48 bool ReserveBudget(blink::mojom::BudgetOperationType type) { | 55 bool ReserveBudget(blink::mojom::BudgetOperationType type) { |
49 const GURL origin(kTestOrigin); | 56 const GURL origin(kTestOrigin); |
50 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
51 GetManager()->Reserve( | 58 GetManager()->Reserve( |
52 origin, type, | 59 origin, type, |
53 base::Bind(&BudgetManagerTest::StatusCallback, base::Unretained(this), | 60 base::Bind(&BudgetManagerTest::ReserveCallback, base::Unretained(this), |
54 run_loop.QuitClosure())); | 61 run_loop.QuitClosure())); |
55 run_loop.Run(); | 62 run_loop.Run(); |
56 return success_; | 63 return success_; |
57 } | 64 } |
58 | 65 |
59 bool ConsumeBudget(blink::mojom::BudgetOperationType type) { | 66 bool ConsumeBudget(blink::mojom::BudgetOperationType type) { |
60 const GURL origin(kTestOrigin); | 67 const GURL origin(kTestOrigin); |
61 base::RunLoop run_loop; | 68 base::RunLoop run_loop; |
62 GetManager()->Consume( | 69 GetManager()->Consume( |
63 origin, type, | 70 origin, type, |
(...skipping 28 matching lines...) Expand all Loading... |
92 ASSERT_FALSE(ReserveBudget(type)); | 99 ASSERT_FALSE(ReserveBudget(type)); |
93 | 100 |
94 // Try to consume for the 24 messages reserved. | 101 // Try to consume for the 24 messages reserved. |
95 for (int i = 0; i < 24; i++) | 102 for (int i = 0; i < 24; i++) |
96 ASSERT_TRUE(ConsumeBudget(type)); | 103 ASSERT_TRUE(ConsumeBudget(type)); |
97 | 104 |
98 // The next consume should fail, since there is no reservation or budget | 105 // The next consume should fail, since there is no reservation or budget |
99 // available. | 106 // available. |
100 ASSERT_FALSE(ConsumeBudget(type)); | 107 ASSERT_FALSE(ConsumeBudget(type)); |
101 } | 108 } |
OLD | NEW |