chromium/chrome/browser/ui/views/menu_item_view_interactive_uitest.cc

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

#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/ui/views/menu_test_base.h"
#include "ui/base/themed_vector_icon.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"

ASCIIToUTF16;

// Simple test for clicking a menu item.  This template class clicks on an
// item and checks that the returned id matches.  The index of the item
// is the template argument.
template <int INDEX>
class MenuItemViewTestBasic : public MenuTestBase {};

// Click each item of a 3-item menu (with separator).
MenuItemViewTestBasic0;
MenuItemViewTestBasic1;
MenuItemViewTestBasic2;
// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestBasic0, SelectItem0)
VIEW_TEST(MenuItemViewTestBasic1, SelectItem1)
VIEW_TEST(MenuItemViewTestBasic2, SelectItem2)

// Test class for inserting a menu item while the menu is open.
template <int INSERT_INDEX, int SELECT_INDEX>
class MenuItemViewTestInsert : public MenuTestBase {};

// MenuItemViewTestInsertXY inserts an item at index X and selects the
// item at index Y (after the insertion).  The tests here cover
// inserting at the beginning, middle, and end, crossbarred with
// selecting the first and last item.
MenuItemViewTestInsert00;
MenuItemViewTestInsert02;
MenuItemViewTestInsert10;
MenuItemViewTestInsert12;
MenuItemViewTestInsert20;
MenuItemViewTestInsert22;

// If this flakes, disable and log details in http://crbug.com/523255.
#if defined(MEMORY_SANITIZER)
#define MAYBE_InsertItem00
#else
#define MAYBE_InsertItem00
#endif
VIEW_TEST(MenuItemViewTestInsert00, MAYBE_InsertItem00)

// TODO(b/523255): Test is failing consistently on "Linux Tests (Wayland)".
// If this flakes, disable and log details in http://crbug.com/523255.
// #if defined(MEMORY_SANITIZER)
// #define MAYBE_InsertItem02 DISABLED_InsertItem02
// #else
// #define MAYBE_InsertItem02 InsertItem02
// #endif
VIEW_TEST(MenuItemViewTestInsert02, DISABLED_InsertItem02)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestInsert10, InsertItem10)

// If this flakes, disable and log details in http://crbug.com/523255.
#if defined(MEMORY_SANITIZER)
#define MAYBE_InsertItem12
#else
#define MAYBE_InsertItem12
#endif
VIEW_TEST(MenuItemViewTestInsert12, MAYBE_InsertItem12)

// If this flakes, disable and log details in http://crbug.com/523255.
#if defined(MEMORY_SANITIZER)
#define MAYBE_InsertItem20
#else
#define MAYBE_InsertItem20
#endif
VIEW_TEST(MenuItemViewTestInsert20, MAYBE_InsertItem20)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestInsert22, InsertItem22)

// Test class for inserting a menu item while a submenu is open.
template <int INSERT_INDEX>
class MenuItemViewTestInsertWithSubmenu : public MenuTestBase {};

// MenuItemViewTestInsertWithSubmenuX posts a menu and its submenu,
// then inserts an item in the top-level menu at X.
MenuItemViewTestInsertWithSubmenu0;
MenuItemViewTestInsertWithSubmenu1;

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestInsertWithSubmenu0, InsertItemWithSubmenu0)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestInsertWithSubmenu1, InsertItemWithSubmenu1)

// Test class for removing a menu item while the menu is open.
template <int REMOVE_INDEX, int SELECT_INDEX>
class MenuItemViewTestRemove : public MenuTestBase {};

MenuItemViewTestRemove00;
MenuItemViewTestRemove01;
MenuItemViewTestRemove10;
MenuItemViewTestRemove11;
MenuItemViewTestRemove20;
MenuItemViewTestRemove21;
// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestRemove00, RemoveItem00)

// If this flakes, disable and log details in http://crbug.com/523255.
// Super flaky on Wayland.
#if BUILDFLAG(IS_OZONE)
#define MAYBE_RemoveItem01
#else
#define MAYBE_RemoveItem01
#endif
VIEW_TEST(MenuItemViewTestRemove01, MAYBE_RemoveItem01)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestRemove10, RemoveItem10)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestRemove11, RemoveItem11)

// If this flakes, disable and log details in http://crbug.com/523255.
VIEW_TEST(MenuItemViewTestRemove20, RemoveItem20)

// If this flakes, disable and log details in http://crbug.com/523255.
// Flaky on Wayland.
#if BUILDFLAG(IS_OZONE) || BUILDFLAG(IS_LINUX)
#define MAYBE_RemoveItem21
#else
#define MAYBE_RemoveItem21
#endif
VIEW_TEST(MenuItemViewTestRemove21, MAYBE_RemoveItem21)

// Test class for removing a menu item while a submenu is open.
template <int REMOVE_INDEX>
class MenuItemViewTestRemoveWithSubmenu : public MenuTestBase {};

MenuItemViewTestRemoveWithSubmenu0;
MenuItemViewTestRemoveWithSubmenu1;

// If this flakes, disable and log details in http://crbug.com/523255.
// Flaky on Wayland.
#if BUILDFLAG(IS_OZONE)
#define MAYBE_RemoveItemWithSubmenu0
#else
#define MAYBE_RemoveItemWithSubmenu0
#endif
VIEW_TEST(MenuItemViewTestRemoveWithSubmenu0, MAYBE_RemoveItemWithSubmenu0)

// If this flakes, disable and log details in http://crbug.com/523255.
// TODO(crbug.com/40244484): Flaky on Wayland.
#if BUILDFLAG(IS_OZONE)
#define MAYBE_RemoveItemWithSubmenu1
#else
#define MAYBE_RemoveItemWithSubmenu1
#endif
VIEW_TEST(MenuItemViewTestRemoveWithSubmenu1, MAYBE_RemoveItemWithSubmenu1)