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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestion_unittest.cc

Issue 2686063003: [remote suggestions] Attach the fetch time to RemoteSnippets, ContentSnippets and SnippetArticle (Closed)
Patch Set: Update RemoteSuggestionTest Created 3 years, 10 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_snippets/remote/remote_suggestion.h" 5 #include "components/ntp_snippets/remote/remote_suggestion.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "components/ntp_snippets/remote/proto/ntp_snippets.pb.h" 14 #include "components/ntp_snippets/remote/proto/ntp_snippets.pb.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace ntp_snippets { 18 namespace ntp_snippets {
18 namespace { 19 namespace {
19 20
20 using ::testing::ElementsAre; 21 using ::testing::ElementsAre;
21 using ::testing::Eq; 22 using ::testing::Eq;
22 using ::testing::IsNull; 23 using ::testing::IsNull;
23 using ::testing::NotNull; 24 using ::testing::NotNull;
24 25
25 std::unique_ptr<RemoteSuggestion> SnippetFromContentSuggestionJSON( 26 std::unique_ptr<RemoteSuggestion> SnippetFromContentSuggestionJSON(
26 const std::string& json) { 27 const std::string& json,
28 const base::Time fetch_date) {
Marc Treib 2017/02/13 15:20:31 nit: &
markusheintz_ 2017/02/13 15:55:01 Done.
27 auto json_value = base::JSONReader::Read(json); 29 auto json_value = base::JSONReader::Read(json);
28 base::DictionaryValue* json_dict; 30 base::DictionaryValue* json_dict;
29 if (!json_value->GetAsDictionary(&json_dict)) { 31 if (!json_value->GetAsDictionary(&json_dict)) {
30 return nullptr; 32 return nullptr;
31 } 33 }
32 return RemoteSuggestion::CreateFromContentSuggestionsDictionary( 34 return RemoteSuggestion::CreateFromContentSuggestionsDictionary(
33 *json_dict, kArticlesRemoteId); 35 *json_dict, kArticlesRemoteId, fetch_date);
34 } 36 }
35 37
36 TEST(RemoteSuggestionTest, FromChromeContentSuggestionsDictionary) { 38 TEST(RemoteSuggestionTest, FromChromeContentSuggestionsDictionary) {
37 const std::string kJsonStr = 39 const std::string kJsonStr =
38 "{" 40 "{"
39 " \"ids\" : [\"http://localhost/foobar\"]," 41 " \"ids\" : [\"http://localhost/foobar\"],"
40 " \"title\" : \"Foo Barred from Baz\"," 42 " \"title\" : \"Foo Barred from Baz\","
41 " \"snippet\" : \"...\"," 43 " \"snippet\" : \"...\","
42 " \"fullPageUrl\" : \"http://localhost/foobar\"," 44 " \"fullPageUrl\" : \"http://localhost/foobar\","
43 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 45 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
44 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," 46 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
45 " \"attribution\" : \"Foo News\"," 47 " \"attribution\" : \"Foo News\","
46 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 48 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
47 " \"ampUrl\" : \"http://localhost/amp\"," 49 " \"ampUrl\" : \"http://localhost/amp\","
48 " \"faviconUrl\" : \"http://localhost/favicon.ico\", " 50 " \"faviconUrl\" : \"http://localhost/favicon.ico\", "
49 " \"score\": 9001,\n" 51 " \"score\": 9001,\n"
50 " \"notificationInfo\": {\n" 52 " \"notificationInfo\": {\n"
51 " \"shouldNotify\": true," 53 " \"shouldNotify\": true,"
52 " \"deadline\": \"2016-06-30T13:01:37.000Z\"\n" 54 " \"deadline\": \"2016-06-30T13:01:37.000Z\"\n"
53 " }\n" 55 " }\n"
54 "}"; 56 "}";
55 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr); 57 const base::Time fetch_date = base::Time::Now();
Marc Treib 2017/02/13 15:20:31 This feels wrong... Can we use a hardcoded fixed d
markusheintz_ 2017/02/13 15:55:01 Done.
58 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr, fetch_date);
56 ASSERT_THAT(snippet, NotNull()); 59 ASSERT_THAT(snippet, NotNull());
57 60
58 EXPECT_EQ(snippet->id(), "http://localhost/foobar"); 61 EXPECT_EQ(snippet->id(), "http://localhost/foobar");
59 EXPECT_EQ(snippet->title(), "Foo Barred from Baz"); 62 EXPECT_EQ(snippet->title(), "Foo Barred from Baz");
60 EXPECT_EQ(snippet->snippet(), "..."); 63 EXPECT_EQ(snippet->snippet(), "...");
61 EXPECT_EQ(snippet->salient_image_url(), GURL("http://localhost/foobar.jpg")); 64 EXPECT_EQ(snippet->salient_image_url(), GURL("http://localhost/foobar.jpg"));
62 EXPECT_EQ(snippet->score(), 9001); 65 EXPECT_EQ(snippet->score(), 9001);
63 auto unix_publish_date = snippet->publish_date() - base::Time::UnixEpoch(); 66 auto unix_publish_date = snippet->publish_date() - base::Time::UnixEpoch();
64 auto expiry_duration = snippet->expiry_date() - snippet->publish_date(); 67 auto expiry_duration = snippet->expiry_date() - snippet->publish_date();
65 EXPECT_FLOAT_EQ(unix_publish_date.InSecondsF(), 1467284497.000000f); 68 EXPECT_FLOAT_EQ(unix_publish_date.InSecondsF(), 1467284497.000000f);
66 EXPECT_FLOAT_EQ(expiry_duration.InSecondsF(), 86400.000000f); 69 EXPECT_FLOAT_EQ(expiry_duration.InSecondsF(), 86400.000000f);
67 70
68 EXPECT_EQ(snippet->publisher_name(), "Foo News"); 71 EXPECT_EQ(snippet->publisher_name(), "Foo News");
69 EXPECT_EQ(snippet->url(), GURL("http://localhost/foobar")); 72 EXPECT_EQ(snippet->url(), GURL("http://localhost/foobar"));
70 EXPECT_EQ(snippet->amp_url(), GURL("http://localhost/amp")); 73 EXPECT_EQ(snippet->amp_url(), GURL("http://localhost/amp"));
71 74
72 EXPECT_TRUE(snippet->should_notify()); 75 EXPECT_TRUE(snippet->should_notify());
73 auto notification_duration = 76 auto notification_duration =
74 snippet->notification_deadline() - snippet->publish_date(); 77 snippet->notification_deadline() - snippet->publish_date();
75 EXPECT_EQ(7200.0f, notification_duration.InSecondsF()); 78 EXPECT_EQ(7200.0f, notification_duration.InSecondsF());
79 EXPECT_EQ(fetch_date, snippet->fetch_date());
76 } 80 }
77 81
78 std::unique_ptr<RemoteSuggestion> SnippetFromChromeReaderDict( 82 std::unique_ptr<RemoteSuggestion> SnippetFromChromeReaderDict(
79 std::unique_ptr<base::DictionaryValue> dict) { 83 std::unique_ptr<base::DictionaryValue> dict,
84 const base::Time& fetch_date) {
80 if (!dict) { 85 if (!dict) {
81 return nullptr; 86 return nullptr;
82 } 87 }
83 return RemoteSuggestion::CreateFromChromeReaderDictionary(*dict); 88 return RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_date);
84 } 89 }
85 90
86 const char kChromeReaderCreationTimestamp[] = "1234567890"; 91 const char kChromeReaderCreationTimestamp[] = "1234567890";
87 const char kChromeReaderExpiryTimestamp[] = "2345678901"; 92 const char kChromeReaderExpiryTimestamp[] = "2345678901";
88 93
89 // Old form, from chromereader-pa.googleapis.com. Two sources. 94 // Old form, from chromereader-pa.googleapis.com. Two sources.
90 std::unique_ptr<base::DictionaryValue> ChromeReaderSnippetWithTwoSources() { 95 std::unique_ptr<base::DictionaryValue> ChromeReaderSnippetWithTwoSources() {
91 const std::string kJsonStr = base::StringPrintf( 96 const std::string kJsonStr = base::StringPrintf(
92 "{\n" 97 "{\n"
93 " \"contentInfo\": {\n" 98 " \"contentInfo\": {\n"
(...skipping 23 matching lines...) Expand all
117 122
118 auto json_value = base::JSONReader::Read(kJsonStr); 123 auto json_value = base::JSONReader::Read(kJsonStr);
119 base::DictionaryValue* json_dict; 124 base::DictionaryValue* json_dict;
120 if (!json_value->GetAsDictionary(&json_dict)) { 125 if (!json_value->GetAsDictionary(&json_dict)) {
121 return nullptr; 126 return nullptr;
122 } 127 }
123 return json_dict->CreateDeepCopy(); 128 return json_dict->CreateDeepCopy();
124 } 129 }
125 130
126 TEST(RemoteSuggestionTest, TestMultipleSources) { 131 TEST(RemoteSuggestionTest, TestMultipleSources) {
127 auto snippet = 132 auto snippet = SnippetFromChromeReaderDict(
128 SnippetFromChromeReaderDict(ChromeReaderSnippetWithTwoSources()); 133 ChromeReaderSnippetWithTwoSources(), base::Time::Now());
Marc Treib 2017/02/13 15:20:32 Also here and everywhere below: I'd prefer to avoi
markusheintz_ 2017/02/13 15:55:01 Done.
129 ASSERT_THAT(snippet, NotNull()); 134 ASSERT_THAT(snippet, NotNull());
130 135
131 // Expect the first source to be chosen. 136 // Expect the first source to be chosen.
132 EXPECT_EQ(snippet->id(), "http://url.com"); 137 EXPECT_EQ(snippet->id(), "http://url.com");
133 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 138 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
134 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 139 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
135 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com")); 140 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com"));
136 } 141 }
137 142
138 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources1) { 143 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources1) {
139 // Set Source 2 to have no AMP url, and Source 1 to have no publisher name 144 // Set Source 2 to have no AMP url, and Source 1 to have no publisher name
140 // Source 2 should win since we favor publisher name over amp url 145 // Source 2 should win since we favor publisher name over amp url
141 auto dict = ChromeReaderSnippetWithTwoSources(); 146 auto dict = ChromeReaderSnippetWithTwoSources();
142 base::ListValue* sources; 147 base::ListValue* sources;
143 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 148 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
144 base::DictionaryValue* source; 149 base::DictionaryValue* source;
145 ASSERT_TRUE(sources->GetDictionary(0, &source)); 150 ASSERT_TRUE(sources->GetDictionary(0, &source));
146 source->Remove("publisherData.sourceName", nullptr); 151 source->Remove("publisherData.sourceName", nullptr);
147 ASSERT_TRUE(sources->GetDictionary(1, &source)); 152 ASSERT_TRUE(sources->GetDictionary(1, &source));
148 source->Remove("ampUrl", nullptr); 153 source->Remove("ampUrl", nullptr);
149 154
150 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 155 auto snippet =
156 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
151 ASSERT_THAT(snippet, NotNull()); 157 ASSERT_THAT(snippet, NotNull());
152 158
153 EXPECT_EQ(snippet->id(), "http://url.com"); 159 EXPECT_EQ(snippet->id(), "http://url.com");
154 EXPECT_EQ(snippet->url(), GURL("http://source2.com")); 160 EXPECT_EQ(snippet->url(), GURL("http://source2.com"));
155 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2")); 161 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2"));
156 EXPECT_EQ(snippet->amp_url(), GURL()); 162 EXPECT_EQ(snippet->amp_url(), GURL());
157 } 163 }
158 164
159 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources2) { 165 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources2) {
160 // Set Source 1 to have no AMP url, and Source 2 to have no publisher name 166 // Set Source 1 to have no AMP url, and Source 2 to have no publisher name
161 // Source 1 should win in this case since we prefer publisher name to AMP url 167 // Source 1 should win in this case since we prefer publisher name to AMP url
162 auto dict = ChromeReaderSnippetWithTwoSources(); 168 auto dict = ChromeReaderSnippetWithTwoSources();
163 base::ListValue* sources; 169 base::ListValue* sources;
164 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 170 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
165 base::DictionaryValue* source; 171 base::DictionaryValue* source;
166 ASSERT_TRUE(sources->GetDictionary(0, &source)); 172 ASSERT_TRUE(sources->GetDictionary(0, &source));
167 source->Remove("ampUrl", nullptr); 173 source->Remove("ampUrl", nullptr);
168 ASSERT_TRUE(sources->GetDictionary(1, &source)); 174 ASSERT_TRUE(sources->GetDictionary(1, &source));
169 source->Remove("publisherData.sourceName", nullptr); 175 source->Remove("publisherData.sourceName", nullptr);
170 176
171 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 177 auto snippet =
178 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
172 ASSERT_THAT(snippet, NotNull()); 179 ASSERT_THAT(snippet, NotNull());
173 180
174 EXPECT_EQ(snippet->id(), "http://url.com"); 181 EXPECT_EQ(snippet->id(), "http://url.com");
175 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 182 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
176 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 183 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
177 EXPECT_EQ(snippet->amp_url(), GURL()); 184 EXPECT_EQ(snippet->amp_url(), GURL());
178 } 185 }
179 186
180 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources3) { 187 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources3) {
181 // Set source 1 to have no AMP url and no source, and source 2 to only have 188 // Set source 1 to have no AMP url and no source, and source 2 to only have
182 // amp url. There should be no snippets since we only add sources we consider 189 // amp url. There should be no snippets since we only add sources we consider
183 // complete 190 // complete
184 auto dict = ChromeReaderSnippetWithTwoSources(); 191 auto dict = ChromeReaderSnippetWithTwoSources();
185 base::ListValue* sources; 192 base::ListValue* sources;
186 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 193 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
187 base::DictionaryValue* source; 194 base::DictionaryValue* source;
188 ASSERT_TRUE(sources->GetDictionary(0, &source)); 195 ASSERT_TRUE(sources->GetDictionary(0, &source));
189 source->Remove("publisherData.sourceName", nullptr); 196 source->Remove("publisherData.sourceName", nullptr);
190 source->Remove("ampUrl", nullptr); 197 source->Remove("ampUrl", nullptr);
191 ASSERT_TRUE(sources->GetDictionary(1, &source)); 198 ASSERT_TRUE(sources->GetDictionary(1, &source));
192 source->Remove("publisherData.sourceName", nullptr); 199 source->Remove("publisherData.sourceName", nullptr);
193 200
194 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 201 auto snippet =
202 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
195 ASSERT_THAT(snippet, NotNull()); 203 ASSERT_THAT(snippet, NotNull());
196 ASSERT_FALSE(snippet->is_complete()); 204 ASSERT_FALSE(snippet->is_complete());
197 } 205 }
198 206
199 TEST(RemoteSuggestionTest, ShouldFillInCreation) { 207 TEST(RemoteSuggestionTest, ShouldFillInCreation) {
200 auto dict = ChromeReaderSnippetWithTwoSources(); 208 auto dict = ChromeReaderSnippetWithTwoSources();
201 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 209 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
202 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 210 auto snippet =
211 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
203 ASSERT_THAT(snippet, NotNull()); 212 ASSERT_THAT(snippet, NotNull());
204 213
205 // Publish date should have been filled with "now" - just make sure it's not 214 // Publish date should have been filled with "now" - just make sure it's not
206 // empty and not the test default value. 215 // empty and not the test default value.
207 base::Time publish_date = snippet->publish_date(); 216 base::Time publish_date = snippet->publish_date();
208 EXPECT_FALSE(publish_date.is_null()); 217 EXPECT_FALSE(publish_date.is_null());
209 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString( 218 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString(
210 kChromeReaderCreationTimestamp)); 219 kChromeReaderCreationTimestamp));
211 // Expiry date should have kept the test default value. 220 // Expiry date should have kept the test default value.
212 base::Time expiry_date = snippet->expiry_date(); 221 base::Time expiry_date = snippet->expiry_date();
213 EXPECT_FALSE(expiry_date.is_null()); 222 EXPECT_FALSE(expiry_date.is_null());
214 EXPECT_EQ(expiry_date, 223 EXPECT_EQ(expiry_date,
215 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp)); 224 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp));
216 } 225 }
217 226
218 TEST(RemoteSuggestionTest, ShouldFillInExpiry) { 227 TEST(RemoteSuggestionTest, ShouldFillInExpiry) {
219 auto dict = ChromeReaderSnippetWithTwoSources(); 228 auto dict = ChromeReaderSnippetWithTwoSources();
220 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr)); 229 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr));
221 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 230 auto snippet =
231 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
222 ASSERT_THAT(snippet, NotNull()); 232 ASSERT_THAT(snippet, NotNull());
223 233
224 base::Time publish_date = snippet->publish_date(); 234 base::Time publish_date = snippet->publish_date();
225 ASSERT_FALSE(publish_date.is_null()); 235 ASSERT_FALSE(publish_date.is_null());
226 // Expiry date should have been filled with creation date + offset. 236 // Expiry date should have been filled with creation date + offset.
227 base::Time expiry_date = snippet->expiry_date(); 237 base::Time expiry_date = snippet->expiry_date();
228 EXPECT_FALSE(expiry_date.is_null()); 238 EXPECT_FALSE(expiry_date.is_null());
229 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes( 239 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes(
230 kChromeReaderDefaultExpiryTimeMins), 240 kChromeReaderDefaultExpiryTimeMins),
231 expiry_date); 241 expiry_date);
232 } 242 }
233 243
234 TEST(RemoteSuggestionTest, ShouldFillInCreationAndExpiry) { 244 TEST(RemoteSuggestionTest, ShouldFillInCreationAndExpiry) {
235 auto dict = ChromeReaderSnippetWithTwoSources(); 245 auto dict = ChromeReaderSnippetWithTwoSources();
236 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 246 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
237 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr)); 247 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr));
238 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 248 auto snippet =
249 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
239 ASSERT_THAT(snippet, NotNull()); 250 ASSERT_THAT(snippet, NotNull());
240 251
241 // Publish date should have been filled with "now" - just make sure it's not 252 // Publish date should have been filled with "now" - just make sure it's not
242 // empty and not the test default value. 253 // empty and not the test default value.
243 base::Time publish_date = snippet->publish_date(); 254 base::Time publish_date = snippet->publish_date();
244 EXPECT_FALSE(publish_date.is_null()); 255 EXPECT_FALSE(publish_date.is_null());
245 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString( 256 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString(
246 kChromeReaderCreationTimestamp)); 257 kChromeReaderCreationTimestamp));
247 // Expiry date should have been filled with creation date + offset. 258 // Expiry date should have been filled with creation date + offset.
248 base::Time expiry_date = snippet->expiry_date(); 259 base::Time expiry_date = snippet->expiry_date();
249 EXPECT_FALSE(expiry_date.is_null()); 260 EXPECT_FALSE(expiry_date.is_null());
250 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes( 261 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes(
251 kChromeReaderDefaultExpiryTimeMins), 262 kChromeReaderDefaultExpiryTimeMins),
252 expiry_date); 263 expiry_date);
253 } 264 }
254 265
255 TEST(RemoteSuggestionTest, ShouldNotOverwriteExpiry) { 266 TEST(RemoteSuggestionTest, ShouldNotOverwriteExpiry) {
256 auto dict = ChromeReaderSnippetWithTwoSources(); 267 auto dict = ChromeReaderSnippetWithTwoSources();
257 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 268 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
258 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 269 auto snippet =
270 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
259 ASSERT_THAT(snippet, NotNull()); 271 ASSERT_THAT(snippet, NotNull());
260 272
261 // Expiry date should have kept the test default value. 273 // Expiry date should have kept the test default value.
262 base::Time expiry_date = snippet->expiry_date(); 274 base::Time expiry_date = snippet->expiry_date();
263 EXPECT_FALSE(expiry_date.is_null()); 275 EXPECT_FALSE(expiry_date.is_null());
264 EXPECT_EQ(expiry_date, 276 EXPECT_EQ(expiry_date,
265 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp)); 277 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp));
266 } 278 }
267 279
268 // Old form, from chromereader-pa.googleapis.com. Three sources. 280 // Old form, from chromereader-pa.googleapis.com. Three sources.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 322
311 TEST(RemoteSuggestionTest, TestMultipleCompleteSources1) { 323 TEST(RemoteSuggestionTest, TestMultipleCompleteSources1) {
312 // Test 2 complete sources, we should choose the first complete source 324 // Test 2 complete sources, we should choose the first complete source
313 auto dict = ChromeReaderSnippetWithThreeSources(); 325 auto dict = ChromeReaderSnippetWithThreeSources();
314 base::ListValue* sources; 326 base::ListValue* sources;
315 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 327 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
316 base::DictionaryValue* source; 328 base::DictionaryValue* source;
317 ASSERT_TRUE(sources->GetDictionary(1, &source)); 329 ASSERT_TRUE(sources->GetDictionary(1, &source));
318 source->Remove("publisherData.sourceName", nullptr); 330 source->Remove("publisherData.sourceName", nullptr);
319 331
320 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 332 auto snippet =
333 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
321 ASSERT_THAT(snippet, NotNull()); 334 ASSERT_THAT(snippet, NotNull());
322 335
323 EXPECT_EQ(snippet->id(), "http://url.com"); 336 EXPECT_EQ(snippet->id(), "http://url.com");
324 EXPECT_THAT(snippet->GetAllIDs(), 337 EXPECT_THAT(snippet->GetAllIDs(),
325 ElementsAre("http://url.com", "http://source1.com", 338 ElementsAre("http://url.com", "http://source1.com",
326 "http://source2.com", "http://source3.com")); 339 "http://source2.com", "http://source3.com"));
327 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 340 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
328 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 341 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
329 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com")); 342 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com"));
330 } 343 }
331 344
332 TEST(RemoteSuggestionTest, TestMultipleCompleteSources2) { 345 TEST(RemoteSuggestionTest, TestMultipleCompleteSources2) {
333 // Test 2 complete sources, we should choose the first complete source 346 // Test 2 complete sources, we should choose the first complete source
334 auto dict = ChromeReaderSnippetWithThreeSources(); 347 auto dict = ChromeReaderSnippetWithThreeSources();
335 base::ListValue* sources; 348 base::ListValue* sources;
336 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 349 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
337 base::DictionaryValue* source; 350 base::DictionaryValue* source;
338 ASSERT_TRUE(sources->GetDictionary(0, &source)); 351 ASSERT_TRUE(sources->GetDictionary(0, &source));
339 source->Remove("publisherData.sourceName", nullptr); 352 source->Remove("publisherData.sourceName", nullptr);
340 353
341 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 354 auto snippet =
355 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
342 ASSERT_THAT(snippet, NotNull()); 356 ASSERT_THAT(snippet, NotNull());
343 357
344 EXPECT_EQ(snippet->id(), "http://url.com"); 358 EXPECT_EQ(snippet->id(), "http://url.com");
345 EXPECT_EQ(snippet->url(), GURL("http://source2.com")); 359 EXPECT_EQ(snippet->url(), GURL("http://source2.com"));
346 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2")); 360 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2"));
347 EXPECT_EQ(snippet->amp_url(), GURL("http://source2.amp.com")); 361 EXPECT_EQ(snippet->amp_url(), GURL("http://source2.amp.com"));
348 } 362 }
349 363
350 TEST(RemoteSuggestionTest, TestMultipleCompleteSources3) { 364 TEST(RemoteSuggestionTest, TestMultipleCompleteSources3) {
351 // Test 3 complete sources, we should choose the first complete source 365 // Test 3 complete sources, we should choose the first complete source
352 auto dict = ChromeReaderSnippetWithThreeSources(); 366 auto dict = ChromeReaderSnippetWithThreeSources();
353 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 367 auto snippet =
368 SnippetFromChromeReaderDict(std::move(dict), base::Time::Now());
354 ASSERT_THAT(snippet, NotNull()); 369 ASSERT_THAT(snippet, NotNull());
355 370
356 EXPECT_EQ(snippet->id(), "http://url.com"); 371 EXPECT_EQ(snippet->id(), "http://url.com");
357 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 372 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
358 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 373 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
359 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com")); 374 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com"));
360 } 375 }
361 376
362 TEST(RemoteSuggestionTest, 377 TEST(RemoteSuggestionTest,
363 ShouldSupportMultipleIdsFromContentSuggestionsServer) { 378 ShouldSupportMultipleIdsFromContentSuggestionsServer) {
364 const std::string kJsonStr = 379 const std::string kJsonStr =
365 "{" 380 "{"
366 " \"ids\" : [\"http://localhost/foobar\", \"012345\"]," 381 " \"ids\" : [\"http://localhost/foobar\", \"012345\"],"
367 " \"title\" : \"Foo Barred from Baz\"," 382 " \"title\" : \"Foo Barred from Baz\","
368 " \"snippet\" : \"...\"," 383 " \"snippet\" : \"...\","
369 " \"fullPageUrl\" : \"http://localhost/foobar\"," 384 " \"fullPageUrl\" : \"http://localhost/foobar\","
370 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 385 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
371 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," 386 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
372 " \"attribution\" : \"Foo News\"," 387 " \"attribution\" : \"Foo News\","
373 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 388 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
374 " \"ampUrl\" : \"http://localhost/amp\"," 389 " \"ampUrl\" : \"http://localhost/amp\","
375 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " 390 " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
376 "}"; 391 "}";
377 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr); 392 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr, base::Time::Now());
378 ASSERT_THAT(snippet, NotNull()); 393 ASSERT_THAT(snippet, NotNull());
379 394
380 EXPECT_EQ(snippet->id(), "http://localhost/foobar"); 395 EXPECT_EQ(snippet->id(), "http://localhost/foobar");
381 EXPECT_THAT(snippet->GetAllIDs(), 396 EXPECT_THAT(snippet->GetAllIDs(),
382 ElementsAre("http://localhost/foobar", "012345")); 397 ElementsAre("http://localhost/foobar", "012345"));
383 } 398 }
384 399
385 TEST(RemoteSuggestionTest, CreateFromProtoToProtoRoundtrip) { 400 TEST(RemoteSuggestionTest, CreateFromProtoToProtoRoundtrip) {
386 SnippetProto proto; 401 SnippetProto proto;
387 proto.add_ids("foo"); 402 proto.add_ids("foo");
388 proto.add_ids("bar"); 403 proto.add_ids("bar");
389 proto.set_title("a suggestion title"); 404 proto.set_title("a suggestion title");
390 proto.set_snippet("the snippet describing the suggestion."); 405 proto.set_snippet("the snippet describing the suggestion.");
391 proto.set_salient_image_url("http://google.com/logo/"); 406 proto.set_salient_image_url("http://google.com/logo/");
392 proto.set_publish_date(1476095492); 407 proto.set_publish_date(1476095492);
393 proto.set_expiry_date(1476354691); 408 proto.set_expiry_date(1476354691);
394 proto.set_score(0.1f); 409 proto.set_score(0.1f);
395 proto.set_dismissed(false); 410 proto.set_dismissed(false);
396 proto.set_remote_category_id(1); 411 proto.set_remote_category_id(1);
412 proto.set_fetch_date(1476364691);
397 auto source = proto.add_sources(); 413 auto source = proto.add_sources();
398 source->set_url("http://cool-suggestions.com/"); 414 source->set_url("http://cool-suggestions.com/");
399 source->set_publisher_name("Great Suggestions Inc."); 415 source->set_publisher_name("Great Suggestions Inc.");
400 source->set_amp_url("http://cdn.ampproject.org/c/foo/"); 416 source->set_amp_url("http://cdn.ampproject.org/c/foo/");
401 417
402 std::unique_ptr<RemoteSuggestion> snippet = 418 std::unique_ptr<RemoteSuggestion> snippet =
403 RemoteSuggestion::CreateFromProto(proto); 419 RemoteSuggestion::CreateFromProto(proto);
404 ASSERT_THAT(snippet, NotNull()); 420 ASSERT_THAT(snippet, NotNull());
405 // The snippet database relies on the fact that the first id in the protocol 421 // The snippet database relies on the fact that the first id in the protocol
406 // buffer is considered the unique id. 422 // buffer is considered the unique id.
407 EXPECT_EQ(snippet->id(), "foo"); 423 EXPECT_EQ(snippet->id(), "foo");
408 // Unfortunately, we only have MessageLite protocol buffers in Chrome, so 424 // Unfortunately, we only have MessageLite protocol buffers in Chrome, so
409 // comparing via DebugString() or MessageDifferencer is not working. 425 // comparing via DebugString() or MessageDifferencer is not working.
410 // So we either need to compare field-by-field (maintenance heavy) or 426 // So we either need to compare field-by-field (maintenance heavy) or
411 // compare the binary version (unusable diagnostic). Deciding for the latter. 427 // compare the binary version (unusable diagnostic). Deciding for the latter.
412 std::string proto_serialized, round_tripped_serialized; 428 std::string proto_serialized, round_tripped_serialized;
413 proto.SerializeToString(&proto_serialized); 429 proto.SerializeToString(&proto_serialized);
414 snippet->ToProto().SerializeToString(&round_tripped_serialized); 430 snippet->ToProto().SerializeToString(&round_tripped_serialized);
415 EXPECT_EQ(proto_serialized, round_tripped_serialized); 431 EXPECT_EQ(proto_serialized, round_tripped_serialized);
416 } 432 }
417 433
434 TEST(RemoteSuggestionTest, CreateFromProtoIgnoreMissingFetchDate) {
435 SnippetProto proto;
436 proto.add_ids("foo");
437 proto.add_ids("bar");
438 proto.set_title("a suggestion title");
439 proto.set_snippet("the snippet describing the suggestion.");
440 proto.set_salient_image_url("http://google.com/logo/");
441 proto.set_publish_date(1476095492);
442 proto.set_expiry_date(1476354691);
443 proto.set_score(0.1f);
444 proto.set_dismissed(false);
445 proto.set_remote_category_id(1);
446 auto source = proto.add_sources();
447 source->set_url("http://cool-suggestions.com/");
448 source->set_publisher_name("Great Suggestions Inc.");
449 source->set_amp_url("http://cdn.ampproject.org/c/foo/");
450
451 std::unique_ptr<RemoteSuggestion> snippet =
452 RemoteSuggestion::CreateFromProto(proto);
453 ASSERT_THAT(snippet, NotNull());
454 // The snippet database relies on the fact that the first id in the protocol
455 // buffer is considered the unique id.
456 EXPECT_EQ(snippet->id(), "foo");
457 EXPECT_EQ(snippet->fetch_date(), base::Time());
458 }
459
418 // New form, from chromecontentsuggestions-pa.googleapis.com. 460 // New form, from chromecontentsuggestions-pa.googleapis.com.
419 std::unique_ptr<base::DictionaryValue> ContentSuggestionSnippet() { 461 std::unique_ptr<base::DictionaryValue> ContentSuggestionSnippet() {
420 const std::string kJsonStr = 462 const std::string kJsonStr =
421 "{" 463 "{"
422 " \"ids\" : [\"http://localhost/foobar\"]," 464 " \"ids\" : [\"http://localhost/foobar\"],"
423 " \"title\" : \"Foo Barred from Baz\"," 465 " \"title\" : \"Foo Barred from Baz\","
424 " \"snippet\" : \"...\"," 466 " \"snippet\" : \"...\","
425 " \"fullPageUrl\" : \"http://localhost/foobar\"," 467 " \"fullPageUrl\" : \"http://localhost/foobar\","
426 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 468 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
427 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," 469 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
428 " \"attribution\" : \"Foo News\"," 470 " \"attribution\" : \"Foo News\","
429 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 471 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
430 " \"ampUrl\" : \"http://localhost/amp\"," 472 " \"ampUrl\" : \"http://localhost/amp\","
431 " \"faviconUrl\" : \"http://localhost/favicon.ico\", " 473 " \"faviconUrl\" : \"http://localhost/favicon.ico\", "
432 " \"score\": 9001\n" 474 " \"score\": 9001\n"
433 "}"; 475 "}";
434 auto json_value = base::JSONReader::Read(kJsonStr); 476 auto json_value = base::JSONReader::Read(kJsonStr);
435 base::DictionaryValue* json_dict; 477 base::DictionaryValue* json_dict;
436 CHECK(json_value->GetAsDictionary(&json_dict)); 478 CHECK(json_value->GetAsDictionary(&json_dict));
437 return json_dict->CreateDeepCopy(); 479 return json_dict->CreateDeepCopy();
438 } 480 }
439 481
440 TEST(RemoteSuggestionTest, NotifcationInfoAllSpecified) { 482 TEST(RemoteSuggestionTest, NotifcationInfoAllSpecified) {
441 auto json = ContentSuggestionSnippet(); 483 auto json = ContentSuggestionSnippet();
442 json->SetBoolean("notificationInfo.shouldNotify", true); 484 json->SetBoolean("notificationInfo.shouldNotify", true);
443 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z"); 485 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
444 auto snippet = 486 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
445 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 487 *json, 0, base::Time::Now());
446 EXPECT_TRUE(snippet->should_notify()); 488 EXPECT_TRUE(snippet->should_notify());
447 EXPECT_EQ(7200.0f, 489 EXPECT_EQ(7200.0f,
448 (snippet->notification_deadline() - snippet->publish_date()) 490 (snippet->notification_deadline() - snippet->publish_date())
449 .InSecondsF()); 491 .InSecondsF());
450 } 492 }
451 493
452 TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) { 494 TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) {
453 auto json = ContentSuggestionSnippet(); 495 auto json = ContentSuggestionSnippet();
454 json->SetBoolean("notificationInfo.shouldNotify", true); 496 json->SetBoolean("notificationInfo.shouldNotify", true);
455 json->SetInteger("notificationInfo.notificationDeadline", 0); 497 json->SetInteger("notificationInfo.notificationDeadline", 0);
456 auto snippet = 498 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
457 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 499 *json, 0, base::Time::Now());
458 EXPECT_TRUE(snippet->should_notify()); 500 EXPECT_TRUE(snippet->should_notify());
459 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline()); 501 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
460 } 502 }
461 503
462 TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) { 504 TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) {
463 auto json = ContentSuggestionSnippet(); 505 auto json = ContentSuggestionSnippet();
464 json->SetBoolean("notificationInfo.shouldNotify", true); 506 json->SetBoolean("notificationInfo.shouldNotify", true);
465 auto snippet = 507 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
466 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 508 *json, 0, base::Time::Now());
467 EXPECT_TRUE(snippet->should_notify()); 509 EXPECT_TRUE(snippet->should_notify());
468 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline()); 510 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
469 } 511 }
470 512
471 TEST(RemoteSuggestionTest, NotificationInfoShouldNotifyInvalid) { 513 TEST(RemoteSuggestionTest, NotificationInfoShouldNotifyInvalid) {
472 auto json = ContentSuggestionSnippet(); 514 auto json = ContentSuggestionSnippet();
473 json->SetString("notificationInfo.shouldNotify", "non-bool"); 515 json->SetString("notificationInfo.shouldNotify", "non-bool");
474 auto snippet = 516 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
475 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 517 *json, 0, base::Time::Now());
476 EXPECT_FALSE(snippet->should_notify()); 518 EXPECT_FALSE(snippet->should_notify());
477 } 519 }
478 520
479 TEST(RemoteSuggestionTest, NotificationInfoAbsent) { 521 TEST(RemoteSuggestionTest, NotificationInfoAbsent) {
480 auto json = ContentSuggestionSnippet(); 522 auto json = ContentSuggestionSnippet();
481 auto snippet = 523 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
482 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 524 *json, 0, base::Time::Now());
483 EXPECT_FALSE(snippet->should_notify()); 525 EXPECT_FALSE(snippet->should_notify());
484 } 526 }
485 527
486 TEST(RemoteSuggestionTest, ToContentSuggestion) { 528 TEST(RemoteSuggestionTest, ToContentSuggestion) {
487 auto json = ContentSuggestionSnippet(); 529 auto json = ContentSuggestionSnippet();
488 auto snippet = 530 const base::Time fetch_date = base::Time::Now();
489 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 531 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
532 *json, 0, fetch_date);
490 ASSERT_THAT(snippet, NotNull()); 533 ASSERT_THAT(snippet, NotNull());
491 ContentSuggestion sugg = snippet->ToContentSuggestion( 534 ContentSuggestion sugg = snippet->ToContentSuggestion(
492 Category::FromKnownCategory(KnownCategories::ARTICLES)); 535 Category::FromKnownCategory(KnownCategories::ARTICLES));
493 536
494 EXPECT_THAT(sugg.id().category(), 537 EXPECT_THAT(sugg.id().category(),
495 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES))); 538 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES)));
496 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar")); 539 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar"));
497 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp"))); 540 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp")));
498 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz"))); 541 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz")));
499 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("..."))); 542 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("...")));
500 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000)); 543 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000));
501 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News"))); 544 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News")));
502 EXPECT_THAT(sugg.score(), Eq(9001)); 545 EXPECT_THAT(sugg.score(), Eq(9001));
503 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull()); 546 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull());
504 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull()); 547 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull());
505 EXPECT_THAT(sugg.notification_extra(), IsNull()); 548 EXPECT_THAT(sugg.notification_extra(), IsNull());
549 EXPECT_THAT(sugg.fetch_date(), Eq(fetch_date));
506 } 550 }
507 551
508 TEST(RemoteSuggestionTest, ToContentSuggestionWithNotificationInfo) { 552 TEST(RemoteSuggestionTest, ToContentSuggestionWithNotificationInfo) {
509 auto json = ContentSuggestionSnippet(); 553 auto json = ContentSuggestionSnippet();
510 json->SetBoolean("notificationInfo.shouldNotify", true); 554 json->SetBoolean("notificationInfo.shouldNotify", true);
511 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z"); 555 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
512 auto snippet = 556 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
513 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 557 *json, 0, base::Time::Now());
514 ASSERT_THAT(snippet, NotNull()); 558 ASSERT_THAT(snippet, NotNull());
515 ContentSuggestion sugg = snippet->ToContentSuggestion( 559 ContentSuggestion sugg = snippet->ToContentSuggestion(
516 Category::FromKnownCategory(KnownCategories::ARTICLES)); 560 Category::FromKnownCategory(KnownCategories::ARTICLES));
517 561
518 EXPECT_THAT(sugg.id().category(), 562 EXPECT_THAT(sugg.id().category(),
519 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES))); 563 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES)));
520 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar")); 564 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar"));
521 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp"))); 565 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp")));
522 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz"))); 566 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz")));
523 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("..."))); 567 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("...")));
524 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000)); 568 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000));
525 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News"))); 569 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News")));
526 EXPECT_THAT(sugg.score(), Eq(9001)); 570 EXPECT_THAT(sugg.score(), Eq(9001));
527 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull()); 571 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull());
528 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull()); 572 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull());
529 ASSERT_THAT(sugg.notification_extra(), NotNull()); 573 ASSERT_THAT(sugg.notification_extra(), NotNull());
530 EXPECT_THAT(sugg.notification_extra()->deadline.ToJavaTime(), 574 EXPECT_THAT(sugg.notification_extra()->deadline.ToJavaTime(),
531 Eq(1467291697000)); 575 Eq(1467291697000));
532 } 576 }
533 577
534 } // namespace 578 } // namespace
535 } // namespace ntp_snippets 579 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698