@@ -44,6 +44,10 @@ class BraveStatsUpdaterTest: public testing::Test {
44
44
brave::BraveStatsUpdaterParams::SetCurrentTimeForTest (current_time);
45
45
}
46
46
47
+ void SetFirstRunForTest (bool first_run) {
48
+ brave::BraveStatsUpdaterParams::SetFirstRunForTest (first_run);
49
+ }
50
+
47
51
private:
48
52
TestingPrefServiceSimple testing_local_state_;
49
53
};
@@ -148,6 +152,83 @@ TEST_F(BraveStatsUpdaterTest, IsMonthlyUpdateNeededLastCheckedNextMonth) {
148
152
ASSERT_EQ (GetLocalState ()->GetInteger (kLastCheckMonth ), kThisMonth );
149
153
}
150
154
155
+ TEST_F (BraveStatsUpdaterTest, HasDateOfInstallationFirstRun) {
156
+ base::Time::Exploded exploded;
157
+ base::Time current_time;
158
+
159
+ // Set date to 2018-11-04 (ISO week #44)
160
+ exploded.hour = 0 ;
161
+ exploded.minute = 0 ;
162
+ exploded.second = 0 ;
163
+ exploded.millisecond = 0 ;
164
+ exploded.day_of_week = 0 ;
165
+ exploded.year = 2018 ;
166
+ exploded.month = 11 ;
167
+ exploded.day_of_month = 4 ;
168
+
169
+ ASSERT_TRUE (base::Time::FromLocalExploded (exploded, ¤t_time));
170
+ SetCurrentTimeForTest (current_time);
171
+ SetFirstRunForTest (true );
172
+
173
+ brave::BraveStatsUpdaterParams brave_stats_updater_params (
174
+ GetLocalState (), kToday , kThisWeek , kThisMonth );
175
+ ASSERT_EQ (brave_stats_updater_params.GetDateOfInstallationParam (),
176
+ " 2018-11-04" );
177
+ }
178
+
179
+ TEST_F (BraveStatsUpdaterTest, HasDailyRetention) {
180
+ base::Time::Exploded exploded;
181
+ base::Time current_time, dtoi_time;
182
+
183
+ // Set date to 2018-11-04
184
+ exploded.hour = 0 ;
185
+ exploded.minute = 0 ;
186
+ exploded.second = 0 ;
187
+ exploded.millisecond = 0 ;
188
+ exploded.day_of_week = 0 ;
189
+ exploded.year = 2018 ;
190
+ exploded.month = 11 ;
191
+ exploded.day_of_month = 4 ;
192
+
193
+ ASSERT_TRUE (base::Time::FromLocalExploded (exploded, &dtoi_time));
194
+ // Make first run date 6 days earlier (still within 14 day window)
195
+ exploded.day_of_month = 10 ;
196
+ ASSERT_TRUE (base::Time::FromLocalExploded (exploded, ¤t_time));
197
+
198
+ SetCurrentTimeForTest (dtoi_time);
199
+ brave::BraveStatsUpdaterParams brave_stats_updater_params (
200
+ GetLocalState (), kToday , kThisWeek , kThisMonth );
201
+ SetCurrentTimeForTest (current_time);
202
+ ASSERT_EQ (brave_stats_updater_params.GetDateOfInstallationParam (),
203
+ " 2018-11-04" );
204
+ }
205
+
206
+ TEST_F (BraveStatsUpdaterTest, HasDailyRetentionExpiration) {
207
+ base::Time::Exploded exploded;
208
+ base::Time current_time, dtoi_time;
209
+
210
+ // Set date to 2018-11-04
211
+ exploded.hour = 0 ;
212
+ exploded.minute = 0 ;
213
+ exploded.second = 0 ;
214
+ exploded.millisecond = 0 ;
215
+ exploded.day_of_week = 0 ;
216
+ exploded.year = 2018 ;
217
+ exploded.month = 11 ;
218
+ exploded.day_of_month = 4 ;
219
+
220
+ ASSERT_TRUE (base::Time::FromLocalExploded (exploded, &dtoi_time));
221
+ // Make first run date 14 days earlier (outside 14 day window)
222
+ exploded.day_of_month = 18 ;
223
+ ASSERT_TRUE (base::Time::FromLocalExploded (exploded, ¤t_time));
224
+
225
+ SetCurrentTimeForTest (dtoi_time);
226
+ brave::BraveStatsUpdaterParams brave_stats_updater_params (
227
+ GetLocalState (), kToday , kThisWeek , kThisMonth );
228
+ SetCurrentTimeForTest (current_time);
229
+ ASSERT_EQ (brave_stats_updater_params.GetDateOfInstallationParam (), " null" );
230
+ }
231
+
151
232
// This test ensures that our weekly stats cut over on Monday
152
233
TEST_F (BraveStatsUpdaterTest, IsWeeklyUpdateNeededOnMondayLastCheckedOnSunday) {
153
234
base::Time::Exploded exploded;
0 commit comments