| 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/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "content/public/common/page_zoom.h" | 11 #include "content/public/common/page_zoom.h" |
| 11 #include "content/shell/renderer/test_runner/mock_spell_check.h" | 12 #include "content/shell/renderer/test_runner/mock_spell_check.h" |
| 12 #include "content/shell/renderer/test_runner/test_interfaces.h" | 13 #include "content/shell/renderer/test_runner/test_interfaces.h" |
| 13 #include "content/shell/renderer/test_runner/web_test_delegate.h" | 14 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
| 14 #include "content/shell/renderer/test_runner/web_test_proxy.h" | 15 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
| 15 #include "gin/handle.h" | 16 #include "gin/handle.h" |
| 16 #include "gin/object_template_builder.h" | 17 #include "gin/object_template_builder.h" |
| 17 #include "gin/wrappable.h" | 18 #include "gin/wrappable.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 21 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 21 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
| 22 #include "third_party/WebKit/public/web/WebKit.h" | 23 #include "third_party/WebKit/public/web/WebKit.h" |
| 23 #include "third_party/WebKit/public/web/WebPagePopup.h" | 24 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 24 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
| 26 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 25 #include "ui/events/keycodes/keyboard_codes.h" | 27 #include "ui/events/keycodes/keyboard_codes.h" |
| 26 #include "v8/include/v8.h" | 28 #include "v8/include/v8.h" |
| 27 | 29 |
| 28 using blink::WebContextMenuData; | 30 using blink::WebContextMenuData; |
| 29 using blink::WebDragData; | 31 using blink::WebDragData; |
| 30 using blink::WebDragOperationsMask; | 32 using blink::WebDragOperationsMask; |
| 31 using blink::WebFloatPoint; | 33 using blink::WebFloatPoint; |
| 32 using blink::WebFrame; | 34 using blink::WebFrame; |
| 33 using blink::WebGestureEvent; | 35 using blink::WebGestureEvent; |
| 34 using blink::WebInputEvent; | 36 using blink::WebInputEvent; |
| (...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 // event. This seems to work in the cases I tested. | 1264 // event. This seems to work in the cases I tested. |
| 1263 // FIXME: Should we also generate a KEY_UP? | 1265 // FIXME: Should we also generate a KEY_UP? |
| 1264 | 1266 |
| 1265 bool generate_char = false; | 1267 bool generate_char = false; |
| 1266 | 1268 |
| 1267 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when | 1269 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
| 1268 // Windows uses \r for "Enter". | 1270 // Windows uses \r for "Enter". |
| 1269 int code = 0; | 1271 int code = 0; |
| 1270 int text = 0; | 1272 int text = 0; |
| 1271 bool needs_shift_key_modifier = false; | 1273 bool needs_shift_key_modifier = false; |
| 1274 std::string domString; |
| 1272 | 1275 |
| 1273 if ("\n" == code_str) { | 1276 if ("\n" == code_str) { |
| 1274 generate_char = true; | 1277 generate_char = true; |
| 1275 text = code = ui::VKEY_RETURN; | 1278 text = code = ui::VKEY_RETURN; |
| 1279 domString.assign("Enter"); |
| 1276 } else if ("rightArrow" == code_str) { | 1280 } else if ("rightArrow" == code_str) { |
| 1277 code = ui::VKEY_RIGHT; | 1281 code = ui::VKEY_RIGHT; |
| 1282 domString.assign("ArrowRight"); |
| 1278 } else if ("downArrow" == code_str) { | 1283 } else if ("downArrow" == code_str) { |
| 1279 code = ui::VKEY_DOWN; | 1284 code = ui::VKEY_DOWN; |
| 1285 domString.assign("ArrowDown"); |
| 1280 } else if ("leftArrow" == code_str) { | 1286 } else if ("leftArrow" == code_str) { |
| 1281 code = ui::VKEY_LEFT; | 1287 code = ui::VKEY_LEFT; |
| 1288 domString.assign("ArrowLeft"); |
| 1282 } else if ("upArrow" == code_str) { | 1289 } else if ("upArrow" == code_str) { |
| 1283 code = ui::VKEY_UP; | 1290 code = ui::VKEY_UP; |
| 1291 domString.assign("ArrowUp"); |
| 1284 } else if ("insert" == code_str) { | 1292 } else if ("insert" == code_str) { |
| 1285 code = ui::VKEY_INSERT; | 1293 code = ui::VKEY_INSERT; |
| 1294 domString.assign("Insert"); |
| 1286 } else if ("delete" == code_str) { | 1295 } else if ("delete" == code_str) { |
| 1287 code = ui::VKEY_DELETE; | 1296 code = ui::VKEY_DELETE; |
| 1297 domString.assign("Delete"); |
| 1288 } else if ("pageUp" == code_str) { | 1298 } else if ("pageUp" == code_str) { |
| 1289 code = ui::VKEY_PRIOR; | 1299 code = ui::VKEY_PRIOR; |
| 1300 domString.assign("PageUp"); |
| 1290 } else if ("pageDown" == code_str) { | 1301 } else if ("pageDown" == code_str) { |
| 1291 code = ui::VKEY_NEXT; | 1302 code = ui::VKEY_NEXT; |
| 1303 domString.assign("PageDown"); |
| 1292 } else if ("home" == code_str) { | 1304 } else if ("home" == code_str) { |
| 1293 code = ui::VKEY_HOME; | 1305 code = ui::VKEY_HOME; |
| 1306 domString.assign("Home"); |
| 1294 } else if ("end" == code_str) { | 1307 } else if ("end" == code_str) { |
| 1295 code = ui::VKEY_END; | 1308 code = ui::VKEY_END; |
| 1309 domString.assign("End"); |
| 1296 } else if ("printScreen" == code_str) { | 1310 } else if ("printScreen" == code_str) { |
| 1297 code = ui::VKEY_SNAPSHOT; | 1311 code = ui::VKEY_SNAPSHOT; |
| 1312 domString.assign("PrintScreen"); |
| 1298 } else if ("menu" == code_str) { | 1313 } else if ("menu" == code_str) { |
| 1299 code = ui::VKEY_APPS; | 1314 code = ui::VKEY_APPS; |
| 1315 domString.assign("ContextMenu"); |
| 1300 } else if ("leftControl" == code_str) { | 1316 } else if ("leftControl" == code_str) { |
| 1301 code = ui::VKEY_LCONTROL; | 1317 code = ui::VKEY_LCONTROL; |
| 1318 domString.assign("ControlLeft"); |
| 1302 } else if ("rightControl" == code_str) { | 1319 } else if ("rightControl" == code_str) { |
| 1303 code = ui::VKEY_RCONTROL; | 1320 code = ui::VKEY_RCONTROL; |
| 1321 domString.assign("ControlRight"); |
| 1304 } else if ("leftShift" == code_str) { | 1322 } else if ("leftShift" == code_str) { |
| 1305 code = ui::VKEY_LSHIFT; | 1323 code = ui::VKEY_LSHIFT; |
| 1324 domString.assign("ShiftLeft"); |
| 1306 } else if ("rightShift" == code_str) { | 1325 } else if ("rightShift" == code_str) { |
| 1307 code = ui::VKEY_RSHIFT; | 1326 code = ui::VKEY_RSHIFT; |
| 1327 domString.assign("ShiftRight"); |
| 1308 } else if ("leftAlt" == code_str) { | 1328 } else if ("leftAlt" == code_str) { |
| 1309 code = ui::VKEY_LMENU; | 1329 code = ui::VKEY_LMENU; |
| 1330 domString.assign("AltLeft"); |
| 1310 } else if ("rightAlt" == code_str) { | 1331 } else if ("rightAlt" == code_str) { |
| 1311 code = ui::VKEY_RMENU; | 1332 code = ui::VKEY_RMENU; |
| 1333 domString.assign("AltRight"); |
| 1312 } else if ("numLock" == code_str) { | 1334 } else if ("numLock" == code_str) { |
| 1313 code = ui::VKEY_NUMLOCK; | 1335 code = ui::VKEY_NUMLOCK; |
| 1336 domString.assign("NumLock"); |
| 1314 } else if ("backspace" == code_str) { | 1337 } else if ("backspace" == code_str) { |
| 1315 code = ui::VKEY_BACK; | 1338 code = ui::VKEY_BACK; |
| 1339 domString.assign("Backspace"); |
| 1316 } else if ("escape" == code_str) { | 1340 } else if ("escape" == code_str) { |
| 1317 code = ui::VKEY_ESCAPE; | 1341 code = ui::VKEY_ESCAPE; |
| 1342 domString.assign("Escape"); |
| 1318 } else { | 1343 } else { |
| 1319 // Compare the input string with the function-key names defined by the | 1344 // Compare the input string with the function-key names defined by the |
| 1320 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key | 1345 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
| 1321 // name, set its key code. | 1346 // name, set its key code. |
| 1322 for (int i = 1; i <= 24; ++i) { | 1347 for (int i = 1; i <= 24; ++i) { |
| 1323 std::string function_key_name = base::StringPrintf("F%d", i); | 1348 std::string function_key_name = base::StringPrintf("F%d", i); |
| 1324 if (function_key_name == code_str) { | 1349 if (function_key_name == code_str) { |
| 1325 code = ui::VKEY_F1 + (i - 1); | 1350 code = ui::VKEY_F1 + (i - 1); |
| 1351 domString = function_key_name; |
| 1326 break; | 1352 break; |
| 1327 } | 1353 } |
| 1328 } | 1354 } |
| 1329 if (!code) { | 1355 if (!code) { |
| 1330 WebString web_code_str = | 1356 WebString web_code_str = |
| 1331 WebString::fromUTF8(code_str.data(), code_str.size()); | 1357 WebString::fromUTF8(code_str.data(), code_str.size()); |
| 1332 DCHECK_EQ(1u, web_code_str.length()); | 1358 DCHECK_EQ(1u, web_code_str.length()); |
| 1333 text = code = web_code_str.at(0); | 1359 text = code = web_code_str.at(0); |
| 1334 needs_shift_key_modifier = NeedsShiftModifier(code); | 1360 needs_shift_key_modifier = NeedsShiftModifier(code); |
| 1335 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | 1361 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') |
| 1336 code -= 'a' - 'A'; | 1362 code -= 'a' - 'A'; |
| 1363 if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) { |
| 1364 domString.assign("Key"); |
| 1365 domString.push_back(base::ToUpperASCII(code)); |
| 1366 } else if (code >= '0' && code <= '9') { |
| 1367 domString.assign("Digit"); |
| 1368 domString.push_back(code); |
| 1369 } else if (code == ' ') { |
| 1370 domString.assign("Space"); |
| 1371 } else if (code == 9) { |
| 1372 domString.assign("Tab"); |
| 1373 } |
| 1337 generate_char = true; | 1374 generate_char = true; |
| 1338 } | 1375 } |
| 1339 | 1376 |
| 1340 if ("(" == code_str) { | 1377 if ("(" == code_str) { |
| 1341 code = '9'; | 1378 code = '9'; |
| 1342 needs_shift_key_modifier = true; | 1379 needs_shift_key_modifier = true; |
| 1343 } | 1380 } |
| 1344 } | 1381 } |
| 1345 | 1382 |
| 1346 // For one generated keyboard event, we need to generate a keyDown/keyUp | 1383 // For one generated keyboard event, we need to generate a keyDown/keyUp |
| 1347 // pair; | 1384 // pair; |
| 1348 // On Windows, we might also need to generate a char event to mimic the | 1385 // On Windows, we might also need to generate a char event to mimic the |
| 1349 // Windows event flow; on other platforms we create a merged event and test | 1386 // Windows event flow; on other platforms we create a merged event and test |
| 1350 // the event flow that that platform provides. | 1387 // the event flow that that platform provides. |
| 1351 WebKeyboardEvent event_down; | 1388 WebKeyboardEvent event_down; |
| 1352 event_down.type = WebInputEvent::RawKeyDown; | 1389 event_down.type = WebInputEvent::RawKeyDown; |
| 1353 event_down.modifiers = modifiers; | 1390 event_down.modifiers = modifiers; |
| 1354 event_down.windowsKeyCode = code; | 1391 event_down.windowsKeyCode = code; |
| 1392 event_down.domCode = static_cast<int>( |
| 1393 ui::KeycodeConverter::CodeStringToDomCode(domString.c_str())); |
| 1355 | 1394 |
| 1356 if (generate_char) { | 1395 if (generate_char) { |
| 1357 event_down.text[0] = text; | 1396 event_down.text[0] = text; |
| 1358 event_down.unmodifiedText[0] = text; | 1397 event_down.unmodifiedText[0] = text; |
| 1359 } | 1398 } |
| 1360 | 1399 |
| 1361 event_down.setKeyIdentifierFromWindowsKeyCode(); | 1400 event_down.setKeyIdentifierFromWindowsKeyCode(); |
| 1362 | 1401 |
| 1363 if (event_down.modifiers != 0) | 1402 if (event_down.modifiers != 0) |
| 1364 event_down.isSystemKey = IsSystemKeyEvent(event_down); | 1403 event_down.isSystemKey = IsSystemKeyEvent(event_down); |
| (...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 | 2459 |
| 2421 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2460 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
| 2422 if (WebPagePopup* popup = view_->pagePopup()) { | 2461 if (WebPagePopup* popup = view_->pagePopup()) { |
| 2423 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2462 if (!WebInputEvent::isKeyboardEventType(event.type)) |
| 2424 return popup->handleInputEvent(event); | 2463 return popup->handleInputEvent(event); |
| 2425 } | 2464 } |
| 2426 return view_->handleInputEvent(event); | 2465 return view_->handleInputEvent(event); |
| 2427 } | 2466 } |
| 2428 | 2467 |
| 2429 } // namespace content | 2468 } // namespace content |
| OLD | NEW |