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