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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
// Copyright 2024 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/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_test_util.h"
#include "ash/public/cpp/capture_mode/capture_mode_test_api.h"
#include "ash/system/notification_center/message_popup_animation_waiter.h"
#include "ash/system/notification_center/notification_center_test_api.h"
#include "ash/system/notification_center/notification_center_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_util.h"
#include "ash/test/pixel/ash_pixel_differ.h"
#include "ash/test/pixel/ash_pixel_test_init_params.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
#include "ui/base/ui_base_features.h"
#include "ui/message_center/views/message_popup_view.h"
#include "ui/message_center/views/message_view.h"
namespace ash {
namespace {
constexpr char kScreenCaptureNotificationId[] = "capture_mode_notification";
// The types of the primary display size.
enum class DisplayType {
// The display size is the default one.
kNormal,
// The display's height is much greater than its width.
kUltraHeight,
// The display's width is much greater than its height.
kUltraWidth,
};
// Returns the name of `type`.
std::string GetDisplayTypeName(DisplayType type) {
switch (type) {
case DisplayType::kNormal:
return "normal";
case DisplayType::kUltraWidth:
return "ultra_width";
case DisplayType::kUltraHeight:
return "ultra_height";
}
}
std::string GetScreenshotName(const std::string& test_name, bool new_width) {
return test_name + (new_width ? "_new_width" : "_old_width");
}
} // namespace
class DisplayParameterizedCaptureModePixelTest
: public AshTestBase,
public testing::WithParamInterface<std::tuple<DisplayType, bool>> {
public:
// AshTestBase:
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
void SetUp() override {
AshTestBase::SetUp();
test_api_ = std::make_unique<NotificationCenterTestApi>();
// Change the display size depending on the test param.
switch (GetDisplayType()) {
case DisplayType::kNormal:
break;
case DisplayType::kUltraWidth:
UpdateDisplay("1200x600");
break;
case DisplayType::kUltraHeight:
UpdateDisplay("600x1200");
break;
}
// Create windows so that the screenshot has more contents.
window1_ = CreateAppWindow(/*bounds_in_screen=*/gfx::Rect(200, 200));
window2_ =
CreateAppWindow(/*bounds_in_screen=*/gfx::Rect(220, 220, 100, 100));
DecorateWindow(window1_.get(), u"Window1", SK_ColorDKGRAY);
DecorateWindow(window2_.get(), u"Window2", SK_ColorBLUE);
scoped_feature_list_ = std::make_unique<base::test::ScopedFeatureList>();
scoped_feature_list_->InitWithFeatureState(
chromeos::features::kNotificationWidthIncrease,
IsNotificationWidthIncreaseEnabled());
}
void TearDown() override {
window2_.reset();
window1_.reset();
AshTestBase::TearDown();
}
NotificationCenterTestApi* test_api() { return test_api_.get(); }
DisplayType GetDisplayType() const { return std::get<0>(GetParam()); }
bool IsNotificationWidthIncreaseEnabled() { return std::get<1>(GetParam()); }
private:
std::unique_ptr<aura::Window> window1_;
std::unique_ptr<aura::Window> window2_;
std::unique_ptr<NotificationCenterTestApi> test_api_;
std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
};
INSTANTIATE_TEST_SUITE_P(
DisplaySize,
DisplayParameterizedCaptureModePixelTest,
testing::Combine(testing::ValuesIn({DisplayType::kNormal,
DisplayType::kUltraWidth,
DisplayType::kUltraHeight}),
/*IsNotificationWidthIncreaseEnabled()=*/testing::Bool()));
TEST_P(DisplayParameterizedCaptureModePixelTest,
ScreenCaptureNotificationPopup) {
// Take a full screenshot then wait for the file path to the saved image.
ash::CaptureModeController* controller = StartCaptureSession(
CaptureModeSource::kFullscreen, CaptureModeType::kImage);
controller->PerformCapture();
WaitForCaptureFileToBeSaved();
// Wait until the notification popup shows.
MessagePopupAnimationWaiter(
GetPrimaryNotificationCenterTray()->popup_collection())
.Wait();
// Get the notification view.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GetScreenshotName(base::StrCat({"screen_capture_popup_notification_",
GetDisplayTypeName(GetDisplayType())}),
IsNotificationWidthIncreaseEnabled()),
/*revision_number=*/3,
test_api()->GetPopupViewForId(kScreenCaptureNotificationId)));
}
TEST_P(DisplayParameterizedCaptureModePixelTest, VideoCaptureNotification) {
auto* controller = StartCaptureSession(CaptureModeSource::kFullscreen,
CaptureModeType::kVideo);
StartVideoRecordingImmediately();
CaptureModeTestApi().FlushRecordingServiceForTesting();
auto* test_delegate =
static_cast<TestCaptureModeDelegate*>(controller->delegate_for_testing());
// Request and wait for a video frame then wait for the capture notification
// to be posted.
test_delegate->RequestAndWaitForVideoFrame();
CaptureNotificationWaiter waiter;
controller->EndVideoRecording(EndRecordingReason::kStopRecordingButton);
waiter.Wait();
// Wait until the notification popup shows.
MessagePopupAnimationWaiter(
GetPrimaryNotificationCenterTray()->popup_collection())
.Wait();
std::string notification_id = GetPreviewNotification()->id();
auto* notification_popup_view =
test_api()->GetPopupViewForId(notification_id);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GetScreenshotName(base::StrCat({"video_capture_notification_popup_",
GetDisplayTypeName(GetDisplayType())}),
IsNotificationWidthIncreaseEnabled()),
/*revision_number=*/4, notification_popup_view));
test_api()->ToggleBubble();
auto* notification_view =
test_api()->GetNotificationViewForId(notification_id);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
GetScreenshotName(base::StrCat({"video_capture_notification_view_",
GetDisplayTypeName(GetDisplayType())}),
IsNotificationWidthIncreaseEnabled()),
/*revision_number=*/4, notification_view));
}
} // namespace ash
|