#include <stddef.h>
#include "base/check.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/combobox_model.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/test/focus_manager_test.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
ASCIIToUTF16;
namespace views {
namespace {
enum { … };
class DummyComboboxModel : public ui::ComboboxModel { … };
class PaneView : public View, public FocusTraversable { … };
BEGIN_METADATA(…)
class BorderView : public NativeViewHost { … };
BEGIN_METADATA(…)
}
class FocusTraversalTest : public FocusManagerTest { … };
FocusTraversalTest::FocusTraversalTest() = default;
FocusTraversalTest::~FocusTraversalTest() = default;
void FocusTraversalTest::InitContentView() { … }
TEST_F(FocusTraversalTest, NormalTraversal) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(FocusTraversalTest, NormalTraversalMac) {
GetFocusManager()->SetKeyboardAccessible(false);
const int kTraversalIDs[] = {APPLE_TEXTFIELD_ID, ORANGE_TEXTFIELD_ID,
BANANA_TEXTFIELD_ID, KIWI_TEXTFIELD_ID,
STYLE_TEXT_EDIT_ID, SEARCH_TEXTFIELD_ID,
THUMBNAIL_CONTAINER_ID};
SCOPED_TRACE("NormalTraversalMac");
GetFocusManager()->ClearFocus();
AdvanceEntireFocusLoop(kTraversalIDs, false);
GetFocusManager()->ClearFocus();
AdvanceEntireFocusLoop(kTraversalIDs, true);
}
TEST_F(FocusTraversalTest, FullKeyboardToggle) {
FindViewByID(TOP_CHECKBOX_ID)->RequestFocus();
EXPECT_EQ(TOP_CHECKBOX_ID, GetFocusManager()->GetFocusedView()->GetID());
GetFocusManager()->SetKeyboardAccessible(false);
EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->GetID());
GetFocusManager()->SetKeyboardAccessible(true);
EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->GetID());
FindViewByID(SEARCH_BUTTON_ID)->RequestFocus();
EXPECT_EQ(SEARCH_BUTTON_ID, GetFocusManager()->GetFocusedView()->GetID());
GetFocusManager()->SetKeyboardAccessible(false);
EXPECT_EQ(THUMBNAIL_CONTAINER_ID,
GetFocusManager()->GetFocusedView()->GetID());
GetFocusManager()->AdvanceFocus(false);
EXPECT_EQ(APPLE_TEXTFIELD_ID, GetFocusManager()->GetFocusedView()->GetID());
GetFocusManager()->AdvanceFocus(true);
EXPECT_EQ(THUMBNAIL_CONTAINER_ID,
GetFocusManager()->GetFocusedView()->GetID());
}
#endif
TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { … }
TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) { … }
TEST_F(FocusTraversalTest, PaneTraversal) { … }
TEST_F(FocusTraversalTest, TraversesFocusInFocusOrder) { … }
class FocusTraversalNonFocusableTest : public FocusManagerTest { … };
void FocusTraversalNonFocusableTest::InitContentView() { … }
TEST_F(FocusTraversalNonFocusableTest, PathologicalSiblingTraversal) { … }
}