#include "ui/base/accelerators/accelerator.h"
#include <string>
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/event.h"
#include "ui/events/types/event_type.h"
namespace ui {
TEST(AcceleratorTest, Repeat) { … }
TEST(AcceleratorTest, TimeStamp) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_GetShortcutText …
#else
#define MAYBE_GetShortcutText …
#endif
TEST(AcceleratorTest, MAYBE_GetShortcutText) { … }
TEST(AcceleratorTest, ShortcutTextForUnknownKey) { … }
TEST(AcceleratorTest, VerifyToKeyEventConstructor) { … }
TEST(AcceleratorTest, ConversionFromKeyEvent) { … }
#if BUILDFLAG(IS_MAC)
class AcceleratorTestMac : public testing::Test {
public:
AcceleratorTestMac() = default;
~AcceleratorTestMac() override = default;
std::u16string ShortFormStringForModifiers(int modifier_flags) {
ui::KeyEvent key_event(ui::EventType::kKeyPressed, ui::VKEY_F,
modifier_flags);
Accelerator accelerator(key_event);
return accelerator.ApplyShortFormModifiers(std::u16string());
}
};
TEST_F(AcceleratorTestMac, ModifierFlagsShortFormRepresentation) {
int modifier_flag = 1 << 0;
while (modifier_flag) {
if (Accelerator::MaskOutKeyEventFlags(modifier_flag) &&
modifier_flag != EF_ALTGR_DOWN) {
EXPECT_GT(this->ShortFormStringForModifiers(modifier_flag).size(), 0UL);
}
modifier_flag <<= 1;
}
}
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST(AcceleratorTest, ConversionFromKeyEvent_Ash) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
::features::kImprovedKeyboardShortcuts);
ui::KeyEvent key_event(ui::EventType::kKeyPressed, ui::VKEY_F,
ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN);
Accelerator accelerator(key_event);
EXPECT_EQ(accelerator.key_code(), ui::VKEY_F);
EXPECT_EQ(accelerator.modifiers(), ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN);
EXPECT_EQ(accelerator.code(), DomCode::US_F);
accelerator.reset_code();
EXPECT_EQ(accelerator.code(), DomCode::NONE);
}
#endif
}