diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-11 04:41:21 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-11 04:41:21 +0000 |
commit | 8b048323819876b75e3875cd1de5ef01f1f54375 (patch) | |
tree | 1397552dd2d5c6d1461d253523e7e0118eb8b520 /chrome/renderer/mock_keyboard.cc | |
parent | da4f93efcfa81849826a188b39c92fb3b94a87f6 (diff) | |
download | chromium_src-8b048323819876b75e3875cd1de5ef01f1f54375.zip chromium_src-8b048323819876b75e3875cd1de5ef01f1f54375.tar.gz chromium_src-8b048323819876b75e3875cd1de5ef01f1f54375.tar.bz2 |
Implements keyboard events for RenderViewTest.This change implements a function RenderViewTest::SendKeyEvent() that sends a keyboard event to a RenderView object.To emulate not only US keyboards but also non-US keyboards, this change adds a new class "MockKeyboard", which implements a mapping function from a triple <keyboard type, key code, modifiers> to a Unicode character so that engineers can write RenderViewTest cases without taking care of keyboard types.As samples for this new function, I updated my test RenderViewTest.OnHandleKeyboardEvent and added another test RenderViewTest.InsertCharacters.I wish this class help engineers write more RenderViewTest cases.
Review URL: http://codereview.chromium.org/92122
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15748 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/mock_keyboard.cc')
-rw-r--r-- | chrome/renderer/mock_keyboard.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/chrome/renderer/mock_keyboard.cc b/chrome/renderer/mock_keyboard.cc new file mode 100644 index 0000000..b18f3f6 --- /dev/null +++ b/chrome/renderer/mock_keyboard.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/renderer/mock_keyboard.h" + +#include "base/logging.h" + +MockKeyboard::MockKeyboard() + : keyboard_layout_(LAYOUT_NULL), + keyboard_modifiers_(INVALID) { +} + +MockKeyboard::~MockKeyboard() { +} + +int MockKeyboard::GetCharacters(Layout layout, + int key_code, + Modifiers modifiers, + std::wstring* output) { +#if defined(OS_WIN) + CHECK(output); + // Change the keyboard layout only when we have to because it takes a lot of + // time to load a keyboard-layout driver. + // When we change the layout, we reset the modifier status to force updating + // the keyboard status. + if (layout != keyboard_layout_) { + if (!driver_.SetLayout(layout)) + return -1; + keyboard_layout_ = layout; + keyboard_modifiers_ = INVALID; + } + + // Update the keyboard states. + if (modifiers != keyboard_modifiers_) { + if (!driver_.SetModifiers(modifiers)) + return -1; + keyboard_modifiers_ = modifiers; + } + + // Retrieve Unicode characters associate with the key code. + return driver_.GetCharacters(key_code, output); +#else + NOTIMPLEMENTED(); + return -1; +#endif +} |