Chromium Code Reviews| 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 | |
| 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 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 | |
| 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 |
| OLD | NEW |