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
ash / quick_insert / views / quick_insert_list_item_container_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_list_item_container_view.h"
#include <memory>
#include "ash/quick_insert/views/quick_insert_list_item_view.h"
#include "ash/quick_insert/views/quick_insert_traversable_item_container.h"
#include "base/functional/callback_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/view.h"
namespace ash {
namespace {
using QuickInsertListItemContainerViewTest = views::ViewsTestBase;
TEST_F(QuickInsertListItemContainerViewTest, GetsTopItem) {
QuickInsertListItemContainerView container;
QuickInsertListItemView* top_item = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetTopItem(), top_item);
}
TEST_F(QuickInsertListItemContainerViewTest, EmptyContainerHasNoTopItem) {
QuickInsertListItemContainerView container;
EXPECT_EQ(container.GetTopItem(), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, GetsBottomItem) {
QuickInsertListItemContainerView container;
container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
QuickInsertListItemView* bottom_item = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetBottomItem(), bottom_item);
}
TEST_F(QuickInsertListItemContainerViewTest, EmptyContainerHasNoBottomItem) {
QuickInsertListItemContainerView container;
EXPECT_EQ(container.GetBottomItem(), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, GetsItemAbove) {
QuickInsertListItemContainerView container;
QuickInsertListItemView* item1 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
QuickInsertListItemView* item2 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetItemAbove(item1), nullptr);
EXPECT_EQ(container.GetItemAbove(item2), item1);
}
TEST_F(QuickInsertListItemContainerViewTest, ItemNotInContainerHasNoItemAbove) {
QuickInsertListItemContainerView container;
QuickInsertListItemView item_not_in_container(base::DoNothing());
EXPECT_EQ(container.GetItemAbove(&item_not_in_container), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, GetsItemBelow) {
QuickInsertListItemContainerView container;
QuickInsertListItemView* item1 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
QuickInsertListItemView* item2 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetItemBelow(item1), item2);
EXPECT_EQ(container.GetItemBelow(item2), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, ItemNotInContainerHasNoItemBelow) {
QuickInsertListItemContainerView container;
QuickInsertListItemView item_not_in_container(base::DoNothing());
EXPECT_EQ(container.GetItemBelow(&item_not_in_container), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, NoItemLeftOf) {
QuickInsertListItemContainerView container;
QuickInsertListItemView* item1 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
QuickInsertListItemView* item2 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetItemLeftOf(item1), nullptr);
EXPECT_EQ(container.GetItemLeftOf(item2), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, NoItemRightOf) {
QuickInsertListItemContainerView container;
QuickInsertListItemView* item1 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
QuickInsertListItemView* item2 = container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.GetItemRightOf(item1), nullptr);
EXPECT_EQ(container.GetItemRightOf(item2), nullptr);
}
TEST_F(QuickInsertListItemContainerViewTest, ChildrenHasListItemRole) {
QuickInsertListItemContainerView container;
container.AddListItem(
std::make_unique<QuickInsertListItemView>(base::DoNothing()));
EXPECT_EQ(container.children()[0]->GetAccessibleRole(),
ax::mojom::Role::kListItem);
}
} // namespace
} // namespace ash