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

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

Issue 2284933002: Remove OfflineURL from offline page (Closed)
Patch Set: Remove accidentally added new file during 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/recent_tab_suggestions_provider. h" 5 #include "components/ntp_snippets/offline_pages/recent_tab_suggestions_provider. 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 }; 138 };
139 139
140 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { 140 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) {
141 std::vector<OfflinePageItem> offline_pages = CreateDummyRecentTabs({1, 2, 3}); 141 std::vector<OfflinePageItem> offline_pages = CreateDummyRecentTabs({1, 2, 3});
142 142
143 EXPECT_CALL( 143 EXPECT_CALL(
144 *observer(), 144 *observer(),
145 OnNewSuggestions(_, recent_tabs_category(), 145 OnNewSuggestions(_, recent_tabs_category(),
146 UnorderedElementsAre( 146 UnorderedElementsAre(
147 Property(&ContentSuggestion::url, 147 Property(&ContentSuggestion::url,
148 GURL("file:///some/folder/test1.mhtml")), 148 GURL("http://dummy.com/1")),
149 Property(&ContentSuggestion::url, 149 Property(&ContentSuggestion::url,
150 GURL("file:///some/folder/test2.mhtml")), 150 GURL("http://dummy.com/2")),
151 Property(&ContentSuggestion::url, 151 Property(&ContentSuggestion::url,
152 GURL("file:///some/folder/test3.mhtml"))))); 152 GURL("http://dummy.com/3")))));
153 FireOfflinePageModelChanged(offline_pages); 153 FireOfflinePageModelChanged(offline_pages);
154 } 154 }
155 155
156 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByMostRecentlyVisited) { 156 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByMostRecentlyVisited) {
157 base::Time now = base::Time::Now(); 157 base::Time now = base::Time::Now();
158 base::Time yesterday = now - base::TimeDelta::FromDays(1); 158 base::Time yesterday = now - base::TimeDelta::FromDays(1);
159 base::Time tomorrow = now + base::TimeDelta::FromDays(1); 159 base::Time tomorrow = now + base::TimeDelta::FromDays(1);
160 std::vector<OfflinePageItem> offline_pages = { 160 std::vector<OfflinePageItem> offline_pages = {
161 CreateDummyRecentTab(1, now), CreateDummyRecentTab(2, yesterday), 161 CreateDummyRecentTab(1, now), CreateDummyRecentTab(2, yesterday),
162 CreateDummyRecentTab(3, tomorrow)}; 162 CreateDummyRecentTab(3, tomorrow)};
163 163
164 EXPECT_CALL( 164 EXPECT_CALL(
165 *observer(), 165 *observer(),
166 OnNewSuggestions( 166 OnNewSuggestions(
167 _, recent_tabs_category(), 167 _, recent_tabs_category(),
168 ElementsAre(Property(&ContentSuggestion::url, 168 ElementsAre(Property(&ContentSuggestion::url,
169 GURL("file:///some/folder/test3.mhtml")), 169 GURL("http://dummy.com/3")),
170 Property(&ContentSuggestion::url, 170 Property(&ContentSuggestion::url,
171 GURL("file:///some/folder/test1.mhtml")), 171 GURL("http://dummy.com/1")),
172 Property(&ContentSuggestion::url, 172 Property(&ContentSuggestion::url,
173 GURL("file:///some/folder/test2.mhtml"))))); 173 GURL("http://dummy.com/2")))));
174 FireOfflinePageModelChanged(offline_pages); 174 FireOfflinePageModelChanged(offline_pages);
175 } 175 }
176 176
177 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { 177 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) {
178 EXPECT_FALSE( 178 EXPECT_FALSE(
179 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button()); 179 provider()->GetCategoryInfo(recent_tabs_category()).has_more_button());
180 } 180 }
181 181
182 TEST_F(RecentTabSuggestionsProviderTest, ShouldDismiss) { 182 TEST_F(RecentTabSuggestionsProviderTest, ShouldDismiss) {
183 // OfflinePageModel is initialised here because 183 // OfflinePageModel is initialised here because
184 // |GetDismissedSuggestionsForDebugging| may need to call |GetAllPages| 184 // |GetDismissedSuggestionsForDebugging| may need to call |GetAllPages|
185 *(model()->mutable_items()) = CreateDummyRecentTabs({1, 2, 3, 4}); 185 *(model()->mutable_items()) = CreateDummyRecentTabs({1, 2, 3, 4});
186 FireOfflinePageModelChanged(model()->items()); 186 FireOfflinePageModelChanged(model()->items());
187 187
188 // Dismiss 2 and 3. 188 // Dismiss 2 and 3.
189 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0); 189 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(0);
190 provider()->DismissSuggestion(GetDummySuggestionId(2)); 190 provider()->DismissSuggestion(GetDummySuggestionId(2));
191 provider()->DismissSuggestion(GetDummySuggestionId(3)); 191 provider()->DismissSuggestion(GetDummySuggestionId(3));
192 Mock::VerifyAndClearExpectations(observer()); 192 Mock::VerifyAndClearExpectations(observer());
193 193
194 // They should disappear from the reported suggestions. 194 // They should disappear from the reported suggestions.
195 EXPECT_CALL( 195 EXPECT_CALL(
196 *observer(), 196 *observer(),
197 OnNewSuggestions(_, recent_tabs_category(), 197 OnNewSuggestions(_, recent_tabs_category(),
198 UnorderedElementsAre( 198 UnorderedElementsAre(
199 Property(&ContentSuggestion::url, 199 Property(&ContentSuggestion::url,
200 GURL("file:///some/folder/test1.mhtml")), 200 GURL("http://dummy.com/1")),
201 Property(&ContentSuggestion::url, 201 Property(&ContentSuggestion::url,
202 GURL("file:///some/folder/test4.mhtml"))))); 202 GURL("http://dummy.com/4")))));
203 203
204 FireOfflinePageModelChanged(model()->items()); 204 FireOfflinePageModelChanged(model()->items());
205 Mock::VerifyAndClearExpectations(observer()); 205 Mock::VerifyAndClearExpectations(observer());
206 206
207 // And appear in the dismissed suggestions. 207 // And appear in the dismissed suggestions.
208 std::vector<ContentSuggestion> dismissed_suggestions; 208 std::vector<ContentSuggestion> dismissed_suggestions;
209 provider()->GetDismissedSuggestionsForDebugging( 209 provider()->GetDismissedSuggestionsForDebugging(
210 recent_tabs_category(), 210 recent_tabs_category(),
211 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 211 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
212 EXPECT_THAT( 212 EXPECT_THAT(
213 dismissed_suggestions, 213 dismissed_suggestions,
214 UnorderedElementsAre(Property(&ContentSuggestion::url, 214 UnorderedElementsAre(Property(&ContentSuggestion::url,
215 GURL("file:///some/folder/test2.mhtml")), 215 GURL("http://dummy.com/2")),
216 Property(&ContentSuggestion::url, 216 Property(&ContentSuggestion::url,
217 GURL("file:///some/folder/test3.mhtml")))); 217 GURL("http://dummy.com/3"))));
218 218
219 // Clear dismissed suggestions. 219 // Clear dismissed suggestions.
220 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); 220 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category());
221 221
222 // They should be gone from the dismissed suggestions. 222 // They should be gone from the dismissed suggestions.
223 dismissed_suggestions.clear(); 223 dismissed_suggestions.clear();
224 provider()->GetDismissedSuggestionsForDebugging( 224 provider()->GetDismissedSuggestionsForDebugging(
225 recent_tabs_category(), 225 recent_tabs_category(),
226 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 226 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
227 EXPECT_THAT(dismissed_suggestions, IsEmpty()); 227 EXPECT_THAT(dismissed_suggestions, IsEmpty());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 EXPECT_THAT(ReadDismissedIDsFromPrefs(), SizeIs(2)); 263 EXPECT_THAT(ReadDismissedIDsFromPrefs(), SizeIs(2));
264 264
265 FireOfflinePageModelChanged(CreateDummyRecentTabs({2})); 265 FireOfflinePageModelChanged(CreateDummyRecentTabs({2}));
266 EXPECT_THAT(ReadDismissedIDsFromPrefs(), SizeIs(1)); 266 EXPECT_THAT(ReadDismissedIDsFromPrefs(), SizeIs(1));
267 267
268 FireOfflinePageModelChanged(std::vector<OfflinePageItem>()); 268 FireOfflinePageModelChanged(std::vector<OfflinePageItem>());
269 EXPECT_THAT(ReadDismissedIDsFromPrefs(), IsEmpty()); 269 EXPECT_THAT(ReadDismissedIDsFromPrefs(), IsEmpty());
270 } 270 }
271 271
272 } // namespace ntp_snippets 272 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698