#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/test/chromedriver/key_converter.h"
#include <stddef.h>
#include <string>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/ui_events.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/test/keyboard_layout.h"
namespace {
void CheckEvents(const std::u16string& keys,
const std::vector<KeyEvent>& expected_events,
bool release_modifiers,
int expected_modifiers) { … }
void CheckEventsReleaseModifiers(const std::u16string& keys,
const std::vector<KeyEvent>& expected_events) { … }
void CheckEventsReleaseModifiers(const std::string& keys,
std::vector<KeyEvent>& expected_events) { … }
void CheckNonShiftChar(ui::KeyboardCode key_code, char character) { … }
void CheckShiftChar(ui::KeyboardCode key_code, char character, char lower) { … }
}
TEST(KeyConverter, SingleChar) { … }
TEST(KeyConverter, SingleNumber) { … }
TEST(KeyConverter, MultipleChars) { … }
TEST(KeyConverter, WebDriverSpecialChar) { … }
TEST(KeyConverter, WebDriverSpecialNonCharKey) { … }
#if BUILDFLAG(IS_WIN)
TEST(KeyConverter, NeedsCtrlAndAlt) {
KeyEventBuilder ctrl_builder;
ctrl_builder.SetKeyCode(ui::VKEY_CONTROL);
KeyEventBuilder alt_builder;
alt_builder.SetKeyCode(ui::VKEY_MENU);
KeyEventBuilder q_builder;
q_builder.SetModifiers(kControlKeyModifierMask | kAltKeyModifierMask)
->SetKeyCode(ui::VKEY_Q)
->SetText("q", "@");
std::vector<KeyEvent> key_events;
key_events.push_back(ctrl_builder.SetType(kRawKeyDownEventType)->Build());
key_events.push_back(alt_builder.SetType(kRawKeyDownEventType)->Build());
q_builder.Generate(&key_events);
key_events.push_back(alt_builder.SetType(kKeyUpEventType)->Build());
key_events.push_back(ctrl_builder.SetType(kKeyUpEventType)->Build());
ui::ScopedKeyboardLayout keyboard_layout(ui::KEYBOARD_LAYOUT_GERMAN);
CheckEventsReleaseModifiers("@", key_events);
}
#endif
TEST(KeyConverter, UppercaseCharDoesShift) { … }
TEST(KeyConverter, UppercaseSymbolCharDoesShift) { … }
TEST(KeyConverter, UppercaseCharUsesShiftOnlyIfNecessary) { … }
TEST(KeyConverter, ToggleModifiers) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_AllEnglishKeyboardSymbols …
#else
#define MAYBE_AllEnglishKeyboardSymbols …
#endif
TEST(KeyConverter, MAYBE_AllEnglishKeyboardSymbols) { … }
TEST(KeyConverter, AllEnglishKeyboardTextChars) { … }
TEST(KeyConverter, AllSpecialWebDriverKeysOnEnglishKeyboard) { … }
TEST(KeyConverter, ModifiersState) { … }
TEST(KeyConverter, ReleaseModifiers) { … }
TEST(KeyConverter, CommandA) { … }