| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/keyboard_codes.h" |
| 6 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
| 7 #include "chrome/common/content_settings.h" | 8 #include "chrome/common/content_settings.h" |
| 8 #include "chrome/common/native_web_keyboard_event.h" | 9 #include "chrome/common/native_web_keyboard_event.h" |
| 9 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/renderer/print_web_view_helper.h" | 11 #include "chrome/renderer/print_web_view_helper.h" |
| 11 #include "chrome/test/render_view_test.h" | 12 #include "chrome/test/render_view_test.h" |
| 12 #include "gfx/codec/jpeg_codec.h" | 13 #include "gfx/codec/jpeg_codec.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "printing/image.h" | 15 #include "printing/image.h" |
| 15 #include "printing/native_metafile.h" | 16 #include "printing/native_metafile.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 } | 526 } |
| 526 ASSERT_TRUE(!is_white); | 527 ASSERT_TRUE(!is_white); |
| 527 #else | 528 #else |
| 528 NOTIMPLEMENTED(); | 529 NOTIMPLEMENTED(); |
| 529 #endif | 530 #endif |
| 530 } | 531 } |
| 531 | 532 |
| 532 // Test that we can receive correct DOM events when we send input events | 533 // Test that we can receive correct DOM events when we send input events |
| 533 // through the RenderWidget::OnHandleInputEvent() function. | 534 // through the RenderWidget::OnHandleInputEvent() function. |
| 534 TEST_F(RenderViewTest, FLAKY_OnHandleKeyboardEvent) { | 535 TEST_F(RenderViewTest, FLAKY_OnHandleKeyboardEvent) { |
| 535 #if defined(OS_WIN) | 536 #if defined(OS_WIN) || defined(OS_LINUX) |
| 536 // Load an HTML page consisting of one <input> element and three | 537 // Load an HTML page consisting of one <input> element and three |
| 537 // contentediable <div> elements. | 538 // contentediable <div> elements. |
| 538 // The <input> element is used for sending keyboard events, and the <div> | 539 // The <input> element is used for sending keyboard events, and the <div> |
| 539 // elements are used for writing DOM events in the following format: | 540 // elements are used for writing DOM events in the following format: |
| 540 // "<keyCode>,<shiftKey>,<controlKey>,<altKey>". | 541 // "<keyCode>,<shiftKey>,<controlKey>,<altKey>". |
| 541 // TODO(hbono): <http://crbug.com/2215> Our WebKit port set |ev.metaKey| to | 542 // TODO(hbono): <http://crbug.com/2215> Our WebKit port set |ev.metaKey| to |
| 542 // true when pressing an alt key, i.e. the |ev.metaKey| value is not | 543 // true when pressing an alt key, i.e. the |ev.metaKey| value is not |
| 543 // trustworthy. We will check the |ev.metaKey| value when this issue is fixed. | 544 // trustworthy. We will check the |ev.metaKey| value when this issue is fixed. |
| 544 view_->set_send_content_state_immediately(true); | 545 view_->set_send_content_state_immediately(true); |
| 545 LoadHTML("<html>" | 546 LoadHTML("<html>" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 586 |
| 586 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLayouts); ++i) { | 587 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLayouts); ++i) { |
| 587 // For each key code, we send three keyboard events. | 588 // For each key code, we send three keyboard events. |
| 588 // * we press only the key; | 589 // * we press only the key; |
| 589 // * we press the key and a left-shift key, and; | 590 // * we press the key and a left-shift key, and; |
| 590 // * we press the key and a right-alt (AltGr) key. | 591 // * we press the key and a right-alt (AltGr) key. |
| 591 // For each modifiers, we need a string used for formatting its expected | 592 // For each modifiers, we need a string used for formatting its expected |
| 592 // result. (See the above comment for its format.) | 593 // result. (See the above comment for its format.) |
| 593 static const struct { | 594 static const struct { |
| 594 MockKeyboard::Modifiers modifiers; | 595 MockKeyboard::Modifiers modifiers; |
| 595 const wchar_t* expected_result; | 596 const char* expected_result; |
| 596 } kModifierData[] = { | 597 } kModifierData[] = { |
| 597 {MockKeyboard::NONE, L"false,false,false"}, | 598 {MockKeyboard::NONE, "false,false,false"}, |
| 598 {MockKeyboard::LEFT_SHIFT, L"true,false,false"}, | 599 {MockKeyboard::LEFT_SHIFT, "true,false,false"}, |
| 599 {MockKeyboard::RIGHT_ALT, L"false,false,true"}, | 600 #if defined(OS_WIN) |
| 601 // TODO(estade): figure out why this one doesn't work on Linux. |
| 602 {MockKeyboard::RIGHT_ALT, "false,false,true"}, |
| 603 #endif |
| 600 }; | 604 }; |
| 601 | 605 |
| 602 MockKeyboard::Layout layout = kLayouts[i]; | 606 MockKeyboard::Layout layout = kLayouts[i]; |
| 603 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kModifierData); ++j) { | 607 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kModifierData); ++j) { |
| 604 // Virtual key codes used for this test. | 608 // Virtual key codes used for this test. |
| 605 static const int kKeyCodes[] = { | 609 static const int kKeyCodes[] = { |
| 606 '0', '1', '2', '3', '4', '5', '6', '7', | 610 '0', '1', '2', '3', '4', '5', '6', '7', |
| 607 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', | 611 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', |
| 608 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', | 612 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', |
| 609 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', | 613 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', |
| 610 'W', 'X', 'Y', 'Z', | 614 'W', 'X', 'Y', 'Z', |
| 611 VK_OEM_1, | 615 base::VKEY_OEM_1, |
| 612 VK_OEM_PLUS, | 616 base::VKEY_OEM_PLUS, |
| 613 VK_OEM_COMMA, | 617 base::VKEY_OEM_COMMA, |
| 614 VK_OEM_MINUS, | 618 base::VKEY_OEM_MINUS, |
| 615 VK_OEM_PERIOD, | 619 base::VKEY_OEM_PERIOD, |
| 616 VK_OEM_2, | 620 base::VKEY_OEM_2, |
| 617 VK_OEM_3, | 621 base::VKEY_OEM_3, |
| 618 VK_OEM_4, | 622 base::VKEY_OEM_4, |
| 619 VK_OEM_5, | 623 base::VKEY_OEM_5, |
| 620 VK_OEM_6, | 624 base::VKEY_OEM_6, |
| 621 VK_OEM_7, | 625 base::VKEY_OEM_7, |
| 622 VK_OEM_8, | 626 #if defined(OS_WIN) |
| 627 // Not sure how to handle this key on Linux. |
| 628 base::VKEY_OEM_8, |
| 629 #endif |
| 623 }; | 630 }; |
| 624 | 631 |
| 625 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; | 632 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; |
| 626 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { | 633 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { |
| 627 // Send a keyboard event to the RenderView object. | 634 // Send a keyboard event to the RenderView object. |
| 628 // We should test a keyboard event only when the given keyboard-layout | 635 // We should test a keyboard event only when the given keyboard-layout |
| 629 // driver is installed in a PC and the driver can assign a Unicode | 636 // driver is installed in a PC and the driver can assign a Unicode |
| 630 // charcter for the given tuple (key-code and modifiers). | 637 // charcter for the given tuple (key-code and modifiers). |
| 631 int key_code = kKeyCodes[k]; | 638 int key_code = kKeyCodes[k]; |
| 632 std::wstring char_code; | 639 std::wstring char_code; |
| 633 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 640 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) |
| 634 continue; | 641 continue; |
| 635 | 642 |
| 636 // Create an expected result from the virtual-key code, the character | 643 // Create an expected result from the virtual-key code, the character |
| 637 // code, and the modifier-key status. | 644 // code, and the modifier-key status. |
| 638 // We format a string that emulates a DOM-event string produced hy | 645 // We format a string that emulates a DOM-event string produced hy |
| 639 // our JavaScript function. (See the above comment for the format.) | 646 // our JavaScript function. (See the above comment for the format.) |
| 640 static wchar_t expected_result[1024]; | 647 static char expected_result[1024]; |
| 641 wsprintf(&expected_result[0], | 648 expected_result[0] = NULL; |
| 642 L"\x000A" // texts in the <input> element | 649 sprintf(&expected_result[0], |
| 643 L"%d,%s\x000A" // texts in the first <div> element | 650 "\n" // texts in the <input> element |
| 644 L"%d,%s\x000A" // texts in the second <div> element | 651 "%d,%s\n" // texts in the first <div> element |
| 645 L"%d,%s", // texts in the third <div> element | 652 "%d,%s\n" // texts in the second <div> element |
| 646 key_code, kModifierData[j].expected_result, | 653 "%d,%s", // texts in the third <div> element |
| 647 char_code[0], kModifierData[j].expected_result, | 654 key_code, kModifierData[j].expected_result, |
| 648 key_code, kModifierData[j].expected_result); | 655 char_code[0], kModifierData[j].expected_result, |
| 656 key_code, kModifierData[j].expected_result); |
| 649 | 657 |
| 650 // Retrieve the text in the test page and compare it with the expected | 658 // Retrieve the text in the test page and compare it with the expected |
| 651 // text created from a virtual-key code, a character code, and the | 659 // text created from a virtual-key code, a character code, and the |
| 652 // modifier-key status. | 660 // modifier-key status. |
| 653 const int kMaxOutputCharacters = 1024; | 661 const int kMaxOutputCharacters = 1024; |
| 654 std::wstring output = UTF16ToWideHack( | 662 std::string output = UTF16ToUTF8( |
| 655 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 663 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 656 EXPECT_EQ(expected_result, output); | 664 EXPECT_EQ(expected_result, output); |
| 657 } | 665 } |
| 658 } | 666 } |
| 659 } | 667 } |
| 660 #else | 668 #else |
| 661 NOTIMPLEMENTED(); | 669 NOTIMPLEMENTED(); |
| 662 #endif | 670 #endif |
| 663 } | 671 } |
| 664 | 672 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 833 |
| 826 MockKeyboard::Layout layout = kLayouts[i].layout; | 834 MockKeyboard::Layout layout = kLayouts[i].layout; |
| 827 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kModifiers); ++j) { | 835 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kModifiers); ++j) { |
| 828 // Virtual key codes used for this test. | 836 // Virtual key codes used for this test. |
| 829 static const int kKeyCodes[] = { | 837 static const int kKeyCodes[] = { |
| 830 '0', '1', '2', '3', '4', '5', '6', '7', | 838 '0', '1', '2', '3', '4', '5', '6', '7', |
| 831 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', | 839 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', |
| 832 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', | 840 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', |
| 833 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', | 841 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', |
| 834 'W', 'X', 'Y', 'Z', | 842 'W', 'X', 'Y', 'Z', |
| 835 VK_OEM_1, | 843 base::VKEY_OEM_1, |
| 836 VK_OEM_PLUS, | 844 base::VKEY_OEM_PLUS, |
| 837 VK_OEM_COMMA, | 845 base::VKEY_OEM_COMMA, |
| 838 VK_OEM_MINUS, | 846 base::VKEY_OEM_MINUS, |
| 839 VK_OEM_PERIOD, | 847 base::VKEY_OEM_PERIOD, |
| 840 VK_OEM_2, | 848 base::VKEY_OEM_2, |
| 841 VK_OEM_3, | 849 base::VKEY_OEM_3, |
| 842 VK_OEM_4, | 850 base::VKEY_OEM_4, |
| 843 VK_OEM_5, | 851 base::VKEY_OEM_5, |
| 844 VK_OEM_6, | 852 base::VKEY_OEM_6, |
| 845 VK_OEM_7, | 853 base::VKEY_OEM_7, |
| 846 VK_OEM_8, | 854 base::VKEY_OEM_8, |
| 847 }; | 855 }; |
| 848 | 856 |
| 849 MockKeyboard::Modifiers modifiers = kModifiers[j]; | 857 MockKeyboard::Modifiers modifiers = kModifiers[j]; |
| 850 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { | 858 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { |
| 851 // Send a keyboard event to the RenderView object. | 859 // Send a keyboard event to the RenderView object. |
| 852 // We should test a keyboard event only when the given keyboard-layout | 860 // We should test a keyboard event only when the given keyboard-layout |
| 853 // driver is installed in a PC and the driver can assign a Unicode | 861 // driver is installed in a PC and the driver can assign a Unicode |
| 854 // charcter for the given tuple (layout, key-code, and modifiers). | 862 // charcter for the given tuple (layout, key-code, and modifiers). |
| 855 int key_code = kKeyCodes[k]; | 863 int key_code = kKeyCodes[k]; |
| 856 std::wstring char_code; | 864 std::wstring char_code; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 EXPECT_NE(-1, block_index); | 956 EXPECT_NE(-1, block_index); |
| 949 EXPECT_LT(navigation_index, block_index); | 957 EXPECT_LT(navigation_index, block_index); |
| 950 } | 958 } |
| 951 | 959 |
| 952 // Regression test for http://crbug.com/41562 | 960 // Regression test for http://crbug.com/41562 |
| 953 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { | 961 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { |
| 954 const GURL invalid_gurl("http://"); | 962 const GURL invalid_gurl("http://"); |
| 955 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); | 963 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); |
| 956 EXPECT_EQ(invalid_gurl, view_->target_url_); | 964 EXPECT_EQ(invalid_gurl, view_->target_url_); |
| 957 } | 965 } |
| OLD | NEW |