chromium/ui/views/controls/combobox/combobox_unittest.cc

// Copyright 2013 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/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;

// A concrete class is needed to test the combobox.
class TestComboboxModel : public ui::ComboboxModel {};

// A combobox model which refers to a vector.
class VectorComboboxModel : public ui::ComboboxModel {};

class EvilListener {};

class TestComboboxListener {};

}  // namespace

class ComboboxTest : public ViewsTestBase {};

#if BUILDFLAG(IS_MAC)
// Tests whether the various Mac specific keyboard shortcuts invoke the dropdown
// menu or not.
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

// Iterate through all the metadata and test each property.
TEST_F(ComboboxTest, MetadataTest) {}

// Check that if a combobox is disabled before it has a native wrapper, then the
// native wrapper inherits the disabled state when it gets created.
TEST_F(ComboboxTest, DisabilityTest) {}

// Ensure the border on the combobox is set correctly when Enabled state
// changes.
TEST_F(ComboboxTest, DisabledBorderTest) {}

// On Mac, key events can't change the currently selected index directly for a
// combobox.
#if !BUILDFLAG(IS_MAC)

// Tests the behavior of various keyboard shortcuts on the currently selected
// index.
TEST_F(ComboboxTest, KeyTest) {}

// Verifies that we don't select a separator line in combobox when navigating
// through keyboard.
TEST_F(ComboboxTest, SkipSeparatorSimple) {}

// Verifies that we never select the separator that is in the beginning of the
// combobox list when navigating through keyboard.
TEST_F(ComboboxTest, SkipSeparatorBeginning) {}

// Verifies that we never select the separator that is in the end of the
// combobox list when navigating through keyboard.
TEST_F(ComboboxTest, SkipSeparatorEnd) {}

// Verifies that we never select any of the adjacent separators (multiple
// consecutive) that appear in the beginning of the combobox list when
// navigating through keyboard.
TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) {}

// Verifies that we never select any of the adjacent separators (multiple
// consecutive) that appear in the middle of the combobox list when navigating
// through keyboard.
TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) {}

// Verifies that we never select any of the adjacent separators (multiple
// consecutive) that appear in the end of the combobox list when navigating
// through keyboard.
TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) {}
#endif  // !BUILDFLAG(IS_MAC)

TEST_F(ComboboxTest, GetTextForRowTest) {}

// Verifies selecting the first matching value (and returning whether found).
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 that accessibility action events show the combobox dropdown.
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 that ensures that the combobox is resized correctly when selecting
// between indices of different label lengths.
TEST_F(ComboboxTest, ContentSizeUpdateOnSetSelectedIndex) {}

TEST_F(ComboboxTest, ContentWidth) {}

// Test that model updates preserve the selected index, so long as it is in
// range.
TEST_F(ComboboxTest, ModelChanged) {}

TEST_F(ComboboxTest, TypingPrefixNotifiesListener) {}

// Test properties on the Combobox menu model.
TEST_F(ComboboxTest, MenuModel) {}

// Verifies SetTooltipTextAndAccessibleName will call NotifyAccessibilityEvent.
TEST_F(ComboboxTest, SetTooltipTextNotifiesAccessibilityEvent) {}

// Regression test for crbug.com/1264288.
// Should fail in ASan build before the fix.
TEST_F(ComboboxTest, NoCrashWhenComboboxOutlivesModel) {}

namespace {

std::string GetComboboxA11yValue(Combobox* combobox) {}

ComboboxDefaultTest;

class ConfigurableComboboxModel final : public ui::ComboboxModel {};

}  // namespace

TEST_F(ComboboxDefaultTest, Default) {}

TEST_F(ComboboxDefaultTest, SetModel) {}

TEST_F(ComboboxDefaultTest, SetOwnedModel) {}

TEST_F(ComboboxDefaultTest, SetModelOverwriteOwned) {}

TEST_F(ComboboxDefaultTest, SetOwnedModelOverwriteOwned) {}

TEST_F(ComboboxDefaultTest, InteractionWithEmptyModel) {}

}  // namespace views