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

Side by Side 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: Expiry timestamps for suggestions 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/suggestions/suggestions_service.h" 5 #include "components/suggestions/suggestions_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 namespace suggestions { 87 namespace suggestions {
88 88
89 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() { 89 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() {
90 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile()); 90 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile());
91 ChromeSuggestion* suggestion = profile->add_suggestions(); 91 ChromeSuggestion* suggestion = profile->add_suggestions();
92 suggestion->set_title(kTestTitle); 92 suggestion->set_title(kTestTitle);
93 suggestion->set_url(kTestUrl); 93 suggestion->set_url(kTestUrl);
94 return profile.Pass(); 94 return profile.Pass();
95 } 95 }
96 96
97 // create one suggestion with expiry timestamp and one without
98 SuggestionsProfile CreateSuggestionsProfile_MultipleSuggestions() {
manzagop (departed) 2014/07/31 15:31:50 CreateSuggestionsProfileWithSomeExpiryTimestamps?
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
99 int64 now = (base::Time::NowFromSystemTime()
100 -base::Time::UnixEpoch()).ToInternalValue();
manzagop (departed) 2014/07/31 15:31:50 indent. See other comments for the details.
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
101
102 SuggestionsProfile profile;
103 ChromeSuggestion* suggestion = profile.add_suggestions();
104 suggestion->set_title(kTestTitle);
105 suggestion->set_url(kTestUrl);
106 suggestion->set_expiry_ts(now);
107
108 suggestion = profile.add_suggestions();
109 suggestion->set_title(kTestTitle);
110 suggestion->set_url(kTestUrl);
111
112 return profile;
113 }
114
97 class MockSuggestionsStore : public suggestions::SuggestionsStore { 115 class MockSuggestionsStore : public suggestions::SuggestionsStore {
98 public: 116 public:
99 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); 117 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*));
100 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); 118 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&));
101 MOCK_METHOD0(ClearSuggestions, void()); 119 MOCK_METHOD0(ClearSuggestions, void());
102 }; 120 };
103 121
104 class MockImageManager : public suggestions::ImageManager { 122 class MockImageManager : public suggestions::ImageManager {
105 public: 123 public:
106 MockImageManager() {} 124 MockImageManager() {}
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 508
491 // Delay increases on failure. 509 // Delay increases on failure.
492 suggestions_service->UpdateBlacklistDelay(false); 510 suggestions_service->UpdateBlacklistDelay(false);
493 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); 511 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay);
494 512
495 // Delay resets on success. 513 // Delay resets on success.
496 suggestions_service->UpdateBlacklistDelay(true); 514 suggestions_service->UpdateBlacklistDelay(true);
497 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); 515 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay());
498 } 516 }
499 517
518 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) {
519
520 scoped_ptr<SuggestionsService> suggestions_service(
521 CreateSuggestionsServiceWithMocks());
522
523 SuggestionsProfile suggestions =
524 CreateSuggestionsProfile_MultipleSuggestions();
525 suggestions_service->AddDefaultExpiryTimestamps(&suggestions);
526
527 int64 now = (base::Time::NowFromSystemTime()
528 -base::Time::UnixEpoch()).ToInternalValue();
529
530 EXPECT_LT(suggestions.suggestions(0).expiry_ts(), now);
manzagop (departed) 2014/07/31 15:31:50 You could simplify testing by having AddDefaultExp
gayane -on leave until 09-2017 2014/08/04 13:46:30 ---- 1. added a const private field in suggestions
531 EXPECT_GT(suggestions.suggestions(1).expiry_ts(), now);
532 }
533
500 } // namespace suggestions 534 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698