#include "ash/system/lock_screen_notification_controller.h"
#include "ash/system/notification_center/notification_center_test_api.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/test/ash_test_base.h"
#include "ui/message_center/message_center.h"
namespace ash {
class LockScreenNotificationControllerTest
: public AshTestBase,
public testing::WithParamInterface<bool> {
public:
LockScreenNotificationControllerTest() = default;
LockScreenNotificationControllerTest(
const LockScreenNotificationControllerTest&) = delete;
LockScreenNotificationControllerTest& operator=(
const LockScreenNotificationControllerTest&) = delete;
~LockScreenNotificationControllerTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
test_api_ = std::make_unique<NotificationCenterTestApi>();
}
bool IsLockScreenNotificationPresent() {
return message_center::MessageCenter::Get()->FindNotificationById(
LockScreenNotificationController::kLockScreenNotificationId);
}
NotificationCenterTestApi* test_api() { return test_api_.get(); }
private:
std::unique_ptr<NotificationCenterTestApi> test_api_;
};
TEST_F(LockScreenNotificationControllerTest,
NoLockScreenNotificationWithoutHiddenNotifications) {
ASSERT_FALSE(IsLockScreenNotificationPresent());
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
EXPECT_FALSE(IsLockScreenNotificationPresent());
}
TEST_F(LockScreenNotificationControllerTest,
LockScreenNotificationWithHiddenNotification) {
test_api()->AddNotification();
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
EXPECT_TRUE(IsLockScreenNotificationPresent());
UnblockUserSession();
EXPECT_FALSE(IsLockScreenNotificationPresent());
}
TEST_F(LockScreenNotificationControllerTest,
NotificationNotShownWithSystemNotifications) {
test_api()->AddSystemNotification();
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
EXPECT_FALSE(IsLockScreenNotificationPresent());
}
TEST_F(LockScreenNotificationControllerTest, NotificationsAddedOnLockScreen) {
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
EXPECT_FALSE(IsLockScreenNotificationPresent());
test_api()->AddSystemNotification();
EXPECT_FALSE(IsLockScreenNotificationPresent());
test_api()->AddNotification();
EXPECT_TRUE(IsLockScreenNotificationPresent());
}
TEST_F(LockScreenNotificationControllerTest, NotificationsRemovedOnLockScreen) {
std::string id, system_id;
system_id = test_api()->AddSystemNotification();
id = test_api()->AddNotification();
BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
EXPECT_TRUE(IsLockScreenNotificationPresent());
test_api()->RemoveNotification(id);
EXPECT_FALSE(IsLockScreenNotificationPresent());
}
}