| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "core/editing/EditingBehavior.h" | 31 #include "core/editing/EditingBehavior.h" |
| 32 #include "core/editing/Editor.h" | 32 #include "core/editing/Editor.h" |
| 33 #include "core/events/EventTarget.h" | 33 #include "core/events/EventTarget.h" |
| 34 #include "core/events/KeyboardEvent.h" | 34 #include "core/events/KeyboardEvent.h" |
| 35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
| 36 #include "platform/KeyboardCodes.h" | 36 #include "platform/KeyboardCodes.h" |
| 37 #include "public/web/WebInputEvent.h" | 37 #include "public/web/WebInputEvent.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 #include "web/WebInputEventConversion.h" | 39 #include "web/WebInputEventConversion.h" |
| 40 #include <memory> |
| 40 | 41 |
| 41 namespace blink { | 42 namespace blink { |
| 42 | 43 |
| 43 class KeyboardTest : public testing::Test { | 44 class KeyboardTest : public testing::Test { |
| 44 public: | 45 public: |
| 45 | 46 |
| 46 // Pass a WebKeyboardEvent into the EditorClient and get back the string | 47 // Pass a WebKeyboardEvent into the EditorClient and get back the string |
| 47 // name of which editing event that key causes. | 48 // name of which editing event that key causes. |
| 48 // E.g., sending in the enter key gives back "InsertNewline". | 49 // E.g., sending in the enter key gives back "InsertNewline". |
| 49 const char* interpretKeyEvent( | 50 const char* interpretKeyEvent( |
| 50 const WebKeyboardEvent& webKeyboardEvent, | 51 const WebKeyboardEvent& webKeyboardEvent, |
| 51 PlatformEvent::EventType keyType) | 52 PlatformEvent::EventType keyType) |
| 52 { | 53 { |
| 53 PlatformKeyboardEventBuilder evt(webKeyboardEvent); | 54 PlatformKeyboardEventBuilder evt(webKeyboardEvent); |
| 54 evt.setKeyType(keyType); | 55 evt.setKeyType(keyType); |
| 55 KeyboardEvent* keyboardEvent = KeyboardEvent::create(evt, 0); | 56 KeyboardEvent* keyboardEvent = KeyboardEvent::create(evt, 0); |
| 56 OwnPtr<Settings> settings = Settings::create(); | 57 std::unique_ptr<Settings> settings = Settings::create(); |
| 57 EditingBehavior behavior(settings->editingBehaviorType()); | 58 EditingBehavior behavior(settings->editingBehaviorType()); |
| 58 return behavior.interpretKeyEvent(*keyboardEvent); | 59 return behavior.interpretKeyEvent(*keyboardEvent); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. | 62 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. |
| 62 void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent, | 63 void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent, |
| 63 char keyCode, | 64 char keyCode, |
| 64 int modifiers) | 65 int modifiers) |
| 65 { | 66 { |
| 66 keyboardEvent->windowsKeyCode = keyCode; | 67 keyboardEvent->windowsKeyCode = keyCode; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 { | 185 { |
| 185 EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers)); | 186 EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers)); |
| 186 } | 187 } |
| 187 | 188 |
| 188 TEST_F(KeyboardTest, TestInsertLineBreak) | 189 TEST_F(KeyboardTest, TestInsertLineBreak) |
| 189 { | 190 { |
| 190 EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey)); | 191 EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey)); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |