OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/event_sender.h" | 5 #include "content/shell/renderer/test_runner/event_sender.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "content/public/common/page_zoom.h" | 10 #include "content/public/common/page_zoom.h" |
11 #include "content/shell/renderer/test_runner/mock_spell_check.h" | 11 #include "content/shell/renderer/test_runner/mock_spell_check.h" |
12 #include "content/shell/renderer/test_runner/test_interfaces.h" | 12 #include "content/shell/renderer/test_runner/test_interfaces.h" |
13 #include "content/shell/renderer/test_runner/web_test_delegate.h" | 13 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
14 #include "content/shell/renderer/test_runner/web_test_proxy.h" | 14 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
15 #include "gin/handle.h" | 15 #include "gin/handle.h" |
16 #include "gin/object_template_builder.h" | 16 #include "gin/object_template_builder.h" |
17 #include "gin/wrappable.h" | 17 #include "gin/wrappable.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 20 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebKit.h" | 22 #include "third_party/WebKit/public/web/WebKit.h" |
23 #include "third_party/WebKit/public/web/WebPagePopup.h" | 23 #include "third_party/WebKit/public/web/WebPagePopup.h" |
24 #include "third_party/WebKit/public/web/WebView.h" | 24 #include "third_party/WebKit/public/web/WebView.h" |
25 #include "ui/events/keycodes/dom4/keycode_converter.h" | |
25 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
26 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
27 | 28 |
28 using blink::WebContextMenuData; | 29 using blink::WebContextMenuData; |
29 using blink::WebDragData; | 30 using blink::WebDragData; |
30 using blink::WebDragOperationsMask; | 31 using blink::WebDragOperationsMask; |
31 using blink::WebFloatPoint; | 32 using blink::WebFloatPoint; |
32 using blink::WebFrame; | 33 using blink::WebFrame; |
33 using blink::WebGestureEvent; | 34 using blink::WebGestureEvent; |
34 using blink::WebInputEvent; | 35 using blink::WebInputEvent; |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 // event. This seems to work in the cases I tested. | 1241 // event. This seems to work in the cases I tested. |
1241 // FIXME: Should we also generate a KEY_UP? | 1242 // FIXME: Should we also generate a KEY_UP? |
1242 | 1243 |
1243 bool generate_char = false; | 1244 bool generate_char = false; |
1244 | 1245 |
1245 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when | 1246 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
1246 // Windows uses \r for "Enter". | 1247 // Windows uses \r for "Enter". |
1247 int code = 0; | 1248 int code = 0; |
1248 int text = 0; | 1249 int text = 0; |
1249 bool needs_shift_key_modifier = false; | 1250 bool needs_shift_key_modifier = false; |
1251 std::string domString; | |
1250 | 1252 |
1251 if ("\n" == code_str) { | 1253 if ("\n" == code_str) { |
1252 generate_char = true; | 1254 generate_char = true; |
1253 text = code = ui::VKEY_RETURN; | 1255 text = code = ui::VKEY_RETURN; |
1256 domString.assign("Enter"); | |
1254 } else if ("rightArrow" == code_str) { | 1257 } else if ("rightArrow" == code_str) { |
1255 code = ui::VKEY_RIGHT; | 1258 code = ui::VKEY_RIGHT; |
1259 domString.assign("ArrowRight"); | |
1256 } else if ("downArrow" == code_str) { | 1260 } else if ("downArrow" == code_str) { |
1257 code = ui::VKEY_DOWN; | 1261 code = ui::VKEY_DOWN; |
1262 domString.assign("ArrowDown"); | |
1258 } else if ("leftArrow" == code_str) { | 1263 } else if ("leftArrow" == code_str) { |
1259 code = ui::VKEY_LEFT; | 1264 code = ui::VKEY_LEFT; |
1265 domString.assign("ArrowLeft"); | |
1260 } else if ("upArrow" == code_str) { | 1266 } else if ("upArrow" == code_str) { |
1261 code = ui::VKEY_UP; | 1267 code = ui::VKEY_UP; |
1268 domString.assign("ArrowUp"); | |
1262 } else if ("insert" == code_str) { | 1269 } else if ("insert" == code_str) { |
1263 code = ui::VKEY_INSERT; | 1270 code = ui::VKEY_INSERT; |
1271 domString.assign("Insert"); | |
1264 } else if ("delete" == code_str) { | 1272 } else if ("delete" == code_str) { |
1265 code = ui::VKEY_DELETE; | 1273 code = ui::VKEY_DELETE; |
1274 domString.assign("Delete"); | |
1266 } else if ("pageUp" == code_str) { | 1275 } else if ("pageUp" == code_str) { |
1267 code = ui::VKEY_PRIOR; | 1276 code = ui::VKEY_PRIOR; |
1277 domString.assign("PageUp"); | |
1268 } else if ("pageDown" == code_str) { | 1278 } else if ("pageDown" == code_str) { |
1269 code = ui::VKEY_NEXT; | 1279 code = ui::VKEY_NEXT; |
1280 domString.assign("PageDown"); | |
1270 } else if ("home" == code_str) { | 1281 } else if ("home" == code_str) { |
1271 code = ui::VKEY_HOME; | 1282 code = ui::VKEY_HOME; |
1283 domString.assign("Home"); | |
1272 } else if ("end" == code_str) { | 1284 } else if ("end" == code_str) { |
1273 code = ui::VKEY_END; | 1285 code = ui::VKEY_END; |
1286 domString.assign("End"); | |
1274 } else if ("printScreen" == code_str) { | 1287 } else if ("printScreen" == code_str) { |
1275 code = ui::VKEY_SNAPSHOT; | 1288 code = ui::VKEY_SNAPSHOT; |
1289 domString.assign("PrintScreen"); | |
1276 } else if ("menu" == code_str) { | 1290 } else if ("menu" == code_str) { |
1277 code = ui::VKEY_APPS; | 1291 code = ui::VKEY_APPS; |
1292 domString.assign("ContextMenu"); | |
1278 } else if ("leftControl" == code_str) { | 1293 } else if ("leftControl" == code_str) { |
1279 code = ui::VKEY_LCONTROL; | 1294 code = ui::VKEY_LCONTROL; |
1295 domString.assign("ControlLeft"); | |
1280 } else if ("rightControl" == code_str) { | 1296 } else if ("rightControl" == code_str) { |
1281 code = ui::VKEY_RCONTROL; | 1297 code = ui::VKEY_RCONTROL; |
1298 domString.assign("ControlRight"); | |
1282 } else if ("leftShift" == code_str) { | 1299 } else if ("leftShift" == code_str) { |
1283 code = ui::VKEY_LSHIFT; | 1300 code = ui::VKEY_LSHIFT; |
1301 domString.assign("ShiftLeft"); | |
1284 } else if ("rightShift" == code_str) { | 1302 } else if ("rightShift" == code_str) { |
1285 code = ui::VKEY_RSHIFT; | 1303 code = ui::VKEY_RSHIFT; |
1304 domString.assign("ShiftRight"); | |
1286 } else if ("leftAlt" == code_str) { | 1305 } else if ("leftAlt" == code_str) { |
1287 code = ui::VKEY_LMENU; | 1306 code = ui::VKEY_LMENU; |
1307 domString.assign("AltLeft"); | |
1288 } else if ("rightAlt" == code_str) { | 1308 } else if ("rightAlt" == code_str) { |
1289 code = ui::VKEY_RMENU; | 1309 code = ui::VKEY_RMENU; |
1310 domString.assign("AltRight"); | |
1290 } else if ("numLock" == code_str) { | 1311 } else if ("numLock" == code_str) { |
1291 code = ui::VKEY_NUMLOCK; | 1312 code = ui::VKEY_NUMLOCK; |
1313 domString.assign("NumLock"); | |
1292 } else if ("backspace" == code_str) { | 1314 } else if ("backspace" == code_str) { |
1293 code = ui::VKEY_BACK; | 1315 code = ui::VKEY_BACK; |
1316 domString.assign("Backspace"); | |
1294 } else if ("escape" == code_str) { | 1317 } else if ("escape" == code_str) { |
1295 code = ui::VKEY_ESCAPE; | 1318 code = ui::VKEY_ESCAPE; |
1319 domString.assign("Escape"); | |
1296 } else { | 1320 } else { |
1297 // Compare the input string with the function-key names defined by the | 1321 // Compare the input string with the function-key names defined by the |
1298 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key | 1322 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
1299 // name, set its key code. | 1323 // name, set its key code. |
1300 for (int i = 1; i <= 24; ++i) { | 1324 for (int i = 1; i <= 24; ++i) { |
1301 std::string function_key_name = base::StringPrintf("F%d", i); | 1325 std::string function_key_name = base::StringPrintf("F%d", i); |
1302 if (function_key_name == code_str) { | 1326 if (function_key_name == code_str) { |
1303 code = ui::VKEY_F1 + (i - 1); | 1327 code = ui::VKEY_F1 + (i - 1); |
1328 domString = function_key_name; | |
1304 break; | 1329 break; |
1305 } | 1330 } |
1306 } | 1331 } |
1307 if (!code) { | 1332 if (!code) { |
1308 WebString web_code_str = | 1333 WebString web_code_str = |
1309 WebString::fromUTF8(code_str.data(), code_str.size()); | 1334 WebString::fromUTF8(code_str.data(), code_str.size()); |
1310 DCHECK_EQ(1u, web_code_str.length()); | 1335 DCHECK_EQ(1u, web_code_str.length()); |
1311 text = code = web_code_str.at(0); | 1336 text = code = web_code_str.at(0); |
1312 needs_shift_key_modifier = NeedsShiftModifier(code); | 1337 needs_shift_key_modifier = NeedsShiftModifier(code); |
1313 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | 1338 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') |
1314 code -= 'a' - 'A'; | 1339 code -= 'a' - 'A'; |
1340 if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) { | |
1341 domString.assign("Key"); | |
1342 domString.push_back(toupper(code)); | |
1343 } else if (code >= '0' && code <= '9') { | |
1344 domString.assign("Digit"); | |
1345 domString.push_back(code); | |
1346 } else if (code == ' ') { | |
1347 domString.assign("Space"); | |
1348 } else if (code == 9) { | |
1349 domString.assign("Tab"); | |
1350 } | |
1315 generate_char = true; | 1351 generate_char = true; |
1316 } | 1352 } |
1317 | 1353 |
1318 if ("(" == code_str) { | 1354 if ("(" == code_str) { |
1319 code = '9'; | 1355 code = '9'; |
1320 needs_shift_key_modifier = true; | 1356 needs_shift_key_modifier = true; |
1321 } | 1357 } |
1322 } | 1358 } |
1323 | 1359 |
1324 // For one generated keyboard event, we need to generate a keyDown/keyUp | 1360 // For one generated keyboard event, we need to generate a keyDown/keyUp |
1325 // pair; | 1361 // pair; |
1326 // On Windows, we might also need to generate a char event to mimic the | 1362 // On Windows, we might also need to generate a char event to mimic the |
1327 // Windows event flow; on other platforms we create a merged event and test | 1363 // Windows event flow; on other platforms we create a merged event and test |
1328 // the event flow that that platform provides. | 1364 // the event flow that that platform provides. |
1329 WebKeyboardEvent event_down; | 1365 WebKeyboardEvent event_down; |
1330 event_down.type = WebInputEvent::RawKeyDown; | 1366 event_down.type = WebInputEvent::RawKeyDown; |
1331 event_down.modifiers = modifiers; | 1367 event_down.modifiers = modifiers; |
1332 event_down.windowsKeyCode = code; | 1368 event_down.windowsKeyCode = code; |
1369 event_down.domCode = static_cast<long>( | |
piman
2015/01/28 01:18:04
is domCode supposed to be long or int? We should b
Habib Virji
2015/01/28 10:02:11
It is supposed to be int.
| |
1370 ui::KeycodeConverter::CodeStringToDomCode(domString.c_str())); | |
1333 | 1371 |
1334 if (generate_char) { | 1372 if (generate_char) { |
1335 event_down.text[0] = text; | 1373 event_down.text[0] = text; |
1336 event_down.unmodifiedText[0] = text; | 1374 event_down.unmodifiedText[0] = text; |
1337 } | 1375 } |
1338 | 1376 |
1339 event_down.setKeyIdentifierFromWindowsKeyCode(); | 1377 event_down.setKeyIdentifierFromWindowsKeyCode(); |
1340 | 1378 |
1341 if (event_down.modifiers != 0) | 1379 if (event_down.modifiers != 0) |
1342 event_down.isSystemKey = IsSystemKeyEvent(event_down); | 1380 event_down.isSystemKey = IsSystemKeyEvent(event_down); |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2336 | 2374 |
2337 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2375 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
2338 if (WebPagePopup* popup = view_->pagePopup()) { | 2376 if (WebPagePopup* popup = view_->pagePopup()) { |
2339 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2377 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2340 return popup->handleInputEvent(event); | 2378 return popup->handleInputEvent(event); |
2341 } | 2379 } |
2342 return view_->handleInputEvent(event); | 2380 return view_->handleInputEvent(event); |
2343 } | 2381 } |
2344 | 2382 |
2345 } // namespace content | 2383 } // namespace content |
OLD | NEW |