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

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

Issue 2110393004: Parse snippet times properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/ntp_snippet.h" 5 #include "components/ntp_snippets/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 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) { 15 TEST(NTPSnippetTest, FromChromeContentSuggestionsDictionary) {
16 const std::string kJsonStr = 16 const std::string kJsonStr =
17 "{" 17 "{"
18 " \"id\" : [\"http://localhost/foobar\"]," 18 " \"id\" : [\"http://localhost/foobar\"],"
19 " \"title\" : \"Foo Barred from Baz\"," 19 " \"title\" : \"Foo Barred from Baz\","
20 " \"summaryText\" : \"...\"," 20 " \"summaryText\" : \"...\","
21 " \"fullPageUrl\" : \"http://localhost/foobar\"," 21 " \"fullPageUrl\" : \"http://localhost/foobar\","
22 " \"publishTime\" : {" 22 " \"publishTime\" : \"2016-06-30T11:01:37.000Z\","
23 " \"seconds\": 1466510682," 23 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\","
24 " \"nanos\": 552743000 "
25 " },"
26 " \"expirationTime\" : {"
27 " \"seconds\" : 1466597082,"
28 " \"nanos\" : 552743000 "
29 " },"
30 " \"publisherName\" : \"Foo News\"," 24 " \"publisherName\" : \"Foo News\","
31 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 25 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
32 " \"ampUrl\" : \"http://localhost/amp\"," 26 " \"ampUrl\" : \"http://localhost/amp\","
33 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " 27 " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
34 "}"; 28 "}";
35 auto json_value = base::JSONReader::Read(kJsonStr); 29 auto json_value = base::JSONReader::Read(kJsonStr);
36 base::DictionaryValue* json_dict; 30 base::DictionaryValue* json_dict;
37 ASSERT_TRUE(json_value->GetAsDictionary(&json_dict)); 31 ASSERT_TRUE(json_value->GetAsDictionary(&json_dict));
38 32
39 auto snippet = NTPSnippet::CreateFromContentSuggestionsDictionary(*json_dict); 33 auto snippet = NTPSnippet::CreateFromContentSuggestionsDictionary(*json_dict);
40 ASSERT_THAT(snippet, testing::NotNull()); 34 ASSERT_THAT(snippet, testing::NotNull());
41 35
42 EXPECT_EQ(snippet->id(), "http://localhost/foobar"); 36 EXPECT_EQ(snippet->id(), "http://localhost/foobar");
43 EXPECT_EQ(snippet->title(), "Foo Barred from Baz"); 37 EXPECT_EQ(snippet->title(), "Foo Barred from Baz");
44 EXPECT_EQ(snippet->snippet(), "..."); 38 EXPECT_EQ(snippet->snippet(), "...");
45 EXPECT_EQ(snippet->salient_image_url(), GURL("http://localhost/foobar.jpg")); 39 EXPECT_EQ(snippet->salient_image_url(), GURL("http://localhost/foobar.jpg"));
46 auto unix_publish_date = snippet->publish_date() - base::Time::UnixEpoch(); 40 auto unix_publish_date = snippet->publish_date() - base::Time::UnixEpoch();
47 auto expiry_duration = snippet->expiry_date() - snippet->publish_date(); 41 auto expiry_duration = snippet->expiry_date() - snippet->publish_date();
48 EXPECT_FLOAT_EQ(unix_publish_date.InSecondsF(), 1466510682.552743f); 42 EXPECT_FLOAT_EQ(unix_publish_date.InSecondsF(), 1467284497.000000f);
49 EXPECT_FLOAT_EQ(expiry_duration.InSecondsF(), 86400.000000f); 43 EXPECT_FLOAT_EQ(expiry_duration.InSecondsF(), 86400.000000f);
50 44
51 EXPECT_EQ(snippet->best_source().publisher_name, "Foo News"); 45 EXPECT_EQ(snippet->best_source().publisher_name, "Foo News");
52 EXPECT_EQ(snippet->best_source().url, GURL("http://localhost/foobar")); 46 EXPECT_EQ(snippet->best_source().url, GURL("http://localhost/foobar"));
53 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://localhost/amp")); 47 EXPECT_EQ(snippet->best_source().amp_url, GURL("http://localhost/amp"));
54 } 48 }
55 49
56 } // namespace 50 } // namespace
57 } // namespace ntp_snippets 51 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698