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

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: rebase 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) {
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::FromInternalValue(1466634774L);
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());
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 = SnippetFromChromeReaderDict(std::move(dict), base::Time());
151 ASSERT_THAT(snippet, NotNull()); 156 ASSERT_THAT(snippet, NotNull());
152 157
153 EXPECT_EQ(snippet->id(), "http://url.com"); 158 EXPECT_EQ(snippet->id(), "http://url.com");
154 EXPECT_EQ(snippet->url(), GURL("http://source2.com")); 159 EXPECT_EQ(snippet->url(), GURL("http://source2.com"));
155 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2")); 160 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2"));
156 EXPECT_EQ(snippet->amp_url(), GURL()); 161 EXPECT_EQ(snippet->amp_url(), GURL());
157 } 162 }
158 163
159 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources2) { 164 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources2) {
160 // Set Source 1 to have no AMP url, and Source 2 to have no publisher name 165 // 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 166 // Source 1 should win in this case since we prefer publisher name to AMP url
162 auto dict = ChromeReaderSnippetWithTwoSources(); 167 auto dict = ChromeReaderSnippetWithTwoSources();
163 base::ListValue* sources; 168 base::ListValue* sources;
164 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 169 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
165 base::DictionaryValue* source; 170 base::DictionaryValue* source;
166 ASSERT_TRUE(sources->GetDictionary(0, &source)); 171 ASSERT_TRUE(sources->GetDictionary(0, &source));
167 source->Remove("ampUrl", nullptr); 172 source->Remove("ampUrl", nullptr);
168 ASSERT_TRUE(sources->GetDictionary(1, &source)); 173 ASSERT_TRUE(sources->GetDictionary(1, &source));
169 source->Remove("publisherData.sourceName", nullptr); 174 source->Remove("publisherData.sourceName", nullptr);
170 175
171 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 176 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
172 ASSERT_THAT(snippet, NotNull()); 177 ASSERT_THAT(snippet, NotNull());
173 178
174 EXPECT_EQ(snippet->id(), "http://url.com"); 179 EXPECT_EQ(snippet->id(), "http://url.com");
175 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 180 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
176 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 181 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
177 EXPECT_EQ(snippet->amp_url(), GURL()); 182 EXPECT_EQ(snippet->amp_url(), GURL());
178 } 183 }
179 184
180 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources3) { 185 TEST(RemoteSuggestionTest, TestMultipleIncompleteSources3) {
181 // Set source 1 to have no AMP url and no source, and source 2 to only have 186 // 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 187 // amp url. There should be no snippets since we only add sources we consider
183 // complete 188 // complete
184 auto dict = ChromeReaderSnippetWithTwoSources(); 189 auto dict = ChromeReaderSnippetWithTwoSources();
185 base::ListValue* sources; 190 base::ListValue* sources;
186 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 191 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
187 base::DictionaryValue* source; 192 base::DictionaryValue* source;
188 ASSERT_TRUE(sources->GetDictionary(0, &source)); 193 ASSERT_TRUE(sources->GetDictionary(0, &source));
189 source->Remove("publisherData.sourceName", nullptr); 194 source->Remove("publisherData.sourceName", nullptr);
190 source->Remove("ampUrl", nullptr); 195 source->Remove("ampUrl", nullptr);
191 ASSERT_TRUE(sources->GetDictionary(1, &source)); 196 ASSERT_TRUE(sources->GetDictionary(1, &source));
192 source->Remove("publisherData.sourceName", nullptr); 197 source->Remove("publisherData.sourceName", nullptr);
193 198
194 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 199 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
195 ASSERT_THAT(snippet, NotNull()); 200 ASSERT_THAT(snippet, NotNull());
196 ASSERT_FALSE(snippet->is_complete()); 201 ASSERT_FALSE(snippet->is_complete());
197 } 202 }
198 203
199 TEST(RemoteSuggestionTest, ShouldFillInCreation) { 204 TEST(RemoteSuggestionTest, ShouldFillInCreation) {
200 auto dict = ChromeReaderSnippetWithTwoSources(); 205 auto dict = ChromeReaderSnippetWithTwoSources();
201 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 206 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
202 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 207 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
203 ASSERT_THAT(snippet, NotNull()); 208 ASSERT_THAT(snippet, NotNull());
204 209
205 // Publish date should have been filled with "now" - just make sure it's not 210 // Publish date should have been filled with "now" - just make sure it's not
206 // empty and not the test default value. 211 // empty and not the test default value.
207 base::Time publish_date = snippet->publish_date(); 212 base::Time publish_date = snippet->publish_date();
208 EXPECT_FALSE(publish_date.is_null()); 213 EXPECT_FALSE(publish_date.is_null());
209 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString( 214 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString(
210 kChromeReaderCreationTimestamp)); 215 kChromeReaderCreationTimestamp));
211 // Expiry date should have kept the test default value. 216 // Expiry date should have kept the test default value.
212 base::Time expiry_date = snippet->expiry_date(); 217 base::Time expiry_date = snippet->expiry_date();
213 EXPECT_FALSE(expiry_date.is_null()); 218 EXPECT_FALSE(expiry_date.is_null());
214 EXPECT_EQ(expiry_date, 219 EXPECT_EQ(expiry_date,
215 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp)); 220 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp));
216 } 221 }
217 222
218 TEST(RemoteSuggestionTest, ShouldFillInExpiry) { 223 TEST(RemoteSuggestionTest, ShouldFillInExpiry) {
219 auto dict = ChromeReaderSnippetWithTwoSources(); 224 auto dict = ChromeReaderSnippetWithTwoSources();
220 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr)); 225 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr));
221 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 226 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
222 ASSERT_THAT(snippet, NotNull()); 227 ASSERT_THAT(snippet, NotNull());
223 228
224 base::Time publish_date = snippet->publish_date(); 229 base::Time publish_date = snippet->publish_date();
225 ASSERT_FALSE(publish_date.is_null()); 230 ASSERT_FALSE(publish_date.is_null());
226 // Expiry date should have been filled with creation date + offset. 231 // Expiry date should have been filled with creation date + offset.
227 base::Time expiry_date = snippet->expiry_date(); 232 base::Time expiry_date = snippet->expiry_date();
228 EXPECT_FALSE(expiry_date.is_null()); 233 EXPECT_FALSE(expiry_date.is_null());
229 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes( 234 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes(
230 kChromeReaderDefaultExpiryTimeMins), 235 kChromeReaderDefaultExpiryTimeMins),
231 expiry_date); 236 expiry_date);
232 } 237 }
233 238
234 TEST(RemoteSuggestionTest, ShouldFillInCreationAndExpiry) { 239 TEST(RemoteSuggestionTest, ShouldFillInCreationAndExpiry) {
235 auto dict = ChromeReaderSnippetWithTwoSources(); 240 auto dict = ChromeReaderSnippetWithTwoSources();
236 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 241 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
237 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr)); 242 ASSERT_TRUE(dict->Remove("contentInfo.expiryTimestampSec", nullptr));
238 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 243 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
239 ASSERT_THAT(snippet, NotNull()); 244 ASSERT_THAT(snippet, NotNull());
240 245
241 // Publish date should have been filled with "now" - just make sure it's not 246 // Publish date should have been filled with "now" - just make sure it's not
242 // empty and not the test default value. 247 // empty and not the test default value.
243 base::Time publish_date = snippet->publish_date(); 248 base::Time publish_date = snippet->publish_date();
244 EXPECT_FALSE(publish_date.is_null()); 249 EXPECT_FALSE(publish_date.is_null());
245 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString( 250 EXPECT_NE(publish_date, RemoteSuggestion::TimeFromJsonString(
246 kChromeReaderCreationTimestamp)); 251 kChromeReaderCreationTimestamp));
247 // Expiry date should have been filled with creation date + offset. 252 // Expiry date should have been filled with creation date + offset.
248 base::Time expiry_date = snippet->expiry_date(); 253 base::Time expiry_date = snippet->expiry_date();
249 EXPECT_FALSE(expiry_date.is_null()); 254 EXPECT_FALSE(expiry_date.is_null());
250 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes( 255 EXPECT_EQ(publish_date + base::TimeDelta::FromMinutes(
251 kChromeReaderDefaultExpiryTimeMins), 256 kChromeReaderDefaultExpiryTimeMins),
252 expiry_date); 257 expiry_date);
253 } 258 }
254 259
255 TEST(RemoteSuggestionTest, ShouldNotOverwriteExpiry) { 260 TEST(RemoteSuggestionTest, ShouldNotOverwriteExpiry) {
256 auto dict = ChromeReaderSnippetWithTwoSources(); 261 auto dict = ChromeReaderSnippetWithTwoSources();
257 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr)); 262 ASSERT_TRUE(dict->Remove("contentInfo.creationTimestampSec", nullptr));
258 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 263 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
259 ASSERT_THAT(snippet, NotNull()); 264 ASSERT_THAT(snippet, NotNull());
260 265
261 // Expiry date should have kept the test default value. 266 // Expiry date should have kept the test default value.
262 base::Time expiry_date = snippet->expiry_date(); 267 base::Time expiry_date = snippet->expiry_date();
263 EXPECT_FALSE(expiry_date.is_null()); 268 EXPECT_FALSE(expiry_date.is_null());
264 EXPECT_EQ(expiry_date, 269 EXPECT_EQ(expiry_date,
265 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp)); 270 RemoteSuggestion::TimeFromJsonString(kChromeReaderExpiryTimestamp));
266 } 271 }
267 272
268 // Old form, from chromereader-pa.googleapis.com. Three sources. 273 // Old form, from chromereader-pa.googleapis.com. Three sources.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 315
311 TEST(RemoteSuggestionTest, TestMultipleCompleteSources1) { 316 TEST(RemoteSuggestionTest, TestMultipleCompleteSources1) {
312 // Test 2 complete sources, we should choose the first complete source 317 // Test 2 complete sources, we should choose the first complete source
313 auto dict = ChromeReaderSnippetWithThreeSources(); 318 auto dict = ChromeReaderSnippetWithThreeSources();
314 base::ListValue* sources; 319 base::ListValue* sources;
315 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 320 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
316 base::DictionaryValue* source; 321 base::DictionaryValue* source;
317 ASSERT_TRUE(sources->GetDictionary(1, &source)); 322 ASSERT_TRUE(sources->GetDictionary(1, &source));
318 source->Remove("publisherData.sourceName", nullptr); 323 source->Remove("publisherData.sourceName", nullptr);
319 324
320 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 325 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
321 ASSERT_THAT(snippet, NotNull()); 326 ASSERT_THAT(snippet, NotNull());
322 327
323 EXPECT_EQ(snippet->id(), "http://url.com"); 328 EXPECT_EQ(snippet->id(), "http://url.com");
324 EXPECT_THAT(snippet->GetAllIDs(), 329 EXPECT_THAT(snippet->GetAllIDs(),
325 ElementsAre("http://url.com", "http://source1.com", 330 ElementsAre("http://url.com", "http://source1.com",
326 "http://source2.com", "http://source3.com")); 331 "http://source2.com", "http://source3.com"));
327 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 332 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
328 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 333 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
329 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com")); 334 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com"));
330 } 335 }
331 336
332 TEST(RemoteSuggestionTest, TestMultipleCompleteSources2) { 337 TEST(RemoteSuggestionTest, TestMultipleCompleteSources2) {
333 // Test 2 complete sources, we should choose the first complete source 338 // Test 2 complete sources, we should choose the first complete source
334 auto dict = ChromeReaderSnippetWithThreeSources(); 339 auto dict = ChromeReaderSnippetWithThreeSources();
335 base::ListValue* sources; 340 base::ListValue* sources;
336 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources)); 341 ASSERT_TRUE(dict->GetList("contentInfo.sourceCorpusInfo", &sources));
337 base::DictionaryValue* source; 342 base::DictionaryValue* source;
338 ASSERT_TRUE(sources->GetDictionary(0, &source)); 343 ASSERT_TRUE(sources->GetDictionary(0, &source));
339 source->Remove("publisherData.sourceName", nullptr); 344 source->Remove("publisherData.sourceName", nullptr);
340 345
341 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 346 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
342 ASSERT_THAT(snippet, NotNull()); 347 ASSERT_THAT(snippet, NotNull());
343 348
344 EXPECT_EQ(snippet->id(), "http://url.com"); 349 EXPECT_EQ(snippet->id(), "http://url.com");
345 EXPECT_EQ(snippet->url(), GURL("http://source2.com")); 350 EXPECT_EQ(snippet->url(), GURL("http://source2.com"));
346 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2")); 351 EXPECT_EQ(snippet->publisher_name(), std::string("Source 2"));
347 EXPECT_EQ(snippet->amp_url(), GURL("http://source2.amp.com")); 352 EXPECT_EQ(snippet->amp_url(), GURL("http://source2.amp.com"));
348 } 353 }
349 354
350 TEST(RemoteSuggestionTest, TestMultipleCompleteSources3) { 355 TEST(RemoteSuggestionTest, TestMultipleCompleteSources3) {
351 // Test 3 complete sources, we should choose the first complete source 356 // Test 3 complete sources, we should choose the first complete source
352 auto dict = ChromeReaderSnippetWithThreeSources(); 357 auto dict = ChromeReaderSnippetWithThreeSources();
353 auto snippet = SnippetFromChromeReaderDict(std::move(dict)); 358 auto snippet = SnippetFromChromeReaderDict(std::move(dict), base::Time());
354 ASSERT_THAT(snippet, NotNull()); 359 ASSERT_THAT(snippet, NotNull());
355 360
356 EXPECT_EQ(snippet->id(), "http://url.com"); 361 EXPECT_EQ(snippet->id(), "http://url.com");
357 EXPECT_EQ(snippet->url(), GURL("http://source1.com")); 362 EXPECT_EQ(snippet->url(), GURL("http://source1.com"));
358 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1")); 363 EXPECT_EQ(snippet->publisher_name(), std::string("Source 1"));
359 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com")); 364 EXPECT_EQ(snippet->amp_url(), GURL("http://source1.amp.com"));
360 } 365 }
361 366
362 TEST(RemoteSuggestionTest, 367 TEST(RemoteSuggestionTest,
363 ShouldSupportMultipleIdsFromContentSuggestionsServer) { 368 ShouldSupportMultipleIdsFromContentSuggestionsServer) {
364 const std::string kJsonStr = 369 const std::string kJsonStr =
365 "{" 370 "{"
366 " \"ids\" : [\"http://localhost/foobar\", \"012345\"]," 371 " \"ids\" : [\"http://localhost/foobar\", \"012345\"],"
367 " \"title\" : \"Foo Barred from Baz\"," 372 " \"title\" : \"Foo Barred from Baz\","
368 " \"snippet\" : \"...\"," 373 " \"snippet\" : \"...\","
369 " \"fullPageUrl\" : \"http://localhost/foobar\"," 374 " \"fullPageUrl\" : \"http://localhost/foobar\","
370 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 375 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
371 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," 376 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
372 " \"attribution\" : \"Foo News\"," 377 " \"attribution\" : \"Foo News\","
373 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 378 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
374 " \"ampUrl\" : \"http://localhost/amp\"," 379 " \"ampUrl\" : \"http://localhost/amp\","
375 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " 380 " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
376 "}"; 381 "}";
377 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr); 382 auto snippet = SnippetFromContentSuggestionJSON(kJsonStr, base::Time());
378 ASSERT_THAT(snippet, NotNull()); 383 ASSERT_THAT(snippet, NotNull());
379 384
380 EXPECT_EQ(snippet->id(), "http://localhost/foobar"); 385 EXPECT_EQ(snippet->id(), "http://localhost/foobar");
381 EXPECT_THAT(snippet->GetAllIDs(), 386 EXPECT_THAT(snippet->GetAllIDs(),
382 ElementsAre("http://localhost/foobar", "012345")); 387 ElementsAre("http://localhost/foobar", "012345"));
383 } 388 }
384 389
385 TEST(RemoteSuggestionTest, CreateFromProtoToProtoRoundtrip) { 390 TEST(RemoteSuggestionTest, CreateFromProtoToProtoRoundtrip) {
386 SnippetProto proto; 391 SnippetProto proto;
387 proto.add_ids("foo"); 392 proto.add_ids("foo");
388 proto.add_ids("bar"); 393 proto.add_ids("bar");
389 proto.set_title("a suggestion title"); 394 proto.set_title("a suggestion title");
390 proto.set_snippet("the snippet describing the suggestion."); 395 proto.set_snippet("the snippet describing the suggestion.");
391 proto.set_salient_image_url("http://google.com/logo/"); 396 proto.set_salient_image_url("http://google.com/logo/");
392 proto.set_publish_date(1476095492); 397 proto.set_publish_date(1476095492);
393 proto.set_expiry_date(1476354691); 398 proto.set_expiry_date(1476354691);
394 proto.set_score(0.1f); 399 proto.set_score(0.1f);
395 proto.set_dismissed(false); 400 proto.set_dismissed(false);
396 proto.set_remote_category_id(1); 401 proto.set_remote_category_id(1);
402 proto.set_fetch_date(1476364691);
397 auto source = proto.add_sources(); 403 auto source = proto.add_sources();
398 source->set_url("http://cool-suggestions.com/"); 404 source->set_url("http://cool-suggestions.com/");
399 source->set_publisher_name("Great Suggestions Inc."); 405 source->set_publisher_name("Great Suggestions Inc.");
400 source->set_amp_url("http://cdn.ampproject.org/c/foo/"); 406 source->set_amp_url("http://cdn.ampproject.org/c/foo/");
401 407
402 std::unique_ptr<RemoteSuggestion> snippet = 408 std::unique_ptr<RemoteSuggestion> snippet =
403 RemoteSuggestion::CreateFromProto(proto); 409 RemoteSuggestion::CreateFromProto(proto);
404 ASSERT_THAT(snippet, NotNull()); 410 ASSERT_THAT(snippet, NotNull());
405 // The snippet database relies on the fact that the first id in the protocol 411 // The snippet database relies on the fact that the first id in the protocol
406 // buffer is considered the unique id. 412 // buffer is considered the unique id.
407 EXPECT_EQ(snippet->id(), "foo"); 413 EXPECT_EQ(snippet->id(), "foo");
408 // Unfortunately, we only have MessageLite protocol buffers in Chrome, so 414 // Unfortunately, we only have MessageLite protocol buffers in Chrome, so
409 // comparing via DebugString() or MessageDifferencer is not working. 415 // comparing via DebugString() or MessageDifferencer is not working.
410 // So we either need to compare field-by-field (maintenance heavy) or 416 // So we either need to compare field-by-field (maintenance heavy) or
411 // compare the binary version (unusable diagnostic). Deciding for the latter. 417 // compare the binary version (unusable diagnostic). Deciding for the latter.
412 std::string proto_serialized, round_tripped_serialized; 418 std::string proto_serialized, round_tripped_serialized;
413 proto.SerializeToString(&proto_serialized); 419 proto.SerializeToString(&proto_serialized);
414 snippet->ToProto().SerializeToString(&round_tripped_serialized); 420 snippet->ToProto().SerializeToString(&round_tripped_serialized);
415 EXPECT_EQ(proto_serialized, round_tripped_serialized); 421 EXPECT_EQ(proto_serialized, round_tripped_serialized);
416 } 422 }
417 423
424 TEST(RemoteSuggestionTest, CreateFromProtoIgnoreMissingFetchDate) {
425 SnippetProto proto;
426 proto.add_ids("foo");
427 proto.add_ids("bar");
428 proto.set_title("a suggestion title");
429 proto.set_snippet("the snippet describing the suggestion.");
430 proto.set_salient_image_url("http://google.com/logo/");
431 proto.set_publish_date(1476095492);
432 proto.set_expiry_date(1476354691);
433 proto.set_score(0.1f);
434 proto.set_dismissed(false);
435 proto.set_remote_category_id(1);
436 auto source = proto.add_sources();
437 source->set_url("http://cool-suggestions.com/");
438 source->set_publisher_name("Great Suggestions Inc.");
439 source->set_amp_url("http://cdn.ampproject.org/c/foo/");
440
441 std::unique_ptr<RemoteSuggestion> snippet =
442 RemoteSuggestion::CreateFromProto(proto);
443 ASSERT_THAT(snippet, NotNull());
444 // The snippet database relies on the fact that the first id in the protocol
445 // buffer is considered the unique id.
446 EXPECT_EQ(snippet->id(), "foo");
447 EXPECT_EQ(snippet->fetch_date(), base::Time());
448 }
449
418 // New form, from chromecontentsuggestions-pa.googleapis.com. 450 // New form, from chromecontentsuggestions-pa.googleapis.com.
419 std::unique_ptr<base::DictionaryValue> ContentSuggestionSnippet() { 451 std::unique_ptr<base::DictionaryValue> ContentSuggestionSnippet() {
420 const std::string kJsonStr = 452 const std::string kJsonStr =
421 "{" 453 "{"
422 " \"ids\" : [\"http://localhost/foobar\"]," 454 " \"ids\" : [\"http://localhost/foobar\"],"
423 " \"title\" : \"Foo Barred from Baz\"," 455 " \"title\" : \"Foo Barred from Baz\","
424 " \"snippet\" : \"...\"," 456 " \"snippet\" : \"...\","
425 " \"fullPageUrl\" : \"http://localhost/foobar\"," 457 " \"fullPageUrl\" : \"http://localhost/foobar\","
426 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 458 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
427 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," 459 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
428 " \"attribution\" : \"Foo News\"," 460 " \"attribution\" : \"Foo News\","
429 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 461 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
430 " \"ampUrl\" : \"http://localhost/amp\"," 462 " \"ampUrl\" : \"http://localhost/amp\","
431 " \"faviconUrl\" : \"http://localhost/favicon.ico\", " 463 " \"faviconUrl\" : \"http://localhost/favicon.ico\", "
432 " \"score\": 9001\n" 464 " \"score\": 9001\n"
433 "}"; 465 "}";
434 auto json_value = base::JSONReader::Read(kJsonStr); 466 auto json_value = base::JSONReader::Read(kJsonStr);
435 base::DictionaryValue* json_dict; 467 base::DictionaryValue* json_dict;
436 CHECK(json_value->GetAsDictionary(&json_dict)); 468 CHECK(json_value->GetAsDictionary(&json_dict));
437 return json_dict->CreateDeepCopy(); 469 return json_dict->CreateDeepCopy();
438 } 470 }
439 471
440 TEST(RemoteSuggestionTest, NotifcationInfoAllSpecified) { 472 TEST(RemoteSuggestionTest, NotifcationInfoAllSpecified) {
441 auto json = ContentSuggestionSnippet(); 473 auto json = ContentSuggestionSnippet();
442 json->SetBoolean("notificationInfo.shouldNotify", true); 474 json->SetBoolean("notificationInfo.shouldNotify", true);
443 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z"); 475 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
444 auto snippet = 476 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
445 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 477 *json, 0, base::Time());
446 EXPECT_TRUE(snippet->should_notify()); 478 EXPECT_TRUE(snippet->should_notify());
447 EXPECT_EQ(7200.0f, 479 EXPECT_EQ(7200.0f,
448 (snippet->notification_deadline() - snippet->publish_date()) 480 (snippet->notification_deadline() - snippet->publish_date())
449 .InSecondsF()); 481 .InSecondsF());
450 } 482 }
451 483
452 TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) { 484 TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) {
453 auto json = ContentSuggestionSnippet(); 485 auto json = ContentSuggestionSnippet();
454 json->SetBoolean("notificationInfo.shouldNotify", true); 486 json->SetBoolean("notificationInfo.shouldNotify", true);
455 json->SetInteger("notificationInfo.notificationDeadline", 0); 487 json->SetInteger("notificationInfo.notificationDeadline", 0);
456 auto snippet = 488 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
457 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 489 *json, 0, base::Time());
458 EXPECT_TRUE(snippet->should_notify()); 490 EXPECT_TRUE(snippet->should_notify());
459 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline()); 491 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
460 } 492 }
461 493
462 TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) { 494 TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) {
463 auto json = ContentSuggestionSnippet(); 495 auto json = ContentSuggestionSnippet();
464 json->SetBoolean("notificationInfo.shouldNotify", true); 496 json->SetBoolean("notificationInfo.shouldNotify", true);
465 auto snippet = 497 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
466 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 498 *json, 0, base::Time());
467 EXPECT_TRUE(snippet->should_notify()); 499 EXPECT_TRUE(snippet->should_notify());
468 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline()); 500 EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
469 } 501 }
470 502
471 TEST(RemoteSuggestionTest, NotificationInfoShouldNotifyInvalid) { 503 TEST(RemoteSuggestionTest, NotificationInfoShouldNotifyInvalid) {
472 auto json = ContentSuggestionSnippet(); 504 auto json = ContentSuggestionSnippet();
473 json->SetString("notificationInfo.shouldNotify", "non-bool"); 505 json->SetString("notificationInfo.shouldNotify", "non-bool");
474 auto snippet = 506 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
475 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 507 *json, 0, base::Time());
476 EXPECT_FALSE(snippet->should_notify()); 508 EXPECT_FALSE(snippet->should_notify());
477 } 509 }
478 510
479 TEST(RemoteSuggestionTest, NotificationInfoAbsent) { 511 TEST(RemoteSuggestionTest, NotificationInfoAbsent) {
480 auto json = ContentSuggestionSnippet(); 512 auto json = ContentSuggestionSnippet();
481 auto snippet = 513 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
482 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 514 *json, 0, base::Time());
483 EXPECT_FALSE(snippet->should_notify()); 515 EXPECT_FALSE(snippet->should_notify());
484 } 516 }
485 517
486 TEST(RemoteSuggestionTest, ToContentSuggestion) { 518 TEST(RemoteSuggestionTest, ToContentSuggestion) {
487 auto json = ContentSuggestionSnippet(); 519 auto json = ContentSuggestionSnippet();
488 auto snippet = 520 const base::Time fetch_date = base::Time::FromInternalValue(1466634774L);
489 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 521 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
522 *json, 0, fetch_date);
490 ASSERT_THAT(snippet, NotNull()); 523 ASSERT_THAT(snippet, NotNull());
491 ContentSuggestion sugg = snippet->ToContentSuggestion( 524 ContentSuggestion sugg = snippet->ToContentSuggestion(
492 Category::FromKnownCategory(KnownCategories::ARTICLES)); 525 Category::FromKnownCategory(KnownCategories::ARTICLES));
493 526
494 EXPECT_THAT(sugg.id().category(), 527 EXPECT_THAT(sugg.id().category(),
495 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES))); 528 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES)));
496 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar")); 529 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar"));
497 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp"))); 530 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp")));
498 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz"))); 531 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz")));
499 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("..."))); 532 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("...")));
500 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000)); 533 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000));
501 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News"))); 534 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News")));
502 EXPECT_THAT(sugg.score(), Eq(9001)); 535 EXPECT_THAT(sugg.score(), Eq(9001));
503 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull()); 536 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull());
504 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull()); 537 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull());
505 EXPECT_THAT(sugg.notification_extra(), IsNull()); 538 EXPECT_THAT(sugg.notification_extra(), IsNull());
539 EXPECT_THAT(sugg.fetch_date(), Eq(fetch_date));
506 } 540 }
507 541
508 TEST(RemoteSuggestionTest, ToContentSuggestionWithNotificationInfo) { 542 TEST(RemoteSuggestionTest, ToContentSuggestionWithNotificationInfo) {
509 auto json = ContentSuggestionSnippet(); 543 auto json = ContentSuggestionSnippet();
510 json->SetBoolean("notificationInfo.shouldNotify", true); 544 json->SetBoolean("notificationInfo.shouldNotify", true);
511 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z"); 545 json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
512 auto snippet = 546 auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
513 RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0); 547 *json, 0, base::Time());
514 ASSERT_THAT(snippet, NotNull()); 548 ASSERT_THAT(snippet, NotNull());
515 ContentSuggestion sugg = snippet->ToContentSuggestion( 549 ContentSuggestion sugg = snippet->ToContentSuggestion(
516 Category::FromKnownCategory(KnownCategories::ARTICLES)); 550 Category::FromKnownCategory(KnownCategories::ARTICLES));
517 551
518 EXPECT_THAT(sugg.id().category(), 552 EXPECT_THAT(sugg.id().category(),
519 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES))); 553 Eq(Category::FromKnownCategory(KnownCategories::ARTICLES)));
520 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar")); 554 EXPECT_THAT(sugg.id().id_within_category(), Eq("http://localhost/foobar"));
521 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp"))); 555 EXPECT_THAT(sugg.url(), Eq(GURL("http://localhost/amp")));
522 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz"))); 556 EXPECT_THAT(sugg.title(), Eq(base::UTF8ToUTF16("Foo Barred from Baz")));
523 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("..."))); 557 EXPECT_THAT(sugg.snippet_text(), Eq(base::UTF8ToUTF16("...")));
524 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000)); 558 EXPECT_THAT(sugg.publish_date().ToJavaTime(), Eq(1467284497000));
525 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News"))); 559 EXPECT_THAT(sugg.publisher_name(), Eq(base::UTF8ToUTF16("Foo News")));
526 EXPECT_THAT(sugg.score(), Eq(9001)); 560 EXPECT_THAT(sugg.score(), Eq(9001));
527 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull()); 561 EXPECT_THAT(sugg.download_suggestion_extra(), IsNull());
528 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull()); 562 EXPECT_THAT(sugg.recent_tab_suggestion_extra(), IsNull());
529 ASSERT_THAT(sugg.notification_extra(), NotNull()); 563 ASSERT_THAT(sugg.notification_extra(), NotNull());
530 EXPECT_THAT(sugg.notification_extra()->deadline.ToJavaTime(), 564 EXPECT_THAT(sugg.notification_extra()->deadline.ToJavaTime(),
531 Eq(1467291697000)); 565 Eq(1467291697000));
532 } 566 }
533 567
534 } // namespace 568 } // namespace
535 } // namespace ntp_snippets 569 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestion.cc ('k') | components/ntp_snippets/remote/remote_suggestions_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698