Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: ui/views/controls/textfield/native_textfield_views_unittest.cc

Issue 10693061: Fix RenderTextWin base dir and adjacent char code; remove test exceptions; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; add unit test. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 1400
1401 SendKeyEvent(0x05E2); 1401 SendKeyEvent(0x05E2);
1402 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); 1402 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text());
1403 x = GetCursorBounds().x(); 1403 x = GetCursorBounds().x();
1404 EXPECT_GT(prev_x, x); 1404 EXPECT_GT(prev_x, x);
1405 prev_x = x; 1405 prev_x = x;
1406 1406
1407 SendKeyEvent('a'); 1407 SendKeyEvent('a');
1408 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"a"), textfield_->text()); 1408 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"a"), textfield_->text());
1409 x = GetCursorBounds().x(); 1409 x = GetCursorBounds().x();
1410 #if defined(OS_WIN)
1411 // In Windows, the text is always in LTR directionality even in RTL UI.
1412 // TODO(xji): it should change if we fix the directionality in Window's
1413 // NativeTextfieldViews
1414 EXPECT_LT(prev_x, x);
1415 #else
1416 EXPECT_EQ(prev_x, x); 1410 EXPECT_EQ(prev_x, x);
1417 #endif
1418 prev_x = x; 1411 prev_x = x;
1419 1412
1420 SendKeyEvent('b'); 1413 SendKeyEvent('b');
1421 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"ab"), textfield_->text()); 1414 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"ab"), textfield_->text());
1422 x = GetCursorBounds().x(); 1415 x = GetCursorBounds().x();
1423 EXPECT_EQ(prev_x, x); 1416 EXPECT_EQ(prev_x, x);
1424 1417
1425 // Reset locale. 1418 // Reset locale.
1426 base::i18n::SetICUDefaultLocale(locale); 1419 base::i18n::SetICUDefaultLocale(locale);
1427 } 1420 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 MouseClick(bound, 10); 1490 MouseClick(bound, 10);
1498 EXPECT_EQ(bound, GetCursorBounds()); 1491 EXPECT_EQ(bound, GetCursorBounds());
1499 1492
1500 NonClientMouseClick(); 1493 NonClientMouseClick();
1501 1494
1502 // RTL-LTR string in LTR context. 1495 // RTL-LTR string in LTR context.
1503 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab")); 1496 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab"));
1504 1497
1505 SendKeyEvent(ui::VKEY_HOME); 1498 SendKeyEvent(ui::VKEY_HOME);
1506 bound = GetCursorBounds(); 1499 bound = GetCursorBounds();
1507 #if defined(OS_WIN)
1508 MouseClick(bound, -10);
1509 #else
1510 MouseClick(bound, 10); 1500 MouseClick(bound, 10);
1511 #endif
1512 EXPECT_EQ(bound, GetCursorBounds()); 1501 EXPECT_EQ(bound, GetCursorBounds());
1513 1502
1514 SendKeyEvent(ui::VKEY_END); 1503 SendKeyEvent(ui::VKEY_END);
1515 bound = GetCursorBounds(); 1504 bound = GetCursorBounds();
1516 #if defined(OS_WIN)
1517 MouseClick(bound, 10);
1518 #else
1519 MouseClick(bound, -10); 1505 MouseClick(bound, -10);
1520 #endif
1521 EXPECT_EQ(bound, GetCursorBounds()); 1506 EXPECT_EQ(bound, GetCursorBounds());
1522 } 1507 }
1523 1508
1524 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaInRTLTest) { 1509 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaInRTLTest) {
1525 std::string locale = l10n_util::GetApplicationLocale(""); 1510 std::string locale = l10n_util::GetApplicationLocale("");
1526 base::i18n::SetICUDefaultLocale("he"); 1511 base::i18n::SetICUDefaultLocale("he");
1527 1512
1528 InitTextfield(Textfield::STYLE_DEFAULT); 1513 InitTextfield(Textfield::STYLE_DEFAULT);
1529 1514
1530 // RTL-LTR string in RTL context. 1515 // RTL-LTR string in RTL context.
1531 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab")); 1516 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab"));
1532 SendKeyEvent(ui::VKEY_HOME); 1517 SendKeyEvent(ui::VKEY_HOME);
1533 gfx::Rect bound = GetCursorBounds(); 1518 gfx::Rect bound = GetCursorBounds();
1534 MouseClick(bound, 10); 1519 MouseClick(bound, 10);
1535 EXPECT_EQ(bound, GetCursorBounds()); 1520 EXPECT_EQ(bound, GetCursorBounds());
1536 1521
1537 SendKeyEvent(ui::VKEY_END); 1522 SendKeyEvent(ui::VKEY_END);
1538 bound = GetCursorBounds(); 1523 bound = GetCursorBounds();
1539 MouseClick(bound, -10); 1524 MouseClick(bound, -10);
1540 EXPECT_EQ(bound, GetCursorBounds()); 1525 EXPECT_EQ(bound, GetCursorBounds());
1541 1526
1542 NonClientMouseClick(); 1527 NonClientMouseClick();
1543 1528
1544 // LTR-RTL string in RTL context. 1529 // LTR-RTL string in RTL context.
1545 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); 1530 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
1546 SendKeyEvent(ui::VKEY_HOME); 1531 SendKeyEvent(ui::VKEY_HOME);
1547 bound = GetCursorBounds(); 1532 bound = GetCursorBounds();
1548 #if defined(OS_WIN)
1549 MouseClick(bound, 10);
1550 #else
1551 MouseClick(bound, -10); 1533 MouseClick(bound, -10);
1552 #endif
1553 EXPECT_EQ(bound, GetCursorBounds()); 1534 EXPECT_EQ(bound, GetCursorBounds());
1554 1535
1555 SendKeyEvent(ui::VKEY_END); 1536 SendKeyEvent(ui::VKEY_END);
1556 bound = GetCursorBounds(); 1537 bound = GetCursorBounds();
1557 #if defined(OS_WIN)
1558 MouseClick(bound, -10);
1559 #else
1560 MouseClick(bound, 10); 1538 MouseClick(bound, 10);
1561 #endif
1562 EXPECT_EQ(bound, GetCursorBounds()); 1539 EXPECT_EQ(bound, GetCursorBounds());
1563 1540
1564 // Reset locale. 1541 // Reset locale.
1565 base::i18n::SetICUDefaultLocale(locale); 1542 base::i18n::SetICUDefaultLocale(locale);
1566 } 1543 }
1567 1544
1568 // This verifies that |bound| is contained by |display|. |bound|'s right edge 1545 // This verifies that |bound| is contained by |display|. |bound|'s right edge
1569 // must be less than |diaplay|'s right edge. 1546 // must be less than |diaplay|'s right edge.
1570 void OverflowCursorBoundTestVerifier(const gfx::Rect& display, 1547 void OverflowCursorBoundTestVerifier(const gfx::Rect& display,
1571 const gfx::Rect& bound) { 1548 const gfx::Rect& bound) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 1612
1636 1613
1637 #if !defined(OS_WIN) 1614 #if !defined(OS_WIN)
1638 // TODO(jennyz): NonClientMouseClick() does not work for os_win builds; 1615 // TODO(jennyz): NonClientMouseClick() does not work for os_win builds;
1639 // see crbug.com/104150. The mouse click in the next test will be confused 1616 // see crbug.com/104150. The mouse click in the next test will be confused
1640 // as a double click, which breaks the test. Disable the test until the 1617 // as a double click, which breaks the test. Disable the test until the
1641 // issue is fixed. 1618 // issue is fixed.
1642 NonClientMouseClick(); 1619 NonClientMouseClick();
1643 1620
1644 MouseClick(bound, 1); 1621 MouseClick(bound, 1);
1645 #if defined(OS_WIN)
1646 // In Windows, the text is always in LTR directionality even in RTL UI.
1647 // TODO(xji): it should change if we fix the directionality in Window's
1648 // NativeTextfieldViews
1649 EXPECT_EQ(0U, textfield_->GetCursorPosition());
1650 #else
1651 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1622 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1652 #endif
1653 #endif // !defined(OS_WIN) 1623 #endif // !defined(OS_WIN)
1654 1624
1655 // Reset locale. 1625 // Reset locale.
1656 base::i18n::SetICUDefaultLocale(locale); 1626 base::i18n::SetICUDefaultLocale(locale);
1657 } 1627 }
1658 1628
1659 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) { 1629 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) {
1660 InitTextfield(Textfield::STYLE_DEFAULT); 1630 InitTextfield(Textfield::STYLE_DEFAULT);
1661 1631
1662 string16 str; 1632 string16 str;
(...skipping 28 matching lines...) Expand all
1691 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; 1661 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i;
1692 } 1662 }
1693 1663
1694 // Return false if the index is out of range. 1664 // Return false if the index is out of range.
1695 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1665 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1696 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1666 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1697 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1667 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1698 } 1668 }
1699 1669
1700 } // namespace views 1670 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698