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 // Create one suggestion with expiry timestamp and one without | |
Mathieu
2014/08/04 14:39:10
*Creates
Also period at the end of the comment.
gayane -on leave until 09-2017
2014/08/04 16:34:58
Done.
| |
98 SuggestionsProfile CreateSuggestionsProfileWithExpiryTimestamps() { | |
99 int64 now = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
Mathieu
2014/08/04 14:39:10
Have you tried ToJavaTime? I think it could be com
gayane -on leave until 09-2017
2014/08/04 16:34:58
then I would need to do
base::Time::NowFromSystemT
| |
100 .ToInternalValue(); | |
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 Loading... | |
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 SuggestionsProfile suggestions = | |
523 CreateSuggestionsProfileWithExpiryTimestamps(); | |
Mathieu
2014/08/04 14:39:10
Indentation is off. Indent 4 from the start of the
gayane -on leave until 09-2017
2014/08/04 16:34:58
Done.
| |
524 int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) | |
525 .ToInternalValue(); | |
526 int64 default_timestamp_usec = now_usec + | |
527 SuggestionsService::default_expiry_usec; | |
Mathieu
2014/08/04 14:39:10
do you need the "SuggestionsService::"?
gayane -on leave until 09-2017
2014/08/04 16:34:58
Done.
| |
528 suggestions_service->SetDefaultExpiryTimestamps(&suggestions, | |
529 default_timestamp_usec); | |
530 | |
531 EXPECT_NE(suggestions.suggestions(0).expiry_ts(), default_timestamp_usec); | |
532 EXPECT_EQ(suggestions.suggestions(1).expiry_ts(), default_timestamp_usec); | |
533 } | |
500 } // namespace suggestions | 534 } // namespace suggestions |
OLD | NEW |