chromium/ui/message_center/message_center_impl_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {};

// The default app id used to create simple notifications.
const char kDefaultAppId[] =;

}  // anonymous namespace

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) {}

// Right now, MessageCenter::HasNotification() returns regardless of blockers.
bool NotificationsContain(
    const NotificationList::Notifications& notifications,
    const std::string& id) {}

}  // namespace

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) {}

// Similar to other blocker cases but this test case allows |notifier_id2| even
// in blocked.
TEST_F(MessageCenterImplTest, NotificationBlockerAllowsPopups) {}

// NearTotalNotificationBlocker suppresses showing notifications even from the
// list. This would provide the feature to 'separated' message centers
// per-profile for ChromeOS multi-login.
TEST_F(MessageCenterImplTest, NearTotalNotificationBlocker) {}

// Tests that notification state is updated when a notification blocker is
// added.
TEST_F(MessageCenterImplTest, NotificationsUpdatedWhenBlockerAdded) {}

// Tests that notification state is updated when a notification blocker is
// removed.
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);

  // Notification 1: Visible, non-pinned
  message_center()->AddNotification(std::make_unique<Notification>(
      NOTIFICATION_TYPE_SIMPLE, "id1", u"title", u"message",
      ui::ImageModel() /* icon */, std::u16string() /* display_source */,
      GURL(), notifier_id1, RichNotificationData(), nullptr));

  // Notification 2: Invisible, non-pinned
  message_center()->AddNotification(std::make_unique<Notification>(
      NOTIFICATION_TYPE_SIMPLE, "id2", u"title", u"message",
      ui::ImageModel() /* icon */, std::u16string() /* display_source */,
      GURL(), notifier_id2, RichNotificationData(), nullptr));

  // Notification 3: Visible, pinned
  auto notification3 = std::make_unique<Notification>(
      NOTIFICATION_TYPE_SIMPLE, "id3", u"title", u"message",
      ui::ImageModel() /* icon */, std::u16string() /* display_source */,
      GURL(), notifier_id1, RichNotificationData(), nullptr);
  notification3->set_pinned(true);
  message_center()->AddNotification(std::move(notification3));

  // Notification 4: Invisible, pinned
  auto notification4 = std::make_unique<Notification>(
      NOTIFICATION_TYPE_SIMPLE, "id4", u"title", u"message",
      ui::ImageModel() /* icon */, std::u16string() /* display_source */,
      GURL(), notifier_id2, RichNotificationData(), nullptr);
  notification4->set_pinned(true);
  message_center()->AddNotification(std::move(notification4));

  // Remove all the notifications which are visible and non-pinned.
  message_center()->RemoveAllNotifications(
      false /* by_user */, MessageCenter::RemoveType::NON_PINNED);

  EXPECT_EQ(1u, message_center()->NotificationCount());
  blocker.SetNotificationsEnabled(true);  // Show invisible notifications.
  EXPECT_EQ(3u, message_center()->NotificationCount());

  NotificationList::Notifications notifications =
      message_center()->GetVisibleNotifications();
  // Notification 1 should be removed.
  EXPECT_FALSE(NotificationsContain(notifications, "id1"));
  // Notification 2 shouldn't be removed since it was invisible.
  EXPECT_TRUE(NotificationsContain(notifications, "id2"));
  // Notification 3 shouldn't be removed since it was pinned.
  EXPECT_TRUE(NotificationsContain(notifications, "id3"));
  // Notification 4 shouldn't be removed since it was invisible and pinned.
  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) {}

// Regression test for https://crbug.com/1135709
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) {}

}  // namespace internal
}  // namespace message_center