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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 915383003: Fix alignment format in multiline mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disable test on mac Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index e7829f65d6b86089256f61d473a1303e14908990..711bf597b754f1ae3c7c65f150356c71bb957527 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -9,6 +9,7 @@
#include "base/format_macros.h"
#include "base/i18n/break_iterator.h"
#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -2143,6 +2144,57 @@ TEST_F(RenderTextTest, Multiline_NewlineCharacterReplacement) {
}
}
+#if !defined(OS_MACOSX)
msw 2015/02/24 03:27:59 nit: Oh darn, this should work on Mac (using RTHB)
oshima 2015/02/24 03:49:33 This won't work on mac as is. This should work wit
+// Ensure horizontal alignment works in multiline mode.
+TEST_F(RenderTextTest, Multiline_HorizontalAlignment) {
+ const struct {
+ const wchar_t* const text;
+ const gfx::HorizontalAlignment alignment;
+ } kTestStrings[] = {
+ { L"abcdefghij\nhijkl", gfx::ALIGN_LEFT },
+ { L"nhijkl\nabcdefghij", gfx::ALIGN_LEFT },
+ // hebrew, 2nd line shorter
+ { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3",
+ gfx::ALIGN_RIGHT },
+ // hebrew, 2nd line longer
+ { L"\x5d0\x5d1\x5d2\x5d3\n\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7",
+ gfx::ALIGN_RIGHT },
+ // arabic, 2nd line shorter
+ { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664",
+ gfx::ALIGN_RIGHT },
+ // arabic, 2nd line longer
+ { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630",
+ gfx::ALIGN_RIGHT },
+ };
+ const int kGlyphSize = 5;
+ RenderTextHarfBuzz render_text;
+ render_text.SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
+ render_text.set_glyph_width_for_test(kGlyphSize);
+ render_text.SetDisplayRect(Rect(100, 1000));
+ render_text.SetMultiline(true);
+
+ Canvas canvas;
+ for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
+ SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i,
+ kTestStrings[i].text));
+ render_text.SetText(WideToUTF16(kTestStrings[i].text));
+ render_text.Draw(&canvas);
+ ASSERT_LE(2u, render_text.lines().size());
+ if (kTestStrings[i].alignment == gfx::ALIGN_LEFT) {
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x());
+ EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x());
+ } else {
+ std::vector<base::string16> lines;
+ base::SplitString(base::WideToUTF16(kTestStrings[i].text), '\n', &lines);
+ ASSERT_EQ(2u, lines.size());
+ int difference = (lines[0].length() - lines[1].length()) * kGlyphSize;
+ EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference,
+ render_text.GetAlignmentOffset(1).x());
+ }
+ }
+}
+#endif
+
TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) {
const wchar_t* kTestStrings[] = {
L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698