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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 | 138 |
139 RenderViewImpl* view() { | 139 RenderViewImpl* view() { |
140 return static_cast<RenderViewImpl*>(view_); | 140 return static_cast<RenderViewImpl*>(view_); |
141 } | 141 } |
142 | 142 |
143 // Sends IPC messages that emulates a key-press event. | 143 // Sends IPC messages that emulates a key-press event. |
144 int SendKeyEvent(MockKeyboard::Layout layout, | 144 int SendKeyEvent(MockKeyboard::Layout layout, |
145 int key_code, | 145 int key_code, |
146 MockKeyboard::Modifiers modifiers, | 146 MockKeyboard::Modifiers modifiers, |
147 string16* output) { | 147 base::string16* output) { |
148 #if defined(OS_WIN) | 148 #if defined(OS_WIN) |
149 // Retrieve the Unicode character for the given tuple (keyboard-layout, | 149 // Retrieve the Unicode character for the given tuple (keyboard-layout, |
150 // key-code, and modifiers). | 150 // key-code, and modifiers). |
151 // Exit when a keyboard-layout driver cannot assign a Unicode character to | 151 // Exit when a keyboard-layout driver cannot assign a Unicode character to |
152 // the tuple to prevent sending an invalid key code to the RenderView | 152 // the tuple to prevent sending an invalid key code to the RenderView |
153 // object. | 153 // object. |
154 CHECK(mock_keyboard_.get()); | 154 CHECK(mock_keyboard_.get()); |
155 CHECK(output); | 155 CHECK(output); |
156 int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, | 156 int length = mock_keyboard_->GetCharacters(layout, key_code, modifiers, |
157 output); | 157 output); |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1045 |
1046 case IME_CONFIRMCOMPOSITION: | 1046 case IME_CONFIRMCOMPOSITION: |
1047 view()->OnImeConfirmComposition( | 1047 view()->OnImeConfirmComposition( |
1048 WideToUTF16Hack(ime_message->ime_string), | 1048 WideToUTF16Hack(ime_message->ime_string), |
1049 gfx::Range::InvalidRange(), | 1049 gfx::Range::InvalidRange(), |
1050 false); | 1050 false); |
1051 break; | 1051 break; |
1052 | 1052 |
1053 case IME_CANCELCOMPOSITION: | 1053 case IME_CANCELCOMPOSITION: |
1054 view()->OnImeSetComposition( | 1054 view()->OnImeSetComposition( |
1055 string16(), | 1055 base::string16(), |
1056 std::vector<blink::WebCompositionUnderline>(), | 1056 std::vector<blink::WebCompositionUnderline>(), |
1057 0, 0); | 1057 0, 0); |
1058 break; | 1058 break; |
1059 } | 1059 } |
1060 | 1060 |
1061 // Update the status of our IME back-end. | 1061 // Update the status of our IME back-end. |
1062 // TODO(hbono): we should verify messages to be sent from the back-end. | 1062 // TODO(hbono): we should verify messages to be sent from the back-end. |
1063 view()->UpdateTextInputType(); | 1063 view()->UpdateTextInputType(); |
1064 ProcessPendingMessages(); | 1064 ProcessPendingMessages(); |
1065 render_thread_->sink().ClearMessages(); | 1065 render_thread_->sink().ClearMessages(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 #endif | 1233 #endif |
1234 }; | 1234 }; |
1235 | 1235 |
1236 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; | 1236 MockKeyboard::Modifiers modifiers = kModifierData[j].modifiers; |
1237 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { | 1237 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { |
1238 // Send a keyboard event to the RenderView object. | 1238 // Send a keyboard event to the RenderView object. |
1239 // We should test a keyboard event only when the given keyboard-layout | 1239 // We should test a keyboard event only when the given keyboard-layout |
1240 // driver is installed in a PC and the driver can assign a Unicode | 1240 // driver is installed in a PC and the driver can assign a Unicode |
1241 // charcter for the given tuple (key-code and modifiers). | 1241 // charcter for the given tuple (key-code and modifiers). |
1242 int key_code = kKeyCodes[k]; | 1242 int key_code = kKeyCodes[k]; |
1243 string16 char_code; | 1243 base::string16 char_code; |
1244 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 1244 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) |
1245 continue; | 1245 continue; |
1246 | 1246 |
1247 // Create an expected result from the virtual-key code, the character | 1247 // Create an expected result from the virtual-key code, the character |
1248 // code, and the modifier-key status. | 1248 // code, and the modifier-key status. |
1249 // We format a string that emulates a DOM-event string produced hy | 1249 // We format a string that emulates a DOM-event string produced hy |
1250 // our JavaScript function. (See the above comment for the format.) | 1250 // our JavaScript function. (See the above comment for the format.) |
1251 static char expected_result[1024]; | 1251 static char expected_result[1024]; |
1252 expected_result[0] = 0; | 1252 expected_result[0] = 0; |
1253 base::snprintf(&expected_result[0], | 1253 base::snprintf(&expected_result[0], |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 #endif | 1480 #endif |
1481 }; | 1481 }; |
1482 | 1482 |
1483 MockKeyboard::Modifiers modifiers = kModifiers[j]; | 1483 MockKeyboard::Modifiers modifiers = kModifiers[j]; |
1484 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { | 1484 for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) { |
1485 // Send a keyboard event to the RenderView object. | 1485 // Send a keyboard event to the RenderView object. |
1486 // We should test a keyboard event only when the given keyboard-layout | 1486 // We should test a keyboard event only when the given keyboard-layout |
1487 // driver is installed in a PC and the driver can assign a Unicode | 1487 // driver is installed in a PC and the driver can assign a Unicode |
1488 // charcter for the given tuple (layout, key-code, and modifiers). | 1488 // charcter for the given tuple (layout, key-code, and modifiers). |
1489 int key_code = kKeyCodes[k]; | 1489 int key_code = kKeyCodes[k]; |
1490 string16 char_code; | 1490 base::string16 char_code; |
1491 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 1491 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) |
1492 continue; | 1492 continue; |
1493 } | 1493 } |
1494 } | 1494 } |
1495 | 1495 |
1496 // Retrieve the text in the test page and compare it with the expected | 1496 // Retrieve the text in the test page and compare it with the expected |
1497 // text created from a virtual-key code, a character code, and the | 1497 // text created from a virtual-key code, a character code, and the |
1498 // modifier-key status. | 1498 // modifier-key status. |
1499 const int kMaxOutputCharacters = 4096; | 1499 const int kMaxOutputCharacters = 4096; |
1500 std::wstring output = UTF16ToWideHack( | 1500 std::wstring output = UTF16ToWideHack( |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 SendWebMouseEvent(mouse_event); | 1738 SendWebMouseEvent(mouse_event); |
1739 | 1739 |
1740 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 1740 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
1741 ViewHostMsg_ContextMenu::ID)); | 1741 ViewHostMsg_ContextMenu::ID)); |
1742 } | 1742 } |
1743 | 1743 |
1744 TEST_F(RenderViewImplTest, TestBackForward) { | 1744 TEST_F(RenderViewImplTest, TestBackForward) { |
1745 LoadHTML("<div id=pagename>Page A</div>"); | 1745 LoadHTML("<div id=pagename>Page A</div>"); |
1746 blink::WebHistoryItem page_a_item = GetMainFrame()->currentHistoryItem(); | 1746 blink::WebHistoryItem page_a_item = GetMainFrame()->currentHistoryItem(); |
1747 int was_page_a = -1; | 1747 int was_page_a = -1; |
1748 string16 check_page_a = | 1748 base::string16 check_page_a = |
1749 ASCIIToUTF16( | 1749 ASCIIToUTF16( |
1750 "Number(document.getElementById('pagename').innerHTML == 'Page A')"); | 1750 "Number(document.getElementById('pagename').innerHTML == 'Page A')"); |
1751 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a)); | 1751 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a)); |
1752 EXPECT_EQ(1, was_page_a); | 1752 EXPECT_EQ(1, was_page_a); |
1753 | 1753 |
1754 LoadHTML("<div id=pagename>Page B</div>"); | 1754 LoadHTML("<div id=pagename>Page B</div>"); |
1755 int was_page_b = -1; | 1755 int was_page_b = -1; |
1756 string16 check_page_b = | 1756 base::string16 check_page_b = |
1757 ASCIIToUTF16( | 1757 ASCIIToUTF16( |
1758 "Number(document.getElementById('pagename').innerHTML == 'Page B')"); | 1758 "Number(document.getElementById('pagename').innerHTML == 'Page B')"); |
1759 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); | 1759 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); |
1760 EXPECT_EQ(1, was_page_b); | 1760 EXPECT_EQ(1, was_page_b); |
1761 | 1761 |
1762 LoadHTML("<div id=pagename>Page C</div>"); | 1762 LoadHTML("<div id=pagename>Page C</div>"); |
1763 int was_page_c = -1; | 1763 int was_page_c = -1; |
1764 string16 check_page_c = | 1764 base::string16 check_page_c = |
1765 ASCIIToUTF16( | 1765 ASCIIToUTF16( |
1766 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); | 1766 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); |
1767 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); | 1767 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
1768 EXPECT_EQ(1, was_page_b); | 1768 EXPECT_EQ(1, was_page_b); |
1769 | 1769 |
1770 blink::WebHistoryItem forward_item = GetMainFrame()->currentHistoryItem(); | 1770 blink::WebHistoryItem forward_item = GetMainFrame()->currentHistoryItem(); |
1771 GoBack(GetMainFrame()->previousHistoryItem()); | 1771 GoBack(GetMainFrame()->previousHistoryItem()); |
1772 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); | 1772 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); |
1773 EXPECT_EQ(1, was_page_b); | 1773 EXPECT_EQ(1, was_page_b); |
1774 | 1774 |
(...skipping 20 matching lines...) Expand all Loading... |
1795 | 1795 |
1796 #if defined(OS_WIN) | 1796 #if defined(OS_WIN) |
1797 // http://crbug.com/304193 | 1797 // http://crbug.com/304193 |
1798 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 1798 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
1799 return; | 1799 return; |
1800 #endif | 1800 #endif |
1801 | 1801 |
1802 LoadHTML("<textarea id=\"test\"></textarea>"); | 1802 LoadHTML("<textarea id=\"test\"></textarea>"); |
1803 ExecuteJavaScript("document.getElementById('test').focus();"); | 1803 ExecuteJavaScript("document.getElementById('test').focus();"); |
1804 | 1804 |
1805 const string16 empty_string = UTF8ToUTF16(""); | 1805 const base::string16 empty_string = UTF8ToUTF16(""); |
1806 const std::vector<blink::WebCompositionUnderline> empty_underline; | 1806 const std::vector<blink::WebCompositionUnderline> empty_underline; |
1807 std::vector<gfx::Rect> bounds; | 1807 std::vector<gfx::Rect> bounds; |
1808 view()->OnSetFocus(true); | 1808 view()->OnSetFocus(true); |
1809 view()->OnSetInputMethodActive(true); | 1809 view()->OnSetInputMethodActive(true); |
1810 | 1810 |
1811 // ASCII composition | 1811 // ASCII composition |
1812 const string16 ascii_composition = UTF8ToUTF16("aiueo"); | 1812 const base::string16 ascii_composition = UTF8ToUTF16("aiueo"); |
1813 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); | 1813 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); |
1814 view()->GetCompositionCharacterBounds(&bounds); | 1814 view()->GetCompositionCharacterBounds(&bounds); |
1815 ASSERT_EQ(ascii_composition.size(), bounds.size()); | 1815 ASSERT_EQ(ascii_composition.size(), bounds.size()); |
1816 for (size_t i = 0; i < bounds.size(); ++i) | 1816 for (size_t i = 0; i < bounds.size(); ++i) |
1817 EXPECT_LT(0, bounds[i].width()); | 1817 EXPECT_LT(0, bounds[i].width()); |
1818 view()->OnImeConfirmComposition( | 1818 view()->OnImeConfirmComposition( |
1819 empty_string, gfx::Range::InvalidRange(), false); | 1819 empty_string, gfx::Range::InvalidRange(), false); |
1820 | 1820 |
1821 // Non surrogate pair unicode character. | 1821 // Non surrogate pair unicode character. |
1822 const string16 unicode_composition = UTF8ToUTF16( | 1822 const base::string16 unicode_composition = UTF8ToUTF16( |
1823 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); | 1823 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
1824 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); | 1824 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); |
1825 view()->GetCompositionCharacterBounds(&bounds); | 1825 view()->GetCompositionCharacterBounds(&bounds); |
1826 ASSERT_EQ(unicode_composition.size(), bounds.size()); | 1826 ASSERT_EQ(unicode_composition.size(), bounds.size()); |
1827 for (size_t i = 0; i < bounds.size(); ++i) | 1827 for (size_t i = 0; i < bounds.size(); ++i) |
1828 EXPECT_LT(0, bounds[i].width()); | 1828 EXPECT_LT(0, bounds[i].width()); |
1829 view()->OnImeConfirmComposition( | 1829 view()->OnImeConfirmComposition( |
1830 empty_string, gfx::Range::InvalidRange(), false); | 1830 empty_string, gfx::Range::InvalidRange(), false); |
1831 | 1831 |
1832 // Surrogate pair character. | 1832 // Surrogate pair character. |
1833 const string16 surrogate_pair_char = UTF8ToUTF16("\xF0\xA0\xAE\x9F"); | 1833 const base::string16 surrogate_pair_char = UTF8ToUTF16("\xF0\xA0\xAE\x9F"); |
1834 view()->OnImeSetComposition(surrogate_pair_char, | 1834 view()->OnImeSetComposition(surrogate_pair_char, |
1835 empty_underline, | 1835 empty_underline, |
1836 0, | 1836 0, |
1837 0); | 1837 0); |
1838 view()->GetCompositionCharacterBounds(&bounds); | 1838 view()->GetCompositionCharacterBounds(&bounds); |
1839 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); | 1839 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); |
1840 EXPECT_LT(0, bounds[0].width()); | 1840 EXPECT_LT(0, bounds[0].width()); |
1841 EXPECT_EQ(0, bounds[1].width()); | 1841 EXPECT_EQ(0, bounds[1].width()); |
1842 view()->OnImeConfirmComposition( | 1842 view()->OnImeConfirmComposition( |
1843 empty_string, gfx::Range::InvalidRange(), false); | 1843 empty_string, gfx::Range::InvalidRange(), false); |
1844 | 1844 |
1845 // Mixed string. | 1845 // Mixed string. |
1846 const string16 surrogate_pair_mixed_composition = | 1846 const base::string16 surrogate_pair_mixed_composition = |
1847 surrogate_pair_char + UTF8ToUTF16("\xE3\x81\x82") + surrogate_pair_char + | 1847 surrogate_pair_char + UTF8ToUTF16("\xE3\x81\x82") + surrogate_pair_char + |
1848 UTF8ToUTF16("b") + surrogate_pair_char; | 1848 UTF8ToUTF16("b") + surrogate_pair_char; |
1849 const size_t utf16_length = 8UL; | 1849 const size_t utf16_length = 8UL; |
1850 const bool is_surrogate_pair_empty_rect[8] = { | 1850 const bool is_surrogate_pair_empty_rect[8] = { |
1851 false, true, false, false, true, false, false, true }; | 1851 false, true, false, false, true, false, false, true }; |
1852 view()->OnImeSetComposition(surrogate_pair_mixed_composition, | 1852 view()->OnImeSetComposition(surrogate_pair_mixed_composition, |
1853 empty_underline, | 1853 empty_underline, |
1854 0, | 1854 0, |
1855 0); | 1855 0); |
1856 view()->GetCompositionCharacterBounds(&bounds); | 1856 view()->GetCompositionCharacterBounds(&bounds); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 virtual bool ShouldSuppressErrorPage(const GURL& url) OVERRIDE { | 2038 virtual bool ShouldSuppressErrorPage(const GURL& url) OVERRIDE { |
2039 return url == GURL("http://example.com/suppress"); | 2039 return url == GURL("http://example.com/suppress"); |
2040 } | 2040 } |
2041 | 2041 |
2042 virtual void GetNavigationErrorStrings( | 2042 virtual void GetNavigationErrorStrings( |
2043 blink::WebFrame* frame, | 2043 blink::WebFrame* frame, |
2044 const blink::WebURLRequest& failed_request, | 2044 const blink::WebURLRequest& failed_request, |
2045 const blink::WebURLError& error, | 2045 const blink::WebURLError& error, |
2046 const std::string& accept_languages, | 2046 const std::string& accept_languages, |
2047 std::string* error_html, | 2047 std::string* error_html, |
2048 string16* error_description) OVERRIDE { | 2048 base::string16* error_description) OVERRIDE { |
2049 if (error_html) | 2049 if (error_html) |
2050 *error_html = "A suffusion of yellow."; | 2050 *error_html = "A suffusion of yellow."; |
2051 } | 2051 } |
2052 }; | 2052 }; |
2053 | 2053 |
2054 TestContentRendererClient client_; | 2054 TestContentRendererClient client_; |
2055 }; | 2055 }; |
2056 | 2056 |
2057 #if defined(OS_ANDROID) | 2057 #if defined(OS_ANDROID) |
2058 // Crashing on Android: http://crbug.com/311341 | 2058 // Crashing on Android: http://crbug.com/311341 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 view()->OnCandidateWindowHidden(); | 2144 view()->OnCandidateWindowHidden(); |
2145 | 2145 |
2146 // Retrieve the content and check if it is expected. | 2146 // Retrieve the content and check if it is expected. |
2147 const int kMaxOutputCharacters = 50; | 2147 const int kMaxOutputCharacters = 50; |
2148 std::string output = UTF16ToUTF8( | 2148 std::string output = UTF16ToUTF8( |
2149 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 2149 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
2150 EXPECT_EQ(output, "\nResult:showupdatehide"); | 2150 EXPECT_EQ(output, "\nResult:showupdatehide"); |
2151 } | 2151 } |
2152 | 2152 |
2153 } // namespace content | 2153 } // namespace content |
OLD | NEW |