#include "chrome/browser/notifications/notification_display_service_impl.h"
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/notifications/notification_blocker.h"
#include "chrome/browser/notifications/notification_display_queue.h"
#include "chrome/browser/notifications/notification_platform_bridge_delegator.h"
#include "chrome/common/notifications/notification_operation.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_contents_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/nearby_sharing/nearby_sharing_service_factory.h"
#endif
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/notifications/muted_notification_handler.h"
#include "chrome/browser/notifications/screen_capture_notification_blocker.h"
#endif
namespace {
class FakeNotificationBlocker : public NotificationBlocker { … };
class TestNotificationPlatformBridgeDelegator
: public NotificationPlatformBridgeDelegator { … };
message_center::Notification CreateNotification(const std::string& id,
const GURL& origin = { … }
}
class BaseNotificationDisplayServiceImplTest : public testing::Test { … };
class NotificationDisplayServiceImplTest
: public BaseNotificationDisplayServiceImplTest { … };
TEST_F(NotificationDisplayServiceImplTest, DisplayWithoutBlockers) { … }
TEST_F(NotificationDisplayServiceImplTest, DisplayWithAllowingBlocker) { … }
TEST_F(NotificationDisplayServiceImplTest, DisplayWithBlockingBlocker) { … }
TEST_F(NotificationDisplayServiceImplTest, UnblockQueuedNotification) { … }
TEST_F(NotificationDisplayServiceImplTest, CloseQueuedNotification) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(NotificationDisplayServiceImplTest, NearbyNotificationHandler) {
{
NearbySharingServiceFactory::
SetIsNearbyShareSupportedForBrowserContextForTesting(false);
NotificationDisplayServiceImpl service(profile());
EXPECT_FALSE(service.GetNotificationHandler(
NotificationHandler::Type::NEARBY_SHARE));
}
{
NearbySharingServiceFactory::
SetIsNearbyShareSupportedForBrowserContextForTesting(true);
NotificationDisplayServiceImpl service(profile());
EXPECT_TRUE(service.GetNotificationHandler(
NotificationHandler::Type::NEARBY_SHARE));
}
}
#endif
#if !BUILDFLAG(IS_ANDROID)
class DesktopNotificationDisplayServiceImplTest
: public BaseNotificationDisplayServiceImplTest { … };
TEST_F(DesktopNotificationDisplayServiceImplTest, SnoozeDuringScreenCapture) { … }
#endif