#include "ui/views/controls/menu/menu_runner.h"
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_tick_clock.h"
#include "build/build_config.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/compositor.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/controls/menu/menu_delegate.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner_impl.h"
#include "ui/views/controls/menu/menu_types.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/controls/menu/test_menu_item_view.h"
#include "ui/views/test/menu_test_utils.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_utils.h"
#if BUILDFLAG(IS_MAC)
#include "ui/views/controls/menu/menu_cocoa_watcher_mac.h"
#endif
namespace views::test {
class MenuRunnerTest : public ViewsTestBase { … };
TEST_F(MenuRunnerTest, AsynchronousRun) { … }
TEST_F(MenuRunnerTest, AsynchronousKeyEventHandling) { … }
#if BUILDFLAG(IS_OZONE)
#define MAYBE_LatinMnemonic …
#else
#define MAYBE_LatinMnemonic …
#endif
TEST_F(MenuRunnerTest, MAYBE_LatinMnemonic) { … }
#if !BUILDFLAG(IS_WIN)
TEST_F(MenuRunnerTest, NonLatinMnemonic) { … }
#endif
TEST_F(MenuRunnerTest, MenuItemViewShowsMnemonics) { … }
TEST_F(MenuRunnerTest, MenuItemViewDoesNotShowMnemonics) { … }
TEST_F(MenuRunnerTest, PrefixSelect) { … }
#if BUILDFLAG(IS_MAC)
TEST_F(MenuRunnerTest, SpaceActivatesItem) {
if (!MenuConfig::instance().all_menus_use_prefix_selection)
return;
views::test::DisableMenuClosureAnimations();
InitMenuRunner(0);
MenuRunner* runner = menu_runner();
runner->RunMenuAt(owner(), nullptr, gfx::Rect(), MenuAnchorPosition::kTopLeft,
ui::MENU_SOURCE_NONE, nullptr);
EXPECT_TRUE(runner->IsRunning());
ui::test::EventGenerator generator(GetContext(), owner()->GetNativeWindow());
generator.PressKey(ui::VKEY_DOWN, 0);
EXPECT_TRUE(IsItemSelected(1));
generator.PressKey(ui::VKEY_SPACE, 0);
views::test::WaitForMenuClosureAnimation();
EXPECT_FALSE(runner->IsRunning());
TestMenuDelegate* delegate = menu_delegate();
EXPECT_EQ(1, delegate->execute_command_id());
EXPECT_EQ(1, delegate->on_menu_closed_called());
EXPECT_NE(nullptr, delegate->on_menu_closed_menu());
}
#endif
TEST_F(MenuRunnerTest, NestingDuringDrag) { … }
namespace {
class MenuLauncherEventHandler : public ui::EventHandler { … };
}
class MenuRunnerWidgetTest : public MenuRunnerTest { … };
TEST_F(MenuRunnerWidgetTest, WidgetDoesntTakeCapture) { … }
TEST_F(MenuRunnerWidgetTest, ClearsMouseHandlerOnRun) { … }
class MenuRunnerImplTest : public MenuRunnerTest { … };
TEST_F(MenuRunnerImplTest, NestedMenuRunnersDestroyedOutOfOrder) { … }
TEST_F(MenuRunnerImplTest, MenuRunnerDestroyedWithNoActiveController) { … }
class MenuRunnerDestructionTest : public MenuRunnerTest { … };
base::WeakPtr<internal::MenuRunnerImpl>
MenuRunnerDestructionTest::MenuRunnerAsWeakPtr(
internal::MenuRunnerImpl* menu_runner) { … }
void MenuRunnerDestructionTest::SetUp() { … }
TEST_F(MenuRunnerDestructionTest, MenuRunnerDestroyedDuringReleaseRef) { … }
TEST_F(MenuRunnerImplTest, FocusOnMenuClose) { … }
TEST_F(MenuRunnerImplTest, FocusOnMenuCloseDeleteAfterRun) { … }
TEST_F(MenuRunnerTest, ShowMenuHostDurationMetricsDoesLog) { … }
TEST_F(MenuRunnerTest, ShowMenuHostDurationMetricsDoesNotLog) { … }
}