chromium/ui/views/controls/editable_combobox/editable_combobox_unittest.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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;

// No-op test double of a ContextMenuController
class TestContextMenuController : public ContextMenuController {};

}  // namespace

class EditableComboboxTest : public ViewsTestBase {};

void EditableComboboxTest::SetUp() {}

void EditableComboboxTest::TearDown() {}

// Initializes the combobox with the given number of items.
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) {}

// Initializes the combobox with the given items.
void EditableComboboxTest::InitEditableCombobox(
    const std::vector<ui::SimpleComboboxModel::Item>& items,
    const bool filter_on_edit,
    const bool show_on_empty) {}

// Initializes the widget where the combobox and the dummy control live.
void EditableComboboxTest::InitWidget() {}

// static
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)
// Flaky on Windows. https://crbug.com/965601
#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, /*alt=*/true, /*shift=*/false,
               /*ctrl_cmd=*/false);
  SendKeyEvent(ui::VKEY_LEFT, /*alt=*/true, /*shift=*/false,
               /*ctrl_cmd=*/false);
  SendKeyEvent(ui::VKEY_X);
  SendKeyEvent(ui::VKEY_RIGHT, /*alt=*/true, /*shift=*/false,
               /*ctrl_cmd=*/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, /*alt=*/false, /*shift=*/false,
               /*ctrl_cmd=*/true);
  SendKeyEvent(ui::VKEY_X);
  SendKeyEvent(ui::VKEY_RIGHT, /*alt=*/false, /*shift=*/false,
               /*ctrl_cmd=*/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)
// Flaky on Windows. https://crbug.com/965601
#define MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem
#else
#define MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem
#endif
TEST_F(EditableComboboxTest,
       MAYBE_F4ClosesMenuWhileSelectingHighlightedMenuItem) {}

TEST_F(EditableComboboxTest, EscClosesMenuWithoutSelectingHighlightedMenuItem) {}

TEST_F(EditableComboboxTest, TypingInTextfieldUnhighlightsMenuItem) {}

// This is different from the regular read-only Combobox, where SPACE
// opens/closes the menu.
TEST_F(EditableComboboxTest, SpaceIsReflectedInTextfield) {}

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
// Flaky on Windows and Linux. https://crbug.com/965601
#define MAYBE_MenuCanAdaptToContentChange
#else
#define MAYBE_MenuCanAdaptToContentChange
#endif
// We test that the menu can adapt to content change by using an
// EditableCombobox with |filter_on_edit| set to true, which will change the
// menu's content as the user types.
TEST_F(EditableComboboxTest, MAYBE_MenuCanAdaptToContentChange) {}

#if BUILDFLAG(IS_LINUX)
// Flaky on Linux. https://crbug.com/1204584
#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) {}

}  // namespace views