| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/ntp_tiles/most_visited_sites.h" | 5 #include "components/ntp_tiles/most_visited_sites.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // gmock makes it simple to create action templates that do for the various | 79 // gmock makes it simple to create action templates that do for the various |
| 80 // possible numbers of arguments. | 80 // possible numbers of arguments. |
| 81 ACTION_TEMPLATE(InvokeCallbackArgument, | 81 ACTION_TEMPLATE(InvokeCallbackArgument, |
| 82 HAS_1_TEMPLATE_PARAMS(int, k), | 82 HAS_1_TEMPLATE_PARAMS(int, k), |
| 83 AND_1_VALUE_PARAMS(p0)) { | 83 AND_1_VALUE_PARAMS(p0)) { |
| 84 ::std::tr1::get<k>(args).Run(p0); | 84 ::std::tr1::get<k>(args).Run(p0); |
| 85 } | 85 } |
| 86 | 86 |
| 87 NTPTile MakeTile(const std::string& title, | 87 NTPTile MakeTile(const std::string& title, |
| 88 const std::string& url, | 88 const std::string& url, |
| 89 NTPTileSource source) { | 89 TileSource source) { |
| 90 NTPTile tile; | 90 NTPTile tile; |
| 91 tile.title = base::ASCIIToUTF16(title); | 91 tile.title = base::ASCIIToUTF16(title); |
| 92 tile.url = GURL(url); | 92 tile.url = GURL(url); |
| 93 tile.source = source; | 93 tile.source = source; |
| 94 return tile; | 94 return tile; |
| 95 } | 95 } |
| 96 | 96 |
| 97 ChromeSuggestion MakeSuggestion(const std::string& title, | 97 ChromeSuggestion MakeSuggestion(const std::string& title, |
| 98 const std::string& url) { | 98 const std::string& url) { |
| 99 ChromeSuggestion suggestion; | 99 ChromeSuggestion suggestion; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 EXPECT_CALL(*mock_top_sites_, SyncWithHistory()); | 367 EXPECT_CALL(*mock_top_sites_, SyncWithHistory()); |
| 368 EXPECT_CALL(mock_suggestions_service_, AddCallback(_)) | 368 EXPECT_CALL(mock_suggestions_service_, AddCallback(_)) |
| 369 .WillOnce(Invoke(&suggestions_service_callbacks_, | 369 .WillOnce(Invoke(&suggestions_service_callbacks_, |
| 370 &SuggestionsService::ResponseCallbackList::Add)); | 370 &SuggestionsService::ResponseCallbackList::Add)); |
| 371 EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache()) | 371 EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache()) |
| 372 .WillOnce(Return(SuggestionsProfile())); // Empty cache. | 372 .WillOnce(Return(SuggestionsProfile())); // Empty cache. |
| 373 if (IsPopularSitesEnabledViaVariations()) { | 373 if (IsPopularSitesEnabledViaVariations()) { |
| 374 EXPECT_CALL( | 374 EXPECT_CALL( |
| 375 mock_observer_, | 375 mock_observer_, |
| 376 OnMostVisitedURLsAvailable(ElementsAre( | 376 OnMostVisitedURLsAvailable(ElementsAre( |
| 377 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 377 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 378 MatchesTile("PopularSite1", "http://popularsite1/", | 378 MatchesTile("PopularSite1", "http://popularsite1/", |
| 379 NTPTileSource::POPULAR), | 379 TileSource::POPULAR), |
| 380 MatchesTile("PopularSite2", "http://popularsite2/", | 380 MatchesTile("PopularSite2", "http://popularsite2/", |
| 381 NTPTileSource::POPULAR)))); | 381 TileSource::POPULAR)))); |
| 382 } else { | 382 } else { |
| 383 EXPECT_CALL(mock_observer_, | 383 EXPECT_CALL(mock_observer_, |
| 384 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( | 384 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( |
| 385 "Site 1", "http://site1/", NTPTileSource::TOP_SITES)))); | 385 "Site 1", "http://site1/", TileSource::TOP_SITES)))); |
| 386 } | 386 } |
| 387 EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData()) | 387 EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData()) |
| 388 .WillOnce(Return(true)); | 388 .WillOnce(Return(true)); |
| 389 | 389 |
| 390 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_, | 390 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_, |
| 391 /*num_sites=*/3); | 391 /*num_sites=*/3); |
| 392 VerifyAndClearExpectations(); | 392 VerifyAndClearExpectations(); |
| 393 EXPECT_FALSE(suggestions_service_callbacks_.empty()); | 393 EXPECT_FALSE(suggestions_service_callbacks_.empty()); |
| 394 CHECK(top_sites_callbacks_.empty()); | 394 CHECK(top_sites_callbacks_.empty()); |
| 395 | 395 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 424 EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache()) | 424 EXPECT_CALL(mock_suggestions_service_, GetSuggestionsDataFromCache()) |
| 425 .WillOnce(Return(MakeProfile({ | 425 .WillOnce(Return(MakeProfile({ |
| 426 MakeSuggestion("Site 1", "http://site1/"), | 426 MakeSuggestion("Site 1", "http://site1/"), |
| 427 MakeSuggestion("Site 2", "http://site2/"), | 427 MakeSuggestion("Site 2", "http://site2/"), |
| 428 MakeSuggestion("Site 3", "http://site3/"), | 428 MakeSuggestion("Site 3", "http://site3/"), |
| 429 }))); | 429 }))); |
| 430 if (IsPopularSitesEnabledViaVariations()) { | 430 if (IsPopularSitesEnabledViaVariations()) { |
| 431 EXPECT_CALL(mock_observer_, | 431 EXPECT_CALL(mock_observer_, |
| 432 OnMostVisitedURLsAvailable(ElementsAre( | 432 OnMostVisitedURLsAvailable(ElementsAre( |
| 433 MatchesTile("Site 1", "http://site1/", | 433 MatchesTile("Site 1", "http://site1/", |
| 434 NTPTileSource::SUGGESTIONS_SERVICE), | 434 TileSource::SUGGESTIONS_SERVICE), |
| 435 MatchesTile("Site 2", "http://site2/", | 435 MatchesTile("Site 2", "http://site2/", |
| 436 NTPTileSource::SUGGESTIONS_SERVICE), | 436 TileSource::SUGGESTIONS_SERVICE), |
| 437 MatchesTile("Site 3", "http://site3/", | 437 MatchesTile("Site 3", "http://site3/", |
| 438 NTPTileSource::SUGGESTIONS_SERVICE), | 438 TileSource::SUGGESTIONS_SERVICE), |
| 439 MatchesTile("PopularSite1", "http://popularsite1/", | 439 MatchesTile("PopularSite1", "http://popularsite1/", |
| 440 NTPTileSource::POPULAR)))); | 440 TileSource::POPULAR)))); |
| 441 } else { | 441 } else { |
| 442 EXPECT_CALL(mock_observer_, | 442 EXPECT_CALL(mock_observer_, |
| 443 OnMostVisitedURLsAvailable(ElementsAre( | 443 OnMostVisitedURLsAvailable(ElementsAre( |
| 444 MatchesTile("Site 1", "http://site1/", | 444 MatchesTile("Site 1", "http://site1/", |
| 445 NTPTileSource::SUGGESTIONS_SERVICE), | 445 TileSource::SUGGESTIONS_SERVICE), |
| 446 MatchesTile("Site 2", "http://site2/", | 446 MatchesTile("Site 2", "http://site2/", |
| 447 NTPTileSource::SUGGESTIONS_SERVICE), | 447 TileSource::SUGGESTIONS_SERVICE), |
| 448 MatchesTile("Site 3", "http://site3/", | 448 MatchesTile("Site 3", "http://site3/", |
| 449 NTPTileSource::SUGGESTIONS_SERVICE)))); | 449 TileSource::SUGGESTIONS_SERVICE)))); |
| 450 } | 450 } |
| 451 EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData()) | 451 EXPECT_CALL(mock_suggestions_service_, FetchSuggestionsData()) |
| 452 .WillOnce(Return(true)); | 452 .WillOnce(Return(true)); |
| 453 | 453 |
| 454 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_, | 454 most_visited_sites_->SetMostVisitedURLsObserver(&mock_observer_, |
| 455 /*num_sites=*/4); | 455 /*num_sites=*/4); |
| 456 VerifyAndClearExpectations(); | 456 VerifyAndClearExpectations(); |
| 457 | 457 |
| 458 EXPECT_FALSE(suggestions_service_callbacks_.empty()); | 458 EXPECT_FALSE(suggestions_service_callbacks_.empty()); |
| 459 EXPECT_TRUE(top_sites_callbacks_.empty()); | 459 EXPECT_TRUE(top_sites_callbacks_.empty()); |
| 460 } | 460 } |
| 461 }; | 461 }; |
| 462 | 462 |
| 463 TEST_P(MostVisitedSitesWithCacheHitTest, ShouldFavorSuggestionsServiceCache) { | 463 TEST_P(MostVisitedSitesWithCacheHitTest, ShouldFavorSuggestionsServiceCache) { |
| 464 // Constructor sets basic expectations for a suggestions service cache hit. | 464 // Constructor sets basic expectations for a suggestions service cache hit. |
| 465 } | 465 } |
| 466 | 466 |
| 467 TEST_P(MostVisitedSitesWithCacheHitTest, | 467 TEST_P(MostVisitedSitesWithCacheHitTest, |
| 468 ShouldPropagateUpdateBySuggestionsService) { | 468 ShouldPropagateUpdateBySuggestionsService) { |
| 469 EXPECT_CALL(mock_observer_, | 469 EXPECT_CALL(mock_observer_, |
| 470 OnMostVisitedURLsAvailable(ElementsAre( | 470 OnMostVisitedURLsAvailable( |
| 471 MatchesTile("Site 4", "http://site4/", | 471 ElementsAre(MatchesTile("Site 4", "http://site4/", |
| 472 NTPTileSource::SUGGESTIONS_SERVICE), | 472 TileSource::SUGGESTIONS_SERVICE), |
| 473 MatchesTile("Site 5", "http://site5/", | 473 MatchesTile("Site 5", "http://site5/", |
| 474 NTPTileSource::SUGGESTIONS_SERVICE), | 474 TileSource::SUGGESTIONS_SERVICE), |
| 475 MatchesTile("Site 6", "http://site6/", | 475 MatchesTile("Site 6", "http://site6/", |
| 476 NTPTileSource::SUGGESTIONS_SERVICE), | 476 TileSource::SUGGESTIONS_SERVICE), |
| 477 MatchesTile("Site 7", "http://site7/", | 477 MatchesTile("Site 7", "http://site7/", |
| 478 NTPTileSource::SUGGESTIONS_SERVICE)))); | 478 TileSource::SUGGESTIONS_SERVICE)))); |
| 479 suggestions_service_callbacks_.Notify( | 479 suggestions_service_callbacks_.Notify( |
| 480 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), | 480 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), |
| 481 MakeSuggestion("Site 5", "http://site5/"), | 481 MakeSuggestion("Site 5", "http://site5/"), |
| 482 MakeSuggestion("Site 6", "http://site6/"), | 482 MakeSuggestion("Site 6", "http://site6/"), |
| 483 MakeSuggestion("Site 7", "http://site7/")})); | 483 MakeSuggestion("Site 7", "http://site7/")})); |
| 484 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_P(MostVisitedSitesWithCacheHitTest, ShouldTruncateList) { | 487 TEST_P(MostVisitedSitesWithCacheHitTest, ShouldTruncateList) { |
| 488 EXPECT_CALL(mock_observer_, OnMostVisitedURLsAvailable(SizeIs(4))); | 488 EXPECT_CALL(mock_observer_, OnMostVisitedURLsAvailable(SizeIs(4))); |
| 489 suggestions_service_callbacks_.Notify( | 489 suggestions_service_callbacks_.Notify( |
| 490 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), | 490 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), |
| 491 MakeSuggestion("Site 5", "http://site5/"), | 491 MakeSuggestion("Site 5", "http://site5/"), |
| 492 MakeSuggestion("Site 6", "http://site6/"), | 492 MakeSuggestion("Site 6", "http://site6/"), |
| 493 MakeSuggestion("Site 7", "http://site7/"), | 493 MakeSuggestion("Site 7", "http://site7/"), |
| 494 MakeSuggestion("Site 8", "http://site8/")})); | 494 MakeSuggestion("Site 8", "http://site8/")})); |
| 495 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 TEST_P(MostVisitedSitesWithCacheHitTest, | 498 TEST_P(MostVisitedSitesWithCacheHitTest, |
| 499 ShouldCompleteWithPopularSitesIffEnabled) { | 499 ShouldCompleteWithPopularSitesIffEnabled) { |
| 500 if (IsPopularSitesEnabledViaVariations()) { | 500 if (IsPopularSitesEnabledViaVariations()) { |
| 501 EXPECT_CALL(mock_observer_, | 501 EXPECT_CALL(mock_observer_, |
| 502 OnMostVisitedURLsAvailable(ElementsAre( | 502 OnMostVisitedURLsAvailable(ElementsAre( |
| 503 MatchesTile("Site 4", "http://site4/", | 503 MatchesTile("Site 4", "http://site4/", |
| 504 NTPTileSource::SUGGESTIONS_SERVICE), | 504 TileSource::SUGGESTIONS_SERVICE), |
| 505 MatchesTile("PopularSite1", "http://popularsite1/", | 505 MatchesTile("PopularSite1", "http://popularsite1/", |
| 506 NTPTileSource::POPULAR), | 506 TileSource::POPULAR), |
| 507 MatchesTile("PopularSite2", "http://popularsite2/", | 507 MatchesTile("PopularSite2", "http://popularsite2/", |
| 508 NTPTileSource::POPULAR)))); | 508 TileSource::POPULAR)))); |
| 509 } else { | 509 } else { |
| 510 EXPECT_CALL( | 510 EXPECT_CALL( |
| 511 mock_observer_, | 511 mock_observer_, |
| 512 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( | 512 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( |
| 513 "Site 4", "http://site4/", NTPTileSource::SUGGESTIONS_SERVICE)))); | 513 "Site 4", "http://site4/", TileSource::SUGGESTIONS_SERVICE)))); |
| 514 } | 514 } |
| 515 suggestions_service_callbacks_.Notify( | 515 suggestions_service_callbacks_.Notify( |
| 516 MakeProfile({MakeSuggestion("Site 4", "http://site4/")})); | 516 MakeProfile({MakeSuggestion("Site 4", "http://site4/")})); |
| 517 base::RunLoop().RunUntilIdle(); | 517 base::RunLoop().RunUntilIdle(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 TEST_P(MostVisitedSitesWithCacheHitTest, | 520 TEST_P(MostVisitedSitesWithCacheHitTest, |
| 521 ShouldSwitchToTopSitesIfEmptyUpdateBySuggestionsService) { | 521 ShouldSwitchToTopSitesIfEmptyUpdateBySuggestionsService) { |
| 522 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) | 522 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) |
| 523 .WillOnce(Invoke(&top_sites_callbacks_, &TopSitesCallbackList::Add)); | 523 .WillOnce(Invoke(&top_sites_callbacks_, &TopSitesCallbackList::Add)); |
| 524 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 524 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 525 VerifyAndClearExpectations(); | 525 VerifyAndClearExpectations(); |
| 526 | 526 |
| 527 EXPECT_CALL( | 527 EXPECT_CALL( |
| 528 mock_observer_, | 528 mock_observer_, |
| 529 OnMostVisitedURLsAvailable(ElementsAre( | 529 OnMostVisitedURLsAvailable(ElementsAre( |
| 530 MatchesTile("Site 4", "http://site4/", NTPTileSource::TOP_SITES), | 530 MatchesTile("Site 4", "http://site4/", TileSource::TOP_SITES), |
| 531 MatchesTile("Site 5", "http://site5/", NTPTileSource::TOP_SITES), | 531 MatchesTile("Site 5", "http://site5/", TileSource::TOP_SITES), |
| 532 MatchesTile("Site 6", "http://site6/", NTPTileSource::TOP_SITES), | 532 MatchesTile("Site 6", "http://site6/", TileSource::TOP_SITES), |
| 533 MatchesTile("Site 7", "http://site7/", NTPTileSource::TOP_SITES)))); | 533 MatchesTile("Site 7", "http://site7/", TileSource::TOP_SITES)))); |
| 534 top_sites_callbacks_.ClearAndNotify( | 534 top_sites_callbacks_.ClearAndNotify( |
| 535 {MakeMostVisitedURL("Site 4", "http://site4/"), | 535 {MakeMostVisitedURL("Site 4", "http://site4/"), |
| 536 MakeMostVisitedURL("Site 5", "http://site5/"), | 536 MakeMostVisitedURL("Site 5", "http://site5/"), |
| 537 MakeMostVisitedURL("Site 6", "http://site6/"), | 537 MakeMostVisitedURL("Site 6", "http://site6/"), |
| 538 MakeMostVisitedURL("Site 7", "http://site7/")}); | 538 MakeMostVisitedURL("Site 7", "http://site7/")}); |
| 539 base::RunLoop().RunUntilIdle(); | 539 base::RunLoop().RunUntilIdle(); |
| 540 } | 540 } |
| 541 | 541 |
| 542 INSTANTIATE_TEST_CASE_P(MostVisitedSitesWithCacheHitTest, | 542 INSTANTIATE_TEST_CASE_P(MostVisitedSitesWithCacheHitTest, |
| 543 MostVisitedSitesWithCacheHitTest, | 543 MostVisitedSitesWithCacheHitTest, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 573 ShouldQueryTopSitesAndSuggestionsService) { | 573 ShouldQueryTopSitesAndSuggestionsService) { |
| 574 // Constructor sets basic expectations for a suggestions service cache miss. | 574 // Constructor sets basic expectations for a suggestions service cache miss. |
| 575 } | 575 } |
| 576 | 576 |
| 577 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 577 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 578 ShouldCompleteWithPopularSitesIffEnabled) { | 578 ShouldCompleteWithPopularSitesIffEnabled) { |
| 579 if (IsPopularSitesEnabledViaVariations()) { | 579 if (IsPopularSitesEnabledViaVariations()) { |
| 580 EXPECT_CALL(mock_observer_, | 580 EXPECT_CALL(mock_observer_, |
| 581 OnMostVisitedURLsAvailable(ElementsAre( | 581 OnMostVisitedURLsAvailable(ElementsAre( |
| 582 MatchesTile("Site 4", "http://site4/", | 582 MatchesTile("Site 4", "http://site4/", |
| 583 NTPTileSource::SUGGESTIONS_SERVICE), | 583 TileSource::SUGGESTIONS_SERVICE), |
| 584 MatchesTile("PopularSite1", "http://popularsite1/", | 584 MatchesTile("PopularSite1", "http://popularsite1/", |
| 585 NTPTileSource::POPULAR), | 585 TileSource::POPULAR), |
| 586 MatchesTile("PopularSite2", "http://popularsite2/", | 586 MatchesTile("PopularSite2", "http://popularsite2/", |
| 587 NTPTileSource::POPULAR)))); | 587 TileSource::POPULAR)))); |
| 588 } else { | 588 } else { |
| 589 EXPECT_CALL( | 589 EXPECT_CALL( |
| 590 mock_observer_, | 590 mock_observer_, |
| 591 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( | 591 OnMostVisitedURLsAvailable(ElementsAre(MatchesTile( |
| 592 "Site 4", "http://site4/", NTPTileSource::SUGGESTIONS_SERVICE)))); | 592 "Site 4", "http://site4/", TileSource::SUGGESTIONS_SERVICE)))); |
| 593 } | 593 } |
| 594 suggestions_service_callbacks_.Notify( | 594 suggestions_service_callbacks_.Notify( |
| 595 MakeProfile({MakeSuggestion("Site 4", "http://site4/")})); | 595 MakeProfile({MakeSuggestion("Site 4", "http://site4/")})); |
| 596 base::RunLoop().RunUntilIdle(); | 596 base::RunLoop().RunUntilIdle(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 599 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 600 ShouldIgnoreTopSitesIfSuggestionsServiceFaster) { | 600 ShouldIgnoreTopSitesIfSuggestionsServiceFaster) { |
| 601 // Reply from suggestions service triggers and update to our observer. | 601 // Reply from suggestions service triggers and update to our observer. |
| 602 EXPECT_CALL(mock_observer_, | 602 EXPECT_CALL(mock_observer_, |
| 603 OnMostVisitedURLsAvailable(ElementsAre( | 603 OnMostVisitedURLsAvailable( |
| 604 MatchesTile("Site 1", "http://site1/", | 604 ElementsAre(MatchesTile("Site 1", "http://site1/", |
| 605 NTPTileSource::SUGGESTIONS_SERVICE), | 605 TileSource::SUGGESTIONS_SERVICE), |
| 606 MatchesTile("Site 2", "http://site2/", | 606 MatchesTile("Site 2", "http://site2/", |
| 607 NTPTileSource::SUGGESTIONS_SERVICE), | 607 TileSource::SUGGESTIONS_SERVICE), |
| 608 MatchesTile("Site 3", "http://site3/", | 608 MatchesTile("Site 3", "http://site3/", |
| 609 NTPTileSource::SUGGESTIONS_SERVICE)))); | 609 TileSource::SUGGESTIONS_SERVICE)))); |
| 610 suggestions_service_callbacks_.Notify( | 610 suggestions_service_callbacks_.Notify( |
| 611 MakeProfile({MakeSuggestion("Site 1", "http://site1/"), | 611 MakeProfile({MakeSuggestion("Site 1", "http://site1/"), |
| 612 MakeSuggestion("Site 2", "http://site2/"), | 612 MakeSuggestion("Site 2", "http://site2/"), |
| 613 MakeSuggestion("Site 3", "http://site3/")})); | 613 MakeSuggestion("Site 3", "http://site3/")})); |
| 614 VerifyAndClearExpectations(); | 614 VerifyAndClearExpectations(); |
| 615 | 615 |
| 616 // Reply from top sites is ignored (i.e. not reported to observer). | 616 // Reply from top sites is ignored (i.e. not reported to observer). |
| 617 top_sites_callbacks_.ClearAndNotify( | 617 top_sites_callbacks_.ClearAndNotify( |
| 618 {MakeMostVisitedURL("Site 4", "http://site4/")}); | 618 {MakeMostVisitedURL("Site 4", "http://site4/")}); |
| 619 VerifyAndClearExpectations(); | 619 VerifyAndClearExpectations(); |
| 620 | 620 |
| 621 // Update by TopSites is also ignored. | 621 // Update by TopSites is also ignored. |
| 622 mock_top_sites_->NotifyTopSitesChanged( | 622 mock_top_sites_->NotifyTopSitesChanged( |
| 623 history::TopSitesObserver::ChangeReason::MOST_VISITED); | 623 history::TopSitesObserver::ChangeReason::MOST_VISITED); |
| 624 base::RunLoop().RunUntilIdle(); | 624 base::RunLoop().RunUntilIdle(); |
| 625 } | 625 } |
| 626 | 626 |
| 627 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 627 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 628 ShouldExposeTopSitesIfSuggestionsServiceFasterButEmpty) { | 628 ShouldExposeTopSitesIfSuggestionsServiceFasterButEmpty) { |
| 629 // Empty reply from suggestions service causes no update to our observer. | 629 // Empty reply from suggestions service causes no update to our observer. |
| 630 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 630 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 631 VerifyAndClearExpectations(); | 631 VerifyAndClearExpectations(); |
| 632 | 632 |
| 633 // Reply from top sites is propagated to observer. | 633 // Reply from top sites is propagated to observer. |
| 634 EXPECT_CALL( | 634 EXPECT_CALL( |
| 635 mock_observer_, | 635 mock_observer_, |
| 636 OnMostVisitedURLsAvailable(ElementsAre( | 636 OnMostVisitedURLsAvailable(ElementsAre( |
| 637 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 637 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 638 MatchesTile("Site 2", "http://site2/", NTPTileSource::TOP_SITES), | 638 MatchesTile("Site 2", "http://site2/", TileSource::TOP_SITES), |
| 639 MatchesTile("Site 3", "http://site3/", NTPTileSource::TOP_SITES)))); | 639 MatchesTile("Site 3", "http://site3/", TileSource::TOP_SITES)))); |
| 640 top_sites_callbacks_.ClearAndNotify( | 640 top_sites_callbacks_.ClearAndNotify( |
| 641 {MakeMostVisitedURL("Site 1", "http://site1/"), | 641 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 642 MakeMostVisitedURL("Site 2", "http://site2/"), | 642 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 643 MakeMostVisitedURL("Site 3", "http://site3/")}); | 643 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 644 base::RunLoop().RunUntilIdle(); | 644 base::RunLoop().RunUntilIdle(); |
| 645 } | 645 } |
| 646 | 646 |
| 647 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 647 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 648 ShouldFavorSuggestionsServiceAlthoughSlower) { | 648 ShouldFavorSuggestionsServiceAlthoughSlower) { |
| 649 // Reply from top sites is propagated to observer. | 649 // Reply from top sites is propagated to observer. |
| 650 EXPECT_CALL( | 650 EXPECT_CALL( |
| 651 mock_observer_, | 651 mock_observer_, |
| 652 OnMostVisitedURLsAvailable(ElementsAre( | 652 OnMostVisitedURLsAvailable(ElementsAre( |
| 653 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 653 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 654 MatchesTile("Site 2", "http://site2/", NTPTileSource::TOP_SITES), | 654 MatchesTile("Site 2", "http://site2/", TileSource::TOP_SITES), |
| 655 MatchesTile("Site 3", "http://site3/", NTPTileSource::TOP_SITES)))); | 655 MatchesTile("Site 3", "http://site3/", TileSource::TOP_SITES)))); |
| 656 top_sites_callbacks_.ClearAndNotify( | 656 top_sites_callbacks_.ClearAndNotify( |
| 657 {MakeMostVisitedURL("Site 1", "http://site1/"), | 657 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 658 MakeMostVisitedURL("Site 2", "http://site2/"), | 658 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 659 MakeMostVisitedURL("Site 3", "http://site3/")}); | 659 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 660 VerifyAndClearExpectations(); | 660 VerifyAndClearExpectations(); |
| 661 | 661 |
| 662 // Reply from suggestions service overrides top sites. | 662 // Reply from suggestions service overrides top sites. |
| 663 InSequence seq; | 663 InSequence seq; |
| 664 EXPECT_CALL(mock_observer_, | 664 EXPECT_CALL(mock_observer_, |
| 665 OnMostVisitedURLsAvailable(ElementsAre( | 665 OnMostVisitedURLsAvailable( |
| 666 MatchesTile("Site 4", "http://site4/", | 666 ElementsAre(MatchesTile("Site 4", "http://site4/", |
| 667 NTPTileSource::SUGGESTIONS_SERVICE), | 667 TileSource::SUGGESTIONS_SERVICE), |
| 668 MatchesTile("Site 5", "http://site5/", | 668 MatchesTile("Site 5", "http://site5/", |
| 669 NTPTileSource::SUGGESTIONS_SERVICE), | 669 TileSource::SUGGESTIONS_SERVICE), |
| 670 MatchesTile("Site 6", "http://site6/", | 670 MatchesTile("Site 6", "http://site6/", |
| 671 NTPTileSource::SUGGESTIONS_SERVICE)))); | 671 TileSource::SUGGESTIONS_SERVICE)))); |
| 672 suggestions_service_callbacks_.Notify( | 672 suggestions_service_callbacks_.Notify( |
| 673 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), | 673 MakeProfile({MakeSuggestion("Site 4", "http://site4/"), |
| 674 MakeSuggestion("Site 5", "http://site5/"), | 674 MakeSuggestion("Site 5", "http://site5/"), |
| 675 MakeSuggestion("Site 6", "http://site6/")})); | 675 MakeSuggestion("Site 6", "http://site6/")})); |
| 676 base::RunLoop().RunUntilIdle(); | 676 base::RunLoop().RunUntilIdle(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 679 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 680 ShouldIgnoreSuggestionsServiceIfSlowerAndEmpty) { | 680 ShouldIgnoreSuggestionsServiceIfSlowerAndEmpty) { |
| 681 // Reply from top sites is propagated to observer. | 681 // Reply from top sites is propagated to observer. |
| 682 EXPECT_CALL( | 682 EXPECT_CALL( |
| 683 mock_observer_, | 683 mock_observer_, |
| 684 OnMostVisitedURLsAvailable(ElementsAre( | 684 OnMostVisitedURLsAvailable(ElementsAre( |
| 685 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 685 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 686 MatchesTile("Site 2", "http://site2/", NTPTileSource::TOP_SITES), | 686 MatchesTile("Site 2", "http://site2/", TileSource::TOP_SITES), |
| 687 MatchesTile("Site 3", "http://site3/", NTPTileSource::TOP_SITES)))); | 687 MatchesTile("Site 3", "http://site3/", TileSource::TOP_SITES)))); |
| 688 top_sites_callbacks_.ClearAndNotify( | 688 top_sites_callbacks_.ClearAndNotify( |
| 689 {MakeMostVisitedURL("Site 1", "http://site1/"), | 689 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 690 MakeMostVisitedURL("Site 2", "http://site2/"), | 690 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 691 MakeMostVisitedURL("Site 3", "http://site3/")}); | 691 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 692 VerifyAndClearExpectations(); | 692 VerifyAndClearExpectations(); |
| 693 | 693 |
| 694 // Reply from suggestions service is empty and thus ignored. | 694 // Reply from suggestions service is empty and thus ignored. |
| 695 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 695 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 696 base::RunLoop().RunUntilIdle(); | 696 base::RunLoop().RunUntilIdle(); |
| 697 } | 697 } |
| 698 | 698 |
| 699 TEST_P(MostVisitedSitesWithEmptyCacheTest, ShouldPropagateUpdateByTopSites) { | 699 TEST_P(MostVisitedSitesWithEmptyCacheTest, ShouldPropagateUpdateByTopSites) { |
| 700 // Reply from top sites is propagated to observer. | 700 // Reply from top sites is propagated to observer. |
| 701 EXPECT_CALL( | 701 EXPECT_CALL( |
| 702 mock_observer_, | 702 mock_observer_, |
| 703 OnMostVisitedURLsAvailable(ElementsAre( | 703 OnMostVisitedURLsAvailable(ElementsAre( |
| 704 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 704 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 705 MatchesTile("Site 2", "http://site2/", NTPTileSource::TOP_SITES), | 705 MatchesTile("Site 2", "http://site2/", TileSource::TOP_SITES), |
| 706 MatchesTile("Site 3", "http://site3/", NTPTileSource::TOP_SITES)))); | 706 MatchesTile("Site 3", "http://site3/", TileSource::TOP_SITES)))); |
| 707 top_sites_callbacks_.ClearAndNotify( | 707 top_sites_callbacks_.ClearAndNotify( |
| 708 {MakeMostVisitedURL("Site 1", "http://site1/"), | 708 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 709 MakeMostVisitedURL("Site 2", "http://site2/"), | 709 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 710 MakeMostVisitedURL("Site 3", "http://site3/")}); | 710 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 711 VerifyAndClearExpectations(); | 711 VerifyAndClearExpectations(); |
| 712 | 712 |
| 713 // Reply from suggestions service is empty and thus ignored. | 713 // Reply from suggestions service is empty and thus ignored. |
| 714 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 714 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 715 VerifyAndClearExpectations(); | 715 VerifyAndClearExpectations(); |
| 716 EXPECT_TRUE(top_sites_callbacks_.empty()); | 716 EXPECT_TRUE(top_sites_callbacks_.empty()); |
| 717 | 717 |
| 718 // Update from top sites is propagated to observer. | 718 // Update from top sites is propagated to observer. |
| 719 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) | 719 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) |
| 720 .WillOnce(InvokeCallbackArgument<0>( | 720 .WillOnce(InvokeCallbackArgument<0>( |
| 721 MostVisitedURLList{MakeMostVisitedURL("Site 4", "http://site4/"), | 721 MostVisitedURLList{MakeMostVisitedURL("Site 4", "http://site4/"), |
| 722 MakeMostVisitedURL("Site 5", "http://site5/"), | 722 MakeMostVisitedURL("Site 5", "http://site5/"), |
| 723 MakeMostVisitedURL("Site 6", "http://site6/")})); | 723 MakeMostVisitedURL("Site 6", "http://site6/")})); |
| 724 EXPECT_CALL( | 724 EXPECT_CALL( |
| 725 mock_observer_, | 725 mock_observer_, |
| 726 OnMostVisitedURLsAvailable(ElementsAre( | 726 OnMostVisitedURLsAvailable(ElementsAre( |
| 727 MatchesTile("Site 4", "http://site4/", NTPTileSource::TOP_SITES), | 727 MatchesTile("Site 4", "http://site4/", TileSource::TOP_SITES), |
| 728 MatchesTile("Site 5", "http://site5/", NTPTileSource::TOP_SITES), | 728 MatchesTile("Site 5", "http://site5/", TileSource::TOP_SITES), |
| 729 MatchesTile("Site 6", "http://site6/", NTPTileSource::TOP_SITES)))); | 729 MatchesTile("Site 6", "http://site6/", TileSource::TOP_SITES)))); |
| 730 mock_top_sites_->NotifyTopSitesChanged( | 730 mock_top_sites_->NotifyTopSitesChanged( |
| 731 history::TopSitesObserver::ChangeReason::MOST_VISITED); | 731 history::TopSitesObserver::ChangeReason::MOST_VISITED); |
| 732 base::RunLoop().RunUntilIdle(); | 732 base::RunLoop().RunUntilIdle(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 735 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 736 ShouldSendEmptyListIfBothTopSitesAndSuggestionsServiceEmpty) { | 736 ShouldSendEmptyListIfBothTopSitesAndSuggestionsServiceEmpty) { |
| 737 if (IsPopularSitesEnabledViaVariations()) { | 737 if (IsPopularSitesEnabledViaVariations()) { |
| 738 EXPECT_CALL(mock_observer_, | 738 EXPECT_CALL(mock_observer_, |
| 739 OnMostVisitedURLsAvailable(ElementsAre( | 739 OnMostVisitedURLsAvailable(ElementsAre( |
| 740 MatchesTile("PopularSite1", "http://popularsite1/", | 740 MatchesTile("PopularSite1", "http://popularsite1/", |
| 741 NTPTileSource::POPULAR), | 741 TileSource::POPULAR), |
| 742 MatchesTile("PopularSite2", "http://popularsite2/", | 742 MatchesTile("PopularSite2", "http://popularsite2/", |
| 743 NTPTileSource::POPULAR)))); | 743 TileSource::POPULAR)))); |
| 744 } else { | 744 } else { |
| 745 // The Android NTP doesn't finish initialization until it gets tiles, so a | 745 // The Android NTP doesn't finish initialization until it gets tiles, so a |
| 746 // 0-tile notification is always needed. | 746 // 0-tile notification is always needed. |
| 747 EXPECT_CALL(mock_observer_, OnMostVisitedURLsAvailable(IsEmpty())); | 747 EXPECT_CALL(mock_observer_, OnMostVisitedURLsAvailable(IsEmpty())); |
| 748 } | 748 } |
| 749 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 749 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 750 top_sites_callbacks_.ClearAndNotify(MostVisitedURLList{}); | 750 top_sites_callbacks_.ClearAndNotify(MostVisitedURLList{}); |
| 751 | 751 |
| 752 base::RunLoop().RunUntilIdle(); | 752 base::RunLoop().RunUntilIdle(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 755 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 756 ShouldNotifyOnceIfTopSitesUnchanged) { | 756 ShouldNotifyOnceIfTopSitesUnchanged) { |
| 757 EXPECT_CALL( | 757 EXPECT_CALL( |
| 758 mock_observer_, | 758 mock_observer_, |
| 759 OnMostVisitedURLsAvailable(ElementsAre( | 759 OnMostVisitedURLsAvailable(ElementsAre( |
| 760 MatchesTile("Site 1", "http://site1/", NTPTileSource::TOP_SITES), | 760 MatchesTile("Site 1", "http://site1/", TileSource::TOP_SITES), |
| 761 MatchesTile("Site 2", "http://site2/", NTPTileSource::TOP_SITES), | 761 MatchesTile("Site 2", "http://site2/", TileSource::TOP_SITES), |
| 762 MatchesTile("Site 3", "http://site3/", NTPTileSource::TOP_SITES)))); | 762 MatchesTile("Site 3", "http://site3/", TileSource::TOP_SITES)))); |
| 763 | 763 |
| 764 suggestions_service_callbacks_.Notify(SuggestionsProfile()); | 764 suggestions_service_callbacks_.Notify(SuggestionsProfile()); |
| 765 | 765 |
| 766 top_sites_callbacks_.ClearAndNotify( | 766 top_sites_callbacks_.ClearAndNotify( |
| 767 {MakeMostVisitedURL("Site 1", "http://site1/"), | 767 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 768 MakeMostVisitedURL("Site 2", "http://site2/"), | 768 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 769 MakeMostVisitedURL("Site 3", "http://site3/")}); | 769 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 770 base::RunLoop().RunUntilIdle(); | 770 base::RunLoop().RunUntilIdle(); |
| 771 | 771 |
| 772 for (int i = 0; i < 4; ++i) { | 772 for (int i = 0; i < 4; ++i) { |
| 773 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) | 773 EXPECT_CALL(*mock_top_sites_, GetMostVisitedURLs(_, false)) |
| 774 .WillOnce(Invoke(&top_sites_callbacks_, &TopSitesCallbackList::Add)); | 774 .WillOnce(Invoke(&top_sites_callbacks_, &TopSitesCallbackList::Add)); |
| 775 mock_top_sites_->NotifyTopSitesChanged( | 775 mock_top_sites_->NotifyTopSitesChanged( |
| 776 history::TopSitesObserver::ChangeReason::MOST_VISITED); | 776 history::TopSitesObserver::ChangeReason::MOST_VISITED); |
| 777 EXPECT_FALSE(top_sites_callbacks_.empty()); | 777 EXPECT_FALSE(top_sites_callbacks_.empty()); |
| 778 top_sites_callbacks_.ClearAndNotify( | 778 top_sites_callbacks_.ClearAndNotify( |
| 779 {MakeMostVisitedURL("Site 1", "http://site1/"), | 779 {MakeMostVisitedURL("Site 1", "http://site1/"), |
| 780 MakeMostVisitedURL("Site 2", "http://site2/"), | 780 MakeMostVisitedURL("Site 2", "http://site2/"), |
| 781 MakeMostVisitedURL("Site 3", "http://site3/")}); | 781 MakeMostVisitedURL("Site 3", "http://site3/")}); |
| 782 base::RunLoop().RunUntilIdle(); | 782 base::RunLoop().RunUntilIdle(); |
| 783 } | 783 } |
| 784 } | 784 } |
| 785 | 785 |
| 786 TEST_P(MostVisitedSitesWithEmptyCacheTest, | 786 TEST_P(MostVisitedSitesWithEmptyCacheTest, |
| 787 ShouldNotifyOnceIfSuggestionsUnchanged) { | 787 ShouldNotifyOnceIfSuggestionsUnchanged) { |
| 788 EXPECT_CALL(mock_observer_, | 788 EXPECT_CALL(mock_observer_, |
| 789 OnMostVisitedURLsAvailable(ElementsAre( | 789 OnMostVisitedURLsAvailable( |
| 790 MatchesTile("Site 1", "http://site1/", | 790 ElementsAre(MatchesTile("Site 1", "http://site1/", |
| 791 NTPTileSource::SUGGESTIONS_SERVICE), | 791 TileSource::SUGGESTIONS_SERVICE), |
| 792 MatchesTile("Site 2", "http://site2/", | 792 MatchesTile("Site 2", "http://site2/", |
| 793 NTPTileSource::SUGGESTIONS_SERVICE), | 793 TileSource::SUGGESTIONS_SERVICE), |
| 794 MatchesTile("Site 3", "http://site3/", | 794 MatchesTile("Site 3", "http://site3/", |
| 795 NTPTileSource::SUGGESTIONS_SERVICE)))); | 795 TileSource::SUGGESTIONS_SERVICE)))); |
| 796 | 796 |
| 797 for (int i = 0; i < 5; ++i) { | 797 for (int i = 0; i < 5; ++i) { |
| 798 suggestions_service_callbacks_.Notify( | 798 suggestions_service_callbacks_.Notify( |
| 799 MakeProfile({MakeSuggestion("Site 1", "http://site1/"), | 799 MakeProfile({MakeSuggestion("Site 1", "http://site1/"), |
| 800 MakeSuggestion("Site 2", "http://site2/"), | 800 MakeSuggestion("Site 2", "http://site2/"), |
| 801 MakeSuggestion("Site 3", "http://site3/")})); | 801 MakeSuggestion("Site 3", "http://site3/")})); |
| 802 } | 802 } |
| 803 } | 803 } |
| 804 | 804 |
| 805 INSTANTIATE_TEST_CASE_P(MostVisitedSitesWithEmptyCacheTest, | 805 INSTANTIATE_TEST_CASE_P(MostVisitedSitesWithEmptyCacheTest, |
| 806 MostVisitedSitesWithEmptyCacheTest, | 806 MostVisitedSitesWithEmptyCacheTest, |
| 807 ::testing::Bool()); | 807 ::testing::Bool()); |
| 808 | 808 |
| 809 // This a test for MostVisitedSites::MergeTiles(...) method, and thus has the | 809 // This a test for MostVisitedSites::MergeTiles(...) method, and thus has the |
| 810 // same scope as the method itself. This tests merging popular sites with | 810 // same scope as the method itself. This tests merging popular sites with |
| 811 // personal tiles. | 811 // personal tiles. |
| 812 // More important things out of the scope of testing presently: | 812 // More important things out of the scope of testing presently: |
| 813 // - Removing blacklisted tiles. | 813 // - Removing blacklisted tiles. |
| 814 // - Correct host extraction from the URL. | 814 // - Correct host extraction from the URL. |
| 815 // - Ensuring personal tiles are not duplicated in popular tiles. | 815 // - Ensuring personal tiles are not duplicated in popular tiles. |
| 816 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesWithPersonalOnly) { | 816 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesWithPersonalOnly) { |
| 817 std::vector<NTPTile> personal_tiles{ | 817 std::vector<NTPTile> personal_tiles{ |
| 818 MakeTile("Site 1", "https://www.site1.com/", NTPTileSource::TOP_SITES), | 818 MakeTile("Site 1", "https://www.site1.com/", TileSource::TOP_SITES), |
| 819 MakeTile("Site 2", "https://www.site2.com/", NTPTileSource::TOP_SITES), | 819 MakeTile("Site 2", "https://www.site2.com/", TileSource::TOP_SITES), |
| 820 MakeTile("Site 3", "https://www.site3.com/", NTPTileSource::TOP_SITES), | 820 MakeTile("Site 3", "https://www.site3.com/", TileSource::TOP_SITES), |
| 821 MakeTile("Site 4", "https://www.site4.com/", NTPTileSource::TOP_SITES), | 821 MakeTile("Site 4", "https://www.site4.com/", TileSource::TOP_SITES), |
| 822 }; | 822 }; |
| 823 // Without any popular tiles, the result after merge should be the personal | 823 // Without any popular tiles, the result after merge should be the personal |
| 824 // tiles. | 824 // tiles. |
| 825 EXPECT_THAT(MostVisitedSites::MergeTiles(std::move(personal_tiles), | 825 EXPECT_THAT(MostVisitedSites::MergeTiles(std::move(personal_tiles), |
| 826 /*whitelist_tiles=*/NTPTilesVector(), | 826 /*whitelist_tiles=*/NTPTilesVector(), |
| 827 /*popular_tiles=*/NTPTilesVector()), | 827 /*popular_tiles=*/NTPTilesVector()), |
| 828 ElementsAre(MatchesTile("Site 1", "https://www.site1.com/", | 828 ElementsAre(MatchesTile("Site 1", "https://www.site1.com/", |
| 829 NTPTileSource::TOP_SITES), | 829 TileSource::TOP_SITES), |
| 830 MatchesTile("Site 2", "https://www.site2.com/", | 830 MatchesTile("Site 2", "https://www.site2.com/", |
| 831 NTPTileSource::TOP_SITES), | 831 TileSource::TOP_SITES), |
| 832 MatchesTile("Site 3", "https://www.site3.com/", | 832 MatchesTile("Site 3", "https://www.site3.com/", |
| 833 NTPTileSource::TOP_SITES), | 833 TileSource::TOP_SITES), |
| 834 MatchesTile("Site 4", "https://www.site4.com/", | 834 MatchesTile("Site 4", "https://www.site4.com/", |
| 835 NTPTileSource::TOP_SITES))); | 835 TileSource::TOP_SITES))); |
| 836 } | 836 } |
| 837 | 837 |
| 838 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesWithPopularOnly) { | 838 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesWithPopularOnly) { |
| 839 std::vector<NTPTile> popular_tiles{ | 839 std::vector<NTPTile> popular_tiles{ |
| 840 MakeTile("Site 1", "https://www.site1.com/", NTPTileSource::POPULAR), | 840 MakeTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), |
| 841 MakeTile("Site 2", "https://www.site2.com/", NTPTileSource::POPULAR), | 841 MakeTile("Site 2", "https://www.site2.com/", TileSource::POPULAR), |
| 842 MakeTile("Site 3", "https://www.site3.com/", NTPTileSource::POPULAR), | 842 MakeTile("Site 3", "https://www.site3.com/", TileSource::POPULAR), |
| 843 MakeTile("Site 4", "https://www.site4.com/", NTPTileSource::POPULAR), | 843 MakeTile("Site 4", "https://www.site4.com/", TileSource::POPULAR), |
| 844 }; | 844 }; |
| 845 // Without any personal tiles, the result after merge should be the popular | 845 // Without any personal tiles, the result after merge should be the popular |
| 846 // tiles. | 846 // tiles. |
| 847 EXPECT_THAT( | 847 EXPECT_THAT( |
| 848 MostVisitedSites::MergeTiles(/*personal_tiles=*/NTPTilesVector(), | 848 MostVisitedSites::MergeTiles(/*personal_tiles=*/NTPTilesVector(), |
| 849 /*whitelist_tiles=*/NTPTilesVector(), | 849 /*whitelist_tiles=*/NTPTilesVector(), |
| 850 /*popular_tiles=*/std::move(popular_tiles)), | 850 /*popular_tiles=*/std::move(popular_tiles)), |
| 851 ElementsAre(MatchesTile("Site 1", "https://www.site1.com/", | 851 ElementsAre( |
| 852 NTPTileSource::POPULAR), | 852 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), |
| 853 MatchesTile("Site 2", "https://www.site2.com/", | 853 MatchesTile("Site 2", "https://www.site2.com/", TileSource::POPULAR), |
| 854 NTPTileSource::POPULAR), | 854 MatchesTile("Site 3", "https://www.site3.com/", TileSource::POPULAR), |
| 855 MatchesTile("Site 3", "https://www.site3.com/", | 855 MatchesTile("Site 4", "https://www.site4.com/", |
| 856 NTPTileSource::POPULAR), | 856 TileSource::POPULAR))); |
| 857 MatchesTile("Site 4", "https://www.site4.com/", | |
| 858 NTPTileSource::POPULAR))); | |
| 859 } | 857 } |
| 860 | 858 |
| 861 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesFavoringPersonalOverPopular) { | 859 TEST(MostVisitedSitesMergeTest, ShouldMergeTilesFavoringPersonalOverPopular) { |
| 862 std::vector<NTPTile> popular_tiles{ | 860 std::vector<NTPTile> popular_tiles{ |
| 863 MakeTile("Site 1", "https://www.site1.com/", NTPTileSource::POPULAR), | 861 MakeTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), |
| 864 MakeTile("Site 2", "https://www.site2.com/", NTPTileSource::POPULAR), | 862 MakeTile("Site 2", "https://www.site2.com/", TileSource::POPULAR), |
| 865 }; | 863 }; |
| 866 std::vector<NTPTile> personal_tiles{ | 864 std::vector<NTPTile> personal_tiles{ |
| 867 MakeTile("Site 3", "https://www.site3.com/", NTPTileSource::TOP_SITES), | 865 MakeTile("Site 3", "https://www.site3.com/", TileSource::TOP_SITES), |
| 868 MakeTile("Site 4", "https://www.site4.com/", NTPTileSource::TOP_SITES), | 866 MakeTile("Site 4", "https://www.site4.com/", TileSource::TOP_SITES), |
| 869 }; | 867 }; |
| 870 EXPECT_THAT( | 868 EXPECT_THAT( |
| 871 MostVisitedSites::MergeTiles(std::move(personal_tiles), | 869 MostVisitedSites::MergeTiles(std::move(personal_tiles), |
| 872 /*whitelist_tiles=*/NTPTilesVector(), | 870 /*whitelist_tiles=*/NTPTilesVector(), |
| 873 /*popular_tiles=*/std::move(popular_tiles)), | 871 /*popular_tiles=*/std::move(popular_tiles)), |
| 874 ElementsAre(MatchesTile("Site 3", "https://www.site3.com/", | 872 ElementsAre( |
| 875 NTPTileSource::TOP_SITES), | 873 MatchesTile("Site 3", "https://www.site3.com/", |
| 876 MatchesTile("Site 4", "https://www.site4.com/", | 874 TileSource::TOP_SITES), |
| 877 NTPTileSource::TOP_SITES), | 875 MatchesTile("Site 4", "https://www.site4.com/", |
| 878 MatchesTile("Site 1", "https://www.site1.com/", | 876 TileSource::TOP_SITES), |
| 879 NTPTileSource::POPULAR), | 877 MatchesTile("Site 1", "https://www.site1.com/", TileSource::POPULAR), |
| 880 MatchesTile("Site 2", "https://www.site2.com/", | 878 MatchesTile("Site 2", "https://www.site2.com/", |
| 881 NTPTileSource::POPULAR))); | 879 TileSource::POPULAR))); |
| 882 } | 880 } |
| 883 | 881 |
| 884 } // namespace | 882 } // namespace |
| 885 } // namespace ntp_tiles | 883 } // namespace ntp_tiles |
| OLD | NEW |