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

Unified Diff: components/ntp_snippets/ntp_snippets_service_unittest.cc

Issue 2260783002: Make GetDismissedSuggestionsForDebugging asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace function pointer, use multiple if-continue Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/ntp_snippets_service_unittest.cc
diff --git a/components/ntp_snippets/ntp_snippets_service_unittest.cc b/components/ntp_snippets/ntp_snippets_service_unittest.cc
index 4a988657369bbb8487d8ba821dc535fed552207b..6930165e5081fc515130541cbe9841388a58928b 100644
--- a/components/ntp_snippets/ntp_snippets_service_unittest.cc
+++ b/components/ntp_snippets/ntp_snippets_service_unittest.cc
@@ -280,6 +280,18 @@ class MockImageFetcher : public ImageFetcher {
base::Callback<void(const std::string&, const gfx::Image&)>));
};
+class MockDismissedSuggestionsCallback
+ : public ContentSuggestionsProvider::DismissedSuggestionsCallback {
+ public:
+ MOCK_METHOD2(MockRun,
+ void(Category category,
+ std::vector<ContentSuggestion>* dismissed_suggestions));
+ void Run(Category category,
+ std::vector<ContentSuggestion> dismissed_suggestions) {
+ MockRun(category, &dismissed_suggestions);
+ }
+};
+
} // namespace
class NTPSnippetsServiceTest : public test::NTPSnippetsTestBase {
@@ -553,18 +565,36 @@ TEST_F(NTPSnippetsServiceTest, GetDismissed) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
- std::vector<ContentSuggestion> suggestions =
- service()->GetDismissedSuggestionsForDebugging(articles_category());
- EXPECT_EQ(1u, suggestions.size());
- for (auto& suggestion : suggestions) {
- EXPECT_EQ(MakeUniqueID(kSnippetUrl), suggestion.id());
- }
+
+ MockDismissedSuggestionsCallback callback;
+
+ EXPECT_CALL(callback, MockRun(_, _))
+ .WillOnce(
+ Invoke([this](Category category,
+ std::vector<ContentSuggestion>* dismissed_suggestions) {
+ EXPECT_EQ(1u, dismissed_suggestions->size());
+ for (auto& suggestion : *dismissed_suggestions) {
+ EXPECT_EQ(MakeUniqueID(kSnippetUrl), suggestion.id());
+ }
+ }));
+ service()->GetDismissedSuggestionsForDebugging(
+ articles_category(),
+ base::Bind(&MockDismissedSuggestionsCallback::Run,
+ base::Unretained(&callback), articles_category()));
+ Mock::VerifyAndClearExpectations(&callback);
// There should be no dismissed snippet after clearing the list.
+ EXPECT_CALL(callback, MockRun(_, _))
+ .WillOnce(
+ Invoke([this](Category category,
+ std::vector<ContentSuggestion>* dismissed_suggestions) {
+ EXPECT_EQ(0u, dismissed_suggestions->size());
+ }));
service()->ClearDismissedSuggestionsForDebugging(articles_category());
- EXPECT_EQ(0u, service()
- ->GetDismissedSuggestionsForDebugging(articles_category())
- .size());
+ service()->GetDismissedSuggestionsForDebugging(
+ articles_category(),
+ base::Bind(&MockDismissedSuggestionsCallback::Run,
+ base::Unretained(&callback), articles_category()));
}
TEST_F(NTPSnippetsServiceTest, CreationTimestampParseFail) {

Powered by Google App Engine
This is Rietveld 408576698