| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include <gtest/gtest.h> | 33 #include <gtest/gtest.h> |
| 34 | 34 |
| 35 #include "core/editing/EditingBehavior.h" | 35 #include "core/editing/EditingBehavior.h" |
| 36 #include "core/editing/Editor.h" | 36 #include "core/editing/Editor.h" |
| 37 #include "core/events/EventTarget.h" | 37 #include "core/events/EventTarget.h" |
| 38 #include "core/events/KeyboardEvent.h" | 38 #include "core/events/KeyboardEvent.h" |
| 39 #include "core/frame/FrameView.h" |
| 39 #include "core/frame/Settings.h" | 40 #include "core/frame/Settings.h" |
| 41 #include "core/page/Page.h" |
| 42 #include "core/testing/URLTestHelpers.h" |
| 40 #include "platform/KeyboardCodes.h" | 43 #include "platform/KeyboardCodes.h" |
| 44 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebUnitTestSupport.h" |
| 41 #include "public/web/WebInputEvent.h" | 46 #include "public/web/WebInputEvent.h" |
| 42 #include "web/WebInputEventConversion.h" | 47 #include "web/WebInputEventConversion.h" |
| 48 #include "web/WebViewImpl.h" |
| 49 #include "web/tests/FrameTestHelpers.h" |
| 43 | 50 |
| 44 using namespace blink; | 51 using namespace blink; |
| 45 | 52 |
| 46 namespace { | 53 namespace { |
| 47 | 54 |
| 48 class KeyboardTest : public testing::Test { | 55 class KeyboardTest : public testing::Test { |
| 49 public: | 56 public: |
| 50 | 57 |
| 51 // Pass a WebKeyboardEvent into the EditorClient and get back the string | 58 // Pass a WebKeyboardEvent into the EditorClient and get back the string |
| 52 // name of which editing event that key causes. | 59 // name of which editing event that key causes. |
| 53 // E.g., sending in the enter key gives back "InsertNewline". | 60 // E.g., sending in the enter key gives back "InsertNewline". |
| 54 const char* interpretKeyEvent( | 61 const char* interpretKeyEvent( |
| 55 const WebKeyboardEvent& webKeyboardEvent, | 62 const WebKeyboardEvent& webKeyboardEvent, |
| 56 PlatformEvent::Type keyType) | 63 PlatformEvent::Type keyType) |
| 57 { | 64 { |
| 58 PlatformKeyboardEventBuilder evt(webKeyboardEvent); | 65 PlatformKeyboardEventBuilder evt(toLocalFrame(m_webView->page()->mainFra
me())->view(), webKeyboardEvent); |
| 59 evt.setKeyType(keyType); | 66 evt.setKeyType(keyType); |
| 60 RefPtrWillBeRawPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(
evt, 0); | 67 RefPtrWillBeRawPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(
evt, 0); |
| 61 OwnPtr<Settings> settings = Settings::create(); | 68 OwnPtr<Settings> settings = Settings::create(); |
| 62 EditingBehavior behavior(settings->editingBehaviorType()); | 69 EditingBehavior behavior(settings->editingBehaviorType()); |
| 63 return behavior.interpretKeyEvent(*keyboardEvent); | 70 return behavior.interpretKeyEvent(*keyboardEvent); |
| 64 } | 71 } |
| 65 | 72 |
| 66 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. | 73 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. |
| 67 void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent, | 74 void setupKeyDownEvent(WebKeyboardEvent* keyboardEvent, |
| 68 char keyCode, | 75 char keyCode, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 114 } |
| 108 | 115 |
| 109 // Like interpretKeyEvent, but with typing a newline. | 116 // Like interpretKeyEvent, but with typing a newline. |
| 110 const char* interpretNewLine(int modifiers) | 117 const char* interpretNewLine(int modifiers) |
| 111 { | 118 { |
| 112 WebKeyboardEvent keyboardEvent; | 119 WebKeyboardEvent keyboardEvent; |
| 113 setupKeyDownEvent(&keyboardEvent, '\r', modifiers); | 120 setupKeyDownEvent(&keyboardEvent, '\r', modifiers); |
| 114 return interpretKeyEvent(keyboardEvent, PlatformEvent::Char); | 121 return interpretKeyEvent(keyboardEvent, PlatformEvent::Char); |
| 115 } | 122 } |
| 116 | 123 |
| 124 void initializeAndLoad() |
| 125 { |
| 126 const std::string baseURL("http://www.test5.com/"); |
| 127 const std::string fileName("fixed_layout.html"); |
| 128 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL
.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 129 m_webView = m_helper.initializeAndLoad(baseURL + fileName, true); |
| 130 m_webView->resize(WebSize(640, 480)); |
| 131 m_webView->layout(); |
| 132 } |
| 133 |
| 134 virtual ~KeyboardTest() |
| 135 { |
| 136 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 137 } |
| 138 |
| 117 // A name for "no modifiers set". | 139 // A name for "no modifiers set". |
| 118 static const int noModifiers = 0; | 140 static const int noModifiers = 0; |
| 141 |
| 142 private: |
| 143 FrameTestHelpers::WebViewHelper m_helper; |
| 144 WebViewImpl* m_webView; |
| 119 }; | 145 }; |
| 120 | 146 |
| 121 TEST_F(KeyboardTest, TestCtrlReturn) | 147 TEST_F(KeyboardTest, TestCtrlReturn) |
| 122 { | 148 { |
| 149 initializeAndLoad(); |
| 123 EXPECT_STREQ("InsertNewline", interpretCtrlKeyPress(0xD)); | 150 EXPECT_STREQ("InsertNewline", interpretCtrlKeyPress(0xD)); |
| 124 } | 151 } |
| 125 | 152 |
| 126 TEST_F(KeyboardTest, TestOSModifierZ) | 153 TEST_F(KeyboardTest, TestOSModifierZ) |
| 127 { | 154 { |
| 155 initializeAndLoad(); |
| 128 #if !OS(MACOSX) | 156 #if !OS(MACOSX) |
| 129 EXPECT_STREQ("Undo", interpretOSModifierKeyPress('Z')); | 157 EXPECT_STREQ("Undo", interpretOSModifierKeyPress('Z')); |
| 130 #endif | 158 #endif |
| 131 } | 159 } |
| 132 | 160 |
| 133 TEST_F(KeyboardTest, TestOSModifierY) | 161 TEST_F(KeyboardTest, TestOSModifierY) |
| 134 { | 162 { |
| 163 initializeAndLoad(); |
| 135 #if !OS(MACOSX) | 164 #if !OS(MACOSX) |
| 136 EXPECT_STREQ("Redo", interpretOSModifierKeyPress('Y')); | 165 EXPECT_STREQ("Redo", interpretOSModifierKeyPress('Y')); |
| 137 #endif | 166 #endif |
| 138 } | 167 } |
| 139 | 168 |
| 140 TEST_F(KeyboardTest, TestOSModifierA) | 169 TEST_F(KeyboardTest, TestOSModifierA) |
| 141 { | 170 { |
| 171 initializeAndLoad(); |
| 142 #if !OS(MACOSX) | 172 #if !OS(MACOSX) |
| 143 EXPECT_STREQ("SelectAll", interpretOSModifierKeyPress('A')); | 173 EXPECT_STREQ("SelectAll", interpretOSModifierKeyPress('A')); |
| 144 #endif | 174 #endif |
| 145 } | 175 } |
| 146 | 176 |
| 147 TEST_F(KeyboardTest, TestOSModifierX) | 177 TEST_F(KeyboardTest, TestOSModifierX) |
| 148 { | 178 { |
| 179 initializeAndLoad(); |
| 149 #if !OS(MACOSX) | 180 #if !OS(MACOSX) |
| 150 EXPECT_STREQ("Cut", interpretOSModifierKeyPress('X')); | 181 EXPECT_STREQ("Cut", interpretOSModifierKeyPress('X')); |
| 151 #endif | 182 #endif |
| 152 } | 183 } |
| 153 | 184 |
| 154 TEST_F(KeyboardTest, TestOSModifierC) | 185 TEST_F(KeyboardTest, TestOSModifierC) |
| 155 { | 186 { |
| 187 initializeAndLoad(); |
| 156 #if !OS(MACOSX) | 188 #if !OS(MACOSX) |
| 157 EXPECT_STREQ("Copy", interpretOSModifierKeyPress('C')); | 189 EXPECT_STREQ("Copy", interpretOSModifierKeyPress('C')); |
| 158 #endif | 190 #endif |
| 159 } | 191 } |
| 160 | 192 |
| 161 TEST_F(KeyboardTest, TestOSModifierV) | 193 TEST_F(KeyboardTest, TestOSModifierV) |
| 162 { | 194 { |
| 195 initializeAndLoad(); |
| 163 #if !OS(MACOSX) | 196 #if !OS(MACOSX) |
| 164 EXPECT_STREQ("Paste", interpretOSModifierKeyPress('V')); | 197 EXPECT_STREQ("Paste", interpretOSModifierKeyPress('V')); |
| 165 #endif | 198 #endif |
| 166 } | 199 } |
| 167 | 200 |
| 168 TEST_F(KeyboardTest, TestEscape) | 201 TEST_F(KeyboardTest, TestEscape) |
| 169 { | 202 { |
| 203 initializeAndLoad(); |
| 170 WebKeyboardEvent keyboardEvent; | 204 WebKeyboardEvent keyboardEvent; |
| 171 setupKeyDownEvent(&keyboardEvent, VKEY_ESCAPE, noModifiers); | 205 setupKeyDownEvent(&keyboardEvent, VKEY_ESCAPE, noModifiers); |
| 172 | 206 |
| 173 const char* result = interpretKeyEvent(keyboardEvent, | 207 const char* result = interpretKeyEvent(keyboardEvent, |
| 174 PlatformEvent::RawKeyDown); | 208 PlatformEvent::RawKeyDown); |
| 175 EXPECT_STREQ("Cancel", result); | 209 EXPECT_STREQ("Cancel", result); |
| 176 } | 210 } |
| 177 | 211 |
| 178 TEST_F(KeyboardTest, TestInsertTab) | 212 TEST_F(KeyboardTest, TestInsertTab) |
| 179 { | 213 { |
| 214 initializeAndLoad(); |
| 180 EXPECT_STREQ("InsertTab", interpretTab(noModifiers)); | 215 EXPECT_STREQ("InsertTab", interpretTab(noModifiers)); |
| 181 } | 216 } |
| 182 | 217 |
| 183 TEST_F(KeyboardTest, TestInsertBackTab) | 218 TEST_F(KeyboardTest, TestInsertBackTab) |
| 184 { | 219 { |
| 220 initializeAndLoad(); |
| 185 EXPECT_STREQ("InsertBacktab", interpretTab(WebInputEvent::ShiftKey)); | 221 EXPECT_STREQ("InsertBacktab", interpretTab(WebInputEvent::ShiftKey)); |
| 186 } | 222 } |
| 187 | 223 |
| 188 TEST_F(KeyboardTest, TestInsertNewline) | 224 TEST_F(KeyboardTest, TestInsertNewline) |
| 189 { | 225 { |
| 226 initializeAndLoad(); |
| 190 EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers)); | 227 EXPECT_STREQ("InsertNewline", interpretNewLine(noModifiers)); |
| 191 } | 228 } |
| 192 | 229 |
| 193 TEST_F(KeyboardTest, TestInsertNewline2) | 230 TEST_F(KeyboardTest, TestInsertNewline2) |
| 194 { | 231 { |
| 232 initializeAndLoad(); |
| 195 EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::ControlKey)); | 233 EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::ControlKey)); |
| 196 } | 234 } |
| 197 | 235 |
| 198 TEST_F(KeyboardTest, TestInsertLineBreak) | 236 TEST_F(KeyboardTest, TestInsertLineBreak) |
| 199 { | 237 { |
| 238 initializeAndLoad(); |
| 200 EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey)); | 239 EXPECT_STREQ("InsertLineBreak", interpretNewLine(WebInputEvent::ShiftKey)); |
| 201 } | 240 } |
| 202 | 241 |
| 203 TEST_F(KeyboardTest, TestInsertNewline3) | 242 TEST_F(KeyboardTest, TestInsertNewline3) |
| 204 { | 243 { |
| 244 initializeAndLoad(); |
| 205 EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::AltKey)); | 245 EXPECT_STREQ("InsertNewline", interpretNewLine(WebInputEvent::AltKey)); |
| 206 } | 246 } |
| 207 | 247 |
| 208 TEST_F(KeyboardTest, TestInsertNewline4) | 248 TEST_F(KeyboardTest, TestInsertNewline4) |
| 209 { | 249 { |
| 250 initializeAndLoad(); |
| 210 int modifiers = WebInputEvent::AltKey | WebInputEvent::ShiftKey; | 251 int modifiers = WebInputEvent::AltKey | WebInputEvent::ShiftKey; |
| 211 const char* result = interpretNewLine(modifiers); | 252 const char* result = interpretNewLine(modifiers); |
| 212 EXPECT_STREQ("InsertNewline", result); | 253 EXPECT_STREQ("InsertNewline", result); |
| 213 } | 254 } |
| 214 | 255 |
| 215 } // empty namespace | 256 } // empty namespace |
| OLD | NEW |