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_store.h" | 5 #include "components/suggestions/suggestions_store.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include "base/macros.h" |
7 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
8 #include "base/time/time.h" | 11 #include "base/time/time.h" |
9 #include "components/pref_registry/testing_pref_service_syncable.h" | 12 #include "components/pref_registry/testing_pref_service_syncable.h" |
10 #include "components/suggestions/proto/suggestions.pb.h" | 13 #include "components/suggestions/proto/suggestions.pb.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 | 15 |
13 using user_prefs::TestingPrefServiceSyncable; | 16 using user_prefs::TestingPrefServiceSyncable; |
14 | 17 |
15 namespace suggestions { | 18 namespace suggestions { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 const char kTestTitle[] = "Foo site"; | 22 const char kTestTitle[] = "Foo site"; |
20 const char kTestUrl[] = "http://foo.com/"; | 23 const char kTestUrl[] = "http://foo.com/"; |
21 | 24 |
22 void AddSuggestion(SuggestionsProfile* suggestions, const char *title, | 25 void AddSuggestion(SuggestionsProfile* suggestions, |
23 const char *url, int64 expiry_ts) { | 26 const char* title, |
| 27 const char* url, |
| 28 int64_t expiry_ts) { |
24 ChromeSuggestion* suggestion = suggestions->add_suggestions(); | 29 ChromeSuggestion* suggestion = suggestions->add_suggestions(); |
25 suggestion->set_url(title); | 30 suggestion->set_url(title); |
26 suggestion->set_title(url); | 31 suggestion->set_title(url); |
27 suggestion->set_expiry_ts(expiry_ts); | 32 suggestion->set_expiry_ts(expiry_ts); |
28 } | 33 } |
29 | 34 |
30 SuggestionsProfile CreateTestSuggestions() { | 35 SuggestionsProfile CreateTestSuggestions() { |
31 SuggestionsProfile suggestions; | 36 SuggestionsProfile suggestions; |
32 ChromeSuggestion* suggestion = suggestions.add_suggestions(); | 37 ChromeSuggestion* suggestion = suggestions.add_suggestions(); |
33 suggestion->set_url(kTestTitle); | 38 suggestion->set_url(kTestTitle); |
34 suggestion->set_title(kTestUrl); | 39 suggestion->set_title(kTestUrl); |
35 return suggestions; | 40 return suggestions; |
36 } | 41 } |
37 | 42 |
38 SuggestionsProfile CreateTestSuggestionsProfileWithExpiry( | 43 SuggestionsProfile CreateTestSuggestionsProfileWithExpiry( |
39 base::Time current_time, | 44 base::Time current_time, |
40 int expired_count, | 45 int expired_count, |
41 int valid_count) { | 46 int valid_count) { |
42 int64 current_time_usec = | 47 int64_t current_time_usec = |
43 (current_time - base::Time::UnixEpoch()).ToInternalValue(); | 48 (current_time - base::Time::UnixEpoch()).ToInternalValue(); |
44 int64 offset_usec = 5 * base::Time::kMicrosecondsPerMinute; | 49 int64_t offset_usec = 5 * base::Time::kMicrosecondsPerMinute; |
45 | 50 |
46 SuggestionsProfile suggestions; | 51 SuggestionsProfile suggestions; |
47 for (int i = 1; i <= valid_count; i++) | 52 for (int i = 1; i <= valid_count; i++) |
48 AddSuggestion(&suggestions, kTestTitle, kTestUrl, | 53 AddSuggestion(&suggestions, kTestTitle, kTestUrl, |
49 current_time_usec + offset_usec * i); | 54 current_time_usec + offset_usec * i); |
50 for (int i = 1; i <= expired_count; i++) | 55 for (int i = 1; i <= expired_count; i++) |
51 AddSuggestion(&suggestions, kTestTitle, kTestUrl, | 56 AddSuggestion(&suggestions, kTestTitle, kTestUrl, |
52 current_time_usec - offset_usec * i); | 57 current_time_usec - offset_usec * i); |
53 | 58 |
54 return suggestions; | 59 return suggestions; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 EXPECT_TRUE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); | 153 EXPECT_TRUE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); |
149 ValidateSuggestions(suggestions, recovered_suggestions); | 154 ValidateSuggestions(suggestions, recovered_suggestions); |
150 | 155 |
151 // Clear. | 156 // Clear. |
152 suggestions_store_->ClearSuggestions(); | 157 suggestions_store_->ClearSuggestions(); |
153 EXPECT_FALSE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); | 158 EXPECT_FALSE(suggestions_store_->LoadSuggestions(&recovered_suggestions)); |
154 ValidateSuggestions(empty_suggestions, recovered_suggestions); | 159 ValidateSuggestions(empty_suggestions, recovered_suggestions); |
155 } | 160 } |
156 | 161 |
157 } // namespace suggestions | 162 } // namespace suggestions |
OLD | NEW |