Chromium Code Reviews| 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/test/simple_test_clock.h" | 9 #include "base/test/simple_test_clock.h" |
| 10 #include "chrome/browser/engagement/site_engagement_service.h" | 10 #include "chrome/browser/engagement/site_engagement_service.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 DictionaryPrefUpdate update(profile()->GetPrefs(), | 207 DictionaryPrefUpdate update(profile()->GetPrefs(), |
| 208 prefs::kBackgroundBudgetMap); | 208 prefs::kBackgroundBudgetMap); |
| 209 base::DictionaryValue* update_map = update.Get(); | 209 base::DictionaryValue* update_map = update.Get(); |
| 210 update_map->SetStringWithoutPathExpansion(origin.spec(), "20#2.0"); | 210 update_map->SetStringWithoutPathExpansion(origin.spec(), "20#2.0"); |
| 211 | 211 |
| 212 // Get the budget, expect that it will return SES. | 212 // Get the budget, expect that it will return SES. |
| 213 double budget = GetService()->GetBudget(origin); | 213 double budget = GetService()->GetBudget(origin); |
| 214 | 214 |
| 215 EXPECT_DOUBLE_EQ(budget, kTestSES); | 215 EXPECT_DOUBLE_EQ(budget, kTestSES); |
| 216 } | 216 } |
| 217 | |
| 218 TEST_F(BackgroundBudgetServiceTest, GetBudgetNegativeTime) { | |
| 219 // Manually construct a BackgroundBudgetService with a clock that the test | |
| 220 // can control so that we can fast forward in time. | |
| 221 BackgroundBudgetService* service = GetService(); | |
| 222 base::SimpleTestClock* clock = SetClockForTesting(); | |
| 223 base::Time starting_time = clock->Now(); | |
| 224 | |
| 225 // Set initial SES and budget values. | |
| 226 const GURL origin(kTestOrigin); | |
| 227 SetSiteEngagementScore(origin, kTestSES); | |
| 228 service->StoreBudget(origin, kTestBudget); | |
| 229 double budget = 0.0; | |
|
johnme
2016/06/01 18:24:38
Nit: declare this variable as `double budget = ser
harkness
2016/06/02 10:06:34
Done.
| |
| 230 | |
| 231 // Move time forward an hour and get the budget. | |
| 232 clock->SetNow(starting_time + base::TimeDelta::FromHours(1)); | |
| 233 budget = service->GetBudget(origin); | |
|
johnme
2016/06/01 18:24:38
Nit: add an assert that this budget is different f
harkness
2016/06/02 10:06:34
Done.
| |
| 234 service->StoreBudget(origin, budget); | |
| 235 | |
| 236 // Now move time backwards a day and make sure that the current | |
| 237 // budget matches the budget of the most foward time. | |
| 238 clock->SetNow(starting_time - base::TimeDelta::FromDays(1)); | |
| 239 double back_budget = service->GetBudget(origin); | |
| 240 EXPECT_NEAR(budget, back_budget, 0.01); | |
| 241 } | |
| OLD | NEW |