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

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

Issue 2402323002: [NTP Snippets] Persist non-article remote suggestions in the DB (Closed)
Patch Set: review Created 4 years, 2 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/ntp_snippet.h" 5 #include "components/ntp_snippets/remote/ntp_snippet.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace ntp_snippets { 12 namespace ntp_snippets {
13 namespace { 13 namespace {
14 14
15 std::unique_ptr<NTPSnippet> SnippetFromContentSuggestionJSON( 15 std::unique_ptr<NTPSnippet> SnippetFromContentSuggestionJSON(
16 const std::string& json) { 16 const std::string& json) {
17 auto json_value = base::JSONReader::Read(json); 17 auto json_value = base::JSONReader::Read(json);
18 base::DictionaryValue* json_dict; 18 base::DictionaryValue* json_dict;
19 if (!json_value->GetAsDictionary(&json_dict)) { 19 if (!json_value->GetAsDictionary(&json_dict)) {
20 return nullptr; 20 return nullptr;
21 } 21 }
22 return NTPSnippet::CreateFromContentSuggestionsDictionary(*json_dict); 22 return NTPSnippet::CreateFromContentSuggestionsDictionary(*json_dict,
23 kArticlesRemoteId);
23 } 24 }
24 25
25 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) { 26 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) {
26 const std::string kJsonStr = 27 const std::string kJsonStr =
27 "{" 28 "{"
28 " \"ids\" : [\"http://localhost/foobar\"]," 29 " \"ids\" : [\"http://localhost/foobar\"],"
29 " \"title\" : \"Foo Barred from Baz\"," 30 " \"title\" : \"Foo Barred from Baz\","
30 " \"snippet\" : \"...\"," 31 " \"snippet\" : \"...\","
31 " \"fullPageUrl\" : \"http://localhost/foobar\"," 32 " \"fullPageUrl\" : \"http://localhost/foobar\","
32 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," 33 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\","
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 259
259 EXPECT_EQ(snippet->sources().size(), 3u); 260 EXPECT_EQ(snippet->sources().size(), 3u);
260 EXPECT_EQ(snippet->id(), "http://url.com"); 261 EXPECT_EQ(snippet->id(), "http://url.com");
261 EXPECT_EQ(snippet->best_source().url, GURL("http://source1.com")); 262 EXPECT_EQ(snippet->best_source().url, GURL("http://source1.com"));
262 EXPECT_EQ(snippet->best_source().publisher_name, std::string("Source 1")); 263 EXPECT_EQ(snippet->best_source().publisher_name, std::string("Source 1"));
263 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://source1.amp.com")); 264 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://source1.amp.com"));
264 } 265 }
265 266
266 } // namespace 267 } // namespace
267 } // namespace ntp_snippets 268 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/ntp_snippet.cc ('k') | components/ntp_snippets/remote/ntp_snippets_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698