Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, 1); |
|
Bernhard Bauer
2016/10/10 13:54:54
You could expose the remote category in the header
Marc Treib
2016/10/10 15:54:47
Done.
| |
| 23 } | 23 } |
| 24 | 24 |
| 25 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) { | 25 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) { |
| 26 const std::string kJsonStr = | 26 const std::string kJsonStr = |
| 27 "{" | 27 "{" |
| 28 " \"ids\" : [\"http://localhost/foobar\"]," | 28 " \"ids\" : [\"http://localhost/foobar\"]," |
| 29 " \"title\" : \"Foo Barred from Baz\"," | 29 " \"title\" : \"Foo Barred from Baz\"," |
| 30 " \"snippet\" : \"...\"," | 30 " \"snippet\" : \"...\"," |
| 31 " \"fullPageUrl\" : \"http://localhost/foobar\"," | 31 " \"fullPageUrl\" : \"http://localhost/foobar\"," |
| 32 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," | 32 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 | 258 |
| 259 EXPECT_EQ(snippet->sources().size(), 3u); | 259 EXPECT_EQ(snippet->sources().size(), 3u); |
| 260 EXPECT_EQ(snippet->id(), "http://url.com"); | 260 EXPECT_EQ(snippet->id(), "http://url.com"); |
| 261 EXPECT_EQ(snippet->best_source().url, GURL("http://source1.com")); | 261 EXPECT_EQ(snippet->best_source().url, GURL("http://source1.com")); |
| 262 EXPECT_EQ(snippet->best_source().publisher_name, std::string("Source 1")); | 262 EXPECT_EQ(snippet->best_source().publisher_name, std::string("Source 1")); |
| 263 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://source1.amp.com")); | 263 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://source1.amp.com")); |
| 264 } | 264 } |
| 265 | 265 |
| 266 } // namespace | 266 } // namespace |
| 267 } // namespace ntp_snippets | 267 } // namespace ntp_snippets |
| OLD | NEW |