|
1 |
| -/* This Source Code Form is subject to the terms of the Mozilla Public |
| 1 | +/* Copyright (c) 2019 The Brave Authors. All rights reserved. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
2 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
3 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */
|
4 | 5 |
|
@@ -32,8 +33,8 @@ class BraveStatsUpdaterTest: public testing::Test {
|
32 | 33 |
|
33 | 34 | void SetUp() override {
|
34 | 35 | brave::RegisterPrefsForBraveStatsUpdater(testing_local_state_.registry());
|
35 |
| - brave::RegisterPrefsForBraveReferralsService(testing_local_state_.registry()); |
36 |
| - brave::BraveStatsUpdaterParams::SetCurrentTimeForTest(base::Time::Now()); |
| 36 | + brave::RegisterPrefsForBraveReferralsService( |
| 37 | + testing_local_state_.registry()); |
37 | 38 | }
|
38 | 39 |
|
39 | 40 | PrefService* GetLocalState() { return &testing_local_state_; }
|
@@ -218,3 +219,69 @@ TEST_F(BraveStatsUpdaterTest, IsWeeklyUpdateNeededOnMondayLastCheckedOnSunday) {
|
218 | 219 | ASSERT_EQ(GetLocalState()->GetInteger(kLastCheckWOY), 45);
|
219 | 220 | }
|
220 | 221 | }
|
| 222 | + |
| 223 | +TEST_F(BraveStatsUpdaterTest, HasCorrectWeekOfInstallation) { |
| 224 | + base::Time::Exploded exploded; |
| 225 | + base::Time current_time; |
| 226 | + |
| 227 | + { |
| 228 | + // Set date to 2019-03-24 (Sunday) |
| 229 | + exploded.hour = 0; |
| 230 | + exploded.minute = 0; |
| 231 | + exploded.second = 0; |
| 232 | + exploded.millisecond = 0; |
| 233 | + exploded.day_of_week = 0; |
| 234 | + exploded.year = 2019; |
| 235 | + exploded.month = 3; |
| 236 | + exploded.day_of_month = 24; |
| 237 | + |
| 238 | + ASSERT_TRUE(base::Time::FromLocalExploded(exploded, ¤t_time)); |
| 239 | + SetCurrentTimeForTest(current_time); |
| 240 | + |
| 241 | + // Make sure that week of installation is previous Monday |
| 242 | + brave::BraveStatsUpdaterParams brave_stats_updater_params(GetLocalState()); |
| 243 | + ASSERT_EQ(brave_stats_updater_params.GetWeekOfInstallationParam(), |
| 244 | + "2019-03-18"); |
| 245 | + } |
| 246 | + |
| 247 | + { |
| 248 | + // Set date to 2019-03-25 (Monday) |
| 249 | + exploded.hour = 0; |
| 250 | + exploded.minute = 0; |
| 251 | + exploded.second = 0; |
| 252 | + exploded.millisecond = 0; |
| 253 | + exploded.day_of_week = 0; |
| 254 | + exploded.year = 2019; |
| 255 | + exploded.month = 3; |
| 256 | + exploded.day_of_month = 25; |
| 257 | + |
| 258 | + ASSERT_TRUE(base::Time::FromLocalExploded(exploded, ¤t_time)); |
| 259 | + SetCurrentTimeForTest(current_time); |
| 260 | + |
| 261 | + // Make sure that week of installation is today, since today is a |
| 262 | + // Monday |
| 263 | + brave::BraveStatsUpdaterParams brave_stats_updater_params(GetLocalState()); |
| 264 | + ASSERT_EQ(brave_stats_updater_params.GetWeekOfInstallationParam(), |
| 265 | + "2019-03-25"); |
| 266 | + } |
| 267 | + |
| 268 | + { |
| 269 | + // Set date to 2019-03-30 (Saturday) |
| 270 | + exploded.hour = 0; |
| 271 | + exploded.minute = 0; |
| 272 | + exploded.second = 0; |
| 273 | + exploded.millisecond = 0; |
| 274 | + exploded.day_of_week = 0; |
| 275 | + exploded.year = 2019; |
| 276 | + exploded.month = 3; |
| 277 | + exploded.day_of_month = 30; |
| 278 | + |
| 279 | + ASSERT_TRUE(base::Time::FromLocalExploded(exploded, ¤t_time)); |
| 280 | + SetCurrentTimeForTest(current_time); |
| 281 | + |
| 282 | + // Make sure that week of installation is previous Monday |
| 283 | + brave::BraveStatsUpdaterParams brave_stats_updater_params(GetLocalState()); |
| 284 | + ASSERT_EQ(brave_stats_updater_params.GetWeekOfInstallationParam(), |
| 285 | + "2019-03-25"); |
| 286 | + } |
| 287 | +} |
0 commit comments