| Index: chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler_unittest.cc
|
| diff --git a/content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc b/chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler_unittest.cc
|
| similarity index 67%
|
| copy from content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc
|
| copy to chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler_unittest.cc
|
| index fed67d5e370f79b9da53721b517b8bf1a4236499..6877bd5752fd1ef4ab4c6d857d4243bf9c0dd668 100644
|
| --- a/content/browser/renderer_host/gtk_key_bindings_handler_unittest.cc
|
| +++ b/chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler_unittest.cc
|
| @@ -2,83 +2,55 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/renderer_host/gtk_key_bindings_handler.h"
|
| +#include "chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler.h"
|
|
|
| #include <gdk/gdkkeysyms.h>
|
| +
|
| #include <string>
|
| #include <utility>
|
| #include <vector>
|
|
|
| +#include "base/base_paths.h"
|
| #include "base/basictypes.h"
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/path_service.h"
|
| #include "base/strings/string_util.h"
|
| -#include "content/common/edit_command.h"
|
| +#include "chrome/browser/ui/libgtk2ui/gtk2_key_bindings_handler_unittest_helper.h"
|
| #include "content/public/browser/native_web_keyboard_event.h"
|
| #include "content/public/common/content_paths.h"
|
| +#include "content/public/common/edit_command.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/events/event.h"
|
|
|
| -namespace content {
|
| +namespace libgtk2ui {
|
|
|
| -class GtkKeyBindingsHandlerTest : public testing::Test {
|
| +class Gtk2KeyBindingsHandlerTest : public testing::Test {
|
| protected:
|
| struct EditCommand {
|
| const char* name;
|
| const char* value;
|
| };
|
|
|
| - GtkKeyBindingsHandlerTest()
|
| - : window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)),
|
| - handler_(NULL) {
|
| + Gtk2KeyBindingsHandlerTest()
|
| + : handler_(NULL) {
|
| base::FilePath gtkrc;
|
| - PathService::Get(DIR_TEST_DATA, >krc);
|
| + PathService::Get(base::DIR_TEST_DATA, >krc);
|
| gtkrc = gtkrc.AppendASCII("gtk_key_bindings_test_gtkrc");
|
| EXPECT_TRUE(base::PathExists(gtkrc));
|
|
|
| gtk_rc_parse(gtkrc.value().c_str());
|
|
|
| - GtkWidget* fixed = gtk_fixed_new();
|
| - handler_ = new GtkKeyBindingsHandler(fixed);
|
| - gtk_container_add(GTK_CONTAINER(window_), fixed);
|
| - gtk_widget_show(fixed);
|
| - gtk_widget_show(window_);
|
| + handler_ = new Gtk2KeyBindingsHandler();
|
| }
|
| - virtual ~GtkKeyBindingsHandlerTest() {
|
| - gtk_widget_destroy(window_);
|
| + virtual ~Gtk2KeyBindingsHandlerTest() {
|
| delete handler_;
|
| }
|
|
|
| - NativeWebKeyboardEvent NewNativeWebKeyboardEvent(guint keyval, guint state) {
|
| - GdkKeymap* keymap =
|
| - gdk_keymap_get_for_display(gtk_widget_get_display(window_));
|
| -
|
| - GdkKeymapKey *keys = NULL;
|
| - gint n_keys = 0;
|
| - if (gdk_keymap_get_entries_for_keyval(keymap, keyval, &keys, &n_keys)) {
|
| - GdkEventKey event;
|
| - event.type = GDK_KEY_PRESS;
|
| - event.window = NULL;
|
| - event.send_event = 0;
|
| - event.time = 0;
|
| - event.state = state;
|
| - event.keyval = keyval;
|
| - event.length = 0;
|
| - event.string = NULL;
|
| - event.hardware_keycode = keys[0].keycode;
|
| - event.group = keys[0].group;
|
| - event.is_modifier = 0;
|
| - g_free(keys);
|
| - return NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(&event));
|
| - }
|
| - LOG(ERROR) << "Failed to create key event for keyval:" << keyval;
|
| - return NativeWebKeyboardEvent();
|
| - }
|
| -
|
| - void TestKeyBinding(const NativeWebKeyboardEvent& event,
|
| + void TestKeyBinding(const content::NativeWebKeyboardEvent& event,
|
| const EditCommand expected_result[],
|
| size_t size) {
|
| - EditCommands result;
|
| + content::EditCommands result;
|
| ASSERT_TRUE(handler_->Match(event, &result));
|
| ASSERT_EQ(size, result.size());
|
| for (size_t i = 0; i < size; ++i) {
|
| @@ -88,11 +60,10 @@ class GtkKeyBindingsHandlerTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| - GtkWidget* window_;
|
| - GtkKeyBindingsHandler* handler_;
|
| + Gtk2KeyBindingsHandler* handler_;
|
| };
|
|
|
| -TEST_F(GtkKeyBindingsHandlerTest, MoveCursor) {
|
| +TEST_F(Gtk2KeyBindingsHandlerTest, MoveCursor) {
|
| static const EditCommand kEditCommands[] = {
|
| // "move-cursor" (logical-positions, -2, 0)
|
| { "MoveBackward", "" },
|
| @@ -130,11 +101,11 @@ TEST_F(GtkKeyBindingsHandlerTest, MoveCursor) {
|
| { "MoveToEndOfDocument", "" }
|
| };
|
|
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_1, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_1, ui::EF_CONTROL_DOWN),
|
| kEditCommands, arraysize(kEditCommands));
|
| }
|
|
|
| -TEST_F(GtkKeyBindingsHandlerTest, DeleteFromCursor) {
|
| +TEST_F(Gtk2KeyBindingsHandlerTest, DeleteFromCursor) {
|
| static const EditCommand kEditCommands[] = {
|
| // "delete-from-cursor" (chars, -2)
|
| { "DeleteBackward", "" },
|
| @@ -174,53 +145,53 @@ TEST_F(GtkKeyBindingsHandlerTest, DeleteFromCursor) {
|
| { "DeleteToEndOfParagraph", "" },
|
| };
|
|
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_2, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_2, ui::EF_CONTROL_DOWN),
|
| kEditCommands, arraysize(kEditCommands));
|
| }
|
|
|
| -TEST_F(GtkKeyBindingsHandlerTest, OtherActions) {
|
| +TEST_F(Gtk2KeyBindingsHandlerTest, OtherActions) {
|
| static const EditCommand kBackspace[] = {
|
| { "DeleteBackward", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_3, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_3, ui::EF_CONTROL_DOWN),
|
| kBackspace, arraysize(kBackspace));
|
|
|
| static const EditCommand kCopyClipboard[] = {
|
| { "Copy", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_4, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_4, ui::EF_CONTROL_DOWN),
|
| kCopyClipboard, arraysize(kCopyClipboard));
|
|
|
| static const EditCommand kCutClipboard[] = {
|
| { "Cut", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_5, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_5, ui::EF_CONTROL_DOWN),
|
| kCutClipboard, arraysize(kCutClipboard));
|
|
|
| static const EditCommand kInsertAtCursor[] = {
|
| { "InsertText", "hello" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_6, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_6, ui::EF_CONTROL_DOWN),
|
| kInsertAtCursor, arraysize(kInsertAtCursor));
|
|
|
| static const EditCommand kPasteClipboard[] = {
|
| { "Paste", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_7, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_7, ui::EF_CONTROL_DOWN),
|
| kPasteClipboard, arraysize(kPasteClipboard));
|
|
|
| static const EditCommand kSelectAll[] = {
|
| { "Unselect", "" },
|
| { "SelectAll", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_8, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_8, ui::EF_CONTROL_DOWN),
|
| kSelectAll, arraysize(kSelectAll));
|
|
|
| static const EditCommand kSetAnchor[] = {
|
| { "SetMark", "" }
|
| };
|
| - TestKeyBinding(NewNativeWebKeyboardEvent(GDK_9, GDK_CONTROL_MASK),
|
| + TestKeyBinding(NewNativeWebKeyboardEvent(ui::VKEY_9, ui::EF_CONTROL_DOWN),
|
| kSetAnchor, arraysize(kSetAnchor));
|
| }
|
|
|
| -} // namespace content
|
| +} // namespace libgtk2ui
|
|
|