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