camera_mic_tray_item_view_unittest.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2020 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/unified/camera_mic_tray_item_view.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "ash/public/cpp/media_controller.h"
  8. #include "ash/strings/grit/ash_strings.h"
  9. #include "ash/test/ash_test_base.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. namespace ash {
  13. namespace {
  14. using Type = CameraMicTrayItemView::Type;
  15. } // namespace
  16. class BaseCameraMicTrayItemViewTest : public AshTestBase {
  17. public:
  18. void SetUpWithType(Type type) {
  19. AshTestBase::SetUp();
  20. camera_mic_tray_item_view_ =
  21. std::make_unique<CameraMicTrayItemView>(GetPrimaryShelf(), type);
  22. // Relogin to make sure `OnActiveUserSessionChanged` is triggered.
  23. ClearLogin();
  24. SimulateUserLogin("user@test.com");
  25. }
  26. void TearDown() override {
  27. camera_mic_tray_item_view_.reset();
  28. AshTestBase::TearDown();
  29. }
  30. protected:
  31. std::unique_ptr<CameraMicTrayItemView> camera_mic_tray_item_view_;
  32. };
  33. class CameraMicTrayItemViewTest : public BaseCameraMicTrayItemViewTest,
  34. public testing::WithParamInterface<Type> {
  35. public:
  36. // AshTestBase:
  37. void SetUp() override { SetUpWithType(GetParam()); }
  38. };
  39. TEST_P(CameraMicTrayItemViewTest, GetVisible) {
  40. Type type = GetParam();
  41. EXPECT_FALSE(camera_mic_tray_item_view_->GetVisible());
  42. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  43. /*camera=*/true,
  44. /*mic=*/false,
  45. /*camera_and_mic=*/false);
  46. EXPECT_EQ(camera_mic_tray_item_view_->GetVisible(), type == Type::kCamera);
  47. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  48. /*camera=*/false,
  49. /*mic=*/false,
  50. /*camera_and_mic=*/true);
  51. EXPECT_EQ(camera_mic_tray_item_view_->GetVisible(), type == Type::kCamera);
  52. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  53. /*camera=*/false,
  54. /*mic=*/true,
  55. /*camera_and_mic=*/false);
  56. EXPECT_EQ(camera_mic_tray_item_view_->GetVisible(), type == Type::kMic);
  57. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  58. /*camera=*/true,
  59. /*mic=*/true,
  60. /*camera_and_mic=*/false);
  61. EXPECT_TRUE(camera_mic_tray_item_view_->GetVisible());
  62. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  63. /*camera=*/true,
  64. /*mic=*/true,
  65. /*camera_and_mic=*/true);
  66. EXPECT_TRUE(camera_mic_tray_item_view_->GetVisible());
  67. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  68. /*camera=*/false,
  69. /*mic=*/false,
  70. /*camera_and_mic=*/false);
  71. EXPECT_FALSE(camera_mic_tray_item_view_->GetVisible());
  72. }
  73. TEST_P(CameraMicTrayItemViewTest, HideForNonPrimaryUser) {
  74. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  75. /*camera=*/true,
  76. /*mic=*/true,
  77. /*camera_and_mic=*/true);
  78. EXPECT_TRUE(camera_mic_tray_item_view_->GetVisible());
  79. SimulateUserLogin("user2@test.com");
  80. EXPECT_FALSE(camera_mic_tray_item_view_->GetVisible());
  81. }
  82. INSTANTIATE_TEST_SUITE_P(All,
  83. CameraMicTrayItemViewTest,
  84. testing::Values(Type::kCamera, Type::kMic));
  85. // For testing that the camera tray item switch the message depending on whether
  86. // the "camera and mic" notification is active.
  87. class CameraMicTrayItemViewMessageTest : public BaseCameraMicTrayItemViewTest {
  88. // AshTestBase:
  89. void SetUp() override { SetUpWithType(Type::kCamera); }
  90. };
  91. TEST_F(CameraMicTrayItemViewMessageTest, Message) {
  92. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  93. /*camera=*/true,
  94. /*mic=*/false,
  95. /*camera_and_mic=*/false);
  96. EXPECT_EQ(camera_mic_tray_item_view_->GetAccessibleNameString(),
  97. l10n_util::GetStringUTF16(IDS_ASH_CAMERA_MIC_VM_USING_CAMERA));
  98. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  99. /*camera=*/false,
  100. /*mic=*/false,
  101. /*camera_and_mic=*/true);
  102. EXPECT_EQ(
  103. camera_mic_tray_item_view_->GetAccessibleNameString(),
  104. l10n_util::GetStringUTF16(IDS_ASH_CAMERA_MIC_VM_USING_CAMERA_AND_MIC));
  105. camera_mic_tray_item_view_->OnVmMediaNotificationChanged(
  106. /*camera=*/true,
  107. /*mic=*/false,
  108. /*camera_and_mic=*/true);
  109. EXPECT_EQ(
  110. camera_mic_tray_item_view_->GetAccessibleNameString(),
  111. l10n_util::GetStringUTF16(IDS_ASH_CAMERA_MIC_VM_USING_CAMERA_AND_MIC));
  112. }
  113. } // namespace ash