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 "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
11 #include "chrome/browser/budget_service/budget_manager.h" | 11 #include "chrome/browser/budget_service/budget_manager.h" |
12 #include "chrome/browser/budget_service/budget_manager_factory.h" | 12 #include "chrome/browser/budget_service/budget_manager_factory.h" |
13 #include "chrome/browser/engagement/site_engagement_service.h" | 13 #include "chrome/browser/engagement/site_engagement_service.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
17 #include "components/prefs/scoped_user_pref_update.h" | 17 #include "components/prefs/scoped_user_pref_update.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const char kTestOrigin[] = "https://example.com"; | 24 const char kTestOrigin[] = "https://example.com"; |
24 const double kTestBudget = 10.0; | 25 const double kTestBudget = 10.0; |
25 const double kTestSES = 48.0; | 26 const double kTestSES = 48.0; |
26 const double kLowSES = 1.0; | 27 const double kLowSES = 1.0; |
27 const double kMaxSES = 100.0; | 28 const double kMaxSES = 100.0; |
28 // Mirrors definition in BudgetManager, this is 10 days of seconds. | 29 // Mirrors definition in BudgetManager, this is 10 days of seconds. |
29 const double kSecondsToAccumulate = 864000.0; | 30 const double kSecondsToAccumulate = 864000.0; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 double budget = 0.0; | 187 double budget = 0.0; |
187 | 188 |
188 // Measure over 200 hours. In each hour a message is received, and for 1 in | 189 // Measure over 200 hours. In each hour a message is received, and for 1 in |
189 // 10, budget is consumed. | 190 // 10, budget is consumed. |
190 for (int i = 0; i < 200; i++) { | 191 for (int i = 0; i < 200; i++) { |
191 // Query for the budget after 1 hour has passed. | 192 // Query for the budget after 1 hour has passed. |
192 clock->Advance(base::TimeDelta::FromHours(1)); | 193 clock->Advance(base::TimeDelta::FromHours(1)); |
193 budget = GetBudget(); | 194 budget = GetBudget(); |
194 | 195 |
195 if (i % 10 == 0) { | 196 if (i % 10 == 0) { |
196 double cost = | 197 double cost = BudgetManager::GetCost( |
197 BudgetManager::GetCost(BudgetManager::CostType::SILENT_PUSH); | 198 blink::mojom::BudgetOperationType::SILENT_PUSH); |
198 StoreBudget(budget - cost); | 199 StoreBudget(budget - cost); |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 // With a SES of 48.0, the origin will get a budget of 2.4 per day, but the | 203 // With a SES of 48.0, the origin will get a budget of 2.4 per day, but the |
203 // old budget will also decay. At the end, we expect the budget to be lower | 204 // old budget will also decay. At the end, we expect the budget to be lower |
204 // than the starting budget. | 205 // than the starting budget. |
205 EXPECT_GT(budget, 0.0); | 206 EXPECT_GT(budget, 0.0); |
206 EXPECT_LT(budget, kTestBudget); | 207 EXPECT_LT(budget, kTestBudget); |
207 } | 208 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 240 |
240 // Store the updated budget. | 241 // Store the updated budget. |
241 StoreBudget(original_budget); | 242 StoreBudget(original_budget); |
242 EXPECT_NE(kTestBudget, original_budget); | 243 EXPECT_NE(kTestBudget, original_budget); |
243 | 244 |
244 // Now move time backwards a day and make sure that the current | 245 // Now move time backwards a day and make sure that the current |
245 // budget matches the budget of the most foward time. | 246 // budget matches the budget of the most foward time. |
246 clock->SetNow(starting_time - base::TimeDelta::FromDays(1)); | 247 clock->SetNow(starting_time - base::TimeDelta::FromDays(1)); |
247 EXPECT_NEAR(original_budget, GetBudget(), 0.01); | 248 EXPECT_NEAR(original_budget, GetBudget(), 0.01); |
248 } | 249 } |
OLD | NEW |