summaryrefslogtreecommitdiffstats
path: root/ui/gfx/render_text_unittest.cc
diff options
context:
space:
mode:
authorasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 00:14:21 +0000
committerasvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 00:14:21 +0000
commit588de5bdf333b29748abc98412e64017b252632d (patch)
treed4586ac993d0c7fd4eaa24dd2373c6d45b8883e8 /ui/gfx/render_text_unittest.cc
parent0078ab5fed5004af0c4c5be7091c64a923f4a4f9 (diff)
downloadchromium_src-588de5bdf333b29748abc98412e64017b252632d.zip
chromium_src-588de5bdf333b29748abc98412e64017b252632d.tar.gz
chromium_src-588de5bdf333b29748abc98412e64017b252632d.tar.bz2
Add a RenderText test that checks that matching parentheses use the same font.
This is a test for http://crbug.com/125792, which I had fixed earlier. BUG=125792, 105550 TEST=This is one. Checked that this test fails without the fix for http://crbug.com/125792. Review URL: https://chromiumcodereview.appspot.com/10388092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136720 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_unittest.cc')
-rw-r--r--ui/gfx/render_text_unittest.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 607869c..f0802410 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -15,6 +15,17 @@
namespace gfx {
+namespace {
+
+// Checks whether |range| contains |index|. This is not the same as calling
+// |range.Contains(ui::Range(index))| - as that would return true when
+// |index| == |range.end()|.
+bool IndexInRange(const ui::Range& range, size_t index) {
+ return index >= range.start() && index < range.end();
+}
+
+} // namespace
+
class RenderTextTest : public testing::Test {
};
@@ -1026,6 +1037,81 @@ TEST_F(RenderTextTest, OriginForDrawing) {
EXPECT_EQ(origin.y(), 1);
}
+TEST_F(RenderTextTest, SameFontForParentheses) {
+ struct {
+ const char16 left_char;
+ const char16 right_char;
+ } punctuation_pairs[] = {
+ { '(', ')' },
+ { '{', '}' },
+ { '<', '>' },
+ };
+ struct {
+ string16 text;
+ } cases[] = {
+ // English(English)
+ { WideToUTF16(L"Hello World(a)") },
+ // English(English)English
+ { WideToUTF16(L"Hello World(a)Hello World") },
+
+ // Japanese(English)
+ { WideToUTF16(L"\x6328\x62f6(a)") },
+ // Japanese(English)Japanese
+ { WideToUTF16(L"\x6328\x62f6(a)\x6328\x62f6") },
+ // English(Japanese)English
+ { WideToUTF16(L"Hello World(\x6328\x62f6)Hello World") },
+
+ // Hindi(English)
+ { WideToUTF16(L"\x0915\x093f(a)") },
+ // Hindi(English)Hindi
+ { WideToUTF16(L"\x0915\x093f(a)\x0915\x093f") },
+ // English(Hindi)English
+ { WideToUTF16(L"Hello World(\x0915\x093f)Hello World") },
+
+ // Hebrew(English)
+ { WideToUTF16(L"\x05e0\x05b8(a)") },
+ // Hebrew(English)Hebrew
+ { WideToUTF16(L"\x05e0\x05b8(a)\x05e0\x05b8") },
+ // English(Hebrew)English
+ { WideToUTF16(L"Hello World(\x05e0\x05b8)Hello World") },
+ };
+
+ scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ string16 text = cases[i].text;
+ const size_t start_paren_char_index = text.find('(');
+ ASSERT_NE(string16::npos, start_paren_char_index);
+ const size_t end_paren_char_index = text.find(')');
+ ASSERT_NE(string16::npos, end_paren_char_index);
+
+ for (size_t j = 0; j < ARRAYSIZE_UNSAFE(punctuation_pairs); ++j) {
+ text[start_paren_char_index] = punctuation_pairs[j].left_char;
+ text[end_paren_char_index] = punctuation_pairs[j].right_char;
+ render_text->SetText(text);
+
+ const std::vector<RenderText::FontSpan> spans =
+ render_text->GetFontSpansForTesting();
+
+ int start_paren_span_index = -1;
+ int end_paren_span_index = -1;
+ for (size_t k = 0; k < spans.size(); ++k) {
+ if (IndexInRange(spans[k].second, start_paren_char_index))
+ start_paren_span_index = k;
+ if (IndexInRange(spans[k].second, end_paren_char_index))
+ end_paren_span_index = k;
+ }
+ ASSERT_NE(-1, start_paren_span_index);
+ ASSERT_NE(-1, end_paren_span_index);
+
+ const Font& start_font = spans[start_paren_span_index].first;
+ const Font& end_font = spans[end_paren_span_index].first;
+ EXPECT_EQ(start_font.GetFontName(), end_font.GetFontName());
+ EXPECT_EQ(start_font.GetFontSize(), end_font.GetFontSize());
+ EXPECT_EQ(start_font.GetStyle(), end_font.GetStyle());
+ }
+ }
+}
+
TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));