Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc

Issue 2667623002: [Remote suggestions] Clean up variation params in the status service (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_impl.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 1521
1522 // The same article from the AOL domain should now be detected as dismissed. 1522 // The same article from the AOL domain should now be detected as dismissed.
1523 LoadFromJSONString(service.get(), 1523 LoadFromJSONString(service.get(),
1524 GetTestJson({GetSuggestionWithUrlAndTimesAndSource( 1524 GetTestJson({GetSuggestionWithUrlAndTimesAndSource(
1525 source_urls, source_urls[1], creation, expiry, 1525 source_urls, source_urls[1], creation, expiry,
1526 publishers[1], amp_urls[1])})); 1526 publishers[1], amp_urls[1])}));
1527 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()), 1527 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()),
1528 IsEmpty()); 1528 IsEmpty());
1529 } 1529 }
1530 1530
1531 TEST_F(RemoteSuggestionsProviderImplTest, StatusChanges) {
1532 auto service = MakeSuggestionsProvider();
1533
1534 // Simulate user signed out
1535 SetUpFetchResponse(GetTestJson({GetSuggestion()}));
1536 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN,
1537 RemoteSuggestionsStatus::SIGNED_OUT_AND_DISABLED);
1538
1539 base::RunLoop().RunUntilIdle();
1540 EXPECT_THAT(observer().StatusForCategory(articles_category()),
1541 Eq(CategoryStatus::SIGNED_OUT));
1542 EXPECT_THAT(RemoteSuggestionsProviderImpl::State::DISABLED,
1543 Eq(service->state_));
1544 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()),
1545 IsEmpty()); // No fetch should be made.
1546
1547 // Simulate user sign in. The service should be ready again and load
1548 // suggestions.
1549 SetUpFetchResponse(GetTestJson({GetSuggestion()}));
1550 service->OnStatusChanged(RemoteSuggestionsStatus::SIGNED_OUT_AND_DISABLED,
1551 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN);
1552 EXPECT_THAT(observer().StatusForCategory(articles_category()),
1553 Eq(CategoryStatus::AVAILABLE_LOADING));
1554
1555 base::RunLoop().RunUntilIdle();
1556 EXPECT_THAT(observer().StatusForCategory(articles_category()),
1557 Eq(CategoryStatus::AVAILABLE));
1558 EXPECT_THAT(RemoteSuggestionsProviderImpl::State::READY, Eq(service->state_));
1559 EXPECT_FALSE(service->GetSuggestionsForTesting(articles_category()).empty());
1560 }
1561
1562 TEST_F(RemoteSuggestionsProviderImplTest, ImageReturnedWithTheSameId) { 1531 TEST_F(RemoteSuggestionsProviderImplTest, ImageReturnedWithTheSameId) {
1563 auto service = MakeSuggestionsProvider(); 1532 auto service = MakeSuggestionsProvider();
1564 1533
1565 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()})); 1534 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()}));
1566 1535
1567 gfx::Image image; 1536 gfx::Image image;
1568 MockFunction<void(const gfx::Image&)> image_fetched; 1537 MockFunction<void(const gfx::Image&)> image_fetched;
1569 ServeImageCallback cb = 1538 ServeImageCallback cb =
1570 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1539 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1571 { 1540 {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 RemoteSuggestionsProvider::ProviderStatus)>::Call, 1820 RemoteSuggestionsProvider::ProviderStatus)>::Call,
1852 base::Unretained(&status_callback)))); 1821 base::Unretained(&status_callback))));
1853 1822
1854 // Should be called when becoming disabled. 1823 // Should be called when becoming disabled.
1855 EXPECT_CALL(status_callback, 1824 EXPECT_CALL(status_callback,
1856 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE)); 1825 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE));
1857 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); 1826 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED);
1858 } 1827 }
1859 1828
1860 } // namespace ntp_snippets 1829 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698