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

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

Issue 2744253004: NTP: clang-format (Closed)
Patch Set: rebase Created 3 years, 8 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 private: 160 private:
161 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest); 161 DISALLOW_COPY_AND_ASSIGN(RecentTabSuggestionsProviderTest);
162 }; 162 };
163 163
164 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) { 164 TEST_F(RecentTabSuggestionsProviderTest, ShouldConvertToSuggestions) {
165 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2); 165 EXPECT_CALL(*observer(), OnNewSuggestions(_, _, _)).Times(2);
166 EXPECT_CALL( 166 EXPECT_CALL(
167 *observer(), 167 *observer(),
168 OnNewSuggestions(_, recent_tabs_category(), 168 OnNewSuggestions(
169 UnorderedElementsAre( 169 _, recent_tabs_category(),
170 Property(&ContentSuggestion::url, 170 UnorderedElementsAre(
171 GURL("http://dummy.com/1")), 171 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")),
172 Property(&ContentSuggestion::url, 172 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")),
173 GURL("http://dummy.com/2")), 173 Property(&ContentSuggestion::url, GURL("http://dummy.com/3")))));
174 Property(&ContentSuggestion::url,
175 GURL("http://dummy.com/3")))));
176 174
177 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3}); 175 auto recent_tabs_list = CreateDummyRecentTabs({1, 2, 3});
178 for (OfflinePageItem& recent_tab : recent_tabs_list) { 176 for (OfflinePageItem& recent_tab : recent_tabs_list) {
179 AddTabAndOfflinePageToModel(recent_tab); 177 AddTabAndOfflinePageToModel(recent_tab);
180 } 178 }
181 } 179 }
182 180
183 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByCreationTime) { 181 TEST_F(RecentTabSuggestionsProviderTest, ShouldSortByCreationTime) {
184 base::Time now = base::Time::Now(); 182 base::Time now = base::Time::Now();
185 base::Time yesterday = now - base::TimeDelta::FromDays(1); 183 base::Time yesterday = now - base::TimeDelta::FromDays(1);
(...skipping 19 matching lines...) Expand all
205 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); 203 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")))));
206 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2, yesterday)); 204 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2, yesterday));
207 205
208 offline_pages[1].last_access_time = 206 offline_pages[1].last_access_time =
209 offline_pages[0].last_access_time + base::TimeDelta::FromHours(1); 207 offline_pages[0].last_access_time + base::TimeDelta::FromHours(1);
210 208
211 EXPECT_CALL( 209 EXPECT_CALL(
212 *observer(), 210 *observer(),
213 OnNewSuggestions( 211 OnNewSuggestions(
214 _, recent_tabs_category(), 212 _, recent_tabs_category(),
215 ElementsAre(Property(&ContentSuggestion::url, 213 ElementsAre(
216 GURL("http://dummy.com/3")), 214 Property(&ContentSuggestion::url, GURL("http://dummy.com/3")),
217 Property(&ContentSuggestion::url, 215 Property(&ContentSuggestion::url, GURL("http://dummy.com/1")),
218 GURL("http://dummy.com/1")), 216 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")))));
219 Property(&ContentSuggestion::url,
220 GURL("http://dummy.com/2")))));
221 AddTabAndOfflinePageToModel(CreateDummyRecentTab(3, tomorrow)); 217 AddTabAndOfflinePageToModel(CreateDummyRecentTab(3, tomorrow));
222 } 218 }
223 219
224 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) { 220 TEST_F(RecentTabSuggestionsProviderTest, ShouldDeliverCorrectCategoryInfo) {
225 EXPECT_EQ( 221 EXPECT_EQ(
226 ContentSuggestionsAdditionalAction::NONE, 222 ContentSuggestionsAdditionalAction::NONE,
227 provider()->GetCategoryInfo(recent_tabs_category()).additional_action()); 223 provider()->GetCategoryInfo(recent_tabs_category()).additional_action());
228 } 224 }
229 225
230 // TODO(vitaliii): Break this test into multiple tests. Currently if it fails, 226 // TODO(vitaliii): Break this test into multiple tests. Currently if it fails,
(...skipping 23 matching lines...) Expand all
254 AddTabAndOfflinePageToModel(CreateDummyRecentTab(4)); 250 AddTabAndOfflinePageToModel(CreateDummyRecentTab(4));
255 Mock::VerifyAndClearExpectations(observer()); 251 Mock::VerifyAndClearExpectations(observer());
256 252
257 // And appear in the dismissed suggestions. 253 // And appear in the dismissed suggestions.
258 std::vector<ContentSuggestion> dismissed_suggestions; 254 std::vector<ContentSuggestion> dismissed_suggestions;
259 provider()->GetDismissedSuggestionsForDebugging( 255 provider()->GetDismissedSuggestionsForDebugging(
260 recent_tabs_category(), 256 recent_tabs_category(),
261 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 257 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
262 EXPECT_THAT( 258 EXPECT_THAT(
263 dismissed_suggestions, 259 dismissed_suggestions,
264 UnorderedElementsAre(Property(&ContentSuggestion::url, 260 UnorderedElementsAre(
265 GURL("http://dummy.com/2")), 261 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")),
266 Property(&ContentSuggestion::url, 262 Property(&ContentSuggestion::url, GURL("http://dummy.com/3"))));
267 GURL("http://dummy.com/3"))));
268 263
269 // Clear dismissed suggestions. 264 // Clear dismissed suggestions.
270 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category()); 265 provider()->ClearDismissedSuggestionsForDebugging(recent_tabs_category());
271 266
272 // They should be gone from the dismissed suggestions. 267 // They should be gone from the dismissed suggestions.
273 dismissed_suggestions.clear(); 268 dismissed_suggestions.clear();
274 provider()->GetDismissedSuggestionsForDebugging( 269 provider()->GetDismissedSuggestionsForDebugging(
275 recent_tabs_category(), 270 recent_tabs_category(),
276 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions)); 271 base::Bind(&CaptureDismissedSuggestions, &dismissed_suggestions));
277 EXPECT_THAT(dismissed_suggestions, IsEmpty()); 272 EXPECT_THAT(dismissed_suggestions, IsEmpty());
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 Property(&ContentSuggestion::url, GURL("http://dummy.com/2"))))); 426 Property(&ContentSuggestion::url, GURL("http://dummy.com/2")))));
432 427
433 AddTabAndOfflinePageToModel(CreateDummyRecentTab(1)); 428 AddTabAndOfflinePageToModel(CreateDummyRecentTab(1));
434 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2)); 429 AddTabAndOfflinePageToModel(CreateDummyRecentTab(2));
435 // The provider is not notified about the recent tabs yet. 430 // The provider is not notified about the recent tabs yet.
436 task_runner()->RunUntilIdle(); 431 task_runner()->RunUntilIdle();
437 // However, it must return both tabs when the model is loaded. 432 // However, it must return both tabs when the model is loaded.
438 } 433 }
439 434
440 } // namespace ntp_snippets 435 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698