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 #include <tuple> | 7 #include <tuple> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 // the window focus while composing a CJK text. To handle such complicated | 1239 // the window focus while composing a CJK text. To handle such complicated |
1240 // cases, this test should not only call IME-related functions in the | 1240 // cases, this test should not only call IME-related functions in the |
1241 // RenderWidget class, but also call some RenderWidget members, e.g. | 1241 // RenderWidget class, but also call some RenderWidget members, e.g. |
1242 // ExecuteJavaScriptForTests(), RenderWidget::OnSetFocus(), etc. | 1242 // ExecuteJavaScriptForTests(), RenderWidget::OnSetFocus(), etc. |
1243 TEST_F(RenderViewImplTest, ImeComposition) { | 1243 TEST_F(RenderViewImplTest, ImeComposition) { |
1244 enum ImeCommand { | 1244 enum ImeCommand { |
1245 IME_INITIALIZE, | 1245 IME_INITIALIZE, |
1246 IME_SETINPUTMODE, | 1246 IME_SETINPUTMODE, |
1247 IME_SETFOCUS, | 1247 IME_SETFOCUS, |
1248 IME_SETCOMPOSITION, | 1248 IME_SETCOMPOSITION, |
1249 IME_CONFIRMCOMPOSITION, | 1249 IME_COMMITTEXT, |
| 1250 IME_FINISHCOMPOSINGTEXT, |
1250 IME_CANCELCOMPOSITION | 1251 IME_CANCELCOMPOSITION |
1251 }; | 1252 }; |
1252 struct ImeMessage { | 1253 struct ImeMessage { |
1253 ImeCommand command; | 1254 ImeCommand command; |
1254 bool enable; | 1255 bool enable; |
1255 int selection_start; | 1256 int selection_start; |
1256 int selection_end; | 1257 int selection_end; |
1257 const wchar_t* ime_string; | 1258 const wchar_t* ime_string; |
1258 const wchar_t* result; | 1259 const wchar_t* result; |
1259 }; | 1260 }; |
1260 static const ImeMessage kImeMessages[] = { | 1261 static const ImeMessage kImeMessages[] = { |
1261 // Scenario 1: input a Chinese word with Microsoft IME (on Vista). | 1262 // Scenario 1: input a Chinese word with Microsoft IME (on Vista). |
1262 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, | 1263 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, |
1263 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, | 1264 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, |
1264 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, | 1265 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, |
1265 {IME_SETCOMPOSITION, false, 1, 1, L"n", L"n"}, | 1266 {IME_SETCOMPOSITION, false, 1, 1, L"n", L"n"}, |
1266 {IME_SETCOMPOSITION, false, 2, 2, L"ni", L"ni"}, | 1267 {IME_SETCOMPOSITION, false, 2, 2, L"ni", L"ni"}, |
1267 {IME_SETCOMPOSITION, false, 3, 3, L"nih", L"nih"}, | 1268 {IME_SETCOMPOSITION, false, 3, 3, L"nih", L"nih"}, |
1268 {IME_SETCOMPOSITION, false, 4, 4, L"niha", L"niha"}, | 1269 {IME_SETCOMPOSITION, false, 4, 4, L"niha", L"niha"}, |
1269 {IME_SETCOMPOSITION, false, 5, 5, L"nihao", L"nihao"}, | 1270 {IME_SETCOMPOSITION, false, 5, 5, L"nihao", L"nihao"}, |
1270 {IME_CONFIRMCOMPOSITION, false, -1, -1, L"\x4F60\x597D", L"\x4F60\x597D"}, | 1271 {IME_COMMITTEXT, false, -1, -1, L"\x4F60\x597D", L"\x4F60\x597D"}, |
1271 // Scenario 2: input a Japanese word with Microsoft IME (on Vista). | 1272 // Scenario 2: input a Japanese word with Microsoft IME (on Vista). |
1272 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, | 1273 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, |
1273 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, | 1274 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, |
1274 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, | 1275 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, |
1275 {IME_SETCOMPOSITION, false, 0, 1, L"\xFF4B", L"\xFF4B"}, | 1276 {IME_SETCOMPOSITION, false, 0, 1, L"\xFF4B", L"\xFF4B"}, |
1276 {IME_SETCOMPOSITION, false, 0, 1, L"\x304B", L"\x304B"}, | 1277 {IME_SETCOMPOSITION, false, 0, 1, L"\x304B", L"\x304B"}, |
1277 {IME_SETCOMPOSITION, false, 0, 2, L"\x304B\xFF4E", L"\x304B\xFF4E"}, | 1278 {IME_SETCOMPOSITION, false, 0, 2, L"\x304B\xFF4E", L"\x304B\xFF4E"}, |
1278 {IME_SETCOMPOSITION, false, 0, 3, L"\x304B\x3093\xFF4A", | 1279 {IME_SETCOMPOSITION, false, 0, 3, L"\x304B\x3093\xFF4A", |
1279 L"\x304B\x3093\xFF4A"}, | 1280 L"\x304B\x3093\xFF4A"}, |
1280 {IME_SETCOMPOSITION, false, 0, 3, L"\x304B\x3093\x3058", | 1281 {IME_SETCOMPOSITION, false, 0, 3, L"\x304B\x3093\x3058", |
1281 L"\x304B\x3093\x3058"}, | 1282 L"\x304B\x3093\x3058"}, |
1282 {IME_SETCOMPOSITION, false, 0, 2, L"\x611F\x3058", L"\x611F\x3058"}, | 1283 {IME_SETCOMPOSITION, false, 0, 2, L"\x611F\x3058", L"\x611F\x3058"}, |
1283 {IME_SETCOMPOSITION, false, 0, 2, L"\x6F22\x5B57", L"\x6F22\x5B57"}, | 1284 {IME_SETCOMPOSITION, false, 0, 2, L"\x6F22\x5B57", L"\x6F22\x5B57"}, |
1284 {IME_CONFIRMCOMPOSITION, false, -1, -1, L"", L"\x6F22\x5B57"}, | 1285 {IME_FINISHCOMPOSINGTEXT, false, -1, -1, L"", L"\x6F22\x5B57"}, |
1285 {IME_CANCELCOMPOSITION, false, -1, -1, L"", L"\x6F22\x5B57"}, | 1286 {IME_CANCELCOMPOSITION, false, -1, -1, L"", L"\x6F22\x5B57"}, |
1286 // Scenario 3: input a Korean word with Microsot IME (on Vista). | 1287 // Scenario 3: input a Korean word with Microsot IME (on Vista). |
1287 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, | 1288 {IME_INITIALIZE, true, 0, 0, NULL, NULL}, |
1288 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, | 1289 {IME_SETINPUTMODE, true, 0, 0, NULL, NULL}, |
1289 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, | 1290 {IME_SETFOCUS, true, 0, 0, NULL, NULL}, |
1290 {IME_SETCOMPOSITION, false, 0, 1, L"\x3147", L"\x3147"}, | 1291 {IME_SETCOMPOSITION, false, 0, 1, L"\x3147", L"\x3147"}, |
1291 {IME_SETCOMPOSITION, false, 0, 1, L"\xC544", L"\xC544"}, | 1292 {IME_SETCOMPOSITION, false, 0, 1, L"\xC544", L"\xC544"}, |
1292 {IME_SETCOMPOSITION, false, 0, 1, L"\xC548", L"\xC548"}, | 1293 {IME_SETCOMPOSITION, false, 0, 1, L"\xC548", L"\xC548"}, |
1293 {IME_CONFIRMCOMPOSITION, false, -1, -1, L"", L"\xC548"}, | 1294 {IME_FINISHCOMPOSINGTEXT, false, -1, -1, L"", L"\xC548"}, |
1294 {IME_SETCOMPOSITION, false, 0, 1, L"\x3134", L"\xC548\x3134"}, | 1295 {IME_SETCOMPOSITION, false, 0, 1, L"\x3134", L"\xC548\x3134"}, |
1295 {IME_SETCOMPOSITION, false, 0, 1, L"\xB140", L"\xC548\xB140"}, | 1296 {IME_SETCOMPOSITION, false, 0, 1, L"\xB140", L"\xC548\xB140"}, |
1296 {IME_SETCOMPOSITION, false, 0, 1, L"\xB155", L"\xC548\xB155"}, | 1297 {IME_SETCOMPOSITION, false, 0, 1, L"\xB155", L"\xC548\xB155"}, |
1297 {IME_CANCELCOMPOSITION, false, -1, -1, L"", L"\xC548"}, | 1298 {IME_CANCELCOMPOSITION, false, -1, -1, L"", L"\xC548"}, |
1298 {IME_SETCOMPOSITION, false, 0, 1, L"\xB155", L"\xC548\xB155"}, | 1299 {IME_SETCOMPOSITION, false, 0, 1, L"\xB155", L"\xC548\xB155"}, |
1299 {IME_CONFIRMCOMPOSITION, false, -1, -1, L"", L"\xC548\xB155"}, | 1300 {IME_FINISHCOMPOSINGTEXT, false, -1, -1, L"", L"\xC548\xB155"}, |
1300 }; | 1301 }; |
1301 | 1302 |
1302 for (size_t i = 0; i < arraysize(kImeMessages); i++) { | 1303 for (size_t i = 0; i < arraysize(kImeMessages); i++) { |
1303 const ImeMessage* ime_message = &kImeMessages[i]; | 1304 const ImeMessage* ime_message = &kImeMessages[i]; |
1304 switch (ime_message->command) { | 1305 switch (ime_message->command) { |
1305 case IME_INITIALIZE: | 1306 case IME_INITIALIZE: |
1306 // Load an HTML page consisting of a content-editable <div> element, | 1307 // Load an HTML page consisting of a content-editable <div> element, |
1307 // and move the input focus to the <div> element, where we can use | 1308 // and move the input focus to the <div> element, where we can use |
1308 // IMEs. | 1309 // IMEs. |
1309 LoadHTML("<html>" | 1310 LoadHTML("<html>" |
(...skipping 16 matching lines...) Expand all Loading... |
1326 | 1327 |
1327 case IME_SETCOMPOSITION: | 1328 case IME_SETCOMPOSITION: |
1328 view()->OnImeSetComposition( | 1329 view()->OnImeSetComposition( |
1329 base::WideToUTF16(ime_message->ime_string), | 1330 base::WideToUTF16(ime_message->ime_string), |
1330 std::vector<blink::WebCompositionUnderline>(), | 1331 std::vector<blink::WebCompositionUnderline>(), |
1331 gfx::Range::InvalidRange(), | 1332 gfx::Range::InvalidRange(), |
1332 ime_message->selection_start, | 1333 ime_message->selection_start, |
1333 ime_message->selection_end); | 1334 ime_message->selection_end); |
1334 break; | 1335 break; |
1335 | 1336 |
1336 case IME_CONFIRMCOMPOSITION: | 1337 case IME_COMMITTEXT: |
1337 view()->OnImeConfirmComposition( | 1338 view()->OnImeCommitText(base::WideToUTF16(ime_message->ime_string), |
1338 base::WideToUTF16(ime_message->ime_string), | 1339 gfx::Range::InvalidRange(), 0); |
1339 gfx::Range::InvalidRange(), | 1340 break; |
1340 false); | 1341 |
| 1342 case IME_FINISHCOMPOSINGTEXT: |
| 1343 view()->OnImeFinishComposingText(false); |
1341 break; | 1344 break; |
1342 | 1345 |
1343 case IME_CANCELCOMPOSITION: | 1346 case IME_CANCELCOMPOSITION: |
1344 view()->OnImeSetComposition( | 1347 view()->OnImeSetComposition( |
1345 base::string16(), | 1348 base::string16(), |
1346 std::vector<blink::WebCompositionUnderline>(), | 1349 std::vector<blink::WebCompositionUnderline>(), |
1347 gfx::Range::InvalidRange(), | 1350 gfx::Range::InvalidRange(), |
1348 0, 0); | 1351 0, 0); |
1349 break; | 1352 break; |
1350 } | 1353 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1586 | 1589 |
1587 // ASCII composition | 1590 // ASCII composition |
1588 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); | 1591 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); |
1589 view()->OnImeSetComposition(ascii_composition, empty_underline, | 1592 view()->OnImeSetComposition(ascii_composition, empty_underline, |
1590 gfx::Range::InvalidRange(), 0, 0); | 1593 gfx::Range::InvalidRange(), 0, 0); |
1591 view()->GetCompositionCharacterBounds(&bounds); | 1594 view()->GetCompositionCharacterBounds(&bounds); |
1592 ASSERT_EQ(ascii_composition.size(), bounds.size()); | 1595 ASSERT_EQ(ascii_composition.size(), bounds.size()); |
1593 | 1596 |
1594 for (size_t i = 0; i < bounds.size(); ++i) | 1597 for (size_t i = 0; i < bounds.size(); ++i) |
1595 EXPECT_LT(0, bounds[i].width()); | 1598 EXPECT_LT(0, bounds[i].width()); |
1596 view()->OnImeConfirmComposition( | 1599 view()->OnImeCommitText(empty_string, gfx::Range::InvalidRange(), 0); |
1597 empty_string, gfx::Range::InvalidRange(), false); | |
1598 | 1600 |
1599 // Non surrogate pair unicode character. | 1601 // Non surrogate pair unicode character. |
1600 const base::string16 unicode_composition = base::UTF8ToUTF16( | 1602 const base::string16 unicode_composition = base::UTF8ToUTF16( |
1601 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); | 1603 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
1602 view()->OnImeSetComposition(unicode_composition, empty_underline, | 1604 view()->OnImeSetComposition(unicode_composition, empty_underline, |
1603 gfx::Range::InvalidRange(), 0, 0); | 1605 gfx::Range::InvalidRange(), 0, 0); |
1604 view()->GetCompositionCharacterBounds(&bounds); | 1606 view()->GetCompositionCharacterBounds(&bounds); |
1605 ASSERT_EQ(unicode_composition.size(), bounds.size()); | 1607 ASSERT_EQ(unicode_composition.size(), bounds.size()); |
1606 for (size_t i = 0; i < bounds.size(); ++i) | 1608 for (size_t i = 0; i < bounds.size(); ++i) |
1607 EXPECT_LT(0, bounds[i].width()); | 1609 EXPECT_LT(0, bounds[i].width()); |
1608 view()->OnImeConfirmComposition( | 1610 view()->OnImeCommitText(empty_string, gfx::Range::InvalidRange(), 0); |
1609 empty_string, gfx::Range::InvalidRange(), false); | |
1610 | 1611 |
1611 // Surrogate pair character. | 1612 // Surrogate pair character. |
1612 const base::string16 surrogate_pair_char = | 1613 const base::string16 surrogate_pair_char = |
1613 base::UTF8ToUTF16("\xF0\xA0\xAE\x9F"); | 1614 base::UTF8ToUTF16("\xF0\xA0\xAE\x9F"); |
1614 view()->OnImeSetComposition(surrogate_pair_char, | 1615 view()->OnImeSetComposition(surrogate_pair_char, |
1615 empty_underline, | 1616 empty_underline, |
1616 gfx::Range::InvalidRange(), | 1617 gfx::Range::InvalidRange(), |
1617 0, | 1618 0, |
1618 0); | 1619 0); |
1619 view()->GetCompositionCharacterBounds(&bounds); | 1620 view()->GetCompositionCharacterBounds(&bounds); |
1620 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); | 1621 ASSERT_EQ(surrogate_pair_char.size(), bounds.size()); |
1621 EXPECT_LT(0, bounds[0].width()); | 1622 EXPECT_LT(0, bounds[0].width()); |
1622 EXPECT_EQ(0, bounds[1].width()); | 1623 EXPECT_EQ(0, bounds[1].width()); |
1623 view()->OnImeConfirmComposition( | 1624 view()->OnImeCommitText(empty_string, gfx::Range::InvalidRange(), 0); |
1624 empty_string, gfx::Range::InvalidRange(), false); | |
1625 | 1625 |
1626 // Mixed string. | 1626 // Mixed string. |
1627 const base::string16 surrogate_pair_mixed_composition = | 1627 const base::string16 surrogate_pair_mixed_composition = |
1628 surrogate_pair_char + base::UTF8ToUTF16("\xE3\x81\x82") + | 1628 surrogate_pair_char + base::UTF8ToUTF16("\xE3\x81\x82") + |
1629 surrogate_pair_char + base::UTF8ToUTF16("b") + surrogate_pair_char; | 1629 surrogate_pair_char + base::UTF8ToUTF16("b") + surrogate_pair_char; |
1630 const size_t utf16_length = 8UL; | 1630 const size_t utf16_length = 8UL; |
1631 const bool is_surrogate_pair_empty_rect[8] = { | 1631 const bool is_surrogate_pair_empty_rect[8] = { |
1632 false, true, false, false, true, false, false, true }; | 1632 false, true, false, false, true, false, false, true }; |
1633 view()->OnImeSetComposition(surrogate_pair_mixed_composition, | 1633 view()->OnImeSetComposition(surrogate_pair_mixed_composition, |
1634 empty_underline, | 1634 empty_underline, |
1635 gfx::Range::InvalidRange(), | 1635 gfx::Range::InvalidRange(), |
1636 0, | 1636 0, |
1637 0); | 1637 0); |
1638 view()->GetCompositionCharacterBounds(&bounds); | 1638 view()->GetCompositionCharacterBounds(&bounds); |
1639 ASSERT_EQ(utf16_length, bounds.size()); | 1639 ASSERT_EQ(utf16_length, bounds.size()); |
1640 for (size_t i = 0; i < utf16_length; ++i) { | 1640 for (size_t i = 0; i < utf16_length; ++i) { |
1641 if (is_surrogate_pair_empty_rect[i]) { | 1641 if (is_surrogate_pair_empty_rect[i]) { |
1642 EXPECT_EQ(0, bounds[i].width()); | 1642 EXPECT_EQ(0, bounds[i].width()); |
1643 } else { | 1643 } else { |
1644 EXPECT_LT(0, bounds[i].width()); | 1644 EXPECT_LT(0, bounds[i].width()); |
1645 } | 1645 } |
1646 } | 1646 } |
1647 view()->OnImeConfirmComposition( | 1647 view()->OnImeCommitText(empty_string, gfx::Range::InvalidRange(), 0); |
1648 empty_string, gfx::Range::InvalidRange(), false); | |
1649 } | 1648 } |
1650 #endif | 1649 #endif |
1651 | 1650 |
1652 TEST_F(RenderViewImplTest, ZoomLimit) { | 1651 TEST_F(RenderViewImplTest, ZoomLimit) { |
1653 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); | 1652 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); |
1654 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); | 1653 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); |
1655 | 1654 |
1656 // Verifies navigation to a URL with preset zoom level indeed sets the level. | 1655 // Verifies navigation to a URL with preset zoom level indeed sets the level. |
1657 // Regression test for http://crbug.com/139559, where the level was not | 1656 // Regression test for http://crbug.com/139559, where the level was not |
1658 // properly set when it is out of the default zoom limits of WebView. | 1657 // properly set when it is out of the default zoom limits of WebView. |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2556 ExpectPauseAndResume(3); | 2555 ExpectPauseAndResume(3); |
2557 blink::WebScriptSource source2( | 2556 blink::WebScriptSource source2( |
2558 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2557 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
2559 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2558 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
2560 | 2559 |
2561 EXPECT_FALSE(IsPaused()); | 2560 EXPECT_FALSE(IsPaused()); |
2562 Detach(); | 2561 Detach(); |
2563 } | 2562 } |
2564 | 2563 |
2565 } // namespace content | 2564 } // namespace content |
OLD | NEW |