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

Unified Diff: components/suggestions/suggestions_service_unittest.cc

Issue 423133003: [Suggestions Service] Add support for expiring the SuggestionsStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test improvement: scoped_ptr for SuggestionsStore object in unittests Created 6 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/suggestions/suggestions_service_unittest.cc
diff --git a/components/suggestions/suggestions_service_unittest.cc b/components/suggestions/suggestions_service_unittest.cc
index 0d082ea4f83f7fa256bc922a4b4dd8ee96bce1c4..41a5b04df8607297db59cb3daa6286e4893689c7 100644
--- a/components/suggestions/suggestions_service_unittest.cc
+++ b/components/suggestions/suggestions_service_unittest.cc
@@ -46,6 +46,12 @@ const char kFakeBlacklistUrlParam[] = "baz";
const char kTestTitle[] = "a title";
const char kTestUrl[] = "http://go.com";
const char kBlacklistUrl[] = "http://blacklist.com";
+const int64 kTestDefaultExpiry =
+ (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
manzagop (departed) 2014/08/06 19:11:18 Does calling those functions bring added value com
gayane -on leave until 09-2017 2014/08/06 21:12:20 Done.
+ .ToInternalValue() + suggestions::kDefaultExpiryUsec;
+const int64 kTestSetExpiry =
+ (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
+ .ToInternalValue();
scoped_ptr<net::FakeURLFetcher> CreateURLFetcher(
const GURL& url, net::URLFetcherDelegate* delegate,
@@ -94,6 +100,21 @@ scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() {
return profile.Pass();
}
+// Creates one suggestion with expiry timestamp and one without.
+SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() {
+ SuggestionsProfile profile;
+ ChromeSuggestion* suggestion = profile.add_suggestions();
+ suggestion->set_title(kTestTitle);
+ suggestion->set_url(kTestUrl);
+ suggestion->set_expiry_ts(kTestSetExpiry);
+
+ suggestion = profile.add_suggestions();
+ suggestion->set_title(kTestTitle);
+ suggestion->set_url(kTestUrl);
+
+ return profile;
+}
+
class MockSuggestionsStore : public suggestions::SuggestionsStore {
public:
MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*));
@@ -497,4 +518,14 @@ TEST_F(SuggestionsServiceTest, UpdateBlacklistDelay) {
EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay());
}
+TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) {
+ scoped_ptr<SuggestionsService> suggestions_service(
+ CreateSuggestionsServiceWithMocks());
+ SuggestionsProfile suggestions =
+ CreateSuggestionsProfileWithExpiryTimestamps();
+ suggestions_service->SetDefaultExpiryTimestamp(&suggestions,
+ kTestDefaultExpiry);
+ EXPECT_EQ(suggestions.suggestions(0).expiry_ts(), kTestSetExpiry);
+ EXPECT_EQ(suggestions.suggestions(1).expiry_ts(), kTestDefaultExpiry);
+}
} // namespace suggestions

Powered by Google App Engine
This is Rietveld 408576698