| 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 &can_compose_inline); | 940 &can_compose_inline); |
| 941 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, type); | 941 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, type); |
| 942 | 942 |
| 943 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInputModeTestCases); i++) { | 943 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kInputModeTestCases); i++) { |
| 944 const InputModeTestCase* test_case = &kInputModeTestCases[i]; | 944 const InputModeTestCase* test_case = &kInputModeTestCases[i]; |
| 945 std::string javascript = | 945 std::string javascript = |
| 946 base::StringPrintf("document.getElementById('%s').focus();", | 946 base::StringPrintf("document.getElementById('%s').focus();", |
| 947 test_case->input_id); | 947 test_case->input_id); |
| 948 // Move the input focus to the target <input> element, where we should | 948 // Move the input focus to the target <input> element, where we should |
| 949 // activate IMEs. | 949 // activate IMEs. |
| 950 ExecuteJavaScriptAndReturnIntValue(ASCIIToUTF16(javascript), NULL); | 950 ExecuteJavaScriptAndReturnIntValue(base::ASCIIToUTF16(javascript), NULL); |
| 951 ProcessPendingMessages(); | 951 ProcessPendingMessages(); |
| 952 render_thread_->sink().ClearMessages(); | 952 render_thread_->sink().ClearMessages(); |
| 953 | 953 |
| 954 // Update the IME status and verify if our IME backend sends an IPC | 954 // Update the IME status and verify if our IME backend sends an IPC |
| 955 // message to activate IMEs. | 955 // message to activate IMEs. |
| 956 view()->UpdateTextInputType(); | 956 view()->UpdateTextInputType(); |
| 957 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0); | 957 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0); |
| 958 EXPECT_TRUE(msg != NULL); | 958 EXPECT_TRUE(msg != NULL); |
| 959 EXPECT_EQ(ViewHostMsg_TextInputTypeChanged::ID, msg->type()); | 959 EXPECT_EQ(ViewHostMsg_TextInputTypeChanged::ID, msg->type()); |
| 960 ViewHostMsg_TextInputTypeChanged::Read(msg, | 960 ViewHostMsg_TextInputTypeChanged::Read(msg, |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 "%d,%s", // texts in the third <div> element | 1288 "%d,%s", // texts in the third <div> element |
| 1289 key_code, kModifierData[j].expected_result, | 1289 key_code, kModifierData[j].expected_result, |
| 1290 static_cast<int>(char_code[0]), | 1290 static_cast<int>(char_code[0]), |
| 1291 kModifierData[j].expected_result, | 1291 kModifierData[j].expected_result, |
| 1292 key_code, kModifierData[j].expected_result); | 1292 key_code, kModifierData[j].expected_result); |
| 1293 | 1293 |
| 1294 // Retrieve the text in the test page and compare it with the expected | 1294 // Retrieve the text in the test page and compare it with the expected |
| 1295 // text created from a virtual-key code, a character code, and the | 1295 // text created from a virtual-key code, a character code, and the |
| 1296 // modifier-key status. | 1296 // modifier-key status. |
| 1297 const int kMaxOutputCharacters = 1024; | 1297 const int kMaxOutputCharacters = 1024; |
| 1298 std::string output = UTF16ToUTF8( | 1298 std::string output = base::UTF16ToUTF8( |
| 1299 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 1299 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 1300 EXPECT_EQ(expected_result, output); | 1300 EXPECT_EQ(expected_result, output); |
| 1301 } | 1301 } |
| 1302 } | 1302 } |
| 1303 } | 1303 } |
| 1304 #else | 1304 #else |
| 1305 NOTIMPLEMENTED(); | 1305 NOTIMPLEMENTED(); |
| 1306 #endif | 1306 #endif |
| 1307 } | 1307 } |
| 1308 | 1308 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 | 1769 |
| 1770 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 1770 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
| 1771 ViewHostMsg_ContextMenu::ID)); | 1771 ViewHostMsg_ContextMenu::ID)); |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 TEST_F(RenderViewImplTest, TestBackForward) { | 1774 TEST_F(RenderViewImplTest, TestBackForward) { |
| 1775 LoadHTML("<div id=pagename>Page A</div>"); | 1775 LoadHTML("<div id=pagename>Page A</div>"); |
| 1776 blink::WebHistoryItem page_a_item = GetMainFrame()->currentHistoryItem(); | 1776 blink::WebHistoryItem page_a_item = GetMainFrame()->currentHistoryItem(); |
| 1777 int was_page_a = -1; | 1777 int was_page_a = -1; |
| 1778 base::string16 check_page_a = | 1778 base::string16 check_page_a = |
| 1779 ASCIIToUTF16( | 1779 base::ASCIIToUTF16( |
| 1780 "Number(document.getElementById('pagename').innerHTML == 'Page A')"); | 1780 "Number(document.getElementById('pagename').innerHTML == 'Page A')"); |
| 1781 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a)); | 1781 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a)); |
| 1782 EXPECT_EQ(1, was_page_a); | 1782 EXPECT_EQ(1, was_page_a); |
| 1783 | 1783 |
| 1784 LoadHTML("<div id=pagename>Page B</div>"); | 1784 LoadHTML("<div id=pagename>Page B</div>"); |
| 1785 int was_page_b = -1; | 1785 int was_page_b = -1; |
| 1786 base::string16 check_page_b = | 1786 base::string16 check_page_b = |
| 1787 ASCIIToUTF16( | 1787 base::ASCIIToUTF16( |
| 1788 "Number(document.getElementById('pagename').innerHTML == 'Page B')"); | 1788 "Number(document.getElementById('pagename').innerHTML == 'Page B')"); |
| 1789 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); | 1789 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); |
| 1790 EXPECT_EQ(1, was_page_b); | 1790 EXPECT_EQ(1, was_page_b); |
| 1791 | 1791 |
| 1792 LoadHTML("<div id=pagename>Page C</div>"); | 1792 LoadHTML("<div id=pagename>Page C</div>"); |
| 1793 int was_page_c = -1; | 1793 int was_page_c = -1; |
| 1794 base::string16 check_page_c = | 1794 base::string16 check_page_c = |
| 1795 ASCIIToUTF16( | 1795 base::ASCIIToUTF16( |
| 1796 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); | 1796 "Number(document.getElementById('pagename').innerHTML == 'Page C')"); |
| 1797 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); | 1797 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c)); |
| 1798 EXPECT_EQ(1, was_page_b); | 1798 EXPECT_EQ(1, was_page_b); |
| 1799 | 1799 |
| 1800 blink::WebHistoryItem forward_item = GetMainFrame()->currentHistoryItem(); | 1800 blink::WebHistoryItem forward_item = GetMainFrame()->currentHistoryItem(); |
| 1801 GoBack(GetMainFrame()->previousHistoryItem()); | 1801 GoBack(GetMainFrame()->previousHistoryItem()); |
| 1802 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); | 1802 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b)); |
| 1803 EXPECT_EQ(1, was_page_b); | 1803 EXPECT_EQ(1, was_page_b); |
| 1804 | 1804 |
| 1805 GoForward(forward_item); | 1805 GoForward(forward_item); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1825 | 1825 |
| 1826 #if defined(OS_WIN) | 1826 #if defined(OS_WIN) |
| 1827 // http://crbug.com/304193 | 1827 // http://crbug.com/304193 |
| 1828 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 1828 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 1829 return; | 1829 return; |
| 1830 #endif | 1830 #endif |
| 1831 | 1831 |
| 1832 LoadHTML("<textarea id=\"test\"></textarea>"); | 1832 LoadHTML("<textarea id=\"test\"></textarea>"); |
| 1833 ExecuteJavaScript("document.getElementById('test').focus();"); | 1833 ExecuteJavaScript("document.getElementById('test').focus();"); |
| 1834 | 1834 |
| 1835 const base::string16 empty_string = UTF8ToUTF16(""); | 1835 const base::string16 empty_string; |
| 1836 const std::vector<blink::WebCompositionUnderline> empty_underline; | 1836 const std::vector<blink::WebCompositionUnderline> empty_underline; |
| 1837 std::vector<gfx::Rect> bounds; | 1837 std::vector<gfx::Rect> bounds; |
| 1838 view()->OnSetFocus(true); | 1838 view()->OnSetFocus(true); |
| 1839 view()->OnSetInputMethodActive(true); | 1839 view()->OnSetInputMethodActive(true); |
| 1840 | 1840 |
| 1841 // ASCII composition | 1841 // ASCII composition |
| 1842 const base::string16 ascii_composition = UTF8ToUTF16("aiueo"); | 1842 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); |
| 1843 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); | 1843 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); |
| 1844 view()->GetCompositionCharacterBounds(&bounds); | 1844 view()->GetCompositionCharacterBounds(&bounds); |
| 1845 ASSERT_EQ(ascii_composition.size(), bounds.size()); | 1845 ASSERT_EQ(ascii_composition.size(), bounds.size()); |
| 1846 for (size_t i = 0; i < bounds.size(); ++i) | 1846 for (size_t i = 0; i < bounds.size(); ++i) |
| 1847 EXPECT_LT(0, bounds[i].width()); | 1847 EXPECT_LT(0, bounds[i].width()); |
| 1848 view()->OnImeConfirmComposition( | 1848 view()->OnImeConfirmComposition( |
| 1849 empty_string, gfx::Range::InvalidRange(), false); | 1849 empty_string, gfx::Range::InvalidRange(), false); |
| 1850 | 1850 |
| 1851 // Non surrogate pair unicode character. | 1851 // Non surrogate pair unicode character. |
| 1852 const base::string16 unicode_composition = UTF8ToUTF16( | 1852 const base::string16 unicode_composition = base::UTF8ToUTF16( |
| 1853 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); | 1853 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
| 1854 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); | 1854 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); |
| 1855 view()->GetCompositionCharacterBounds(&bounds); | 1855 view()->GetCompositionCharacterBounds(&bounds); |
| 1856 ASSERT_EQ(unicode_composition.size(), bounds.size()); | 1856 ASSERT_EQ(unicode_composition.size(), bounds.size()); |
| 1857 for (size_t i = 0; i < bounds.size(); ++i) | 1857 for (size_t i = 0; i < bounds.size(); ++i) |
| 1858 EXPECT_LT(0, bounds[i].width()); | 1858 EXPECT_LT(0, bounds[i].width()); |
| 1859 view()->OnImeConfirmComposition( | 1859 view()->OnImeConfirmComposition( |
| 1860 empty_string, gfx::Range::InvalidRange(), false); | 1860 empty_string, gfx::Range::InvalidRange(), false); |
| 1861 | 1861 |
| 1862 // Surrogate pair character. | 1862 // Surrogate pair character. |
| 1863 const base::string16 surrogate_pair_char = UTF8ToUTF16("\xF0\xA0\xAE\x9F"); | 1863 const base::string16 surrogate_pair_char = |
| 1864 base::UTF8ToUTF16("\xF0\xA0\xAE\x9F"); |
| 1864 view()->OnImeSetComposition(surrogate_pair_char, | 1865 view()->OnImeSetComposition(surrogate_pair_char, |
| 1865 empty_underline, | 1866 empty_underline, |
| 1866 0, | 1867 0, |
| 1867 0); | 1868 0); |
| 1868 view()->GetCompositionCharacterBounds(&bounds); | 1869 view()->GetCompositionCharacterBounds(&bounds); |
| 1869 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); | 1870 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); |
| 1870 EXPECT_LT(0, bounds[0].width()); | 1871 EXPECT_LT(0, bounds[0].width()); |
| 1871 EXPECT_EQ(0, bounds[1].width()); | 1872 EXPECT_EQ(0, bounds[1].width()); |
| 1872 view()->OnImeConfirmComposition( | 1873 view()->OnImeConfirmComposition( |
| 1873 empty_string, gfx::Range::InvalidRange(), false); | 1874 empty_string, gfx::Range::InvalidRange(), false); |
| 1874 | 1875 |
| 1875 // Mixed string. | 1876 // Mixed string. |
| 1876 const base::string16 surrogate_pair_mixed_composition = | 1877 const base::string16 surrogate_pair_mixed_composition = |
| 1877 surrogate_pair_char + UTF8ToUTF16("\xE3\x81\x82") + surrogate_pair_char + | 1878 surrogate_pair_char + base::UTF8ToUTF16("\xE3\x81\x82") + |
| 1878 UTF8ToUTF16("b") + surrogate_pair_char; | 1879 surrogate_pair_char + base::UTF8ToUTF16("b") + surrogate_pair_char; |
| 1879 const size_t utf16_length = 8UL; | 1880 const size_t utf16_length = 8UL; |
| 1880 const bool is_surrogate_pair_empty_rect[8] = { | 1881 const bool is_surrogate_pair_empty_rect[8] = { |
| 1881 false, true, false, false, true, false, false, true }; | 1882 false, true, false, false, true, false, false, true }; |
| 1882 view()->OnImeSetComposition(surrogate_pair_mixed_composition, | 1883 view()->OnImeSetComposition(surrogate_pair_mixed_composition, |
| 1883 empty_underline, | 1884 empty_underline, |
| 1884 0, | 1885 0, |
| 1885 0); | 1886 0); |
| 1886 view()->GetCompositionCharacterBounds(&bounds); | 1887 view()->GetCompositionCharacterBounds(&bounds); |
| 1887 ASSERT_EQ(utf16_length, bounds.size()); | 1888 ASSERT_EQ(utf16_length, bounds.size()); |
| 1888 for (size_t i = 0; i < utf16_length; ++i) { | 1889 for (size_t i = 0; i < utf16_length; ++i) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 "};" | 2169 "};" |
| 2169 "</script>"); | 2170 "</script>"); |
| 2170 | 2171 |
| 2171 // Fire candidatewindow events. | 2172 // Fire candidatewindow events. |
| 2172 view()->OnCandidateWindowShown(); | 2173 view()->OnCandidateWindowShown(); |
| 2173 view()->OnCandidateWindowUpdated(); | 2174 view()->OnCandidateWindowUpdated(); |
| 2174 view()->OnCandidateWindowHidden(); | 2175 view()->OnCandidateWindowHidden(); |
| 2175 | 2176 |
| 2176 // Retrieve the content and check if it is expected. | 2177 // Retrieve the content and check if it is expected. |
| 2177 const int kMaxOutputCharacters = 50; | 2178 const int kMaxOutputCharacters = 50; |
| 2178 std::string output = UTF16ToUTF8( | 2179 std::string output = base::UTF16ToUTF8( |
| 2179 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 2180 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 2180 EXPECT_EQ(output, "\nResult:showupdatehide"); | 2181 EXPECT_EQ(output, "\nResult:showupdatehide"); |
| 2181 } | 2182 } |
| 2182 | 2183 |
| 2183 // Ensure the render view sends favicon url update events correctly. | 2184 // Ensure the render view sends favicon url update events correctly. |
| 2184 TEST_F(RenderViewImplTest, SendFaviconURLUpdateEvent) { | 2185 TEST_F(RenderViewImplTest, SendFaviconURLUpdateEvent) { |
| 2185 // An event should be sent when a favicon url exists. | 2186 // An event should be sent when a favicon url exists. |
| 2186 LoadHTML("<html>" | 2187 LoadHTML("<html>" |
| 2187 "<head>" | 2188 "<head>" |
| 2188 "<link rel='icon' href='http://www.google.com/favicon.ico'>" | 2189 "<link rel='icon' href='http://www.google.com/favicon.ico'>" |
| 2189 "</head>" | 2190 "</head>" |
| 2190 "</html>"); | 2191 "</html>"); |
| 2191 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( | 2192 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching( |
| 2192 ViewHostMsg_UpdateFaviconURL::ID)); | 2193 ViewHostMsg_UpdateFaviconURL::ID)); |
| 2193 render_thread_->sink().ClearMessages(); | 2194 render_thread_->sink().ClearMessages(); |
| 2194 | 2195 |
| 2195 // An event should not be sent if no favicon url exists. This is an assumption | 2196 // An event should not be sent if no favicon url exists. This is an assumption |
| 2196 // made by some of Chrome's favicon handling. | 2197 // made by some of Chrome's favicon handling. |
| 2197 LoadHTML("<html>" | 2198 LoadHTML("<html>" |
| 2198 "<head>" | 2199 "<head>" |
| 2199 "</head>" | 2200 "</head>" |
| 2200 "</html>"); | 2201 "</html>"); |
| 2201 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2202 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 2202 ViewHostMsg_UpdateFaviconURL::ID)); | 2203 ViewHostMsg_UpdateFaviconURL::ID)); |
| 2203 } | 2204 } |
| 2204 | 2205 |
| 2205 } // namespace content | 2206 } // namespace content |
| OLD | NEW |