#include "ui/views/controls/combobox/combobox.h"
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/models/combobox_model_observer.h"
#include "ui/base/models/menu_model.h"
#include "ui/base/models/simple_combobox_model.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.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/text_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/style/platform_style.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/test/combobox_test_api.h"
#include "ui/views/test/view_metadata_test_utils.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/widget/unique_widget_ptr.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_utils.h"
ASCIIToUTF16;
namespace views {
ComboboxTestApi;
namespace {
TestCombobox;
class TestComboboxModel : public ui::ComboboxModel { … };
class VectorComboboxModel : public ui::ComboboxModel { … };
class EvilListener { … };
class TestComboboxListener { … };
}
class ComboboxTest : public ViewsTestBase { … };
#if BUILDFLAG(IS_MAC)
TEST_F(ComboboxTest, KeyTestMac) {
InitCombobox(nullptr);
PressKey(ui::VKEY_END);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(1, menu_show_count_);
PressKey(ui::VKEY_HOME);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(2, menu_show_count_);
PressKey(ui::VKEY_UP, ui::EF_COMMAND_DOWN);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(3, menu_show_count_);
PressKey(ui::VKEY_DOWN, ui::EF_COMMAND_DOWN);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(4, menu_show_count_);
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(5, menu_show_count_);
PressKey(ui::VKEY_RIGHT);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(5, menu_show_count_);
PressKey(ui::VKEY_LEFT);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(5, menu_show_count_);
PressKey(ui::VKEY_UP);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(6, menu_show_count_);
PressKey(ui::VKEY_PRIOR);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(6, menu_show_count_);
PressKey(ui::VKEY_NEXT);
EXPECT_EQ(0u, combobox()->GetSelectedIndex());
EXPECT_EQ(6, menu_show_count_);
}
#endif
TEST_F(ComboboxTest, MetadataTest) { … }
TEST_F(ComboboxTest, DisabilityTest) { … }
TEST_F(ComboboxTest, DisabledBorderTest) { … }
#if !BUILDFLAG(IS_MAC)
TEST_F(ComboboxTest, KeyTest) { … }
TEST_F(ComboboxTest, SkipSeparatorSimple) { … }
TEST_F(ComboboxTest, SkipSeparatorBeginning) { … }
TEST_F(ComboboxTest, SkipSeparatorEnd) { … }
TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { … }
TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { … }
TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { … }
#endif
TEST_F(ComboboxTest, GetTextForRowTest) { … }
TEST_F(ComboboxTest, SelectValue) { … }
TEST_F(ComboboxTest, ListenerHandlesDelete) { … }
TEST_F(ComboboxTest, Click) { … }
TEST_F(ComboboxTest, ClickButDisabled) { … }
TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { … }
TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { … }
TEST_F(ComboboxTest, ShowViaAccessibleAction) { … }
TEST_F(ComboboxTest, ExpandedCollapsedAccessibleState) { … }
TEST_F(ComboboxTest, AccessibleDefaultActionVerb) { … }
TEST_F(ComboboxTest, SetSizePosInSetAccessibleProperties) { … }
TEST_F(ComboboxTest, AccessibleValue) { … }
TEST_F(ComboboxTest, NotifyOnClickWithMouse) { … }
TEST_F(ComboboxTest, ConsumingPressKeyEvents) { … }
TEST_F(ComboboxTest, ContentSizeUpdateOnSetSelectedIndex) { … }
TEST_F(ComboboxTest, ContentWidth) { … }
TEST_F(ComboboxTest, ModelChanged) { … }
TEST_F(ComboboxTest, TypingPrefixNotifiesListener) { … }
TEST_F(ComboboxTest, MenuModel) { … }
TEST_F(ComboboxTest, SetTooltipTextNotifiesAccessibilityEvent) { … }
TEST_F(ComboboxTest, NoCrashWhenComboboxOutlivesModel) { … }
namespace {
std::string GetComboboxA11yValue(Combobox* combobox) { … }
ComboboxDefaultTest;
class ConfigurableComboboxModel final : public ui::ComboboxModel { … };
}
TEST_F(ComboboxDefaultTest, Default) { … }
TEST_F(ComboboxDefaultTest, SetModel) { … }
TEST_F(ComboboxDefaultTest, SetOwnedModel) { … }
TEST_F(ComboboxDefaultTest, SetModelOverwriteOwned) { … }
TEST_F(ComboboxDefaultTest, SetOwnedModelOverwriteOwned) { … }
TEST_F(ComboboxDefaultTest, InteractionWithEmptyModel) { … }
}