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
ash / auth / views / fingerprint_view_pixeltest.cc [blame]
// 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 <memory>
#include <string>
#include "ash/auth/views/fingerprint_view.h"
#include "ash/public/cpp/login_types.h"
#include "ash/shell.h"
#include "ash/style/dark_light_mode_controller_impl.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 "base/check.h"
#include "base/memory/raw_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/background.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {} // namespace
class FingerprintViewPixelTest : public AshTestBase {
public:
FingerprintViewPixelTest() = default;
FingerprintViewPixelTest(const FingerprintViewPixelTest&) = delete;
FingerprintViewPixelTest& operator=(const FingerprintViewPixelTest&) = delete;
~FingerprintViewPixelTest() override = default;
protected:
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
UpdateDisplay("600x800");
widget_ = CreateFramelessTestWidget();
std::unique_ptr<views::View> container_view =
std::make_unique<views::View>();
auto* layout =
container_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kCenter);
container_view->SetPreferredSize(gfx::Size({400, 300}));
container_view->SetBackground(views::CreateThemedRoundedRectBackground(
cros_tokens::kCrosSysSystemBaseElevated, 0));
fingerprint_view_ =
container_view->AddChildView(std::make_unique<FingerprintView>());
widget_->SetBounds({400, 300});
widget_->Show();
container_view_ = widget_->SetContentsView(std::move(container_view));
auto* dark_light_mode_controller = DarkLightModeControllerImpl::Get();
dark_light_mode_controller->SetAutoScheduleEnabled(false);
// Test Base should setup the dark mode.
EXPECT_TRUE(dark_light_mode_controller->IsDarkModeEnabled());
}
void TearDown() override {
AshTestBase::TearDown();
fingerprint_view_ = nullptr;
container_view_ = nullptr;
widget_.reset();
}
raw_ptr<FingerprintView> fingerprint_view_;
raw_ptr<views::View> container_view_ = nullptr;
std::unique_ptr<views::Widget> widget_;
};
// Verify the AVAILABLE_DEFAULT state.
TEST_F(FingerprintViewPixelTest, AvailableTest) {
fingerprint_view_->SetState(FingerprintState::AVAILABLE_DEFAULT);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"AvailableDark", /*revision_number=*/0, fingerprint_view_));
// Switch to day mode.
DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(false);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"Available", /*revision_number=*/0, fingerprint_view_));
}
// Verify the AVAILABLE_WITH_TOUCH_SENSOR_WARNING state.
TEST_F(FingerprintViewPixelTest, AvailableWithTouchSensorWarningTest) {
fingerprint_view_->SetState(FingerprintState::AVAILABLE_DEFAULT);
fingerprint_view_->SetState(
FingerprintState::AVAILABLE_WITH_TOUCH_SENSOR_WARNING);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"AvailableWithTouchSensorWarningDark", /*revision_number=*/0,
fingerprint_view_));
// Switch to day mode.
DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(false);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"AvailableWithTouchSensorWarning", /*revision_number=*/0,
fingerprint_view_));
}
// Verify the AVAILABLE_WITH_FAILED_ATTEMPT state/animation.
TEST_F(FingerprintViewPixelTest, AvailableWithFailedAttemptTest) {
fingerprint_view_->SetState(FingerprintState::AVAILABLE_DEFAULT);
DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(false);
fingerprint_view_->SetState(FingerprintState::AVAILABLE_WITH_FAILED_ATTEMPT);
FingerprintView::TestApi test_api(fingerprint_view_);
// To avoid flakiness we just verify the first and last frames.
test_api.ShowFirstFrame();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"AvailableWithFailedAttemptFirstFrame", /*revision_number=*/1,
fingerprint_view_));
test_api.ShowLastFrame();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"AvailableWithFailedAttemptLastFrame", /*revision_number=*/1,
fingerprint_view_));
}
// Verify the DISABLED_FROM_ATTEMPTS state/animation.
TEST_F(FingerprintViewPixelTest, DisabledFromAttemptsTest) {
fingerprint_view_->SetState(FingerprintState::AVAILABLE_DEFAULT);
DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(false);
fingerprint_view_->SetState(FingerprintState::DISABLED_FROM_ATTEMPTS);
// To avoid flakiness we just verify the first and last frames.
FingerprintView::TestApi test_api(fingerprint_view_);
test_api.ShowFirstFrame();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"DisabledFromAttemptsFirstFrame", /*revision_number=*/0,
fingerprint_view_));
test_api.ShowLastFrame();
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"DisabledFromAttemptsLastFrame", /*revision_number=*/0,
fingerprint_view_));
}
// Verify the DISABLED_FROM_TIMEOUT state.
TEST_F(FingerprintViewPixelTest, DisabledFromTimeoutTest) {
fingerprint_view_->SetState(FingerprintState::AVAILABLE_DEFAULT);
fingerprint_view_->SetState(FingerprintState::DISABLED_FROM_TIMEOUT);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"DisabledFromTimeoutDark", /*revision_number=*/0, fingerprint_view_));
// Switch to day mode.
DarkLightModeControllerImpl::Get()->SetDarkModeEnabledForTest(false);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"DisabledFromTimeout", /*revision_number=*/0, fingerprint_view_));
}
} // namespace ash