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
ash / quick_insert / views / quick_insert_image_item_row_view_unittest.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/quick_insert/views/quick_insert_image_item_row_view.h"
#include <memory>
#include <string>
#include <utility>
#include "ash/quick_insert/views/quick_insert_image_item_view.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/view.h"
namespace ash {
namespace {
using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::Pointee;
using ::testing::Property;
std::unique_ptr<QuickInsertImageItemView> CreateImageItem() {
return std::make_unique<QuickInsertImageItemView>(
std::make_unique<views::ImageView>(ui::ImageModel::FromImageSkia(
gfx::test::CreateImageSkia(/*size=*/100))),
u"image", base::DoNothing());
}
using QuickInsertImageItemRowViewTest = views::ViewsTestBase;
TEST_F(QuickInsertImageItemRowViewTest, HasGridRole) {
QuickInsertImageItemRowView item_row;
EXPECT_EQ(item_row.GetAccessibleRole(), ax::mojom::Role::kGrid);
}
TEST_F(QuickInsertImageItemRowViewTest, HasRowOfItems) {
QuickInsertImageItemRowView item_row;
EXPECT_THAT(item_row.children(),
Contains(Pointee(Property(&views::View::GetAccessibleRole,
ax::mojom::Role::kRow))));
}
TEST_F(QuickInsertImageItemRowViewTest, CreatesImageItems) {
QuickInsertImageItemRowView item_row;
views::View* item1 = item_row.AddImageItem(CreateImageItem());
views::View* item2 = item_row.AddImageItem(CreateImageItem());
// Two columns, one item in each column.
EXPECT_THAT(item_row.GetItems(), ElementsAre(item1, item2));
}
TEST_F(QuickInsertImageItemRowViewTest, ImageItemsAreResizedToSameWidth) {
QuickInsertImageItemRowView item_row;
item_row.SetPreferredSize(gfx::Size(320, 60));
views::View* item1 = item_row.AddImageItem(CreateImageItem());
views::View* item2 = item_row.AddImageItem(CreateImageItem());
EXPECT_EQ(item1->GetPreferredSize().width(),
item2->GetPreferredSize().width());
}
TEST_F(QuickInsertImageItemRowViewTest, GetsTopItem) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
item_row->AddImageItem(CreateImageItem());
item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetTopItem(), item1);
}
TEST_F(QuickInsertImageItemRowViewTest, EmptyRowTopItemIsMoreItemsButton) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
EXPECT_EQ(item_row->GetTopItem(), item_row->GetMoreItemsButtonForTesting());
}
TEST_F(QuickInsertImageItemRowViewTest, GetsBottomItem) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
item_row->AddImageItem(CreateImageItem());
item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetBottomItem(), item1);
}
TEST_F(QuickInsertImageItemRowViewTest, EmptyRowBottomItemIsMoreItemsButton) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
EXPECT_EQ(item_row->GetBottomItem(),
item_row->GetMoreItemsButtonForTesting());
}
TEST_F(QuickInsertImageItemRowViewTest, GetsItemAbove) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
views::View* item2 = item_row->AddImageItem(CreateImageItem());
views::View* item3 = item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetItemAbove(item1), nullptr);
EXPECT_EQ(item_row->GetItemAbove(item2), nullptr);
EXPECT_EQ(item_row->GetItemAbove(item3), nullptr);
EXPECT_EQ(item_row->GetItemAbove(item_row->GetMoreItemsButtonForTesting()),
nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemNotInRowHasNoItemAbove) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
std::unique_ptr<QuickInsertImageItemView> item_not_in_row = CreateImageItem();
EXPECT_EQ(item_row->GetItemAbove(item_not_in_row.get()), nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, GetsItemBelow) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
views::View* item2 = item_row->AddImageItem(CreateImageItem());
views::View* item3 = item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetItemBelow(item1), nullptr);
EXPECT_EQ(item_row->GetItemBelow(item2), nullptr);
EXPECT_EQ(item_row->GetItemBelow(item3), nullptr);
EXPECT_EQ(item_row->GetItemBelow(item_row->GetMoreItemsButtonForTesting()),
nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemNotInRowHasNoItemBelow) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
std::unique_ptr<QuickInsertImageItemView> item_not_in_row = CreateImageItem();
EXPECT_EQ(item_row->GetItemBelow(item_not_in_row.get()), nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, GetsItemLeftOf) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
views::View* item2 = item_row->AddImageItem(CreateImageItem());
views::View* item3 = item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetItemLeftOf(item1), nullptr);
EXPECT_EQ(item_row->GetItemLeftOf(item2), item1);
EXPECT_EQ(item_row->GetItemLeftOf(item3), item2);
EXPECT_EQ(item_row->GetItemLeftOf(item_row->GetMoreItemsButtonForTesting()),
item3);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemLeftOfMoreItemsButtonInEmptyRow) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
EXPECT_EQ(item_row->GetItemLeftOf(item_row->GetMoreItemsButtonForTesting()),
nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemNotInRowHasNoItemLeftOf) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
std::unique_ptr<QuickInsertImageItemView> item_not_in_row = CreateImageItem();
EXPECT_EQ(item_row->GetItemLeftOf(item_not_in_row.get()), nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, GetsItemRightOf) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
views::View* item1 = item_row->AddImageItem(CreateImageItem());
views::View* item2 = item_row->AddImageItem(CreateImageItem());
views::View* item3 = item_row->AddImageItem(CreateImageItem());
EXPECT_EQ(item_row->GetItemRightOf(item1), item2);
EXPECT_EQ(item_row->GetItemRightOf(item2), item3);
EXPECT_EQ(item_row->GetItemRightOf(item3),
item_row->GetMoreItemsButtonForTesting());
EXPECT_EQ(item_row->GetItemRightOf(item_row->GetMoreItemsButtonForTesting()),
nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemRightOfMoreItemsButtonInEmptyRow) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
EXPECT_EQ(item_row->GetItemRightOf(item_row->GetMoreItemsButtonForTesting()),
nullptr);
}
TEST_F(QuickInsertImageItemRowViewTest, ItemNotInRowHasNoItemRightOf) {
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::CLIENT_OWNS_WIDGET);
QuickInsertImageItemRowView* item_row =
widget->SetContentsView(std::make_unique<QuickInsertImageItemRowView>());
std::unique_ptr<QuickInsertImageItemView> item_not_in_row = CreateImageItem();
EXPECT_EQ(item_row->GetItemRightOf(item_not_in_row.get()), nullptr);
}
} // namespace
} // namespace ash