Skip to content

Commit c957080

Browse files
committed
Add new unit test for week of installation validation
1 parent 6a779ff commit c957080

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

browser/brave_stats_updater_unittest.cc

+70-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
23
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
34
* You can obtain one at http://mozilla.org/MPL/2.0/. */
45

@@ -32,8 +33,8 @@ class BraveStatsUpdaterTest: public testing::Test {
3233

3334
void SetUp() override {
3435
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());
3738
}
3839

3940
PrefService* GetLocalState() { return &testing_local_state_; }
@@ -218,3 +219,69 @@ TEST_F(BraveStatsUpdaterTest, IsWeeklyUpdateNeededOnMondayLastCheckedOnSunday) {
218219
ASSERT_EQ(GetLocalState()->GetInteger(kLastCheckWOY), 45);
219220
}
220221
}
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, &current_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, &current_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, &current_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

Comments
 (0)