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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Creates one suggestion with expiry timestamp and one without. | |
98 SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() { | |
99 int64 now = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
100 .ToInternalValue(); | |
101 SuggestionsProfile profile; | |
102 ChromeSuggestion* suggestion = profile.add_suggestions(); | |
103 suggestion->set_title(kTestTitle); | |
104 suggestion->set_url(kTestUrl); | |
105 suggestion->set_expiry_ts(now); | |
106 | |
107 suggestion = profile.add_suggestions(); | |
108 suggestion->set_title(kTestTitle); | |
109 suggestion->set_url(kTestUrl); | |
110 | |
111 return profile; | |
112 } | |
113 | |
97 class MockSuggestionsStore : public suggestions::SuggestionsStore { | 114 class MockSuggestionsStore : public suggestions::SuggestionsStore { |
98 public: | 115 public: |
99 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); | 116 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); |
100 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); | 117 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); |
101 MOCK_METHOD0(ClearSuggestions, void()); | 118 MOCK_METHOD0(ClearSuggestions, void()); |
102 }; | 119 }; |
103 | 120 |
104 class MockImageManager : public suggestions::ImageManager { | 121 class MockImageManager : public suggestions::ImageManager { |
105 public: | 122 public: |
106 MockImageManager() {} | 123 MockImageManager() {} |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 507 |
491 // Delay increases on failure. | 508 // Delay increases on failure. |
492 suggestions_service->UpdateBlacklistDelay(false); | 509 suggestions_service->UpdateBlacklistDelay(false); |
493 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); | 510 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); |
494 | 511 |
495 // Delay resets on success. | 512 // Delay resets on success. |
496 suggestions_service->UpdateBlacklistDelay(true); | 513 suggestions_service->UpdateBlacklistDelay(true); |
497 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); | 514 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); |
498 } | 515 } |
499 | 516 |
517 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) { | |
518 | |
manzagop (departed)
2014/08/04 19:50:26
extra line
gayane -on leave until 09-2017
2014/08/05 14:39:15
Done.
| |
519 scoped_ptr<SuggestionsService> suggestions_service( | |
520 CreateSuggestionsServiceWithMocks()); | |
521 SuggestionsProfile suggestions = | |
522 CreateSuggestionsProfileWithExpiryTimestamps(); | |
523 int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
524 .ToInternalValue(); | |
525 int64 default_timestamp_usec = now_usec + kDefaultExpiryUsec; | |
526 suggestions_service->SetDefaultExpiryTimestamps(&suggestions, | |
527 default_timestamp_usec); | |
528 | |
529 EXPECT_NE(suggestions.suggestions(0).expiry_ts(), default_timestamp_usec); | |
manzagop (departed)
2014/08/04 19:50:25
Perhaps you could ensure it's a specific value by
gayane -on leave until 09-2017
2014/08/05 14:39:15
Done.
| |
530 EXPECT_EQ(suggestions.suggestions(1).expiry_ts(), default_timestamp_usec); | |
531 } | |
500 } // namespace suggestions | 532 } // namespace suggestions |
OLD | NEW |