1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86

ash / system / privacy / privacy_indicators_tray_item_view_pixeltest.cc [blame]

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

#include "ash/system/privacy/privacy_indicators_tray_item_view.h"

#include <memory>

#include "ash/style/dark_light_mode_controller_impl.h"
#include "ash/system/notification_center/notification_center_tray.h"
#include "ash/system/privacy/privacy_indicators_controller.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test/pixel/ash_pixel_test_init_params.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ash {

// Pixel tests for privacy indicators view.
class PrivacyIndicatorsTrayItemViewPixelTest
    : public AshTestBase,
      public testing::WithParamInterface<bool> {
 public:
  // AshTestBase:
  std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
      const override {
    return pixel_test::InitParams();
  }

  void SetUp() override {
    AshTestBase::SetUp();
    DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(IsDarkMode());
  }

  bool IsDarkMode() { return GetParam(); }

  // Simulates animating the view to its fully expanded state before shrinking
  // into a dot.
  void SimulateAnimateToFullyExpandedState(
      PrivacyIndicatorsTrayItemView* privacy_indicators_view) {
    privacy_indicators_view->expand_animation_->End();
  }

  // Simulates completing the animation.
  void SimulateAnimationEnded(
      PrivacyIndicatorsTrayItemView* privacy_indicators_view) {
    privacy_indicators_view->AnimationEnded(
        privacy_indicators_view->shorter_side_shrink_animation_.get());
  }

  std::string GetScreenshotNameSuffix() {
    return IsDarkMode() ? "_dark_mode" : "_light_mode";
  }
};

INSTANTIATE_TEST_SUITE_P(All,
                         PrivacyIndicatorsTrayItemViewPixelTest,
                         /*IsDarkMode()=*/testing::Bool());

TEST_P(PrivacyIndicatorsTrayItemViewPixelTest, Basics) {
  PrivacyIndicatorsController::Get()->UpdatePrivacyIndicators(
      /*app_id=*/"app_id", /*app_name=*/u"App Name",
      /*is_camera_used=*/true,
      /*is_microphone_used=*/true,
      base::MakeRefCounted<PrivacyIndicatorsNotificationDelegate>(),
      PrivacyIndicatorsSource::kApps);

  auto* notification_center_tray = GetPrimaryNotificationCenterTray();
  ASSERT_TRUE(notification_center_tray->GetVisible());

  auto* privacy_indicators_view =
      notification_center_tray->privacy_indicators_view();
  ASSERT_TRUE(privacy_indicators_view->GetVisible());

  SimulateAnimateToFullyExpandedState(privacy_indicators_view);
  EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
      "full_view" + GetScreenshotNameSuffix(),
      /*revision_number=*/1, notification_center_tray));

  SimulateAnimationEnded(privacy_indicators_view);
  EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
      "dot_view" + GetScreenshotNameSuffix(),
      /*revision_number=*/1, notification_center_tray));
}

}  // namespace ash