| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 | 1468 |
| 1469 // Copy the document content to std::wstring and compare with the | 1469 // Copy the document content to std::wstring and compare with the |
| 1470 // expected result. | 1470 // expected result. |
| 1471 const int kMaxOutputCharacters = 16; | 1471 const int kMaxOutputCharacters = 16; |
| 1472 base::string16 output = WebFrameContentDumper::dumpFrameTreeAsText( | 1472 base::string16 output = WebFrameContentDumper::dumpFrameTreeAsText( |
| 1473 GetMainFrame(), kMaxOutputCharacters); | 1473 GetMainFrame(), kMaxOutputCharacters); |
| 1474 EXPECT_EQ(base::WideToUTF16(kTextDirection[i].expected_result), output); | 1474 EXPECT_EQ(base::WideToUTF16(kTextDirection[i].expected_result), output); |
| 1475 } | 1475 } |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 // Test that we can receive correct DOM events when we send input events | |
| 1479 // through the RenderWidget::OnHandleInputEvent() function. | |
| 1480 TEST_F(RenderViewImplTest, OnHandleKeyboardEvent) { | |
| 1481 #if !defined(OS_MACOSX) | |
| 1482 // Load an HTML page consisting of one <input> element and three | |
| 1483 // contentediable <div> elements. | |
| 1484 // The <input> element is used for sending keyboard events, and the <div> | |
| 1485 // elements are used for writing DOM events in the following format: | |
| 1486 // "<keyCode>,<shiftKey>,<controlKey>,<altKey>". | |
| 1487 // TODO(hbono): <http://crbug.com/2215> Our WebKit port set |ev.metaKey| to | |
| 1488 // true when pressing an alt key, i.e. the |ev.metaKey| value is not | |
| 1489 // trustworthy. We will check the |ev.metaKey| value when this issue is fixed. | |
| 1490 view()->set_send_content_state_immediately(true); | |
| 1491 LoadHTML("<html>" | |
| 1492 "<head>" | |
| 1493 "<title></title>" | |
| 1494 "<script type='text/javascript' language='javascript'>" | |
| 1495 "function OnKeyEvent(ev) {" | |
| 1496 " var result = document.getElementById(ev.type);" | |
| 1497 " result.innerText =" | |
| 1498 " (ev.which || ev.keyCode) + ',' +" | |
| 1499 " ev.shiftKey + ',' +" | |
| 1500 " ev.ctrlKey + ',' +" | |
| 1501 " ev.altKey;" | |
| 1502 " return true;" | |
| 1503 "}" | |
| 1504 "</script>" | |
| 1505 "</head>" | |
| 1506 "<body>" | |
| 1507 "<input id='test' type='text'" | |
| 1508 " onkeydown='return OnKeyEvent(event);'" | |
| 1509 " onkeypress='return OnKeyEvent(event);'" | |
| 1510 " onkeyup='return OnKeyEvent(event);'>" | |
| 1511 "</input>" | |
| 1512 "<div id='keydown' contenteditable='true'>" | |
| 1513 "</div>" | |
| 1514 "<div id='keypress' contenteditable='true'>" | |
| 1515 "</div>" | |
| 1516 "<div id='keyup' contenteditable='true'>" | |
| 1517 "</div>" | |
| 1518 "</body>" | |
| 1519 "</html>"); | |
| 1520 ExecuteJavaScriptForTests("document.getElementById('test').focus();"); | |
| 1521 render_thread_->sink().ClearMessages(); | |
| 1522 | |
| 1523 static const MockKeyboard::Layout kLayouts[] = { | |
| 1524 #if defined(OS_WIN) | |
| 1525 // Since we ignore the mock keyboard layout on Linux and instead just use | |
| 1526 // the screen's keyboard layout, these trivially pass. They are commented | |
| 1527 // out to avoid the illusion that they work. | |
| 1528 MockKeyboard::LAYOUT_ARABIC, | |
| 1529 MockKeyboard::LAYOUT_CANADIAN_FRENCH, | |
| 1530 MockKeyboard::LAYOUT_FRENCH, | |
| 1531 MockKeyboard::LAYOUT_HEBREW, | |
| 1532 MockKeyboard::LAYOUT_RUSSIAN, | |
| 1533 #endif | |
| 1534 MockKeyboard::LAYOUT_UNITED_STATES, | |
| 1535 }; | |
| 1536 | |
| 1537 for (size_t i = 0; i < arraysize(kLayouts); ++i) { | |
| 1538 // For each key code, we send three keyboard events. | |
| 1539 // * we press only the key; | |
| 1540 // * we press the key and a left-shift key, and; | |
| 1541 // * we press the key and a right-alt (AltGr) key. | |
| 1542 // For each modifiers, we need a string used for formatting its expected | |
| 1543 // result. (See the above comment for its format.) | |
| 1544 static const struct { | |
| 1545 MockKeyboard::Modifiers modifiers; | |
| 1546 const char* expected_result; | |
| 1547 } kModifierData[] = { | |
| 1548 {MockKeyboard::NONE, "false,false,false"}, | |
| 1549 {MockKeyboard::LEFT_SHIFT, "true,false,false"}, | |
| 1550 #if defined(OS_WIN) | |
| 1551 {MockKeyboard::RIGHT_ALT, "false,false,true"}, | |
| 1552 #endif | |
| 1553 }; | |
| 1554 | |
| 1555 MockKeyboard::Layout layout = kLayouts[i]; | |
| 1556 for (size_t j = 0; j < arraysize(kModifierData); ++j) { | |
| 1557 // Virtual key codes used for this test. | |
| 1558 static const int kKeyCodes[] = { | |
| 1559 '0', '1', '2', '3', '4', '5', '6', '7', | |
| 1560 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', | |
| 1561 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', | |
| 1562 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', | |
| 1563 'W', 'X', 'Y', 'Z', | |
| 1564 ui::VKEY_OEM_1, | |
| 1565 ui::VKEY_OEM_PLUS, | |
| 1566 ui::VKEY_OEM_COMMA, | |
| 1567 ui::VKEY_OEM_MINUS, | |
| 1568 ui::VKEY_OEM_PERIOD, | |
| 1569 ui::VKEY_OEM_2, | |
| 1570 ui::VKEY_OEM_3, | |
| 1571 ui::VKEY_OEM_4, | |
| 1572 ui::VKEY_OEM_5, | |
| 1573 ui::VKEY_OEM_6, | |
| 1574 ui::VKEY_OEM_7, | |
| 1575 #if defined(OS_WIN) | |
| 1576 // Not sure how to handle this key on Linux. | |
| 1577 ui::VKEY_OEM_8, | |
| 1578 #endif | |
| 1579 }; | |
| 1580 | |
| 1581 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; | |
| 1582 for (size_t k = 0; k < arraysize(kKeyCodes); ++k) { | |
| 1583 // Send a keyboard event to the RenderView object. | |
| 1584 // We should test a keyboard event only when the given keyboard-layout | |
| 1585 // driver is installed in a PC and the driver can assign a Unicode | |
| 1586 // charcter for the given tuple (key-code and modifiers). | |
| 1587 int key_code = kKeyCodes[k]; | |
| 1588 base::string16 char_code; | |
| 1589 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | |
| 1590 continue; | |
| 1591 | |
| 1592 // Create an expected result from the virtual-key code, the character | |
| 1593 // code, and the modifier-key status. | |
| 1594 // We format a string that emulates a DOM-event string produced hy | |
| 1595 // our JavaScript function. (See the above comment for the format.) | |
| 1596 static char expected_result[1024]; | |
| 1597 expected_result[0] = 0; | |
| 1598 base::snprintf(&expected_result[0], | |
| 1599 sizeof(expected_result), | |
| 1600 "\n" // texts in the <input> element | |
| 1601 "%d,%s\n" // texts in the first <div> element | |
| 1602 "%d,%s\n" // texts in the second <div> element | |
| 1603 "%d,%s", // texts in the third <div> element | |
| 1604 key_code, kModifierData[j].expected_result, | |
| 1605 static_cast<int>(char_code[0]), | |
| 1606 kModifierData[j].expected_result, | |
| 1607 key_code, kModifierData[j].expected_result); | |
| 1608 | |
| 1609 // Retrieve the text in the test page and compare it with the expected | |
| 1610 // text created from a virtual-key code, a character code, and the | |
| 1611 // modifier-key status. | |
| 1612 const int kMaxOutputCharacters = 1024; | |
| 1613 std::string output = base::UTF16ToUTF8( | |
| 1614 base::StringPiece16(WebFrameContentDumper::dumpFrameTreeAsText( | |
| 1615 GetMainFrame(), kMaxOutputCharacters))); | |
| 1616 EXPECT_EQ(expected_result, output); | |
| 1617 } | |
| 1618 } | |
| 1619 } | |
| 1620 #else | |
| 1621 NOTIMPLEMENTED(); | |
| 1622 #endif | |
| 1623 } | |
| 1624 | |
| 1625 // Test that our EditorClientImpl class can insert characters when we send | 1478 // Test that our EditorClientImpl class can insert characters when we send |
| 1626 // keyboard events through the RenderWidget::OnHandleInputEvent() function. | 1479 // keyboard events through the RenderWidget::OnHandleInputEvent() function. |
| 1627 // This test is for preventing regressions caused only when we use non-US | 1480 // This test is for preventing regressions caused only when we use non-US |
| 1628 // keyboards, such as Issue 10846. | 1481 // keyboards, such as Issue 10846. |
| 1629 // see http://crbug.com/244562 | 1482 // see http://crbug.com/244562 |
| 1630 #if defined(OS_WIN) | 1483 #if defined(OS_WIN) |
| 1631 #define MAYBE_InsertCharacters DISABLED_InsertCharacters | 1484 #define MAYBE_InsertCharacters DISABLED_InsertCharacters |
| 1632 #else | 1485 #else |
| 1633 #define MAYBE_InsertCharacters InsertCharacters | 1486 #define MAYBE_InsertCharacters InsertCharacters |
| 1634 #endif | 1487 #endif |
| (...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2851 FROM_HERE, | 2704 FROM_HERE, |
| 2852 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2705 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
| 2853 ExecuteJavaScriptForTests("debugger;"); | 2706 ExecuteJavaScriptForTests("debugger;"); |
| 2854 | 2707 |
| 2855 // CloseWhilePaused should resume execution and continue here. | 2708 // CloseWhilePaused should resume execution and continue here. |
| 2856 EXPECT_FALSE(IsPaused()); | 2709 EXPECT_FALSE(IsPaused()); |
| 2857 Detach(); | 2710 Detach(); |
| 2858 } | 2711 } |
| 2859 | 2712 |
| 2860 } // namespace content | 2713 } // namespace content |
| OLD | NEW |