summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/mock_keyboard.h
diff options
context:
space:
mode:
authorhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 04:41:21 +0000
committerhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 04:41:21 +0000
commit8b048323819876b75e3875cd1de5ef01f1f54375 (patch)
tree1397552dd2d5c6d1461d253523e7e0118eb8b520 /chrome/renderer/mock_keyboard.h
parentda4f93efcfa81849826a188b39c92fb3b94a87f6 (diff)
downloadchromium_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.h')
-rw-r--r--chrome/renderer/mock_keyboard.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/renderer/mock_keyboard.h b/chrome/renderer/mock_keyboard.h
new file mode 100644
index 0000000..4ff8d1a
--- /dev/null
+++ b/chrome/renderer/mock_keyboard.h
@@ -0,0 +1,106 @@
+// 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.
+
+#ifndef CHROME_RENDERER_MOCK_KEYBOARD_H_
+#define CHROME_RENDERER_MOCK_KEYBOARD_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+
+#if defined(OS_WIN)
+#include "chrome/renderer/mock_keyboard_driver_win.h"
+#endif
+
+// A mock keyboard interface.
+// This class defines a pseudo keyboard device, which implements mappings from
+// a tuple (layout, key code, modifiers) to Unicode characters so that
+// engineers can write RenderViewTest cases without taking care of such
+// mappings. (This mapping is not trivial when using non-US keyboards.)
+// A pseudo keyboard device consists of two parts: a platform-independent part
+// and a platform-dependent part. This class implements the platform-independent
+// part. The platform-dependet part is implemented in the MockKeyboardWin class.
+// This class is usually called from RenderViewTest::SendKeyEvent().
+class MockKeyboard {
+ public:
+ // Represents keyboard-layouts.
+ enum Layout {
+ LAYOUT_NULL,
+ LAYOUT_ARABIC,
+ LAYOUT_BULGARIAN,
+ LAYOUT_CHINESE_TRADITIONAL,
+ LAYOUT_CZECH,
+ LAYOUT_DANISH,
+ LAYOUT_GERMAN,
+ LAYOUT_GREEK,
+ LAYOUT_UNITED_STATES,
+ LAYOUT_SPANISH,
+ LAYOUT_FINNISH,
+ LAYOUT_FRENCH,
+ LAYOUT_HEBREW,
+ LAYOUT_HUNGARIAN,
+ LAYOUT_ICELANDIC,
+ LAYOUT_ITALIAN,
+ LAYOUT_JAPANESE,
+ LAYOUT_KOREAN,
+ LAYOUT_POLISH,
+ LAYOUT_PORTUGUESE_BRAZILIAN,
+ LAYOUT_ROMANIAN,
+ LAYOUT_RUSSIAN,
+ LAYOUT_CROATIAN,
+ LAYOUT_SLOVAK,
+ LAYOUT_THAI,
+ LAYOUT_SWEDISH,
+ LAYOUT_TURKISH_Q,
+ LAYOUT_VIETNAMESE,
+ LAYOUT_DEVANAGARI_INSCRIPT,
+ LAYOUT_PORTUGUESE,
+ LAYOUT_UNITED_STATES_DVORAK,
+ LAYOUT_CANADIAN_FRENCH,
+ };
+
+ // Enumerates keyboard modifiers.
+ // These modifiers explicitly distinguish left-keys and right-keys because we
+ // should emulate AltGr (right-alt) key, used by many European keyboards to
+ // input alternate graph characters.
+ enum Modifiers {
+ INVALID = -1,
+ NONE = 0,
+ LEFT_SHIFT = 1 << 0,
+ LEFT_CONTROL = 1 << 1,
+ LEFT_ALT = 1 << 2,
+ LEFT_META = 1 << 3,
+ RIGHT_SHIFT = 1 << 4,
+ RIGHT_CONTROL = 1 << 5,
+ RIGHT_ALT = 1 << 6,
+ RIGHT_META = 1 << 7,
+ KEYPAD = 1 << 8,
+ AUTOREPEAAT = 1 << 9,
+ };
+
+ MockKeyboard();
+ ~MockKeyboard();
+
+ // Retrieves Unicode characters composed from the the specified keyboard
+ // layout, key code, and modifiers, i.e. characters returned when we type
+ // specified keys on a specified layout.
+ // This function returns the length of Unicode characters filled in the
+ // |output| parameter.
+ int GetCharacters(Layout layout,
+ int key_code,
+ Modifiers modifiers,
+ std::wstring* output);
+
+ private:
+ Layout keyboard_layout_;
+ Modifiers keyboard_modifiers_;
+
+#if defined(OS_WIN)
+ MockKeyboardDriverWin driver_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(MockKeyboard);
+};
+
+#endif // CHROME_RENDERER_MOCK_KEYBOARD_H_