Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(891)

Unified Diff: components/suggestions/suggestions_store_unittest.cc

Issue 816693003: SuggestionsStore unittests not using real time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..13fab216cad874c017187c08a65d46d15c497b99 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) {
+int64 expiry_usec = (expiry_time - base::Time::UnixEpoch())
.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;
}
@@ -71,23 +72,31 @@ void ValidateSuggestions(const SuggestionsProfile& expected,
class SuggestionsStoreTest : public testing::Test {
public:
SuggestionsStoreTest()
- : pref_service_(new user_prefs::TestingPrefServiceSyncable) {}
+ : pref_service_(new user_prefs::TestingPrefServiceSyncable) {
Mathieu 2014/12/18 20:05:28 nit: what this change done by a formatting tool?
gayane -on leave until 09-2017 2014/12/18 21:06:49 No, I added a testing code there and then removed,
+ }
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;
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 +107,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 +119,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.
« components/suggestions/suggestions_store.cc ('K') | « components/suggestions/suggestions_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698