| 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_snippets/remote/remote_suggestions_provider.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 RemoteSuggestionsProviderTest() | 396 RemoteSuggestionsProviderTest() |
| 397 : params_manager_(ntp_snippets::kStudyName, | 397 : params_manager_(ntp_snippets::kStudyName, |
| 398 {{"content_suggestions_backend", | 398 {{"content_suggestions_backend", |
| 399 kTestContentSuggestionsServerEndpoint}, | 399 kTestContentSuggestionsServerEndpoint}, |
| 400 {"fetching_personalization", "non_personal"}}), | 400 {"fetching_personalization", "non_personal"}}), |
| 401 fake_url_fetcher_factory_( | 401 fake_url_fetcher_factory_( |
| 402 /*default_factory=*/&failing_url_fetcher_factory_), | 402 /*default_factory=*/&failing_url_fetcher_factory_), |
| 403 test_url_(kTestContentSuggestionsServerWithAPIKey), | 403 test_url_(kTestContentSuggestionsServerWithAPIKey), |
| 404 user_classifier_(/*pref_service=*/nullptr), | 404 user_classifier_(/*pref_service=*/nullptr), |
| 405 image_fetcher_(nullptr), | 405 image_fetcher_(nullptr), |
| 406 image_decoder_(nullptr) { | 406 image_decoder_(nullptr), |
| 407 database_(nullptr) { |
| 407 RemoteSuggestionsProvider::RegisterProfilePrefs( | 408 RemoteSuggestionsProvider::RegisterProfilePrefs( |
| 408 utils_.pref_service()->registry()); | 409 utils_.pref_service()->registry()); |
| 409 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); | 410 RequestThrottler::RegisterProfilePrefs(utils_.pref_service()->registry()); |
| 410 | 411 |
| 411 EXPECT_TRUE(database_dir_.CreateUniqueTempDir()); | 412 EXPECT_TRUE(database_dir_.CreateUniqueTempDir()); |
| 412 } | 413 } |
| 413 | 414 |
| 414 ~RemoteSuggestionsProviderTest() override { | 415 ~RemoteSuggestionsProviderTest() override { |
| 415 // We need to run the message loop after deleting the database, because | 416 // We need to run the message loop after deleting the database, because |
| 416 // ProtoDatabaseImpl deletes the actual LevelDB asynchronously on the task | 417 // ProtoDatabaseImpl deletes the actual LevelDB asynchronously on the task |
| (...skipping 26 matching lines...) Expand all Loading... |
| 443 utils_.fake_signin_manager()->SignIn("foo@bar.com"); | 444 utils_.fake_signin_manager()->SignIn("foo@bar.com"); |
| 444 | 445 |
| 445 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>(); | 446 auto image_fetcher = base::MakeUnique<NiceMock<MockImageFetcher>>(); |
| 446 | 447 |
| 447 image_fetcher_ = image_fetcher.get(); | 448 image_fetcher_ = image_fetcher.get(); |
| 448 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); | 449 EXPECT_CALL(*image_fetcher, SetImageFetcherDelegate(_)); |
| 449 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); | 450 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); |
| 450 image_decoder_ = image_decoder.get(); | 451 image_decoder_ = image_decoder.get(); |
| 451 EXPECT_FALSE(observer_); | 452 EXPECT_FALSE(observer_); |
| 452 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); | 453 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); |
| 454 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( |
| 455 database_dir_.GetPath(), task_runner); |
| 456 database_ = database.get(); |
| 453 return base::MakeUnique<RemoteSuggestionsProvider>( | 457 return base::MakeUnique<RemoteSuggestionsProvider>( |
| 454 observer_.get(), &category_factory_, utils_.pref_service(), "fr", | 458 observer_.get(), &category_factory_, utils_.pref_service(), "fr", |
| 455 &user_classifier_, &scheduler_, std::move(snippets_fetcher), | 459 &user_classifier_, &scheduler_, std::move(snippets_fetcher), |
| 456 std::move(image_fetcher), std::move(image_decoder), | 460 std::move(image_fetcher), std::move(image_decoder), |
| 457 base::MakeUnique<RemoteSuggestionsDatabase>(database_dir_.GetPath(), | 461 std::move(database), |
| 458 task_runner), | |
| 459 base::MakeUnique<RemoteSuggestionsStatusService>( | 462 base::MakeUnique<RemoteSuggestionsStatusService>( |
| 460 utils_.fake_signin_manager(), utils_.pref_service())); | 463 utils_.fake_signin_manager(), utils_.pref_service())); |
| 461 } | 464 } |
| 462 | 465 |
| 463 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service, | 466 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service, |
| 464 bool set_empty_response) { | 467 bool set_empty_response) { |
| 465 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_); | 468 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_); |
| 466 | 469 |
| 467 // Add an initial fetch response, as the service tries to fetch when there | 470 // Add an initial fetch response, as the service tries to fetch when there |
| 468 // is nothing in the DB. | 471 // is nothing in the DB. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 505 |
| 503 protected: | 506 protected: |
| 504 const GURL& test_url() { return test_url_; } | 507 const GURL& test_url() { return test_url_; } |
| 505 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } | 508 FakeContentSuggestionsProviderObserver& observer() { return *observer_; } |
| 506 MockScheduler& mock_scheduler() { return scheduler_; } | 509 MockScheduler& mock_scheduler() { return scheduler_; } |
| 507 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary | 510 // TODO(tschumann): Make this a strict-mock. We want to avoid unneccesary |
| 508 // network requests. | 511 // network requests. |
| 509 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } | 512 NiceMock<MockImageFetcher>* image_fetcher() { return image_fetcher_; } |
| 510 FakeImageDecoder* image_decoder() { return image_decoder_; } | 513 FakeImageDecoder* image_decoder() { return image_decoder_; } |
| 511 PrefService* pref_service() { return utils_.pref_service(); } | 514 PrefService* pref_service() { return utils_.pref_service(); } |
| 515 RemoteSuggestionsDatabase* database() { return database_; } |
| 512 | 516 |
| 513 // Provide the json to be returned by the fake fetcher. | 517 // Provide the json to be returned by the fake fetcher. |
| 514 void SetUpFetchResponse(const std::string& json) { | 518 void SetUpFetchResponse(const std::string& json) { |
| 515 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, | 519 fake_url_fetcher_factory_.SetFakeResponse(test_url_, json, net::HTTP_OK, |
| 516 net::URLRequestStatus::SUCCESS); | 520 net::URLRequestStatus::SUCCESS); |
| 517 } | 521 } |
| 518 | 522 |
| 519 void LoadFromJSONString(RemoteSuggestionsProvider* service, | 523 void LoadFromJSONString(RemoteSuggestionsProvider* service, |
| 520 const std::string& json) { | 524 const std::string& json) { |
| 521 SetUpFetchResponse(json); | 525 SetUpFetchResponse(json); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 543 const GURL test_url_; | 547 const GURL test_url_; |
| 544 std::unique_ptr<OAuth2TokenService> fake_token_service_; | 548 std::unique_ptr<OAuth2TokenService> fake_token_service_; |
| 545 UserClassifier user_classifier_; | 549 UserClassifier user_classifier_; |
| 546 NiceMock<MockScheduler> scheduler_; | 550 NiceMock<MockScheduler> scheduler_; |
| 547 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; | 551 std::unique_ptr<FakeContentSuggestionsProviderObserver> observer_; |
| 548 CategoryFactory category_factory_; | 552 CategoryFactory category_factory_; |
| 549 NiceMock<MockImageFetcher>* image_fetcher_; | 553 NiceMock<MockImageFetcher>* image_fetcher_; |
| 550 FakeImageDecoder* image_decoder_; | 554 FakeImageDecoder* image_decoder_; |
| 551 | 555 |
| 552 base::ScopedTempDir database_dir_; | 556 base::ScopedTempDir database_dir_; |
| 557 RemoteSuggestionsDatabase* database_; |
| 553 | 558 |
| 554 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderTest); | 559 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsProviderTest); |
| 555 }; | 560 }; |
| 556 | 561 |
| 557 TEST_F(RemoteSuggestionsProviderTest, ScheduleOnStart) { | 562 TEST_F(RemoteSuggestionsProviderTest, ScheduleOnStart) { |
| 558 // We should get two |Schedule| calls: The first when initialization | 563 // We should get two |Schedule| calls: The first when initialization |
| 559 // completes, the second one after the automatic (since the service doesn't | 564 // completes, the second one after the automatic (since the service doesn't |
| 560 // have any data yet) fetch finishes. | 565 // have any data yet) fetch finishes. |
| 561 EXPECT_CALL(mock_scheduler(), Schedule(_, _)).Times(2); | 566 EXPECT_CALL(mock_scheduler(), Schedule(_, _)).Times(2); |
| 562 EXPECT_CALL(mock_scheduler(), Unschedule()).Times(0); | 567 EXPECT_CALL(mock_scheduler(), Unschedule()).Times(0); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 Status status, std::vector<ContentSuggestion> suggestions) { | 928 Status status, std::vector<ContentSuggestion> suggestions) { |
| 924 EXPECT_THAT(suggestions, SizeIs(1)); | 929 EXPECT_THAT(suggestions, SizeIs(1)); |
| 925 EXPECT_THAT(suggestions[0].id().id_within_category(), Eq("http://second")); | 930 EXPECT_THAT(suggestions[0].id().id_within_category(), Eq("http://second")); |
| 926 }); | 931 }); |
| 927 LoadMoreFromJSONString(service.get(), articles_category(), | 932 LoadMoreFromJSONString(service.get(), articles_category(), |
| 928 GetTestJson({GetSnippetWithUrl("http://second")}), | 933 GetTestJson({GetSnippetWithUrl("http://second")}), |
| 929 /*known_ids=*/std::set<std::string>(), | 934 /*known_ids=*/std::set<std::string>(), |
| 930 expect_only_second_suggestion_received); | 935 expect_only_second_suggestion_received); |
| 931 | 936 |
| 932 // Verify we can resolve the image of the new snippets. | 937 // Verify we can resolve the image of the new snippets. |
| 933 ServeImageCallback cb = base::Bind(&ServeOneByOneImage, service.get()); | 938 ServeImageCallback cb = |
| 939 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
| 934 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 940 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 935 .Times(2) | 941 .Times(2) |
| 936 .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); | 942 .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); |
| 937 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); | 943 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); |
| 938 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://first")); | 944 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://first")); |
| 939 EXPECT_FALSE(image.IsEmpty()); | 945 EXPECT_FALSE(image.IsEmpty()); |
| 940 EXPECT_EQ(1, image.Width()); | 946 EXPECT_EQ(1, image.Width()); |
| 941 | 947 |
| 942 image = FetchImage(service.get(), MakeArticleID("http://second")); | 948 image = FetchImage(service.get(), MakeArticleID("http://second")); |
| 943 EXPECT_FALSE(image.IsEmpty()); | 949 EXPECT_FALSE(image.IsEmpty()); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 TEST_F(RemoteSuggestionsProviderTest, Dismiss) { | 1165 TEST_F(RemoteSuggestionsProviderTest, Dismiss) { |
| 1160 auto service = MakeSnippetsService(); | 1166 auto service = MakeSnippetsService(); |
| 1161 | 1167 |
| 1162 std::string json_str( | 1168 std::string json_str( |
| 1163 GetTestJson({GetSnippetWithSources("http://site.com", "Source 1", "")})); | 1169 GetTestJson({GetSnippetWithSources("http://site.com", "Source 1", "")})); |
| 1164 | 1170 |
| 1165 LoadFromJSONString(service.get(), json_str); | 1171 LoadFromJSONString(service.get(), json_str); |
| 1166 | 1172 |
| 1167 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); | 1173 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); |
| 1168 // Load the image to store it in the database. | 1174 // Load the image to store it in the database. |
| 1169 ServeImageCallback cb = base::Bind(&ServeOneByOneImage, service.get()); | 1175 ServeImageCallback cb = |
| 1176 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
| 1170 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 1177 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 1171 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); | 1178 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); |
| 1172 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); | 1179 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); |
| 1173 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); | 1180 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); |
| 1174 EXPECT_FALSE(image.IsEmpty()); | 1181 EXPECT_FALSE(image.IsEmpty()); |
| 1175 EXPECT_EQ(1, image.Width()); | 1182 EXPECT_EQ(1, image.Width()); |
| 1176 | 1183 |
| 1177 // Dismissing a non-existent snippet shouldn't do anything. | 1184 // Dismissing a non-existent snippet shouldn't do anything. |
| 1178 service->DismissSuggestion(MakeArticleID("http://othersite.com")); | 1185 service->DismissSuggestion(MakeArticleID("http://othersite.com")); |
| 1179 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); | 1186 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(1)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 | 1263 |
| 1257 TEST_F(RemoteSuggestionsProviderTest, RemoveExpiredDismissedContent) { | 1264 TEST_F(RemoteSuggestionsProviderTest, RemoveExpiredDismissedContent) { |
| 1258 auto service = MakeSnippetsService(); | 1265 auto service = MakeSnippetsService(); |
| 1259 | 1266 |
| 1260 std::string json_str1(GetTestJson({GetExpiredSnippet()})); | 1267 std::string json_str1(GetTestJson({GetExpiredSnippet()})); |
| 1261 // Load it. | 1268 // Load it. |
| 1262 LoadFromJSONString(service.get(), json_str1); | 1269 LoadFromJSONString(service.get(), json_str1); |
| 1263 // Load the image to store it in the database. | 1270 // Load the image to store it in the database. |
| 1264 // TODO(tschumann): Introduce some abstraction to nicely work with image | 1271 // TODO(tschumann): Introduce some abstraction to nicely work with image |
| 1265 // fetching expectations. | 1272 // fetching expectations. |
| 1266 ServeImageCallback cb = base::Bind(&ServeOneByOneImage, service.get()); | 1273 ServeImageCallback cb = |
| 1274 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
| 1267 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 1275 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 1268 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); | 1276 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); |
| 1269 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); | 1277 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); |
| 1270 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); | 1278 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); |
| 1271 EXPECT_FALSE(image.IsEmpty()); | 1279 EXPECT_FALSE(image.IsEmpty()); |
| 1272 EXPECT_EQ(1, image.Width()); | 1280 EXPECT_EQ(1, image.Width()); |
| 1273 | 1281 |
| 1274 // Dismiss the suggestion | 1282 // Dismiss the suggestion |
| 1275 service->DismissSuggestion( | 1283 service->DismissSuggestion( |
| 1276 ContentSuggestion::ID(articles_category(), kSnippetUrl)); | 1284 ContentSuggestion::ID(articles_category(), kSnippetUrl)); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 EXPECT_FALSE(service->GetSnippetsForTesting(articles_category()).empty()); | 1476 EXPECT_FALSE(service->GetSnippetsForTesting(articles_category()).empty()); |
| 1469 } | 1477 } |
| 1470 | 1478 |
| 1471 TEST_F(RemoteSuggestionsProviderTest, ImageReturnedWithTheSameId) { | 1479 TEST_F(RemoteSuggestionsProviderTest, ImageReturnedWithTheSameId) { |
| 1472 auto service = MakeSnippetsService(); | 1480 auto service = MakeSnippetsService(); |
| 1473 | 1481 |
| 1474 LoadFromJSONString(service.get(), GetTestJson({GetSnippet()})); | 1482 LoadFromJSONString(service.get(), GetTestJson({GetSnippet()})); |
| 1475 | 1483 |
| 1476 gfx::Image image; | 1484 gfx::Image image; |
| 1477 MockFunction<void(const gfx::Image&)> image_fetched; | 1485 MockFunction<void(const gfx::Image&)> image_fetched; |
| 1478 ServeImageCallback cb = base::Bind(&ServeOneByOneImage, service.get()); | 1486 ServeImageCallback cb = |
| 1487 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
| 1479 { | 1488 { |
| 1480 InSequence s; | 1489 InSequence s; |
| 1481 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 1490 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 1482 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); | 1491 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); |
| 1483 EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image)); | 1492 EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image)); |
| 1484 } | 1493 } |
| 1485 | 1494 |
| 1486 service->FetchSuggestionImage( | 1495 service->FetchSuggestionImage( |
| 1487 MakeArticleID(kSnippetUrl), | 1496 MakeArticleID(kSnippetUrl), |
| 1488 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, | 1497 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1502 | 1511 |
| 1503 service->FetchSuggestionImage( | 1512 service->FetchSuggestionImage( |
| 1504 MakeArticleID(kSnippetUrl2), | 1513 MakeArticleID(kSnippetUrl2), |
| 1505 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, | 1514 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, |
| 1506 base::Unretained(&image_fetched))); | 1515 base::Unretained(&image_fetched))); |
| 1507 | 1516 |
| 1508 base::RunLoop().RunUntilIdle(); | 1517 base::RunLoop().RunUntilIdle(); |
| 1509 EXPECT_TRUE(image.IsEmpty()); | 1518 EXPECT_TRUE(image.IsEmpty()); |
| 1510 } | 1519 } |
| 1511 | 1520 |
| 1521 TEST_F(RemoteSuggestionsProviderTest, |
| 1522 FetchingUnknownImageIdShouldNotHitDatabase) { |
| 1523 // Testing that the provider is not accessing the database is tricky. |
| 1524 // Therefore, we simply put in some data making sure that if the provider asks |
| 1525 // the database, it will get a wrong answer. |
| 1526 auto service = MakeSnippetsService(); |
| 1527 |
| 1528 ContentSuggestion::ID unknown_id = MakeArticleID(kSnippetUrl2); |
| 1529 database()->SaveImage(unknown_id.id_within_category(), "some image blob"); |
| 1530 // Set up the image decoder to always return the 1x1 test image. |
| 1531 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); |
| 1532 |
| 1533 // Create a non-empty image so that we can test the image gets updated. |
| 1534 gfx::Image image = gfx::test::CreateImage(2, 2); |
| 1535 MockFunction<void(const gfx::Image&)> image_fetched; |
| 1536 EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image)); |
| 1537 |
| 1538 service->FetchSuggestionImage( |
| 1539 MakeArticleID(kSnippetUrl2), |
| 1540 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, |
| 1541 base::Unretained(&image_fetched))); |
| 1542 |
| 1543 base::RunLoop().RunUntilIdle(); |
| 1544 EXPECT_TRUE(image.IsEmpty()) << "got image with width: " << image.Width(); |
| 1545 } |
| 1546 |
| 1512 TEST_F(RemoteSuggestionsProviderTest, ClearHistoryRemovesAllSuggestions) { | 1547 TEST_F(RemoteSuggestionsProviderTest, ClearHistoryRemovesAllSuggestions) { |
| 1513 auto service = MakeSnippetsService(); | 1548 auto service = MakeSnippetsService(); |
| 1514 | 1549 |
| 1515 std::string first_snippet = GetSnippetWithUrl("http://url1.com"); | 1550 std::string first_snippet = GetSnippetWithUrl("http://url1.com"); |
| 1516 std::string second_snippet = GetSnippetWithUrl("http://url2.com"); | 1551 std::string second_snippet = GetSnippetWithUrl("http://url2.com"); |
| 1517 std::string json_str = GetTestJson({first_snippet, second_snippet}); | 1552 std::string json_str = GetTestJson({first_snippet, second_snippet}); |
| 1518 LoadFromJSONString(service.get(), json_str); | 1553 LoadFromJSONString(service.get(), json_str); |
| 1519 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(2)); | 1554 ASSERT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(2)); |
| 1520 | 1555 |
| 1521 service->DismissSuggestion(MakeArticleID("http://url1.com")); | 1556 service->DismissSuggestion(MakeArticleID("http://url1.com")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1550 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 1585 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
| 1551 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); | 1586 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); |
| 1552 base::RunLoop().RunUntilIdle(); | 1587 base::RunLoop().RunUntilIdle(); |
| 1553 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(2)); | 1588 EXPECT_THAT(service->GetSnippetsForTesting(articles_category()), SizeIs(2)); |
| 1554 } | 1589 } |
| 1555 | 1590 |
| 1556 TEST_F(RemoteSuggestionsProviderTest, ShouldClearOrphanedImagesOnRestart) { | 1591 TEST_F(RemoteSuggestionsProviderTest, ShouldClearOrphanedImagesOnRestart) { |
| 1557 auto service = MakeSnippetsService(); | 1592 auto service = MakeSnippetsService(); |
| 1558 | 1593 |
| 1559 LoadFromJSONString(service.get(), GetTestJson({GetSnippet()})); | 1594 LoadFromJSONString(service.get(), GetTestJson({GetSnippet()})); |
| 1560 ServeImageCallback cb = base::Bind(&ServeOneByOneImage, service.get()); | 1595 ServeImageCallback cb = |
| 1596 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); |
| 1561 | 1597 |
| 1562 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 1598 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 1563 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); | 1599 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); |
| 1564 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); | 1600 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); |
| 1565 | 1601 |
| 1566 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); | 1602 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSnippetUrl)); |
| 1567 EXPECT_EQ(1, image.Width()); | 1603 EXPECT_EQ(1, image.Width()); |
| 1568 EXPECT_FALSE(image.IsEmpty()); | 1604 EXPECT_FALSE(image.IsEmpty()); |
| 1569 | 1605 |
| 1570 // Send new suggestion which don't include the snippet referencing the image. | 1606 // Send new suggestion which don't include the snippet referencing the image. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 service->FetchSnippetsInTheBackground(); | 1656 service->FetchSnippetsInTheBackground(); |
| 1621 base::RunLoop().RunUntilIdle(); | 1657 base::RunLoop().RunUntilIdle(); |
| 1622 EXPECT_EQ( | 1658 EXPECT_EQ( |
| 1623 simple_test_clock_ptr->Now().ToInternalValue(), | 1659 simple_test_clock_ptr->Now().ToInternalValue(), |
| 1624 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); | 1660 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); |
| 1625 // TODO(markusheintz): Add a test that simulates a browser restart once the | 1661 // TODO(markusheintz): Add a test that simulates a browser restart once the |
| 1626 // scheduler refactoring is done (crbug.com/672434). | 1662 // scheduler refactoring is done (crbug.com/672434). |
| 1627 } | 1663 } |
| 1628 | 1664 |
| 1629 } // namespace ntp_snippets | 1665 } // namespace ntp_snippets |
| OLD | NEW |