screen_security_notification_controller_unittest.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/screen_security/screen_security_notification_controller.h"
  5. #include "ash/shell.h"
  6. #include "ash/system/tray/system_tray_notifier.h"
  7. #include "ash/test/ash_test_base.h"
  8. #include "base/callback.h"
  9. #include "base/callback_helpers.h"
  10. #include "ui/message_center/message_center.h"
  11. namespace ash {
  12. using ScreenSecurityNotificationControllerTest = AshTestBase;
  13. namespace {
  14. message_center::Notification* FindNotification(const std::string& id) {
  15. return message_center::MessageCenter::Get()->FindVisibleNotificationById(id);
  16. }
  17. } // namespace
  18. TEST_F(ScreenSecurityNotificationControllerTest,
  19. ShowScreenCaptureNotification) {
  20. Shell::Get()->system_tray_notifier()->NotifyScreenCaptureStart(
  21. base::DoNothing(), base::RepeatingClosure(), std::u16string());
  22. EXPECT_TRUE(FindNotification(kScreenCaptureNotificationId));
  23. Shell::Get()->system_tray_notifier()->NotifyScreenCaptureStop();
  24. EXPECT_FALSE(FindNotification(kScreenCaptureNotificationId));
  25. }
  26. TEST_F(ScreenSecurityNotificationControllerTest, ShowScreenShareNotification) {
  27. Shell::Get()->system_tray_notifier()->NotifyScreenShareStart(
  28. base::DoNothing(), std::u16string());
  29. EXPECT_TRUE(FindNotification(kScreenShareNotificationId));
  30. Shell::Get()->system_tray_notifier()->NotifyScreenShareStop();
  31. EXPECT_FALSE(FindNotification(kScreenShareNotificationId));
  32. }
  33. TEST_F(ScreenSecurityNotificationControllerTest,
  34. DoNotShowScreenCaptureNotificationWhenCasting) {
  35. Shell::Get()->OnCastingSessionStartedOrStopped(true /* started */);
  36. Shell::Get()->system_tray_notifier()->NotifyScreenCaptureStart(
  37. base::DoNothing(), base::RepeatingClosure(), std::u16string());
  38. EXPECT_FALSE(FindNotification(kScreenCaptureNotificationId));
  39. Shell::Get()->system_tray_notifier()->NotifyScreenCaptureStop();
  40. Shell::Get()->OnCastingSessionStartedOrStopped(false /* started */);
  41. EXPECT_FALSE(FindNotification(kScreenCaptureNotificationId));
  42. }
  43. } // namespace ash