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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 924543004: adding baseline options for super/sub scripting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed to ToRoundedInt 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
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..094da7b88f79518cd1dd056df24a32badb769ead 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -174,6 +174,8 @@ TEST_F(RenderTextTest, DefaultStyle) {
const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
for (size_t i = 0; i < arraysize(cases); ++i) {
EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK));
+ EXPECT_TRUE(
+ render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE));
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false));
render_text->SetText(WideToUTF16(cases[i]));
@@ -185,11 +187,13 @@ TEST_F(RenderTextTest, SetColorAndStyle) {
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
const SkColor color = SK_ColorRED;
render_text->SetColor(color);
+ render_text->SetBaselineStyle(SUPERSCRIPT);
render_text->SetStyle(BOLD, true);
render_text->SetStyle(UNDERLINE, false);
const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
for (size_t i = 0; i < arraysize(cases); ++i) {
EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color));
+ EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT));
EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true));
EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false));
render_text->SetText(WideToUTF16(cases[i]));
@@ -208,32 +212,51 @@ TEST_F(RenderTextTest, ApplyColorAndStyle) {
// Apply a ranged color and style and check the resulting breaks.
render_text->ApplyColor(SK_ColorRED, Range(1, 4));
+ render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4));
render_text->ApplyStyle(BOLD, true, Range(2, 5));
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, SK_ColorRED));
expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK));
EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color));
+ std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_style;
+ expected_baseline_style.push_back(
+ std::pair<size_t, BaselineStyle>(0, NORMAL_BASELINE));
+ expected_baseline_style.push_back(
+ std::pair<size_t, BaselineStyle>(2, SUPERIOR));
+ expected_baseline_style.push_back(
+ std::pair<size_t, BaselineStyle>(4, NORMAL_BASELINE));
+ EXPECT_TRUE(
+ render_text->baselines().EqualsForTesting(expected_baseline_style));
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>(2, true));
expected_style.push_back(std::pair<size_t, bool>(5, false));
EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style));
- // Ensure setting a color and style overrides the ranged colors and styles.
+ // Ensure setting a color, baseline, and style overrides the ranged colors,
+ // baseline, and styles.
render_text->SetColor(SK_ColorBLUE);
EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLUE));
+ render_text->SetBaselineStyle(SUBSCRIPT);
+ EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUBSCRIPT));
render_text->SetStyle(BOLD, false);
EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(false));
- // Apply a color and style over the text end and check the resulting breaks.
- // (INT_MAX should be used instead of the text length for the range end)
+ // Apply a color, baseline, and style over the text end and check the
+ // resulting breaks (INT_MAX should be used instead of the text length for
msw 2015/02/25 16:02:33 nit: remove the extra space before the parens. You
dschuyler 2015/02/26 02:11:02 Done.
+ // the range end)
const size_t text_length = render_text->text().length();
render_text->ApplyColor(SK_ColorRED, Range(0, text_length));
+ render_text->ApplyBaselineStyle(SUPERIOR, Range(0, text_length));
render_text->ApplyStyle(BOLD, true, Range(2, text_length));
std::vector<std::pair<size_t, SkColor> > expected_color_end;
expected_color_end.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED));
EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color_end));
+ std::vector<std::pair<size_t, BaselineStyle>> expected_baseline_end;
+ expected_baseline_end.push_back(
+ std::pair<size_t, BaselineStyle>(0, SUPERIOR));
+ EXPECT_TRUE(render_text->baselines().EqualsForTesting(expected_baseline_end));
std::vector<std::pair<size_t, bool> > expected_style_end;
expected_style_end.push_back(std::pair<size_t, bool>(0, false));
expected_style_end.push_back(std::pair<size_t, bool>(2, true));
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text_mac.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698