@@ -207,10 +207,13 @@ class NTPBackgroundImagesViewCounterTest : public testing::Test {
207
207
return ad_info;
208
208
}
209
209
210
+ int GetInitialCountToBrandedWallpaper () const {
211
+ return ViewCounterModel::kInitialCountToBrandedWallpaper ;
212
+ }
213
+
210
214
base::Value TryGetFirstSponsoredImageWallpaper () {
211
215
// Loading initial count times.
212
- for (int i = 0 ; i < ViewCounterModel::kInitialCountToBrandedWallpaper ;
213
- ++i) {
216
+ for (int i = 0 ; i < GetInitialCountToBrandedWallpaper (); ++i) {
214
217
base::Value wallpaper = view_counter_->GetCurrentWallpaperForDisplay ();
215
218
EXPECT_TRUE (wallpaper.FindBoolKey (ntp_background_images::kIsBackgroundKey )
216
219
.value_or (false ));
@@ -367,7 +370,7 @@ TEST_F(NTPBackgroundImagesViewCounterTest, ModelTest) {
367
370
368
371
// Initial count is not changed because branded wallpaper is always
369
372
// visible in SR mode.
370
- int expected_count = ViewCounterModel:: kInitialCountToBrandedWallpaper ;
373
+ int expected_count = GetInitialCountToBrandedWallpaper () ;
371
374
view_counter_->RegisterPageView ();
372
375
view_counter_->RegisterPageView ();
373
376
EXPECT_EQ (expected_count, view_counter_->model_ .count_to_branded_wallpaper_ );
@@ -409,8 +412,9 @@ TEST_F(NTPBackgroundImagesViewCounterTest,
409
412
GetSposoredImageWallpaperAdsServiceDisabled) {
410
413
InitBackgroundAndSponsoredImageWallpapers ();
411
414
412
- EXPECT_CALL (ads_service_, IsEnabled ()).WillOnce (Return (false ));
415
+ EXPECT_CALL (ads_service_, IsEnabled ()).WillRepeatedly (Return (false ));
413
416
EXPECT_CALL (ads_service_, GetPrefetchedNewTabPageAd ()).Times (0 );
417
+ EXPECT_CALL (ads_service_, PrefetchNewTabPageAd ()).Times (0 );
414
418
415
419
base::Value si_wallpaper = TryGetFirstSponsoredImageWallpaper ();
416
420
EXPECT_FALSE (si_wallpaper.FindBoolKey (ntp_background_images::kIsBackgroundKey )
@@ -430,9 +434,11 @@ TEST_F(NTPBackgroundImagesViewCounterTest,
430
434
TEST_F (NTPBackgroundImagesViewCounterTest, SponsoredImageAdFrequencyCapped) {
431
435
InitBackgroundAndSponsoredImageWallpapers ();
432
436
433
- EXPECT_CALL (ads_service_, IsEnabled ()).WillOnce (Return (true ));
437
+ EXPECT_CALL (ads_service_, IsEnabled ()).WillRepeatedly (Return (true ));
434
438
EXPECT_CALL (ads_service_, GetPrefetchedNewTabPageAd ())
435
439
.WillOnce (Return (absl::nullopt));
440
+ EXPECT_CALL (ads_service_, PrefetchNewTabPageAd ())
441
+ .Times (GetInitialCountToBrandedWallpaper ());
436
442
EXPECT_CALL (ads_service_, OnFailedToPrefetchNewTabPageAd (_, _)).Times (0 );
437
443
438
444
base::Value si_wallpaper = TryGetFirstSponsoredImageWallpaper ();
@@ -450,9 +456,11 @@ TEST_F(NTPBackgroundImagesViewCounterTest, SponsoredImageAdServed) {
450
456
ads::NewTabPageAdInfo ad_info = CreateNewTabPageAdInfo ();
451
457
EXPECT_TRUE (AdInfoMatchesSponsoredImage (ad_info, 0 , 1 ));
452
458
453
- EXPECT_CALL (ads_service_, IsEnabled ()).WillOnce (Return (true ));
459
+ EXPECT_CALL (ads_service_, IsEnabled ()).WillRepeatedly (Return (true ));
454
460
EXPECT_CALL (ads_service_, GetPrefetchedNewTabPageAd ())
455
461
.WillOnce (Return (ad_info));
462
+ EXPECT_CALL (ads_service_, PrefetchNewTabPageAd ())
463
+ .Times (GetInitialCountToBrandedWallpaper ());
456
464
EXPECT_CALL (ads_service_, OnFailedToPrefetchNewTabPageAd (_, _)).Times (0 );
457
465
458
466
base::Value si_wallpaper = TryGetFirstSponsoredImageWallpaper ();
@@ -477,9 +485,11 @@ TEST_F(NTPBackgroundImagesViewCounterTest, WrongSponsoredImageAdServed) {
477
485
ad_info.creative_instance_id = " wrong_creative_instance_id" ;
478
486
EXPECT_FALSE (AdInfoMatchesSponsoredImage (ad_info, 0 , 1 ));
479
487
480
- EXPECT_CALL (ads_service_, IsEnabled ()).WillOnce (Return (true ));
488
+ EXPECT_CALL (ads_service_, IsEnabled ()).WillRepeatedly (Return (true ));
481
489
EXPECT_CALL (ads_service_, GetPrefetchedNewTabPageAd ())
482
490
.WillOnce (Return (ad_info));
491
+ EXPECT_CALL (ads_service_, PrefetchNewTabPageAd ())
492
+ .Times (GetInitialCountToBrandedWallpaper ());
483
493
EXPECT_CALL (ads_service_, OnFailedToPrefetchNewTabPageAd (_, _));
484
494
485
495
base::Value si_wallpaper = TryGetFirstSponsoredImageWallpaper ();
0 commit comments