Chromium Code Reviews| 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 300b9646847a09985c6b2f8c83dedca50c787096..8ef0373282344b810b2ed85be3d16c9f4ddeed0c 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,89 @@ TEST_F(NotificationChannelsProviderAndroidTest, |
| EXPECT_TRUE(result); |
| } |
| + |
| +TEST_F(NotificationChannelsProviderAndroidTest, |
| + GetRuleIteratorWhenChannelsShouldNotBeUsed_ReturnsNull) { |
|
raymes
2017/06/04 23:51:22
nit: I think the _ReturnsNull in the name isn't ne
awdf
2017/06/05 16:29:26
Done.
|
| + InitChannelsProvider(false /* should_use_channels */); |
|
raymes
2017/06/04 23:51:21
nit: apparently (according to thakis@) the suggest
Peter Beverloo
2017/06/05 12:40:24
3200 vs. 60 hits. I prefer consistency -- all our
awdf
2017/06/05 16:29:26
Interesting - I agree with Peter that consistency
raymes
2017/06/06 01:39:04
Yeah, there's probably an argument to be had about
|
| + EXPECT_FALSE(channels_provider_->GetRuleIterator( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| + false /* incognito */)); |
| +} |
| + |
| +TEST_F(NotificationChannelsProviderAndroidTest, |
| + GetRuleIteratorForIncognito_ReturnsNull) { |
| + InitChannelsProvider(true /* should_use_channels */); |
| + EXPECT_FALSE( |
| + channels_provider_->GetRuleIterator(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string(), true /* incognito */)); |
| +} |
| + |
| +TEST_F(NotificationChannelsProviderAndroidTest, |
| + GetRuleIteratorWhenNoChannelsExist_ReturnsNull) { |
| + 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(rule.primary_pattern, |
|
raymes
2017/06/04 23:51:22
nit (here and below): The expected value always co
awdf
2017/06/05 16:29:26
Done.
|
| + ContentSettingsPattern::FromString(kTestOrigin)); |
| + EXPECT_EQ(content_settings::ValueToContentSetting(rule.value.get()), |
| + CONTENT_SETTING_BLOCK); |
| + 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(rule.primary_pattern, |
| + ContentSettingsPattern::FromString(kTestOrigin)); |
| + EXPECT_EQ(content_settings::ValueToContentSetting(rule.value.get()), |
| + CONTENT_SETTING_ALLOW); |
| + 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(first_rule.primary_pattern, |
| + ContentSettingsPattern::FromString("https://abc.com")); |
| + EXPECT_EQ(content_settings::ValueToContentSetting(first_rule.value.get()), |
| + CONTENT_SETTING_ALLOW); |
| + EXPECT_TRUE(result->HasNext()); |
| + content_settings::Rule second_rule = result->Next(); |
| + EXPECT_EQ(second_rule.primary_pattern, |
| + ContentSettingsPattern::FromString("https://xyz.com")); |
| + EXPECT_EQ(content_settings::ValueToContentSetting(second_rule.value.get()), |
| + CONTENT_SETTING_BLOCK); |
| + EXPECT_FALSE(result->HasNext()); |
| +} |