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
ash / user_education / welcome_tour / welcome_tour_test_util.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/user_education/welcome_tour/welcome_tour_test_util.h"
#include <string>
#include <vector>
#include "ash/display/window_tree_host_manager.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/style/ash_color_provider_source.h"
#include "ash/user_education/user_education_help_bubble_controller.h"
#include "ash/user_education/welcome_tour/welcome_tour_dialog.h"
#include "ash/user_education/welcome_tour/welcome_tour_scrim.h"
#include "ash/wm/window_state.h"
#include "base/test/run_until.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_provider.h"
#include "ui/compositor/layer.h"
namespace ash {
namespace {
// Aliases.
using ::testing::AllOf;
using ::testing::Conditional;
using ::testing::Contains;
using ::testing::Eq;
using ::testing::Matches;
using ::testing::Not;
// Matchers --------------------------------------------------------------------
MATCHER_P(BackgroundBlur, matcher, "") {
return Matches(matcher)(arg->background_blur());
}
MATCHER_P(BackgroundColor, matcher, "") {
return Matches(matcher)(arg->background_color());
}
MATCHER_P(Bounds, matcher, "") {
return Matches(matcher)(arg->bounds());
}
MATCHER_P2(Index, i, matcher, "") {
return Matches(matcher)(arg.at(i));
}
MATCHER_P(MaskLayer, matcher, "") {
return Matches(matcher)(arg->layer_mask_layer());
}
MATCHER_P(Name, matcher, "") {
return Matches(matcher)(arg->name());
}
// Helpers ---------------------------------------------------------------------
std::vector<RootWindowController*> GetAllRootWindowControllers() {
return Shell::Get()
->window_tree_host_manager()
->GetAllRootWindowControllers();
}
SkColor GetColor(RootWindowController* controller, ui::ColorId id) {
return controller->color_provider_source()->GetColorProvider()->GetColor(id);
}
gfx::Rect GetLocalBounds(const aura::Window* window) {
return gfx::Rect(window->bounds().size());
}
aura::Window* GetHelpBubbleContainer(RootWindowController* controller) {
return controller->GetRootWindow()->GetChildById(
kShellWindowId_HelpBubbleContainer);
}
bool HelpBubblesExist() {
if (auto* controller = UserEducationHelpBubbleController::Get()) {
return !controller->help_bubble_metadata_by_key().empty();
}
return false;
}
} // namespace
// Utilities -------------------------------------------------------------------
void ExpectScrimsOnAllRootWindows(bool exist) {
for (auto* controller : GetAllRootWindowControllers()) {
auto* const help_bubble_container = GetHelpBubbleContainer(controller);
EXPECT_THAT(
help_bubble_container->layer()->children(),
Conditional(
exist,
Index(
0,
AllOf(Name(Eq(WelcomeTourScrim::kLayerName)),
BackgroundBlur(Conditional(HelpBubblesExist(), 3.f, 0.f)),
BackgroundColor(
GetColor(controller, cros_tokens::kCrosSysScrim)),
Bounds(GetLocalBounds(help_bubble_container)),
MaskLayer(AllOf(
Name(Eq(WelcomeTourScrim::kMaskLayerName)),
Bounds(GetLocalBounds(help_bubble_container)))))),
Not(Contains(Name(Eq(WelcomeTourScrim::kLayerName))))));
}
}
const views::View* GetDialogAcceptButton() {
if (auto* const dialog = WelcomeTourDialog::Get()) {
return dialog->GetViewByID(
ViewID::VIEW_ID_STYLE_SYSTEM_DIALOG_DELEGATE_ACCEPT_BUTTON);
}
return nullptr;
}
const views::View* GetDialogCancelButton() {
if (auto* const dialog = WelcomeTourDialog::Get()) {
return dialog->GetViewByID(
ViewID::VIEW_ID_STYLE_SYSTEM_DIALOG_DELEGATE_CANCEL_BUTTON);
}
return nullptr;
}
bool WaitUntilMinimized(aura::Window* window) {
return base::test::RunUntil([&]() {
auto* state = WindowState::Get(window);
return state && state->IsMinimized();
});
}
} // namespace ash