OLD | NEW |
---|---|
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 Loading... | |
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 kTestDefaultExpiry = | |
50 (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.
| |
51 .ToInternalValue() + suggestions::kDefaultExpiryUsec; | |
52 const int64 kTestSetExpiry = | |
53 (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
54 .ToInternalValue(); | |
49 | 55 |
50 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( | 56 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( |
51 const GURL& url, net::URLFetcherDelegate* delegate, | 57 const GURL& url, net::URLFetcherDelegate* delegate, |
52 const std::string& response_data, net::HttpStatusCode response_code, | 58 const std::string& response_data, net::HttpStatusCode response_code, |
53 net::URLRequestStatus::Status status) { | 59 net::URLRequestStatus::Status status) { |
54 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( | 60 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( |
55 url, delegate, response_data, response_code, status)); | 61 url, delegate, response_data, response_code, status)); |
56 | 62 |
57 if (response_code == net::HTTP_OK) { | 63 if (response_code == net::HTTP_OK) { |
58 scoped_refptr<net::HttpResponseHeaders> download_headers( | 64 scoped_refptr<net::HttpResponseHeaders> download_headers( |
(...skipping 28 matching lines...) Expand all Loading... | |
87 namespace suggestions { | 93 namespace suggestions { |
88 | 94 |
89 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() { | 95 scoped_ptr<SuggestionsProfile> CreateSuggestionsProfile() { |
90 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile()); | 96 scoped_ptr<SuggestionsProfile> profile(new SuggestionsProfile()); |
91 ChromeSuggestion* suggestion = profile->add_suggestions(); | 97 ChromeSuggestion* suggestion = profile->add_suggestions(); |
92 suggestion->set_title(kTestTitle); | 98 suggestion->set_title(kTestTitle); |
93 suggestion->set_url(kTestUrl); | 99 suggestion->set_url(kTestUrl); |
94 return profile.Pass(); | 100 return profile.Pass(); |
95 } | 101 } |
96 | 102 |
103 // Creates one suggestion with expiry timestamp and one without. | |
104 SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() { | |
105 SuggestionsProfile profile; | |
106 ChromeSuggestion* suggestion = profile.add_suggestions(); | |
107 suggestion->set_title(kTestTitle); | |
108 suggestion->set_url(kTestUrl); | |
109 suggestion->set_expiry_ts(kTestSetExpiry); | |
110 | |
111 suggestion = profile.add_suggestions(); | |
112 suggestion->set_title(kTestTitle); | |
113 suggestion->set_url(kTestUrl); | |
114 | |
115 return profile; | |
116 } | |
117 | |
97 class MockSuggestionsStore : public suggestions::SuggestionsStore { | 118 class MockSuggestionsStore : public suggestions::SuggestionsStore { |
98 public: | 119 public: |
99 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); | 120 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); |
100 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); | 121 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); |
101 MOCK_METHOD0(ClearSuggestions, void()); | 122 MOCK_METHOD0(ClearSuggestions, void()); |
102 }; | 123 }; |
103 | 124 |
104 class MockImageManager : public suggestions::ImageManager { | 125 class MockImageManager : public suggestions::ImageManager { |
105 public: | 126 public: |
106 MockImageManager() {} | 127 MockImageManager() {} |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 511 |
491 // Delay increases on failure. | 512 // Delay increases on failure. |
492 suggestions_service->UpdateBlacklistDelay(false); | 513 suggestions_service->UpdateBlacklistDelay(false); |
493 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); | 514 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); |
494 | 515 |
495 // Delay resets on success. | 516 // Delay resets on success. |
496 suggestions_service->UpdateBlacklistDelay(true); | 517 suggestions_service->UpdateBlacklistDelay(true); |
497 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); | 518 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); |
498 } | 519 } |
499 | 520 |
521 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) { | |
522 scoped_ptr<SuggestionsService> suggestions_service( | |
523 CreateSuggestionsServiceWithMocks()); | |
524 SuggestionsProfile suggestions = | |
525 CreateSuggestionsProfileWithExpiryTimestamps(); | |
526 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, | |
527 kTestDefaultExpiry); | |
528 EXPECT_EQ(suggestions.suggestions(0).expiry_ts(), kTestSetExpiry); | |
529 EXPECT_EQ(suggestions.suggestions(1).expiry_ts(), kTestDefaultExpiry); | |
530 } | |
500 } // namespace suggestions | 531 } // namespace suggestions |
OLD | NEW |