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
ash / wm / overview / birch / birch_bar_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 "ash/birch/birch_client.h"
#include "ash/birch/birch_item.h"
#include "ash/birch/birch_model.h"
#include "ash/birch/stub_birch_client.h"
#include "ash/public/cpp/test/test_image_downloader.h"
#include "ash/shell.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 "ash/wm/overview/overview_grid_test_api.h"
#include "base/test/scoped_feature_list.h"
#include "ui/gfx/image/image_unittest_util.h"
namespace ash {
namespace {
std::vector<std::unique_ptr<BirchItem>> CreateItems(BirchItemType type) {
static const GURL kTestURL("https://www.example.com");
static const GURL kTestFaviconURL("https://www.favicon.com");
std::vector<std::unique_ptr<BirchItem>> items;
switch (type) {
case BirchItemType::kCalendar:
items.push_back(std::make_unique<BirchCalendarItem>(
/*title=*/u"Event",
/*start_time=*/base::Time(),
/*end_time=*/base::Time(),
/*calendar_url=*/kTestURL,
/*conference_url=*/kTestURL,
/*event_id=*/"event_id",
/*all_day_event=*/false));
items.push_back(std::make_unique<BirchCalendarItem>(
/*title=*/u"Event",
/*start_time=*/base::Time(),
/*end_time=*/base::Time(),
/*calendar_url=*/GURL(),
/*conference_url=*/kTestURL,
/*event_id=*/"event_id",
/*all_day_event=*/false));
break;
case BirchItemType::kAttachment:
items.push_back(std::make_unique<BirchAttachmentItem>(
/*title=*/u"Attachment",
/*file_url=*/kTestURL,
/*favicon_url=*/kTestFaviconURL,
/*start_time=*/base::Time(),
/*end_time=*/base::Time(),
/*file_id=*/"file_id"));
break;
case BirchItemType::kFile:
items.push_back(std::make_unique<BirchFileItem>(
/*file_path=*/base::FilePath("test path"), /*title=*/std::nullopt,
/*justification=*/u"suggestion",
/*timestamp=*/base::Time(),
/*file_id=*/"file_id_0",
/*icon_url=*/"icon_url"));
break;
case BirchItemType::kTab:
items.push_back(std::make_unique<BirchTabItem>(
/*title=*/u"tab", /*url=*/kTestURL,
/*timestamp=*/base::Time(),
/*favicon_url=*/kTestFaviconURL,
/*session_name=*/"session",
/*form_factor=*/BirchTabItem::DeviceFormFactor::kDesktop));
break;
case BirchItemType::kWeather:
items.push_back(std::make_unique<BirchWeatherItem>(
/*weather_description=*/u"cloudy",
/*temperature=*/72.f,
/*icon_url=*/GURL("http://icon.com/")));
break;
case BirchItemType::kReleaseNotes:
items.push_back(std::make_unique<BirchReleaseNotesItem>(
/*release_notes_title=*/u"note",
/*release_notes_text=*/u"explore",
/*url=*/kTestURL,
/*first_seen=*/base::Time()));
break;
case BirchItemType::kSelfShare:
items.push_back(std::make_unique<BirchSelfShareItem>(
/*guid=*/u"self share guid", /*title*/ u"self share tab",
/*url=*/kTestURL,
/*shared_time=*/base::Time(), /*device_name=*/u"my device",
/*secondary_icon_type=*/SecondaryIconType::kTabFromDesktop,
/*activation_callback=*/base::DoNothing()));
break;
case BirchItemType::kMostVisited:
items.push_back(std::make_unique<BirchMostVisitedItem>(
/*title=*/u"Most Visited",
/*url=*/kTestURL));
break;
case BirchItemType::kLastActive:
items.push_back(std::make_unique<BirchLastActiveItem>(
/*title=*/u"Last Active",
/*url=*/kTestURL,
/*last_visit=*/base::Time()));
break;
case BirchItemType::kLostMedia:
items.push_back(std::make_unique<BirchLostMediaItem>(
/*source_url=*/kTestURL,
/*media_title=*/u"lost media",
/*backup_icon=*/std::nullopt,
/*secondary_icon_type=*/SecondaryIconType::kLostMediaVideoConference,
/*activation_callback=*/base::DoNothing()));
items.push_back(std::make_unique<BirchLostMediaItem>(
/*source_url=*/kTestURL,
/*media_title=*/u"lost media",
/*backup_icon=*/std::nullopt,
/*secondary_icon_type=*/SecondaryIconType::kLostMediaVideo,
/*activation_callback=*/base::DoNothing()));
break;
case BirchItemType::kCoral: {
// TODO(zxdan): Create coral pixel tests in a separate test set.
break;
}
case BirchItemType::kTest:
break;
}
return items;
}
} // namespace
struct TestParams {
std::vector<BirchItemType> types;
std::string name;
};
class BirchBarPixelTest : public AshTestBase,
public testing::WithParamInterface<TestParams> {
public:
BirchBarPixelTest() {
scoped_feature_list_.InitWithFeatures(
{features::kForestFeature, features::kBirchWeather}, {});
}
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
Shell::Get()->birch_model()->SetClientAndInit(&stub_birch_client_);
image_downloader_ = std::make_unique<TestImageDownloader>();
}
void TearDown() override {
Shell::Get()->birch_model()->SetClientAndInit(nullptr);
AshTestBase::TearDown();
}
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
private:
StubBirchClient stub_birch_client_;
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<TestImageDownloader> image_downloader_;
};
const TestParams kTestParams[] = {
{.types = {BirchItemType::kCalendar, BirchItemType::kAttachment,
BirchItemType::kFile},
.name = "Calendar_Attachment_File"},
{.types = {BirchItemType::kTab, BirchItemType::kWeather,
BirchItemType::kReleaseNotes, BirchItemType::kSelfShare},
.name = "Tab_Weather_ReleaseNotes_SelfShare"},
{.types = {BirchItemType::kMostVisited, BirchItemType::kLastActive,
BirchItemType::kLostMedia},
.name = "MostVisited_LastActive_LostMedia"}};
INSTANTIATE_TEST_SUITE_P(
All,
BirchBarPixelTest,
testing::ValuesIn(kTestParams),
[](const testing::TestParamInfo<BirchBarPixelTest::ParamType>& info) {
return info.param.name;
});
// TODO(crbug.com/354748639): This test is flaky.
TEST_P(BirchBarPixelTest, DISABLED_VerifyBirchChips) {
EnterOverview();
OverviewGridTestApi overview_test_api(Shell::GetPrimaryRootWindow());
BirchBarView* birch_bar_view = overview_test_api.birch_bar_view();
ASSERT_TRUE(birch_bar_view);
const TestParams& param = GetParam();
std::vector<std::unique_ptr<BirchItem>> items_on_bar;
for (const BirchItemType& type : param.types) {
for (auto& item : CreateItems(type)) {
items_on_bar.emplace_back(std::move(item));
}
}
for (size_t i = 0; i < items_on_bar.size(); i++) {
birch_bar_view->AddChip(items_on_bar[i].get());
}
EXPECT_TRUE(GetPixelDiffer()->CompareUiComponentsOnPrimaryScreen(
param.name, /*revision_number=*/1, birch_bar_view));
// Manually shut down chips of birch bar to avoid dangling ptrs of the fake
// birch items.
birch_bar_view->ShutdownChips();
}
} // namespace ash