| Index: components/ntp_snippets/remote/remote_suggestion_unittest.cc
|
| diff --git a/components/ntp_snippets/remote/remote_suggestion_unittest.cc b/components/ntp_snippets/remote/remote_suggestion_unittest.cc
|
| index 7034ebf58b8ac3112ff1009a4cbd595fcd952cfb..4e144822a17dff950c8db14677f12c0058f539ef 100644
|
| --- a/components/ntp_snippets/remote/remote_suggestion_unittest.cc
|
| +++ b/components/ntp_snippets/remote/remote_suggestion_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/json/json_reader.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/time/time.h"
|
| #include "base/values.h"
|
| #include "components/ntp_snippets/remote/proto/ntp_snippets.pb.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -23,14 +24,15 @@ using ::testing::IsNull;
|
| using ::testing::NotNull;
|
|
|
| std::unique_ptr<RemoteSuggestion> SnippetFromContentSuggestionJSON(
|
| - const std::string& json) {
|
| + const std::string& json,
|
| + const base::Time fetch_time) {
|
| auto json_value = base::JSONReader::Read(json);
|
| base::DictionaryValue* json_dict;
|
| if (!json_value->GetAsDictionary(&json_dict)) {
|
| return nullptr;
|
| }
|
| return RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| - *json_dict, kArticlesRemoteId);
|
| + *json_dict, kArticlesRemoteId, fetch_time);
|
| }
|
|
|
| TEST(RemoteSuggestionTest, FromChromeContentSuggestionsDictionary) {
|
| @@ -52,7 +54,8 @@ TEST(RemoteSuggestionTest, FromChromeContentSuggestionsDictionary) {
|
| " \"deadline\": \"2016-06-30T13:01:37.000Z\"\n"
|
| " }\n"
|
| "}";
|
| - auto snippet = SnippetFromContentSuggestionJSON(kJsonStr);
|
| + const base::Time fetch_time = base::Time::Now();
|
| + auto snippet = SnippetFromContentSuggestionJSON(kJsonStr, fetch_time);
|
| ASSERT_THAT(snippet, NotNull());
|
|
|
| EXPECT_EQ(snippet->id(), "http://localhost/foobar");
|
| @@ -80,7 +83,9 @@ std::unique_ptr<RemoteSuggestion> SnippetFromChromeReaderDict(
|
| if (!dict) {
|
| return nullptr;
|
| }
|
| - return RemoteSuggestion::CreateFromChromeReaderDictionary(*dict);
|
| + // TODO
|
| + return RemoteSuggestion::CreateFromChromeReaderDictionary(*dict,
|
| + base::Time::Now());
|
| }
|
|
|
| const char kChromeReaderCreationTimestamp[] = "1234567890";
|
| @@ -374,7 +379,8 @@ TEST(RemoteSuggestionTest,
|
| " \"ampUrl\" : \"http://localhost/amp\","
|
| " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
|
| "}";
|
| - auto snippet = SnippetFromContentSuggestionJSON(kJsonStr);
|
| + const base::Time fetch_time = base::Time::Now();
|
| + auto snippet = SnippetFromContentSuggestionJSON(kJsonStr, fetch_time);
|
| ASSERT_THAT(snippet, NotNull());
|
|
|
| EXPECT_EQ(snippet->id(), "http://localhost/foobar");
|
| @@ -441,8 +447,8 @@ TEST(RemoteSuggestionTest, NotifcationInfoAllSpecified) {
|
| auto json = ContentSuggestionSnippet();
|
| json->SetBoolean("notificationInfo.shouldNotify", true);
|
| json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| EXPECT_TRUE(snippet->should_notify());
|
| EXPECT_EQ(7200.0f,
|
| (snippet->notification_deadline() - snippet->publish_date())
|
| @@ -453,8 +459,8 @@ TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) {
|
| auto json = ContentSuggestionSnippet();
|
| json->SetBoolean("notificationInfo.shouldNotify", true);
|
| json->SetInteger("notificationInfo.notificationDeadline", 0);
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| EXPECT_TRUE(snippet->should_notify());
|
| EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
|
| }
|
| @@ -462,8 +468,8 @@ TEST(RemoteSuggestionTest, NotificationInfoDeadlineInvalid) {
|
| TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) {
|
| auto json = ContentSuggestionSnippet();
|
| json->SetBoolean("notificationInfo.shouldNotify", true);
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| EXPECT_TRUE(snippet->should_notify());
|
| EXPECT_EQ(base::Time::Max(), snippet->notification_deadline());
|
| }
|
| @@ -471,22 +477,22 @@ TEST(RemoteSuggestionTest, NotificationInfoDeadlineAbsent) {
|
| TEST(RemoteSuggestionTest, NotificationInfoShouldNotifyInvalid) {
|
| auto json = ContentSuggestionSnippet();
|
| json->SetString("notificationInfo.shouldNotify", "non-bool");
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| EXPECT_FALSE(snippet->should_notify());
|
| }
|
|
|
| TEST(RemoteSuggestionTest, NotificationInfoAbsent) {
|
| auto json = ContentSuggestionSnippet();
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| EXPECT_FALSE(snippet->should_notify());
|
| }
|
|
|
| TEST(RemoteSuggestionTest, ToContentSuggestion) {
|
| auto json = ContentSuggestionSnippet();
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| ASSERT_THAT(snippet, NotNull());
|
| ContentSuggestion sugg = snippet->ToContentSuggestion(
|
| Category::FromKnownCategory(KnownCategories::ARTICLES));
|
| @@ -509,8 +515,8 @@ TEST(RemoteSuggestionTest, ToContentSuggestionWithNotificationInfo) {
|
| auto json = ContentSuggestionSnippet();
|
| json->SetBoolean("notificationInfo.shouldNotify", true);
|
| json->SetString("notificationInfo.deadline", "2016-06-30T13:01:37.000Z");
|
| - auto snippet =
|
| - RemoteSuggestion::CreateFromContentSuggestionsDictionary(*json, 0);
|
| + auto snippet = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
|
| + *json, 0, base::Time::Now());
|
| ASSERT_THAT(snippet, NotNull());
|
| ContentSuggestion sugg = snippet->ToContentSuggestion(
|
| Category::FromKnownCategory(KnownCategories::ARTICLES));
|
|
|