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

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: Some fixes. Test class for SuggestionStoreTest 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 28 matching lines...) Expand all
39 namespace { 39 namespace {
40 40
41 const char kFakeSuggestionsURL[] = "https://mysuggestions.com/proto"; 41 const char kFakeSuggestionsURL[] = "https://mysuggestions.com/proto";
42 const char kFakeSuggestionsCommonParams[] = "foo=bar"; 42 const char kFakeSuggestionsCommonParams[] = "foo=bar";
43 const char kFakeBlacklistPath[] = "/blacklist"; 43 const char kFakeBlacklistPath[] = "/blacklist";
44 const char kFakeBlacklistUrlParam[] = "baz"; 44 const char kFakeBlacklistUrlParam[] = "baz";
45 45
46 const char kTestTitle[] = "a title"; 46 const char kTestTitle[] = "a title";
47 const char kTestUrl[] = "http://go.com"; 47 const char kTestUrl[] = "http://go.com";
48 const char kBlacklistUrl[] = "http://blacklist.com"; 48 const char kBlacklistUrl[] = "http://blacklist.com";
49 const int64 kTestExpiry =
50 (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
51 .ToInternalValue() + suggestions::kDefaultExpiryUsec;
49 52
50 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( 53 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher(
51 const GURL& url, net::URLFetcherDelegate* delegate, 54 const GURL& url, net::URLFetcherDelegate* delegate,
52 const std::string& response_data, net::HttpStatusCode response_code, 55 const std::string& response_data, net::HttpStatusCode response_code,
53 net::URLRequestStatus::Status status) { 56 net::URLRequestStatus::Status status) {
54 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( 57 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher(
55 url, delegate, response_data, response_code, status)); 58 url, delegate, response_data, response_code, status));
56 59
57 if (response_code == net::HTTP_OK) { 60 if (response_code == net::HTTP_OK) {
58 scoped_refptr<net::HttpResponseHeaders> download_headers( 61 scoped_refptr<net::HttpResponseHeaders> download_headers(
(...skipping 28 matching lines...) Expand all
87 namespace suggestions { 90 namespace suggestions {
88 91
89 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() { 92 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() {
90 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile()); 93 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile());
91 ChromeSuggestion* suggestion = profile->add_suggestions(); 94 ChromeSuggestion* suggestion = profile->add_suggestions();
92 suggestion->set_title(kTestTitle); 95 suggestion->set_title(kTestTitle);
93 suggestion->set_url(kTestUrl); 96 suggestion->set_url(kTestUrl);
94 return profile.Pass(); 97 return profile.Pass();
95 } 98 }
96 99
100 // Creates one suggestion with expiry timestamp and one without.
101 SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() {
102 int64 now = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
103 .ToInternalValue();
104 SuggestionsProfile profile;
105 ChromeSuggestion* suggestion = profile.add_suggestions();
106 suggestion->set_title(kTestTitle);
107 suggestion->set_url(kTestUrl);
108 suggestion->set_expiry_ts(now);
109
110 suggestion = profile.add_suggestions();
111 suggestion->set_title(kTestTitle);
112 suggestion->set_url(kTestUrl);
113
114 return profile;
115 }
116
97 class MockSuggestionsStore : public suggestions::SuggestionsStore { 117 class MockSuggestionsStore : public suggestions::SuggestionsStore {
98 public: 118 public:
99 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); 119 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*));
100 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); 120 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&));
101 MOCK_METHOD0(ClearSuggestions, void()); 121 MOCK_METHOD0(ClearSuggestions, void());
102 }; 122 };
103 123
104 class MockImageManager : public suggestions::ImageManager { 124 class MockImageManager : public suggestions::ImageManager {
105 public: 125 public:
106 MockImageManager() {} 126 MockImageManager() {}
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 510
491 // Delay increases on failure. 511 // Delay increases on failure.
492 suggestions_service->UpdateBlacklistDelay(false); 512 suggestions_service->UpdateBlacklistDelay(false);
493 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); 513 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay);
494 514
495 // Delay resets on success. 515 // Delay resets on success.
496 suggestions_service->UpdateBlacklistDelay(true); 516 suggestions_service->UpdateBlacklistDelay(true);
497 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); 517 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay());
498 } 518 }
499 519
520 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) {
521 scoped_ptr<SuggestionsService> suggestions_service(
522 CreateSuggestionsServiceWithMocks());
523 SuggestionsProfile suggestions =
524 CreateSuggestionsProfileWithExpiryTimestamps();
525 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, kTestExpiry);
526 EXPECT_NE(suggestions.suggestions(0).expiry_ts(), kTestExpiry);
manzagop (departed) 2014/08/05 15:30:26 An equality test is a stronger statement. I'd keep
gayane -on leave until 09-2017 2014/08/06 14:40:55 Done.
527 EXPECT_EQ(suggestions.suggestions(1).expiry_ts(), kTestExpiry);
528 }
500 } // namespace suggestions 529 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698