Commit bb74bb10 authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[NTP OptOut] Ensuring that hiding the article list disables notifications

Bug: 805177
Change-Id: I81bc5c2b54304f60123f464b155c3a1ee8182c72
Reviewed-on: https://chromium-review.googlesource.com/910148
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536032}
parent f66586bb
......@@ -8,6 +8,7 @@
#include "chrome/common/pref_names.h"
#include "components/ntp_snippets/features.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/variations/variations_associated_data.h"
......@@ -33,6 +34,13 @@ bool IsAutoOptOutEnabled() {
} // namespace
bool ContentSuggestionsNotifier::ShouldSendNotifications(PrefService* prefs) {
// Notifications are blocked when the suggested articles list is hidden.
// The user can hide the list when kArticleSuggestionsExpandableHeader feature
// is enabled.
if (!prefs->GetBoolean(ntp_snippets::prefs::kArticlesListVisible)) {
return false;
}
if (!prefs->GetBoolean(prefs::kContentSuggestionsNotificationsEnabled)) {
return false;
}
......
......@@ -16,6 +16,7 @@
#include "components/ntp_snippets/category_rankers/fake_category_ranker.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/logger.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/ntp_snippets/remote/remote_suggestion_builder.h"
#include "components/ntp_snippets/user_classifier.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
......@@ -55,6 +56,8 @@ RegisteredPrefs() {
ContentSuggestionsService::RegisterProfilePrefs(prefs->registry());
UserClassifier::RegisterProfilePrefs(prefs->registry());
ContentSuggestionsNotifierService::RegisterProfilePrefs(prefs->registry());
prefs->registry()->RegisterBooleanPref(
ntp_snippets::prefs::kArticlesListVisible, true);
return prefs;
}
......
......@@ -7,6 +7,7 @@
#include "chrome/browser/android/ntp/content_suggestions_notifier_service.h"
#include "chrome/common/pref_names.h"
#include "components/ntp_snippets/features.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/variations/variations_params_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -19,6 +20,9 @@ using ContentSuggestionsNotifierTest = ::testing::Test;
TEST_F(ContentSuggestionsNotifierTest, AreNotificationsEnabled) {
sync_preferences::TestingPrefServiceSyncable prefs;
ContentSuggestionsNotifierService::RegisterProfilePrefs(prefs.registry());
prefs.registry()->RegisterBooleanPref(
ntp_snippets::prefs::kArticlesListVisible, true);
EXPECT_TRUE(ContentSuggestionsNotifier::ShouldSendNotifications(&prefs));
prefs.SetBoolean(prefs::kContentSuggestionsNotificationsEnabled, false);
......@@ -26,6 +30,12 @@ TEST_F(ContentSuggestionsNotifierTest, AreNotificationsEnabled) {
prefs.SetBoolean(prefs::kContentSuggestionsNotificationsEnabled, true);
EXPECT_TRUE(ContentSuggestionsNotifier::ShouldSendNotifications(&prefs));
prefs.SetBoolean(ntp_snippets::prefs::kArticlesListVisible, false);
EXPECT_FALSE(ContentSuggestionsNotifier::ShouldSendNotifications(&prefs));
prefs.SetBoolean(ntp_snippets::prefs::kArticlesListVisible, true);
EXPECT_TRUE(ContentSuggestionsNotifier::ShouldSendNotifications(&prefs));
}
TEST_F(ContentSuggestionsNotifierTest, AreNotificationsEnabledAutoOptOut) {
......@@ -39,6 +49,9 @@ TEST_F(ContentSuggestionsNotifierTest, AreNotificationsEnabledAutoOptOut) {
sync_preferences::TestingPrefServiceSyncable prefs;
ContentSuggestionsNotifierService::RegisterProfilePrefs(prefs.registry());
prefs.registry()->RegisterBooleanPref(
ntp_snippets::prefs::kArticlesListVisible, true);
EXPECT_TRUE(ContentSuggestionsNotifier::ShouldSendNotifications(
&prefs)); // Enabled by default.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment