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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 1024543006: [RenderText] added test for AppendText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed AppendText test Created 5 years, 9 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.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 42825579ec6cb0b68fe701de431a2c1444d5c1f7..e34f88c0dd988ddeec7566a057d5ae7d6d682082 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -352,6 +352,43 @@ TEST_F(RenderTextTest, ApplyStyles) {
#endif // OS_MACOSX
}
+TEST_F(RenderTextTest, AppendText) {
msw 2015/03/24 22:20:59 nit: name AppendTextKeepsStyles
dschuyler 2015/03/24 22:38:12 Done.
+ // Ensure AppendText maintains current text styles.
msw 2015/03/24 22:20:59 nit: move this comment down to replace the comment
dschuyler 2015/03/24 22:38:12 Done.
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ // Setup basic functionality.
+ render_text->SetText(ASCIIToUTF16("abc"));
+ const SkColor color = SK_ColorRED;
msw 2015/03/24 22:20:59 nit: just inline SK_ColorRED here and line 367.
dschuyler 2015/03/24 22:38:12 Done.
+ render_text->ApplyColor(color, Range(1, 2));
msw 2015/03/24 22:20:59 nit: make the text red over range 0-1 (for more co
dschuyler 2015/03/24 22:38:12 Done.
+ render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
+ render_text->ApplyStyle(UNDERLINE, true, Range(1, 2));
msw 2015/03/24 22:20:59 nit: apply underline over range 2-3 (for more cove
dschuyler 2015/03/24 22:38:12 Done.
+ // Verify basic functionality.
+ std::vector<std::pair<size_t, SkColor>> expected_color;
+ expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK));
+ expected_color.push_back(std::pair<size_t, SkColor>(1, color));
+ expected_color.push_back(std::pair<size_t, SkColor>(2, SK_ColorBLACK));
+ EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color));
+ std::vector<std::pair<size_t, BaselineStyle>> expected_baseline;
+ expected_baseline.push_back(
+ std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE));
+ expected_baseline.push_back(std::pair<size_t, BaselineStyle>(1, SUPERSCRIPT));
+ expected_baseline.push_back(
+ std::pair<size_t, BaselineStyle>(2, NORMAL_BASELINE));
+ EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline));
+ std::vector<std::pair<size_t, bool>> expected_style;
+ expected_style.push_back(std::pair<size_t, bool>(0, false));
+ expected_style.push_back(std::pair<size_t, bool>(1, true));
+ expected_style.push_back(std::pair<size_t, bool>(2, false));
+ EXPECT_TRUE(
+ render_text->styles()[UNDERLINE].EqualsForTesting(expected_style));
+ // Do the specific test (the core of this test).
+ render_text->AppendText(ASCIIToUTF16("def"));
+ EXPECT_EQ(render_text->GetDisplayText(), ASCIIToUTF16("abcdef"));
+ EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color));
+ EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline));
+ EXPECT_TRUE(
+ render_text->styles()[UNDERLINE].EqualsForTesting(expected_style));
+}
+
// TODO(asvitkine): Cursor movements tests disabled on Mac because RenderTextMac
// does not implement this yet. http://crbug.com/131618
#if !defined(OS_MACOSX)
« no previous file with comments | « ui/gfx/render_text.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698