diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 16:02:09 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-08 16:02:09 +0000 |
commit | 922fdcfdb084f93cf7ca111bab5e325a90725ec0 (patch) | |
tree | 0424a30ca7a89fa0cabe2ca6d4f857bf00c4a4cd /ui/gfx/render_text_unittest.cc | |
parent | 1d85e36be195a8ab2b505099160ed4ffb614541d (diff) | |
download | chromium_src-922fdcfdb084f93cf7ca111bab5e325a90725ec0.zip chromium_src-922fdcfdb084f93cf7ca111bab5e325a90725ec0.tar.gz chromium_src-922fdcfdb084f93cf7ca111bab5e325a90725ec0.tar.bz2 |
Improve RenderTextWin font fallback.
Don't use SCRIPT_UNDEFINED in the case of font fallback,
unless font fallback actually fails to return a script
that can display the characters. This fixes the problem
of some scripts not being properly displayed.
This actually makes RenderTextWin properly validate whether
a text position accepts a cursor, which caused several tests
to fail and revealed some additional issues in RenderTextWin.
The CL includes some modifications to address this.
Some tests are disabled under XP, see:
http://crbug.com/106450
Also, fixes some lint warnings.
BUG=90426
TEST=Run chrome.exe --use-pure-views and paste some Bengali
text into the omnibox. It should show up properly.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=113075
Review URL: http://codereview.chromium.org/8575020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_unittest.cc')
-rw-r--r-- | ui/gfx/render_text_unittest.cc | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc index c564c60..0aa6625 100644 --- a/ui/gfx/render_text_unittest.cc +++ b/ui/gfx/render_text_unittest.cc @@ -8,6 +8,10 @@ #include "base/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + namespace gfx { class RenderTextTest : public testing::Test { @@ -543,6 +547,119 @@ TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { } #endif +TEST_F(RenderTextTest, GraphemePositions) { + // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. + const string16 kText1 = WideToUTF16(L"\x0915\x093f"L"abc"L"\x0915\x093f"); + + // LTR ab, LTR 2-character grapheme, LTR cd. + const string16 kText2 = WideToUTF16(L"ab"L"\x0915\x093f"L"cd"); + + struct { + string16 text; + size_t index; + size_t expected_previous; + size_t expected_next; + } cases[] = { + { string16(), 0, 0, 0 }, + { string16(), 1, 0, 0 }, + { string16(), 50, 0, 0 }, + { kText1, 0, 0, 2 }, + { kText1, 1, 0, 2 }, + { kText1, 2, 0, 3 }, + { kText1, 3, 2, 4 }, + { kText1, 4, 3, 5 }, + { kText1, 5, 4, 7 }, + { kText1, 6, 5, 7 }, + { kText1, 7, 5, 7 }, + { kText1, 8, 7, 7 }, + { kText1, 50, 7, 7 }, + { kText2, 0, 0, 1 }, + { kText2, 1, 0, 2 }, + { kText2, 2, 1, 4 }, + { kText2, 3, 2, 4 }, + { kText2, 4, 2, 5 }, + { kText2, 5, 4, 6 }, + { kText2, 6, 5, 6 }, + { kText2, 7, 6, 6 }, + { kText2, 50, 6, 6 }, + }; + + // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete + // font support for some scripts - http://crbug.com/106450 +#if defined(OS_WIN) + if (base::win::GetVersion() < base::win::VERSION_VISTA) + return; +#endif + + scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { + render_text->SetText(cases[i].text); + + size_t next = render_text->GetIndexOfNextGrapheme(cases[i].index); + EXPECT_EQ(cases[i].expected_next, next); + EXPECT_TRUE(render_text->IsCursorablePosition(next)); + + size_t previous = render_text->GetIndexOfPreviousGrapheme(cases[i].index); + EXPECT_EQ(cases[i].expected_previous, previous); + EXPECT_TRUE(render_text->IsCursorablePosition(previous)); + } +} + +TEST_F(RenderTextTest, SelectionModels) { + // Simple Latin text. + const string16 kLatin = WideToUTF16(L"abc"); + // LTR 2-character grapheme. + const string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f"); + // LTR 2-character grapheme, LTR a, LTR 2-character grapheme. + const string16 kHindiLatin = WideToUTF16(L"\x0915\x093f"L"a"L"\x0915\x093f"); + // RTL 2-character grapheme. + const string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8"); + // RTL 2-character grapheme, LTR a, RTL 2-character grapheme. + const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); + + struct { + string16 text; + size_t expected_left_end_caret; + SelectionModel::CaretPlacement expected_left_end_placement; + size_t expected_right_end_caret; + SelectionModel::CaretPlacement expected_right_end_placement; + } cases[] = { + { string16(), 0, SelectionModel::LEADING, 0, SelectionModel::LEADING }, + { kLatin, 0, SelectionModel::LEADING, 2, SelectionModel::TRAILING }, + { kLTRGrapheme, 0, SelectionModel::LEADING, 0, SelectionModel::TRAILING }, + { kHindiLatin, 0, SelectionModel::LEADING, 3, SelectionModel::TRAILING }, + { kRTLGrapheme, 0, SelectionModel::TRAILING, 0, SelectionModel::LEADING }, +#if defined(OS_LINUX) + // On Linux, the whole string is displayed RTL, rather than individual runs. + { kHebrewLatin, 3, SelectionModel::TRAILING, 0, SelectionModel::LEADING }, +#else + { kHebrewLatin, 0, SelectionModel::TRAILING, 3, SelectionModel::LEADING }, +#endif + }; + + // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete + // font support for some scripts - http://crbug.com/106450 +#if defined(OS_WIN) + if (base::win::GetVersion() < base::win::VERSION_VISTA) + return; +#endif + + scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { + render_text->SetText(cases[i].text); + + SelectionModel model = render_text->LeftEndSelectionModel(); + EXPECT_EQ(cases[i].expected_left_end_caret, model.caret_pos()); + EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); + EXPECT_EQ(cases[i].expected_left_end_placement, model.caret_placement()); + + model = render_text->RightEndSelectionModel(); + EXPECT_EQ(cases[i].expected_right_end_caret, model.caret_pos()); + EXPECT_TRUE(render_text->IsCursorablePosition(model.caret_pos())); + EXPECT_EQ(cases[i].expected_right_end_placement, model.caret_placement()); + } +} + TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |