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 "components/test_runner/event_sender.h" | 5 #include "components/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/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "components/test_runner/mock_spell_check.h" | 11 #include "components/test_runner/mock_spell_check.h" |
12 #include "components/test_runner/test_interfaces.h" | 12 #include "components/test_runner/test_interfaces.h" |
13 #include "components/test_runner/web_test_delegate.h" | 13 #include "components/test_runner/web_test_delegate.h" |
14 #include "components/test_runner/web_test_proxy.h" | 14 #include "components/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/event_constants.h" | |
26 #include "ui/events/keycodes/dom/dom_key.h" | |
25 #include "ui/events/keycodes/dom/keycode_converter.h" | 27 #include "ui/events/keycodes/dom/keycode_converter.h" |
28 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
26 #include "ui/events/keycodes/keyboard_codes.h" | 29 #include "ui/events/keycodes/keyboard_codes.h" |
27 #include "v8/include/v8.h" | 30 #include "v8/include/v8.h" |
28 | 31 |
29 using blink::WebContextMenuData; | 32 using blink::WebContextMenuData; |
30 using blink::WebDragData; | 33 using blink::WebDragData; |
31 using blink::WebDragOperationsMask; | 34 using blink::WebDragOperationsMask; |
32 using blink::WebFloatPoint; | 35 using blink::WebFloatPoint; |
33 using blink::WebFrame; | 36 using blink::WebFrame; |
34 using blink::WebGestureEvent; | 37 using blink::WebGestureEvent; |
35 using blink::WebInputEvent; | 38 using blink::WebInputEvent; |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 int modifiers, | 1248 int modifiers, |
1246 KeyLocationCode location) { | 1249 KeyLocationCode location) { |
1247 // FIXME: I'm not exactly sure how we should convert the string to a key | 1250 // FIXME: I'm not exactly sure how we should convert the string to a key |
1248 // event. This seems to work in the cases I tested. | 1251 // event. This seems to work in the cases I tested. |
1249 // FIXME: Should we also generate a KEY_UP? | 1252 // FIXME: Should we also generate a KEY_UP? |
1250 | 1253 |
1251 bool generate_char = false; | 1254 bool generate_char = false; |
1252 | 1255 |
1253 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when | 1256 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
1254 // Windows uses \r for "Enter". | 1257 // Windows uses \r for "Enter". |
1255 int code = 0; | 1258 int keyCode = 0; |
Wez
2015/06/11 00:09:05
keyCode -> key_code
Chromium style-guide requires
Habib Virji
2015/06/24 14:32:12
Done.
| |
1256 int text = 0; | 1259 int text = 0; |
1257 bool needs_shift_key_modifier = false; | 1260 bool needs_shift_key_modifier = false; |
1258 std::string domString; | |
1259 | 1261 |
1260 if ("\n" == code_str) { | 1262 if ("\n" == code_str) { |
1261 generate_char = true; | 1263 generate_char = true; |
1262 text = code = ui::VKEY_RETURN; | 1264 text = keyCode = ui::VKEY_RETURN; |
1263 domString.assign("Enter"); | |
1264 } else if ("rightArrow" == code_str) { | 1265 } else if ("rightArrow" == code_str) { |
1265 code = ui::VKEY_RIGHT; | 1266 keyCode = ui::VKEY_RIGHT; |
1266 domString.assign("ArrowRight"); | |
1267 } else if ("downArrow" == code_str) { | 1267 } else if ("downArrow" == code_str) { |
1268 code = ui::VKEY_DOWN; | 1268 keyCode = ui::VKEY_DOWN; |
1269 domString.assign("ArrowDown"); | |
1270 } else if ("leftArrow" == code_str) { | 1269 } else if ("leftArrow" == code_str) { |
1271 code = ui::VKEY_LEFT; | 1270 keyCode = ui::VKEY_LEFT; |
1272 domString.assign("ArrowLeft"); | |
1273 } else if ("upArrow" == code_str) { | 1271 } else if ("upArrow" == code_str) { |
1274 code = ui::VKEY_UP; | 1272 keyCode = ui::VKEY_UP; |
1275 domString.assign("ArrowUp"); | |
1276 } else if ("insert" == code_str) { | 1273 } else if ("insert" == code_str) { |
1277 code = ui::VKEY_INSERT; | 1274 keyCode = ui::VKEY_INSERT; |
1278 domString.assign("Insert"); | |
1279 } else if ("delete" == code_str) { | 1275 } else if ("delete" == code_str) { |
1280 code = ui::VKEY_DELETE; | 1276 keyCode = ui::VKEY_DELETE; |
1281 domString.assign("Delete"); | |
1282 } else if ("pageUp" == code_str) { | 1277 } else if ("pageUp" == code_str) { |
1283 code = ui::VKEY_PRIOR; | 1278 keyCode = ui::VKEY_PRIOR; |
1284 domString.assign("PageUp"); | |
1285 } else if ("pageDown" == code_str) { | 1279 } else if ("pageDown" == code_str) { |
1286 code = ui::VKEY_NEXT; | 1280 keyCode = ui::VKEY_NEXT; |
1287 domString.assign("PageDown"); | |
1288 } else if ("home" == code_str) { | 1281 } else if ("home" == code_str) { |
1289 code = ui::VKEY_HOME; | 1282 keyCode = ui::VKEY_HOME; |
1290 domString.assign("Home"); | |
1291 } else if ("end" == code_str) { | 1283 } else if ("end" == code_str) { |
1292 code = ui::VKEY_END; | 1284 keyCode = ui::VKEY_END; |
1293 domString.assign("End"); | |
1294 } else if ("printScreen" == code_str) { | 1285 } else if ("printScreen" == code_str) { |
1295 code = ui::VKEY_SNAPSHOT; | 1286 keyCode = ui::VKEY_SNAPSHOT; |
1296 domString.assign("PrintScreen"); | |
1297 } else if ("menu" == code_str) { | 1287 } else if ("menu" == code_str) { |
1298 code = ui::VKEY_APPS; | 1288 keyCode = ui::VKEY_APPS; |
1299 domString.assign("ContextMenu"); | |
1300 } else if ("leftControl" == code_str) { | 1289 } else if ("leftControl" == code_str) { |
1301 code = ui::VKEY_LCONTROL; | 1290 keyCode = ui::VKEY_LCONTROL; |
1302 domString.assign("ControlLeft"); | |
1303 } else if ("rightControl" == code_str) { | 1291 } else if ("rightControl" == code_str) { |
1304 code = ui::VKEY_RCONTROL; | 1292 keyCode = ui::VKEY_RCONTROL; |
1305 domString.assign("ControlRight"); | |
1306 } else if ("leftShift" == code_str) { | 1293 } else if ("leftShift" == code_str) { |
1307 code = ui::VKEY_LSHIFT; | 1294 keyCode = ui::VKEY_LSHIFT; |
1308 domString.assign("ShiftLeft"); | |
1309 } else if ("rightShift" == code_str) { | 1295 } else if ("rightShift" == code_str) { |
1310 code = ui::VKEY_RSHIFT; | 1296 keyCode = ui::VKEY_RSHIFT; |
1311 domString.assign("ShiftRight"); | |
1312 } else if ("leftAlt" == code_str) { | 1297 } else if ("leftAlt" == code_str) { |
1313 code = ui::VKEY_LMENU; | 1298 keyCode = ui::VKEY_LMENU; |
1314 domString.assign("AltLeft"); | |
1315 } else if ("rightAlt" == code_str) { | 1299 } else if ("rightAlt" == code_str) { |
1316 code = ui::VKEY_RMENU; | 1300 keyCode = ui::VKEY_RMENU; |
1317 domString.assign("AltRight"); | |
1318 } else if ("numLock" == code_str) { | 1301 } else if ("numLock" == code_str) { |
1319 code = ui::VKEY_NUMLOCK; | 1302 keyCode = ui::VKEY_NUMLOCK; |
1320 domString.assign("NumLock"); | |
1321 } else if ("backspace" == code_str) { | 1303 } else if ("backspace" == code_str) { |
1322 code = ui::VKEY_BACK; | 1304 keyCode = ui::VKEY_BACK; |
1323 domString.assign("Backspace"); | |
1324 } else if ("escape" == code_str) { | 1305 } else if ("escape" == code_str) { |
1325 code = ui::VKEY_ESCAPE; | 1306 keyCode = ui::VKEY_ESCAPE; |
1326 domString.assign("Escape"); | |
1327 } else { | 1307 } else { |
1328 // Compare the input string with the function-key names defined by the | 1308 // Compare the input string with the function-key names defined by the |
1329 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key | 1309 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
1330 // name, set its key code. | 1310 // name, set its key code. |
1331 for (int i = 1; i <= 24; ++i) { | 1311 for (int i = 1; i <= 24; ++i) { |
1332 std::string function_key_name = base::StringPrintf("F%d", i); | 1312 std::string function_key_name = base::StringPrintf("F%d", i); |
1333 if (function_key_name == code_str) { | 1313 if (function_key_name == code_str) { |
1334 code = ui::VKEY_F1 + (i - 1); | 1314 keyCode = ui::VKEY_F1 + (i - 1); |
1335 domString = function_key_name; | |
1336 break; | 1315 break; |
1337 } | 1316 } |
1338 } | 1317 } |
1339 if (!code) { | 1318 if (!keyCode) { |
1340 WebString web_code_str = | 1319 WebString web_code_str = |
1341 WebString::fromUTF8(code_str.data(), code_str.size()); | 1320 WebString::fromUTF8(code_str.data(), code_str.size()); |
Wez
2015/06/11 00:09:05
Why do we even convert this to a WebString? We nev
Habib Virji
2015/06/24 14:32:12
I did try just using code_str, but apparently it i
Wez
2015/06/25 10:40:21
All that the conversion is actually doing is takin
Habib Virji
2015/06/26 17:35:38
Thanks this is useful information.
| |
1342 if (web_code_str.length() != 1u) { | 1321 if (web_code_str.length() != 1u) { |
1343 v8::Isolate* isolate = blink::mainThreadIsolate(); | 1322 v8::Isolate* isolate = blink::mainThreadIsolate(); |
1344 isolate->ThrowException(v8::Exception::TypeError( | 1323 isolate->ThrowException(v8::Exception::TypeError( |
1345 gin::StringToV8(isolate, "Invalid web code."))); | 1324 gin::StringToV8(isolate, "Invalid web code."))); |
1346 return; | 1325 return; |
1347 } | 1326 } |
1348 text = code = web_code_str.at(0); | 1327 text = keyCode = web_code_str.at(0); |
Wez
2015/06/11 00:09:05
DOM |code| values for e.g. keys A-Z are of the for
Habib Virji
2015/06/24 14:32:12
Sorry did not followed about the DOM |code| commen
Wez
2015/06/25 10:40:21
Sorry - I mis-read that |web_code_str| contained t
Habib Virji
2015/06/26 17:35:38
I agree with your suggestion. Since unittest has v
| |
1349 needs_shift_key_modifier = NeedsShiftModifier(code); | 1328 needs_shift_key_modifier = NeedsShiftModifier(keyCode); |
1350 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | 1329 if ((keyCode & 0xFF) >= 'a' && (keyCode & 0xFF) <= 'z') |
1351 code -= 'a' - 'A'; | 1330 keyCode -= 'a' - 'A'; |
1352 if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) { | |
1353 domString.assign("Key"); | |
1354 domString.push_back(base::ToUpperASCII(code)); | |
1355 } else if (code >= '0' && code <= '9') { | |
1356 domString.assign("Digit"); | |
1357 domString.push_back(code); | |
1358 } else if (code == ' ') { | |
1359 domString.assign("Space"); | |
1360 } else if (code == 9) { | |
1361 domString.assign("Tab"); | |
1362 } | |
1363 generate_char = true; | 1331 generate_char = true; |
1364 } | 1332 } |
1365 | 1333 |
1366 if ("(" == code_str) { | 1334 if ("(" == code_str) { |
1367 code = '9'; | 1335 keyCode = '9'; |
1368 needs_shift_key_modifier = true; | 1336 needs_shift_key_modifier = true; |
1369 } | 1337 } |
1370 } | 1338 } |
1371 | 1339 |
1340 ui::DomKey domkey = ui::DomKey::NONE; | |
Wez
2015/06/11 00:09:05
nit: domkey -> dom_key, domcode -> dom_code, domke
Habib Virji
2015/06/24 14:32:12
Done.
| |
1341 ui::DomCode domcode = ui::UsLayoutKeyboardCodeToDomCode( | |
1342 static_cast<ui::KeyboardCode>(keyCode)); | |
1343 base::char16 domkey_char; | |
1344 GetMeaningFromKeyCode(static_cast<ui::KeyboardCode>(keyCode), | |
1345 ui::EF_NONE, &domkey, &domkey_char); | |
Wez
2015/06/11 00:09:05
We're trying to get rid of GetMeaningFromKeyCode()
Habib Virji
2015/06/24 14:32:12
Implemented as suggested. It also include now the
| |
1346 | |
1372 // For one generated keyboard event, we need to generate a keyDown/keyUp | 1347 // For one generated keyboard event, we need to generate a keyDown/keyUp |
1373 // pair; | 1348 // pair; |
1374 // On Windows, we might also need to generate a char event to mimic the | 1349 // On Windows, we might also need to generate a char event to mimic the |
1375 // Windows event flow; on other platforms we create a merged event and test | 1350 // Windows event flow; on other platforms we create a merged event and test |
1376 // the event flow that that platform provides. | 1351 // the event flow that that platform provides. |
1377 WebKeyboardEvent event_down; | 1352 WebKeyboardEvent event_down; |
1378 event_down.type = WebInputEvent::RawKeyDown; | 1353 event_down.type = WebInputEvent::RawKeyDown; |
1379 event_down.modifiers = modifiers; | 1354 event_down.modifiers = modifiers; |
1380 event_down.windowsKeyCode = code; | 1355 event_down.windowsKeyCode = keyCode; |
1381 event_down.domCode = static_cast<int>( | 1356 event_down.domCode = static_cast<int>(domcode); |
1382 ui::KeycodeConverter::CodeStringToDomCode(domString.c_str())); | 1357 event_down.domKey = static_cast<int>(domkey); |
1358 event_down.domKeyChar = static_cast<int>(domkey_char); | |
1383 | 1359 |
1384 if (generate_char) { | 1360 if (generate_char) { |
1385 event_down.text[0] = text; | 1361 event_down.text[0] = text; |
1386 event_down.unmodifiedText[0] = text; | 1362 event_down.unmodifiedText[0] = text; |
1387 } | 1363 } |
1388 | 1364 |
1389 event_down.setKeyIdentifierFromWindowsKeyCode(); | 1365 event_down.setKeyIdentifierFromWindowsKeyCode(); |
1390 | 1366 |
1391 if (event_down.modifiers != 0) | 1367 if (event_down.modifiers != 0) |
1392 event_down.isSystemKey = IsSystemKeyEvent(event_down); | 1368 event_down.isSystemKey = IsSystemKeyEvent(event_down); |
(...skipping 17 matching lines...) Expand all Loading... | |
1410 // the command will be dispatched to the renderer just before dispatching | 1386 // the command will be dispatched to the renderer just before dispatching |
1411 // the keyboard event, and then it will be executed in the | 1387 // the keyboard event, and then it will be executed in the |
1412 // RenderView::handleCurrentKeyboardEvent() method. | 1388 // RenderView::handleCurrentKeyboardEvent() method. |
1413 // We just simulate the same behavior here. | 1389 // We just simulate the same behavior here. |
1414 std::string edit_command; | 1390 std::string edit_command; |
1415 if (GetEditCommand(event_down, &edit_command)) | 1391 if (GetEditCommand(event_down, &edit_command)) |
1416 delegate_->SetEditCommand(edit_command, ""); | 1392 delegate_->SetEditCommand(edit_command, ""); |
1417 | 1393 |
1418 HandleInputEventOnViewOrPopup(event_down); | 1394 HandleInputEventOnViewOrPopup(event_down); |
1419 | 1395 |
1420 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1396 if (keyCode == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
1421 WebMouseEvent event; | 1397 WebMouseEvent event; |
1422 InitMouseEvent(WebInputEvent::MouseDown, | 1398 InitMouseEvent(WebInputEvent::MouseDown, |
1423 pressed_button_, | 1399 pressed_button_, |
1424 last_mouse_pos_, | 1400 last_mouse_pos_, |
1425 GetCurrentEventTimeSec(), | 1401 GetCurrentEventTimeSec(), |
1426 click_count_, | 1402 click_count_, |
1427 0, | 1403 0, |
1428 &event); | 1404 &event); |
1429 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1405 FinishDragAndDrop(event, blink::WebDragOperationNone); |
1430 } | 1406 } |
1431 | 1407 |
1432 delegate_->ClearEditCommand(); | 1408 delegate_->ClearEditCommand(); |
1433 | 1409 |
1434 if (generate_char) { | 1410 if (generate_char) { |
1435 WebKeyboardEvent event_char = event_up; | 1411 WebKeyboardEvent event_char = event_up; |
1436 event_char.type = WebInputEvent::Char; | 1412 event_char.type = WebInputEvent::Char; |
1437 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1413 // keyIdentifier is an empty string, unless the Enter key was pressed. |
1438 // This behavior is not standard (keyIdentifier itself is not even a | 1414 // This behavior is not standard (keyIdentifier itself is not even a |
1439 // standard any more), but it matches the actual behavior in Blink. | 1415 // standard any more), but it matches the actual behavior in Blink. |
1440 if (code != ui::VKEY_RETURN) | 1416 if (keyCode != ui::VKEY_RETURN) |
1441 event_char.keyIdentifier[0] = '\0'; | 1417 event_char.keyIdentifier[0] = '\0'; |
1442 HandleInputEventOnViewOrPopup(event_char); | 1418 HandleInputEventOnViewOrPopup(event_char); |
1443 } | 1419 } |
1444 | 1420 |
1445 HandleInputEventOnViewOrPopup(event_up); | 1421 HandleInputEventOnViewOrPopup(event_up); |
1446 } | 1422 } |
1447 | 1423 |
1448 void EventSender::EnableDOMUIEventLogging() {} | 1424 void EventSender::EnableDOMUIEventLogging() {} |
1449 | 1425 |
1450 void EventSender::FireKeyboardEventsToElement() {} | 1426 void EventSender::FireKeyboardEventsToElement() {} |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2474 | 2450 |
2475 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2451 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
2476 if (WebPagePopup* popup = view_->pagePopup()) { | 2452 if (WebPagePopup* popup = view_->pagePopup()) { |
2477 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2453 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2478 return popup->handleInputEvent(event); | 2454 return popup->handleInputEvent(event); |
2479 } | 2455 } |
2480 return view_->handleInputEvent(event); | 2456 return view_->handleInputEvent(event); |
2481 } | 2457 } |
2482 | 2458 |
2483 } // namespace test_runner | 2459 } // namespace test_runner |
OLD | NEW |