#include "ui/message_center/message_center_impl.h"
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/test/test_mock_time_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/message_center/lock_screen/fake_lock_screen_controller.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_types.h"
#include "ui/message_center/notification_blocker.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"
UTF8ToUTF16;
namespace message_center {
namespace {
class CheckObserver : public MessageCenterObserver { … };
class RemoveObserver : public MessageCenterObserver { … };
class TestAddObserver : public MessageCenterObserver { … };
class TestDelegate : public NotificationDelegate { … };
class DeleteOnCloseDelegate : public NotificationDelegate { … };
const char kDefaultAppId[] = …;
}
class MessageCenterImplTest : public testing::Test { … };
namespace {
class ToggledNotificationBlocker : public NotificationBlocker { … };
class PopupNotificationBlocker : public ToggledNotificationBlocker { … };
class NearTotalNotificationBlocker : public PopupNotificationBlocker { … };
class TotalNotificationBlocker : public NotificationBlocker { … };
bool PopupNotificationsContain(
const NotificationList::PopupNotifications& popups,
const std::string& id) { … }
bool NotificationsContain(
const NotificationList::Notifications& notifications,
const std::string& id) { … }
}
namespace internal {
class MockPopupTimersController : public PopupTimersController { … };
TEST_F(MessageCenterImplTest, PopupTimersEmptyController) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerStartTimer) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerCancelTimer) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerPauseAllTimers) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerStartAllTimers) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerStartMultipleTimers) { … }
TEST_F(MessageCenterImplTest, PopupTimersControllerRestartOnUpdate) { … }
TEST_F(MessageCenterImplTest, Renotify) { … }
TEST_F(MessageCenterImplTest, NotificationBlocker) { … }
TEST_F(MessageCenterImplTest, MarkPopupAsShownWhileBlocked) { … }
TEST_F(MessageCenterImplTest, VisibleNotificationsWithoutBlocker) { … }
TEST_F(MessageCenterImplTest, PopupsWithoutBlocker) { … }
TEST_F(MessageCenterImplTest, NotificationsDuringBlocked) { … }
TEST_F(MessageCenterImplTest, GetNotifications) { … }
TEST_F(MessageCenterImplTest, NotificationBlockerAllowsPopups) { … }
TEST_F(MessageCenterImplTest, NearTotalNotificationBlocker) { … }
TEST_F(MessageCenterImplTest, NotificationsUpdatedWhenBlockerAdded) { … }
TEST_F(MessageCenterImplTest, NotificationsUpdatedWhenBlockerRemoved) { … }
TEST_F(MessageCenterImplTest, RemoveAllNotifications) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(MessageCenterImplTest, RemoveAllNotificationsWithPinned) {
NotifierId notifier_id1(NotifierType::APPLICATION, "app1");
NotifierId notifier_id2(NotifierType::APPLICATION, "app2");
NearTotalNotificationBlocker blocker(message_center(), notifier_id1);
blocker.Init();
blocker.SetNotificationsEnabled(false);
message_center()->AddNotification(std::make_unique<Notification>(
NOTIFICATION_TYPE_SIMPLE, "id1", u"title", u"message",
ui::ImageModel() , std::u16string() ,
GURL(), notifier_id1, RichNotificationData(), nullptr));
message_center()->AddNotification(std::make_unique<Notification>(
NOTIFICATION_TYPE_SIMPLE, "id2", u"title", u"message",
ui::ImageModel() , std::u16string() ,
GURL(), notifier_id2, RichNotificationData(), nullptr));
auto notification3 = std::make_unique<Notification>(
NOTIFICATION_TYPE_SIMPLE, "id3", u"title", u"message",
ui::ImageModel() , std::u16string() ,
GURL(), notifier_id1, RichNotificationData(), nullptr);
notification3->set_pinned(true);
message_center()->AddNotification(std::move(notification3));
auto notification4 = std::make_unique<Notification>(
NOTIFICATION_TYPE_SIMPLE, "id4", u"title", u"message",
ui::ImageModel() , std::u16string() ,
GURL(), notifier_id2, RichNotificationData(), nullptr);
notification4->set_pinned(true);
message_center()->AddNotification(std::move(notification4));
message_center()->RemoveAllNotifications(
false , MessageCenter::RemoveType::NON_PINNED);
EXPECT_EQ(1u, message_center()->NotificationCount());
blocker.SetNotificationsEnabled(true);
EXPECT_EQ(3u, message_center()->NotificationCount());
NotificationList::Notifications notifications =
message_center()->GetVisibleNotifications();
EXPECT_FALSE(NotificationsContain(notifications, "id1"));
EXPECT_TRUE(NotificationsContain(notifications, "id2"));
EXPECT_TRUE(NotificationsContain(notifications, "id3"));
EXPECT_TRUE(NotificationsContain(notifications, "id4"));
}
#endif
TEST_F(MessageCenterImplTest, NotifierEnabledChanged) { … }
TEST_F(MessageCenterImplTest, UpdateWhileMessageCenterVisible) { … }
TEST_F(MessageCenterImplTest, AddWhileMessageCenterVisible) { … }
TEST_F(MessageCenterImplTest, RemoveWhileMessageCenterVisible) { … }
TEST_F(MessageCenterImplTest, RemoveNonVisibleNotification) { … }
TEST_F(MessageCenterImplTest, RemoveInCloseHandler) { … }
TEST_F(MessageCenterImplTest, RemoveInCloseHandlerCloseAll) { … }
TEST_F(MessageCenterImplTest, FindNotificationsByAppId) { … }
TEST_F(MessageCenterImplTest, QueueWhenCenterVisible) { … }
TEST_F(MessageCenterImplTest, UpdateProgressNotificationWhenCenterVisible) { … }
TEST_F(MessageCenterImplTest, UpdateNonProgressNotificationWhenCenterVisible) { … }
TEST_F(MessageCenterImplTest,
UpdateNonProgressToProgressNotificationWhenCenterVisible) { … }
TEST_F(MessageCenterImplTest, Click) { … }
TEST_F(MessageCenterImplTest, ButtonClick) { … }
TEST_F(MessageCenterImplTest, RemoveAfterClick) { … }
TEST_F(MessageCenterImplTest, RemoveAfterButtonClick) { … }
TEST_F(MessageCenterImplTest, ButtonClickWithReply) { … }
TEST_F(MessageCenterImplTest, Unlock) { … }
TEST_F(MessageCenterImplTest, ClickOnLockScreen) { … }
TEST_F(MessageCenterImplTest, ClickAndCancelOnLockScreen) { … }
TEST_F(MessageCenterImplTest, ButtonClickOnLockScreen) { … }
TEST_F(MessageCenterImplTest, ButtonClickWithReplyOnLockScreen) { … }
}
}