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
ash / quick_insert / views / quick_insert_submenu_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_submenu_view.h"
#include <memory>
#include <utility>
#include <vector>
#include "ash/quick_insert/views/quick_insert_item_view.h"
#include "ash/quick_insert/views/quick_insert_list_item_view.h"
#include "ash/quick_insert/views/quick_insert_pseudo_focus.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/test/test_future.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/test/views_test_base.h"
namespace ash {
namespace {
constexpr gfx::Rect kDefaultAnchorBounds(200, 100, 100, 10);
using QuickInsertSubmenuViewTest = views::ViewsTestBase;
TEST_F(QuickInsertSubmenuViewTest, GetsTopItem) {
std::vector<std::unique_ptr<QuickInsertListItemView>> items;
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
auto* top_item_ptr = items.front().get();
QuickInsertSubmenuView submenu_view(kDefaultAnchorBounds, std::move(items));
EXPECT_EQ(submenu_view.GetTopItem(), top_item_ptr);
}
TEST_F(QuickInsertSubmenuViewTest, GetsBottomItem) {
std::vector<std::unique_ptr<QuickInsertListItemView>> items;
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
auto* bottom_item_ptr = items.back().get();
QuickInsertSubmenuView submenu_view(kDefaultAnchorBounds, std::move(items));
EXPECT_EQ(submenu_view.GetBottomItem(), bottom_item_ptr);
}
TEST_F(QuickInsertSubmenuViewTest, GetsItemAbove) {
std::vector<std::unique_ptr<QuickInsertListItemView>> items;
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
auto* top_item_ptr = items.front().get();
auto* bottom_item_ptr = items.back().get();
QuickInsertSubmenuView submenu_view(kDefaultAnchorBounds, std::move(items));
EXPECT_EQ(submenu_view.GetItemAbove(top_item_ptr), nullptr);
EXPECT_EQ(submenu_view.GetItemAbove(bottom_item_ptr), top_item_ptr);
}
TEST_F(QuickInsertSubmenuViewTest, GetItemBelow) {
std::vector<std::unique_ptr<QuickInsertListItemView>> items;
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
items.push_back(std::make_unique<QuickInsertListItemView>(base::DoNothing()));
auto* top_item_ptr = items.front().get();
auto* bottom_item_ptr = items.back().get();
QuickInsertSubmenuView submenu_view(kDefaultAnchorBounds, std::move(items));
EXPECT_EQ(submenu_view.GetItemBelow(top_item_ptr), bottom_item_ptr);
EXPECT_EQ(submenu_view.GetItemBelow(bottom_item_ptr), nullptr);
}
TEST_F(QuickInsertSubmenuViewTest, TriggersItemCallbackOnPseudoFocusAction) {
std::vector<std::unique_ptr<QuickInsertListItemView>> items;
base::test::TestFuture<void> select_item_future;
items.push_back(std::make_unique<QuickInsertListItemView>(
select_item_future.GetRepeatingCallback()));
QuickInsertSubmenuView submenu_view(kDefaultAnchorBounds, std::move(items));
EXPECT_TRUE(
DoQuickInsertPseudoFocusedActionOnView(submenu_view.GetTopItem()));
EXPECT_TRUE(select_item_future.Wait());
}
} // namespace
} // namespace ash