#include "ui/views/controls/editable_combobox/editable_combobox.h"
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/models/simple_combobox_model.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox_util.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/menu_test_utils.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_utils.h"
#if BUILDFLAG(IS_OZONE)
#include "ui/events/ozone/layout/keyboard_layout_engine_test_utils.h"
#endif
namespace views {
namespace {
ASCIIToUTF16;
WaitForMenuClosureAnimation;
class TestContextMenuController : public ContextMenuController { … };
}
class EditableComboboxTest : public ViewsTestBase { … };
void EditableComboboxTest::SetUp() { … }
void EditableComboboxTest::TearDown() { … }
void EditableComboboxTest::InitEditableCombobox(const int item_count,
const bool filter_on_edit,
const bool show_on_empty) { … }
void EditableComboboxTest::InitEditableCombobox(
const std::vector<std::u16string>& strings,
bool filter_on_edit,
bool show_on_empty) { … }
void EditableComboboxTest::InitEditableCombobox(
const std::vector<ui::SimpleComboboxModel::Item>& items,
const bool filter_on_edit,
const bool show_on_empty) { … }
void EditableComboboxTest::InitWidget() { … }
size_t EditableComboboxTest::GetItemCount(const EditableCombobox* combobox) { … }
size_t EditableComboboxTest::GetItemCount() const { … }
std::u16string EditableComboboxTest::GetItemAt(size_t index) const { … }
ui::ImageModel EditableComboboxTest::GetIconAt(size_t index,
IconSource icon_source) const { … }
void EditableComboboxTest::ClickArrow() { … }
void EditableComboboxTest::FocusTextfield() { … }
bool EditableComboboxTest::IsTextfieldFocused() const { … }
std::u16string EditableComboboxTest::GetSelectedText() const { … }
void EditableComboboxTest::SetContextMenuController(
ContextMenuController* controller) { … }
void EditableComboboxTest::ClickTextfield() { … }
void EditableComboboxTest::DragMouseTo(const gfx::Point& location) { … }
MenuRunner* EditableComboboxTest::GetMenuRunner() { … }
bool EditableComboboxTest::IsMenuOpen() { … }
Button* EditableComboboxTest::GetArrowButton() { … }
void EditableComboboxTest::PerformMouseEvent(Widget* widget,
const gfx::Point& point,
const ui::EventType type) { … }
void EditableComboboxTest::PerformClick(Widget* widget,
const gfx::Point& point) { … }
void EditableComboboxTest::SendKeyEvent(ui::KeyboardCode key_code,
const bool alt,
const bool shift,
const bool ctrl_cmd) { … }
TEST_F(EditableComboboxTest, FocusOnTextfieldDoesntOpenMenu) { … }
TEST_F(EditableComboboxTest, ArrowDownOpensMenu) { … }
TEST_F(EditableComboboxTest, TabMovesToOtherViewAndClosesMenu) { … }
TEST_F(EditableComboboxTest,
ClickOutsideEditableComboboxWithoutLosingFocusClosesMenu) { … }
TEST_F(EditableComboboxTest, ClickTextfieldDoesntCloseMenu) { … }
TEST_F(EditableComboboxTest, RemovingControlWhileMenuOpenClosesMenu) { … }
TEST_F(EditableComboboxTest, RemovingParentOfControlWhileMenuOpenClosesMenu) { … }
TEST_F(EditableComboboxTest, LeftOrRightKeysMoveInTextfield) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_UpOrDownKeysMoveInMenu …
#else
#define MAYBE_UpOrDownKeysMoveInMenu …
#endif
TEST_F(EditableComboboxTest, MAYBE_UpOrDownKeysMoveInMenu) { … }
TEST_F(EditableComboboxTest, EndOrHomeMovesToBeginningOrEndOfText) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(EditableComboboxTest, AltLeftOrRightMovesToNextWords) {
InitEditableCombobox();
FocusTextfield();
combobox_->SetText(u"foo bar foobar");
SendKeyEvent(ui::VKEY_LEFT, true, false,
false);
SendKeyEvent(ui::VKEY_LEFT, true, false,
false);
SendKeyEvent(ui::VKEY_X);
SendKeyEvent(ui::VKEY_RIGHT, true, false,
false);
SendKeyEvent(ui::VKEY_Y);
EXPECT_EQ(u"foo xbary foobar", combobox_->GetText());
}
TEST_F(EditableComboboxTest, CtrlLeftOrRightMovesToBeginningOrEndOfText) {
InitEditableCombobox();
FocusTextfield();
SendKeyEvent(ui::VKEY_A);
SendKeyEvent(ui::VKEY_B);
SendKeyEvent(ui::VKEY_C);
SendKeyEvent(ui::VKEY_LEFT, false, false,
true);
SendKeyEvent(ui::VKEY_X);
SendKeyEvent(ui::VKEY_RIGHT, false, false,
true);
SendKeyEvent(ui::VKEY_Y);
EXPECT_EQ(u"xabcy", combobox_->GetText());
}
#else
TEST_F(EditableComboboxTest, AltLeftOrRightDoesNothing) { … }
TEST_F(EditableComboboxTest, CtrlLeftOrRightMovesToNextWords) { … }
#endif
TEST_F(EditableComboboxTest, ShiftLeftOrRightSelectsCharInTextfield) { … }
TEST_F(EditableComboboxTest, EnterClosesMenuWhileSelectingHighlightedMenuItem) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem …
#else
#define MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem …
#endif
TEST_F(EditableComboboxTest,
MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem) { … }
TEST_F(EditableComboboxTest, EscClosesMenuWithoutSelectingHighlightedMenuItem) { … }
TEST_F(EditableComboboxTest, TypingInTextfieldUnhighlightsMenuItem) { … }
TEST_F(EditableComboboxTest, SpaceIsReflectedInTextfield) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#define MAYBE_MenuCanAdaptToContentChange …
#else
#define MAYBE_MenuCanAdaptToContentChange …
#endif
TEST_F(EditableComboboxTest, MAYBE_MenuCanAdaptToContentChange) { … }
#if BUILDFLAG(IS_LINUX)
#define MAYBE_RefocusingReopensMenuBasedOnLatestContent …
#else
#define MAYBE_RefocusingReopensMenuBasedOnLatestContent …
#endif
TEST_F(EditableComboboxTest, MAYBE_RefocusingReopensMenuBasedOnLatestContent) { … }
TEST_F(EditableComboboxTest, GetItemsWithoutFiltering) { … }
TEST_F(EditableComboboxTest, FilteringEffectOnGetItems) { … }
TEST_F(EditableComboboxTest, FilteringEffectOnIcons) { … }
TEST_F(EditableComboboxTest, FilteringWithMismatchedCase) { … }
TEST_F(EditableComboboxTest, DontShowOnEmpty) { … }
TEST_F(EditableComboboxTest, NoFilteringNotifiesCallback) { … }
TEST_F(EditableComboboxTest, FilteringNotifiesCallback) { … }
TEST_F(EditableComboboxTest, ArrowButtonOpensAndClosesMenu) { … }
TEST_F(EditableComboboxTest, ShowContextMenuOnMouseRelease) { … }
TEST_F(EditableComboboxTest, DragToSelectDoesntOpenTheMenu) { … }
TEST_F(EditableComboboxTest, AccessibleNameAndRole) { … }
TEST_F(EditableComboboxTest, AccessibleValue) { … }
TEST_F(EditableComboboxTest, AccessibleArrowDefaultActionVerb) { … }
EditableComboboxDefaultTest;
class ConfigurableComboboxModel final : public ui::ComboboxModel { … };
TEST_F(EditableComboboxDefaultTest, Default) { … }
TEST_F(EditableComboboxDefaultTest, SetModel) { … }
TEST_F(EditableComboboxDefaultTest, SetModelOverwrite) { … }
}