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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
ash / wm / snap_group / snap_group_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 <optional>
#include "ash/constants/ash_features.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/wm/overview/overview_item_base.h"
#include "ash/wm/overview/overview_test_util.h"
#include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/scoped_overview_transform_window.h"
#include "ash/wm/snap_group/snap_group_controller.h"
#include "ash/wm/snap_group/snap_group_test_util.h"
#include "ash/wm/splitview/split_view_constants.h"
#include "ash/wm/splitview/split_view_divider.h"
#include "ash/wm/splitview/split_view_test_util.h"
#include "ash/wm/window_cycle/window_cycle_controller.h"
#include "ash/wm/window_cycle/window_cycle_list.h"
#include "ash/wm/window_cycle/window_cycle_view.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"
namespace ash {
// Visual regression tests for Snap Groups feature, comparing visuals against
// established benchmarks.
class SnapGroupPixelTest : public AshTestBase {
public:
SnapGroupPixelTest() {
scoped_feature_list_.InitWithFeatures(
{features::kForestFeature, features::kSavedDeskUiRevamp,
chromeos::features::kOverviewSessionInitOptimizations},
{});
}
SnapGroupPixelTest(const SnapGroupPixelTest&) = delete;
SnapGroupPixelTest& operator=(const SnapGroupPixelTest&) = delete;
~SnapGroupPixelTest() override = default;
private:
// AshTestBase:
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
base::test::ScopedFeatureList scoped_feature_list_;
};
// -----------------------------------------------------------------------------
// Landscape:
// Visual regression test for divider component (default and hover states).
TEST_F(SnapGroupPixelTest, SnapGroupDividerBasic) {
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
auto* w1_widget = views::Widget::GetWidgetForNativeView(w1.get());
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
auto* w2_widget = views::Widget::GetWidgetForNativeView(w2.get());
auto* event_generator = GetEventGenerator();
SnapTwoTestWindows(w1.get(), w2.get(), /*horizontal=*/true, event_generator);
auto* divider_widget = GetTopmostSnapGroupDivider()->divider_widget();
ASSERT_TRUE(divider_widget);
// Verify the snap group divider UI components on default state.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"snap_group_divider_default_state",
/*revision_number=*/0, divider_widget, w1_widget, w2_widget));
// Move the mouse to the position that is a off the center(divider handler
// view).
event_generator->MoveMouseTo(
GetTopmostSnapGroupDividerBoundsInScreen().CenterPoint() +
gfx::Vector2d(0, 10));
// Verify the snap group divider UI components on mouse hover.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"snap_group_divider_hover_state",
/*revision_number=*/0, divider_widget, w1_widget, w2_widget));
}
// Visual regression test partial split screen layout.
TEST_F(SnapGroupPixelTest, PartialSplit) {
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
auto* w1_widget = views::Widget::GetWidgetForNativeView(w1.get());
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
auto* w2_widget = views::Widget::GetWidgetForNativeView(w2.get());
SnapOneTestWindow(w1.get(),
/*state_type=*/chromeos::WindowStateType::kPrimarySnapped,
chromeos::kTwoThirdSnapRatio);
VerifySplitViewOverviewSession(w1.get());
ClickOverviewItem(GetEventGenerator(), w2.get());
auto* snap_group_controller = SnapGroupController::Get();
EXPECT_TRUE(snap_group_controller->AreWindowsInSnapGroup(w1.get(), w2.get()));
auto* divider_widget = GetTopmostSnapGroupDivider()->divider_widget();
ASSERT_TRUE(divider_widget);
// Verify the snap group divider UI components on in 2/3 and 1/3 split screen
// layout.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"snap_group_partial_split",
/*revision_number=*/0, divider_widget, w1_widget, w2_widget));
}
// Visual regression test for `OverviewGroupItem`.
TEST_F(SnapGroupPixelTest, OverviewGroupItem) {
base::test::ScopedFeatureList scoped_feature_list{features::kForestFeature};
ScopedOverviewTransformWindow::SetImmediateCloseForTests(/*immediate=*/true);
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
SnapTwoTestWindows(w1.get(), /*window2=*/w2.get(), /*horizontal=*/true,
GetEventGenerator());
ToggleOverview();
ASSERT_TRUE(IsInOverviewSession());
OverviewItemBase* overview_group_item = GetOverviewItemForWindow(w1.get());
ASSERT_TRUE(overview_group_item);
auto* group_item_widget = overview_group_item->item_widget();
ASSERT_TRUE(group_item_widget);
// Verify the `OverviewGroupItem` visuals.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"overviewgroupitem",
/*revision_number=*/2, group_item_widget));
// Verify the visuals after one of the windows in the group got destroyed.
w2.reset();
OverviewItemBase* item_after_destruction = GetOverviewItemForWindow(w1.get());
ASSERT_TRUE(item_after_destruction);
auto* remaining_item_widget = item_after_destruction->item_widget();
ASSERT_TRUE(item_after_destruction);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"remaining_item_widget",
/*revision_number=*/2, remaining_item_widget));
}
// Visual regression test for Snap Group in window cycle view.
TEST_F(SnapGroupPixelTest, WindowCycleView) {
WindowCycleList::SetDisableInitialDelayForTesting(true);
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
SnapTwoTestWindows(w1.get(), w2.get(), /*horizontal=*/true,
GetEventGenerator());
// Explicitly activate the primary-snapped window so that it comes before
// secondary-snapped window in MRU order, anticipating a future Alt+Tab
// revamp.
wm::ActivateWindow(w1.get());
auto* event_generator = GetEventGenerator();
event_generator->PressAndReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
WindowCycleController* window_cycle_controller =
Shell::Get()->window_cycle_controller();
EXPECT_TRUE(window_cycle_controller->IsCycling());
const WindowCycleView* window_cycle_view =
window_cycle_controller->window_cycle_list()->cycle_view();
ASSERT_TRUE(window_cycle_view);
views::Widget* window_cycle_widget =
const_cast<views::Widget*>(window_cycle_view->GetWidget());
ASSERT_TRUE(window_cycle_widget);
// Verify the visuals with secondary-snapped window gets focused.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"window_cycle_with_snap_group_secondary_focused",
/*revision_number=*/2, window_cycle_widget));
// Verify the visuals with primary-snapped window gets focused.
event_generator->PressAndReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"window_cycle_with_snap_group_primary_focused",
/*revision_number=*/2, window_cycle_widget));
// Verify the visuals after one of the windows in the group got destroyed
// while stepping.
w2.reset();
EXPECT_TRUE(window_cycle_controller->IsCycling());
const WindowCycleView* updated_window_cycle_view =
window_cycle_controller->window_cycle_list()->cycle_view();
ASSERT_TRUE(updated_window_cycle_view);
views::Widget* updated_window_cycle_widget =
const_cast<views::Widget*>(window_cycle_view->GetWidget());
ASSERT_TRUE(updated_window_cycle_widget);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"window_cycle_with_snap_group_window_destruction",
/*revision_number=*/2, updated_window_cycle_widget));
}
// -----------------------------------------------------------------------------
// Portrait:
// Visual regression test for divider component in portrait mode (default and
// hover states).
TEST_F(SnapGroupPixelTest, SnapGroupDividerBasicInPortrait) {
UpdateDisplay("900x1200");
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
auto* w1_widget = views::Widget::GetWidgetForNativeView(w1.get());
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
auto* w2_widget = views::Widget::GetWidgetForNativeView(w2.get());
auto* event_generator = GetEventGenerator();
SnapTwoTestWindows(w1.get(), w2.get(), /*horizontal=*/false, event_generator);
auto* divider_widget = GetTopmostSnapGroupDivider()->divider_widget();
ASSERT_TRUE(divider_widget);
// Verify the snap group divider UI components on default state in portrait
// mode.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"snap_group_divider_default_state_in_portrait",
/*revision_number=*/0, divider_widget, w1_widget, w2_widget));
// Move the mouse to the position that is a off the center(divider handler
// view).
event_generator->MoveMouseTo(
GetTopmostSnapGroupDividerBoundsInScreen().CenterPoint() +
gfx::Vector2d(10, 0));
// Verify the snap group divider UI components on mouse hover in portrait
// mode.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"snap_group_divider_hover_state_in_portrait",
/*revision_number=*/0, divider_widget, w1_widget, w2_widget));
}
// Visual regression test for `OverviewGroupItem` in portrait mode.
TEST_F(SnapGroupPixelTest, OverviewGroupItemInPortrait) {
base::test::ScopedFeatureList scoped_feature_list{features::kForestFeature};
UpdateDisplay("900x1200");
ScopedOverviewTransformWindow::SetImmediateCloseForTests(/*immediate=*/true);
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
SnapTwoTestWindows(w1.get(), /*window2=*/w2.get(), /*horizontal=*/false,
GetEventGenerator());
ToggleOverview();
ASSERT_TRUE(IsInOverviewSession());
OverviewItemBase* overview_group_item = GetOverviewItemForWindow(w1.get());
ASSERT_TRUE(overview_group_item);
auto* group_item_widget = overview_group_item->item_widget();
ASSERT_TRUE(group_item_widget);
// Verify the `OverviewGroupItem` visuals in portrait.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"overviewgroupitem_in_portrait",
/*revision_number=*/2, group_item_widget));
}
// Portrait mode visual regression test for Snap Group visuals in window cycle
// view.
TEST_F(SnapGroupPixelTest, WindowCycleViewInPortrait) {
UpdateDisplay("900x1200");
WindowCycleList::SetDisableInitialDelayForTesting(true);
std::unique_ptr<aura::Window> w1(CreateAppWindow());
DecorateWindow(w1.get(), /*title=*/u"w1", SK_ColorGREEN);
std::unique_ptr<aura::Window> w2(CreateAppWindow());
DecorateWindow(w2.get(), /*title=*/u"w2", SK_ColorBLUE);
SnapTwoTestWindows(w1.get(), w2.get(), /*horizontal=*/false,
GetEventGenerator());
// Explicitly activate the primary-snapped window so that it comes before
// secondary-snapped window in MRU order, anticipating a future Alt+Tab
// revamp.
wm::ActivateWindow(w1.get());
auto* event_generator = GetEventGenerator();
event_generator->PressAndReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
WindowCycleController* window_cycle_controller =
Shell::Get()->window_cycle_controller();
EXPECT_TRUE(window_cycle_controller->IsCycling());
const WindowCycleView* window_cycle_view =
window_cycle_controller->window_cycle_list()->cycle_view();
ASSERT_TRUE(window_cycle_view);
views::Widget* window_cycle_widget =
const_cast<views::Widget*>(window_cycle_view->GetWidget());
ASSERT_TRUE(window_cycle_widget);
// Verify the visuals with secondary-snapped window gets focused.
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"window_cycle_with_snap_group_secondary_focused_in_portrait",
/*revision_number=*/2, window_cycle_widget));
// Verify the visuals with primary-snapped window gets focused.
event_generator->PressAndReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN);
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
"window_cycle_with_snap_group_primary_focused_in_portrait",
/*revision_number=*/2, window_cycle_widget));
}
} // namespace ash