Index: chrome/browser/notifications/notification_channels_provider_android_unittest.cc |
diff --git a/chrome/browser/notifications/notification_channels_provider_android_unittest.cc b/chrome/browser/notifications/notification_channels_provider_android_unittest.cc |
index 2024fcabd15b4970d258cc3ee7441f881e8e4609..991f1a49a4b965e75d23337b6df69fe86e90811c 100644 |
--- a/chrome/browser/notifications/notification_channels_provider_android_unittest.cc |
+++ b/chrome/browser/notifications/notification_channels_provider_android_unittest.cc |
@@ -7,6 +7,8 @@ |
#include "base/memory/ptr_util.h" |
#include "base/values.h" |
#include "components/content_settings/core/browser/content_settings_pref.h" |
+#include "components/content_settings/core/browser/content_settings_rule.h" |
+#include "components/content_settings/core/browser/content_settings_utils.h" |
#include "components/content_settings/core/common/content_settings_pattern.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -26,6 +28,7 @@ class MockNotificationChannelsBridge |
MOCK_METHOD2(CreateChannel, void(const std::string&, bool)); |
MOCK_METHOD1(GetChannelStatus, NotificationChannelStatus(const std::string&)); |
MOCK_METHOD1(DeleteChannel, void(const std::string&)); |
+ MOCK_METHOD0(GetChannels, std::vector<NotificationChannel>()); |
}; |
class NotificationChannelsProviderAndroidTest : public testing::Test { |
@@ -129,3 +132,88 @@ TEST_F(NotificationChannelsProviderAndroidTest, |
EXPECT_TRUE(result); |
} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, |
+ GetRuleIteratorWhenChannelsShouldNotBeUsed) { |
+ InitChannelsProvider(false /* should_use_channels */); |
+ EXPECT_FALSE(channels_provider_->GetRuleIterator( |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
+ false /* incognito */)); |
+} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, GetRuleIteratorForIncognito) { |
+ InitChannelsProvider(true /* should_use_channels */); |
+ EXPECT_FALSE( |
+ channels_provider_->GetRuleIterator(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ std::string(), true /* incognito */)); |
+} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, |
+ GetRuleIteratorWhenNoChannelsExist) { |
+ InitChannelsProvider(true /* should_use_channels */); |
+ EXPECT_CALL(*mock_bridge_, GetChannels()); |
+ EXPECT_FALSE(channels_provider_->GetRuleIterator( |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
+ false /* incognito */)); |
+} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, |
+ GetRuleIteratorWhenOneBlockedChannelExists) { |
+ InitChannelsProvider(true /* should_use_channels */); |
+ std::vector<NotificationChannel> channels; |
+ channels.emplace_back(kTestOrigin, NotificationChannelStatus::BLOCKED); |
+ EXPECT_CALL(*mock_bridge_, GetChannels()).WillOnce(Return(channels)); |
+ std::unique_ptr<content_settings::RuleIterator> result = |
+ channels_provider_->GetRuleIterator(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ std::string(), false /* incognito */); |
+ EXPECT_TRUE(result->HasNext()); |
+ content_settings::Rule rule = result->Next(); |
+ EXPECT_EQ(ContentSettingsPattern::FromString(kTestOrigin), |
+ rule.primary_pattern); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ content_settings::ValueToContentSetting(rule.value.get())); |
+ EXPECT_FALSE(result->HasNext()); |
+} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, |
+ GetRuleIteratorWhenOneAllowedChannelExists) { |
+ InitChannelsProvider(true /* should_use_channels */); |
+ std::vector<NotificationChannel> channels; |
+ channels.emplace_back(kTestOrigin, NotificationChannelStatus::ENABLED); |
+ EXPECT_CALL(*mock_bridge_, GetChannels()).WillOnce(Return(channels)); |
+ std::unique_ptr<content_settings::RuleIterator> result = |
+ channels_provider_->GetRuleIterator(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ std::string(), false /* incognito */); |
+ EXPECT_TRUE(result->HasNext()); |
+ content_settings::Rule rule = result->Next(); |
+ EXPECT_EQ(ContentSettingsPattern::FromString(kTestOrigin), |
+ rule.primary_pattern); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ content_settings::ValueToContentSetting(rule.value.get())); |
+ EXPECT_FALSE(result->HasNext()); |
+} |
+ |
+TEST_F(NotificationChannelsProviderAndroidTest, |
+ GetRuleIteratorWhenMultipleChannelsExist) { |
+ InitChannelsProvider(true /* should_use_channels */); |
+ std::vector<NotificationChannel> channels; |
+ channels.emplace_back("https://abc.com", NotificationChannelStatus::ENABLED); |
+ channels.emplace_back("https://xyz.com", NotificationChannelStatus::BLOCKED); |
+ EXPECT_CALL(*mock_bridge_, GetChannels()).WillOnce(Return(channels)); |
+ std::unique_ptr<content_settings::RuleIterator> result = |
+ channels_provider_->GetRuleIterator(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ std::string(), false /* incognito */); |
+ EXPECT_TRUE(result->HasNext()); |
+ content_settings::Rule first_rule = result->Next(); |
+ EXPECT_EQ(ContentSettingsPattern::FromString("https://abc.com"), |
+ first_rule.primary_pattern); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ content_settings::ValueToContentSetting(first_rule.value.get())); |
+ EXPECT_TRUE(result->HasNext()); |
+ content_settings::Rule second_rule = result->Next(); |
+ EXPECT_EQ(ContentSettingsPattern::FromString("https://xyz.com"), |
+ second_rule.primary_pattern); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ content_settings::ValueToContentSetting(second_rule.value.get())); |
+ EXPECT_FALSE(result->HasNext()); |
+} |