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

Side by Side Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider_unittest.cc

Issue 2377663002: [NTP Snippets] Introduce ContentSuggestion::ID (Closed)
Patch Set: rebase Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/offline_pages/offline_page_suggestions_provide r.h" 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide r.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 Category recent_tabs_category() { 129 Category recent_tabs_category() {
130 return category_factory_.FromKnownCategory(KnownCategories::RECENT_TABS); 130 return category_factory_.FromKnownCategory(KnownCategories::RECENT_TABS);
131 } 131 }
132 132
133 Category downloads_category() { 133 Category downloads_category() {
134 return category_factory_.FromKnownCategory(KnownCategories::DOWNLOADS); 134 return category_factory_.FromKnownCategory(KnownCategories::DOWNLOADS);
135 } 135 }
136 136
137 std::string GetDummySuggestionId(Category category, int id) { 137 ContentSuggestion::ID GetDummySuggestionId(Category category, int id) {
138 return provider_->MakeUniqueID(category, base::IntToString(id)); 138 return ContentSuggestion::ID(category, base::IntToString(id));
139 } 139 }
140 140
141 ContentSuggestion CreateDummySuggestion(Category category, int id) { 141 ContentSuggestion CreateDummySuggestion(Category category, int id) {
142 std::string strid = base::IntToString(id); 142 std::string strid = base::IntToString(id);
143 ContentSuggestion result( 143 ContentSuggestion result(
144 GetDummySuggestionId(category, id), 144 GetDummySuggestionId(category, id),
145 GURL("file:///some/folder/test" + strid + ".mhtml")); 145 GURL("file:///some/folder/test" + strid + ".mhtml"));
146 result.set_title(base::UTF8ToUTF16("http://dummy.com/" + strid)); 146 result.set_title(base::UTF8ToUTF16("http://dummy.com/" + strid));
147 return result; 147 return result;
148 } 148 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 341 }
342 342
343 TEST_F(OfflinePageSuggestionsProviderTest, 343 TEST_F(OfflinePageSuggestionsProviderTest,
344 ShouldInvalidateWhenOfflinePageDeleted) { 344 ShouldInvalidateWhenOfflinePageDeleted) {
345 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); 345 model()->mutable_items()->push_back(CreateDummyRecentTab(1));
346 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); 346 model()->mutable_items()->push_back(CreateDummyRecentTab(2));
347 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); 347 model()->mutable_items()->push_back(CreateDummyRecentTab(3));
348 FireOfflinePageModelChanged(); 348 FireOfflinePageModelChanged();
349 349
350 // Invalidation of suggestion 2 should be forwarded. 350 // Invalidation of suggestion 2 should be forwarded.
351 EXPECT_CALL( 351 EXPECT_CALL(*observer(),
352 *observer(), 352 OnSuggestionInvalidated(
353 OnSuggestionInvalidated(_, recent_tabs_category(), 353 _, GetDummySuggestionId(recent_tabs_category(), 2)));
354 GetDummySuggestionId(recent_tabs_category(), 2)));
355 FireOfflinePageDeleted(model()->items().at(1)); 354 FireOfflinePageDeleted(model()->items().at(1));
356 } 355 }
357 356
358 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnInvalidate) { 357 TEST_F(OfflinePageSuggestionsProviderTest, ShouldClearDismissedOnInvalidate) {
359 model()->mutable_items()->push_back(CreateDummyRecentTab(1)); 358 model()->mutable_items()->push_back(CreateDummyRecentTab(1));
360 model()->mutable_items()->push_back(CreateDummyRecentTab(2)); 359 model()->mutable_items()->push_back(CreateDummyRecentTab(2));
361 model()->mutable_items()->push_back(CreateDummyRecentTab(3)); 360 model()->mutable_items()->push_back(CreateDummyRecentTab(3));
362 FireOfflinePageModelChanged(); 361 FireOfflinePageModelChanged();
363 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); 362 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty());
364 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); 363 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty());
(...skipping 25 matching lines...) Expand all
390 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); 389 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty());
391 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1)); 390 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), SizeIs(1));
392 391
393 model()->mutable_items()->clear(); 392 model()->mutable_items()->clear();
394 FireOfflinePageModelChanged(); 393 FireOfflinePageModelChanged();
395 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty()); 394 EXPECT_THAT(ReadDismissedIDsFromPrefs(recent_tabs_category()), IsEmpty());
396 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty()); 395 EXPECT_THAT(ReadDismissedIDsFromPrefs(downloads_category()), IsEmpty());
397 } 396 }
398 397
399 } // namespace ntp_snippets 398 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698