Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: components/test_runner/event_sender.cc

Issue 1948763002: [EventSender] Fill DomKey in synthetic key events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove two more keyboardevent-key-expected.txt Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/events/keyboardevent-key.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 // event. This seems to work in the cases I tested. 1388 // event. This seems to work in the cases I tested.
1389 // FIXME: Should we also generate a KEY_UP? 1389 // FIXME: Should we also generate a KEY_UP?
1390 1390
1391 bool generate_char = false; 1391 bool generate_char = false;
1392 1392
1393 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when 1393 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when
1394 // Windows uses \r for "Enter". 1394 // Windows uses \r for "Enter".
1395 int code = 0; 1395 int code = 0;
1396 int text = 0; 1396 int text = 0;
1397 bool needs_shift_key_modifier = false; 1397 bool needs_shift_key_modifier = false;
1398 std::string domString; 1398 std::string domKeyString;
1399 std::string domCodeString;
1399 1400
1400 if ("\n" == code_str) { 1401 if ("\n" == code_str) {
1401 generate_char = true; 1402 generate_char = true;
1402 text = code = ui::VKEY_RETURN; 1403 text = code = ui::VKEY_RETURN;
1403 domString.assign("Enter"); 1404 domKeyString.assign("Enter");
1405 domCodeString.assign("Enter");
1404 } else if ("rightArrow" == code_str) { 1406 } else if ("rightArrow" == code_str) {
1405 code = ui::VKEY_RIGHT; 1407 code = ui::VKEY_RIGHT;
1406 domString.assign("ArrowRight"); 1408 domKeyString.assign("ArrowRight");
1409 domCodeString.assign("ArrowRight");
1407 } else if ("downArrow" == code_str) { 1410 } else if ("downArrow" == code_str) {
1408 code = ui::VKEY_DOWN; 1411 code = ui::VKEY_DOWN;
1409 domString.assign("ArrowDown"); 1412 domKeyString.assign("ArrowDown");
1413 domCodeString.assign("ArrowDown");
1410 } else if ("leftArrow" == code_str) { 1414 } else if ("leftArrow" == code_str) {
1411 code = ui::VKEY_LEFT; 1415 code = ui::VKEY_LEFT;
1412 domString.assign("ArrowLeft"); 1416 domKeyString.assign("ArrowLeft");
1417 domCodeString.assign("ArrowLeft");
1413 } else if ("upArrow" == code_str) { 1418 } else if ("upArrow" == code_str) {
1414 code = ui::VKEY_UP; 1419 code = ui::VKEY_UP;
1415 domString.assign("ArrowUp"); 1420 domKeyString.assign("ArrowUp");
1421 domCodeString.assign("ArrowUp");
1416 } else if ("insert" == code_str) { 1422 } else if ("insert" == code_str) {
1417 code = ui::VKEY_INSERT; 1423 code = ui::VKEY_INSERT;
1418 domString.assign("Insert"); 1424 domKeyString.assign("Insert");
1425 domCodeString.assign("Insert");
1419 } else if ("delete" == code_str) { 1426 } else if ("delete" == code_str) {
1420 code = ui::VKEY_DELETE; 1427 code = ui::VKEY_DELETE;
1421 domString.assign("Delete"); 1428 domKeyString.assign("Delete");
1429 domCodeString.assign("Delete");
1422 } else if ("pageUp" == code_str) { 1430 } else if ("pageUp" == code_str) {
1423 code = ui::VKEY_PRIOR; 1431 code = ui::VKEY_PRIOR;
1424 domString.assign("PageUp"); 1432 domKeyString.assign("PageUp");
1433 domCodeString.assign("PageUp");
1425 } else if ("pageDown" == code_str) { 1434 } else if ("pageDown" == code_str) {
1426 code = ui::VKEY_NEXT; 1435 code = ui::VKEY_NEXT;
1427 domString.assign("PageDown"); 1436 domKeyString.assign("PageDown");
1437 domCodeString.assign("PageDown");
1428 } else if ("home" == code_str) { 1438 } else if ("home" == code_str) {
1429 code = ui::VKEY_HOME; 1439 code = ui::VKEY_HOME;
1430 domString.assign("Home"); 1440 domKeyString.assign("Home");
1441 domCodeString.assign("Home");
1431 } else if ("end" == code_str) { 1442 } else if ("end" == code_str) {
1432 code = ui::VKEY_END; 1443 code = ui::VKEY_END;
1433 domString.assign("End"); 1444 domKeyString.assign("End");
1445 domCodeString.assign("End");
1434 } else if ("printScreen" == code_str) { 1446 } else if ("printScreen" == code_str) {
1435 code = ui::VKEY_SNAPSHOT; 1447 code = ui::VKEY_SNAPSHOT;
1436 domString.assign("PrintScreen"); 1448 domKeyString.assign("PrintScreen");
1449 domCodeString.assign("PrintScreen");
1437 } else if ("menu" == code_str) { 1450 } else if ("menu" == code_str) {
1438 code = ui::VKEY_APPS; 1451 code = ui::VKEY_APPS;
1439 domString.assign("ContextMenu"); 1452 domKeyString.assign("ContextMenu");
1453 domCodeString.assign("ContextMenu");
1440 } else if ("leftControl" == code_str) { 1454 } else if ("leftControl" == code_str) {
1441 code = ui::VKEY_CONTROL; 1455 code = ui::VKEY_CONTROL;
1442 domString.assign("ControlLeft"); 1456 domKeyString.assign("Control");
1457 domCodeString.assign("ControlLeft");
1443 location = DOMKeyLocationLeft; 1458 location = DOMKeyLocationLeft;
1444 } else if ("rightControl" == code_str) { 1459 } else if ("rightControl" == code_str) {
1445 code = ui::VKEY_CONTROL; 1460 code = ui::VKEY_CONTROL;
1446 domString.assign("ControlRight"); 1461 domKeyString.assign("Control");
1462 domCodeString.assign("ControlRight");
1447 location = DOMKeyLocationRight; 1463 location = DOMKeyLocationRight;
1448 } else if ("leftShift" == code_str) { 1464 } else if ("leftShift" == code_str) {
1449 code = ui::VKEY_SHIFT; 1465 code = ui::VKEY_SHIFT;
1450 domString.assign("ShiftLeft"); 1466 domKeyString.assign("Shift");
1467 domCodeString.assign("ShiftLeft");
1451 location = DOMKeyLocationLeft; 1468 location = DOMKeyLocationLeft;
1452 } else if ("rightShift" == code_str) { 1469 } else if ("rightShift" == code_str) {
1453 code = ui::VKEY_SHIFT; 1470 code = ui::VKEY_SHIFT;
1454 domString.assign("ShiftRight"); 1471 domKeyString.assign("Shift");
1472 domCodeString.assign("ShiftRight");
1455 location = DOMKeyLocationRight; 1473 location = DOMKeyLocationRight;
1456 } else if ("leftAlt" == code_str) { 1474 } else if ("leftAlt" == code_str) {
1457 code = ui::VKEY_MENU; 1475 code = ui::VKEY_MENU;
1458 domString.assign("AltLeft"); 1476 domKeyString.assign("Alt");
1477 domCodeString.assign("AltLeft");
1459 location = DOMKeyLocationLeft; 1478 location = DOMKeyLocationLeft;
1460 } else if ("rightAlt" == code_str) { 1479 } else if ("rightAlt" == code_str) {
1461 code = ui::VKEY_MENU; 1480 code = ui::VKEY_MENU;
1462 domString.assign("AltRight"); 1481 domKeyString.assign("Alt");
1482 domCodeString.assign("AltRight");
1463 location = DOMKeyLocationRight; 1483 location = DOMKeyLocationRight;
1464 } else if ("numLock" == code_str) { 1484 } else if ("numLock" == code_str) {
1465 code = ui::VKEY_NUMLOCK; 1485 code = ui::VKEY_NUMLOCK;
1466 domString.assign("NumLock"); 1486 domKeyString.assign("NumLock");
1487 domCodeString.assign("NumLock");
1467 } else if ("backspace" == code_str) { 1488 } else if ("backspace" == code_str) {
1468 code = ui::VKEY_BACK; 1489 code = ui::VKEY_BACK;
1469 domString.assign("Backspace"); 1490 domKeyString.assign("Backspace");
1491 domCodeString.assign("Backspace");
1470 } else if ("escape" == code_str) { 1492 } else if ("escape" == code_str) {
1471 code = ui::VKEY_ESCAPE; 1493 code = ui::VKEY_ESCAPE;
1472 domString.assign("Escape"); 1494 domKeyString.assign("Escape");
1495 domCodeString.assign("Escape");
1473 } else { 1496 } else {
1474 // Compare the input string with the function-key names defined by the 1497 // Compare the input string with the function-key names defined by the
1475 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key 1498 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key
1476 // name, set its key code. 1499 // name, set its key code.
1477 for (int i = 1; i <= 24; ++i) { 1500 for (int i = 1; i <= 24; ++i) {
1478 std::string function_key_name = base::StringPrintf("F%d", i); 1501 std::string function_key_name = base::StringPrintf("F%d", i);
1479 if (function_key_name == code_str) { 1502 if (function_key_name == code_str) {
1480 code = ui::VKEY_F1 + (i - 1); 1503 code = ui::VKEY_F1 + (i - 1);
1481 domString = function_key_name; 1504 domKeyString = function_key_name;
1505 domCodeString = function_key_name;
1482 break; 1506 break;
1483 } 1507 }
1484 } 1508 }
1485 if (!code) { 1509 if (!code) {
1486 base::string16 code_str16 = base::UTF8ToUTF16(code_str); 1510 base::string16 code_str16 = base::UTF8ToUTF16(code_str);
1487 if (code_str16.size() != 1u) { 1511 if (code_str16.size() != 1u) {
1488 v8::Isolate* isolate = blink::mainThreadIsolate(); 1512 v8::Isolate* isolate = blink::mainThreadIsolate();
1489 isolate->ThrowException(v8::Exception::TypeError( 1513 isolate->ThrowException(v8::Exception::TypeError(
1490 gin::StringToV8(isolate, "Invalid web code."))); 1514 gin::StringToV8(isolate, "Invalid web code.")));
1491 return; 1515 return;
1492 } 1516 }
1493 text = code = code_str16[0]; 1517 text = code = code_str16[0];
1494 needs_shift_key_modifier = base::IsAsciiUpper(code & 0xFF); 1518 needs_shift_key_modifier = base::IsAsciiUpper(code & 0xFF);
1495 if (base::IsAsciiLower(code & 0xFF)) 1519 if (base::IsAsciiLower(code & 0xFF))
1496 code -= 'a' - 'A'; 1520 code -= 'a' - 'A';
1497 if (base::IsAsciiAlpha(code)) { 1521 if (base::IsAsciiAlpha(code)) {
1498 domString.assign("Key"); 1522 domKeyString.assign(code_str);
1499 domString.push_back( 1523 domCodeString.assign("Key");
1524 domCodeString.push_back(
1500 base::ToUpperASCII(static_cast<base::char16>(code))); 1525 base::ToUpperASCII(static_cast<base::char16>(code)));
1501 } else if (base::IsAsciiDigit(code)) { 1526 } else if (base::IsAsciiDigit(code)) {
1502 domString.assign("Digit"); 1527 domKeyString.assign(code_str);
1503 domString.push_back(code); 1528 domCodeString.assign("Digit");
1529 domCodeString.push_back(code);
1504 } else if (code == ' ') { 1530 } else if (code == ' ') {
1505 domString.assign("Space"); 1531 domKeyString.assign(code_str);
1532 domCodeString.assign("Space");
1506 } else if (code == 9) { 1533 } else if (code == 9) {
1507 domString.assign("Tab"); 1534 domKeyString.assign("Tab");
1535 domCodeString.assign("Tab");
1508 } 1536 }
1509 generate_char = true; 1537 generate_char = true;
1510 } 1538 }
1511 1539
1512 if ("(" == code_str) { 1540 if ("(" == code_str) {
1513 code = '9'; 1541 code = '9';
1514 needs_shift_key_modifier = true; 1542 needs_shift_key_modifier = true;
1543 domKeyString.assign("(");
1544 domCodeString.assign("Digit9");
1515 } 1545 }
1516 } 1546 }
1517 1547
1518 // For one generated keyboard event, we need to generate a keyDown/keyUp 1548 // For one generated keyboard event, we need to generate a keyDown/keyUp
1519 // pair; 1549 // pair;
1520 // On Windows, we might also need to generate a char event to mimic the 1550 // On Windows, we might also need to generate a char event to mimic the
1521 // Windows event flow; on other platforms we create a merged event and test 1551 // Windows event flow; on other platforms we create a merged event and test
1522 // the event flow that that platform provides. 1552 // the event flow that that platform provides.
1523 WebKeyboardEvent event_down; 1553 WebKeyboardEvent event_down;
1524 event_down.timeStampSeconds = GetCurrentEventTimeSec(); 1554 event_down.timeStampSeconds = GetCurrentEventTimeSec();
1525 event_down.type = WebInputEvent::RawKeyDown; 1555 event_down.type = WebInputEvent::RawKeyDown;
1526 event_down.modifiers = modifiers; 1556 event_down.modifiers = modifiers;
1527 event_down.windowsKeyCode = code; 1557 event_down.windowsKeyCode = code;
1558 event_down.domKey = static_cast<int>(
1559 ui::KeycodeConverter::KeyStringToDomKey(domKeyString));
1528 event_down.domCode = static_cast<int>( 1560 event_down.domCode = static_cast<int>(
1529 ui::KeycodeConverter::CodeStringToDomCode(domString)); 1561 ui::KeycodeConverter::CodeStringToDomCode(domCodeString));
1530 1562
1531 if (generate_char) { 1563 if (generate_char) {
1532 event_down.text[0] = text; 1564 event_down.text[0] = text;
1533 event_down.unmodifiedText[0] = text; 1565 event_down.unmodifiedText[0] = text;
1534 } 1566 }
1535 1567
1536 event_down.setKeyIdentifierFromWindowsKeyCode(); 1568 event_down.setKeyIdentifierFromWindowsKeyCode();
1537 1569
1538 if (event_down.modifiers != 0) 1570 if (event_down.modifiers != 0)
1539 event_down.isSystemKey = IsSystemKeyEvent(event_down); 1571 event_down.isSystemKey = IsSystemKeyEvent(event_down);
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2741 2773
2742 const blink::WebView* EventSender::view() const { 2774 const blink::WebView* EventSender::view() const {
2743 return web_test_proxy_base_->web_view(); 2775 return web_test_proxy_base_->web_view();
2744 } 2776 }
2745 2777
2746 blink::WebView* EventSender::view() { 2778 blink::WebView* EventSender::view() {
2747 return web_test_proxy_base_->web_view(); 2779 return web_test_proxy_base_->web_view();
2748 } 2780 }
2749 2781
2750 } // namespace test_runner 2782 } // namespace test_runner
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/events/keyboardevent-key.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698