Index: components/suggestions/suggestions_store_unittest.cc |
diff --git a/components/suggestions/suggestions_store_unittest.cc b/components/suggestions/suggestions_store_unittest.cc |
index ad5aa2aa0a06a090cfdd5df8371003a7d1df23a8..fad70651228260673945e10b25b91c83de7b76bf 100644 |
--- a/components/suggestions/suggestions_store_unittest.cc |
+++ b/components/suggestions/suggestions_store_unittest.cc |
@@ -4,6 +4,7 @@ |
#include "components/suggestions/suggestions_store.h" |
+#include "base/test/simple_test_clock.h" |
#include "base/time/time.h" |
#include "components/pref_registry/testing_pref_service_syncable.h" |
#include "components/suggestions/proto/suggestions.pb.h" |
@@ -34,19 +35,19 @@ SuggestionsProfile CreateTestSuggestions() { |
return suggestions; |
} |
-SuggestionsProfile CreateTestSuggestionsProfileWithExpiry(int expired_count, |
- int valid_count) { |
- int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) |
+SuggestionsProfile CreateTestSuggestionsProfileWithExpiry( |
+ base::Time expiry_time, int expired_count, int valid_count) { |
Matt Giuca
2014/12/18 22:51:14
The name "expiry_time" is misleading. The expiry t
gayane -on leave until 09-2017
2014/12/22 16:29:38
Done.
|
+int64 expiry_usec = (expiry_time - base::Time::UnixEpoch()) |
Matt Giuca
2014/12/18 22:51:13
Indentation (git cl format).
Matt Giuca
2014/12/18 22:51:14
As above, this is not an expiry time, it is a simu
gayane -on leave until 09-2017
2014/12/22 16:29:38
Done.
gayane -on leave until 09-2017
2014/12/22 16:29:38
Renamed to current_time_usec, because having one n
|
.ToInternalValue(); |
int64 offset_usec = 5 * base::Time::kMicrosecondsPerMinute; |
SuggestionsProfile suggestions; |
for (int i = 1; i <= valid_count; i++) |
AddSuggestion(&suggestions, kTestTitle, kTestUrl, |
- now_usec + offset_usec * i); |
+ expiry_usec + offset_usec * i); |
for (int i = 1; i <= expired_count; i++) |
AddSuggestion(&suggestions, kTestTitle, kTestUrl, |
- now_usec - offset_usec * i); |
+ expiry_usec - offset_usec * i); |
return suggestions; |
} |
@@ -76,18 +77,25 @@ class SuggestionsStoreTest : public testing::Test { |
void SetUp() override { |
SuggestionsStore::RegisterProfilePrefs(pref_service_->registry()); |
suggestions_store_.reset(new SuggestionsStore(pref_service_.get())); |
+ |
+ base::SimpleTestClock* test_clock(new base::SimpleTestClock()); |
+ expiry_time = base::Time::FromInternalValue(13063394337546738); |
+ test_clock->SetNow(expiry_time); |
+ suggestions_store_->SetClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
} |
protected: |
scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; |
scoped_ptr<SuggestionsStore> suggestions_store_; |
+ base::Time expiry_time; |
Matt Giuca
2014/12/18 22:51:14
As above, this is not an expiry time. Rename to cu
gayane -on leave until 09-2017
2014/12/22 16:29:38
Done.
|
DISALLOW_COPY_AND_ASSIGN(SuggestionsStoreTest); |
}; |
// Tests LoadSuggestions function to filter expired suggestions. |
TEST_F(SuggestionsStoreTest, LoadAllExpired) { |
- SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry(5, 0); |
+ SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry( |
+ expiry_time, 5, 0); |
SuggestionsProfile filtered_suggestions; |
// Store and load. Expired suggestions should not be loaded. |
@@ -98,7 +106,8 @@ TEST_F(SuggestionsStoreTest, LoadAllExpired) { |
// Tests LoadSuggestions function to filter expired suggestions. |
TEST_F(SuggestionsStoreTest, LoadValidAndExpired) { |
- SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry(5, 3); |
+ SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry( |
+ expiry_time, 5, 3); |
SuggestionsProfile filtered_suggestions; |
// Store and load. Expired suggestions should not be loaded. |
@@ -109,7 +118,8 @@ TEST_F(SuggestionsStoreTest, LoadValidAndExpired) { |
// Tests LoadSuggestions function to filter expired suggestions. |
TEST_F(SuggestionsStoreTest, CheckStoreAfterLoadExpired) { |
- SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry(5, 3); |
+ SuggestionsProfile suggestions = CreateTestSuggestionsProfileWithExpiry( |
+ expiry_time, 5, 3); |
SuggestionsProfile filtered_suggestions; |
// Store and load. Expired suggestions should not be loaded. |