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

Unified Diff: ui/gfx/render_text_unittest.cc

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for review issues. Created 4 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
Index: ui/gfx/render_text_unittest.cc
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index d07c8f5393b9ded8a8ae35a422a432d6b210c901..d60711fc58ac7061559fe7f083217788d29872b1 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -261,13 +261,14 @@ TEST_F(RenderTextTest, SetStyles) {
const SkColor color = SK_ColorRED;
render_text->SetColor(color);
render_text->SetBaselineStyle(SUPERSCRIPT);
- render_text->SetStyle(BOLD, true);
+ render_text->SetWeight(gfx::Font::WEIGHT_BOLD);
msw 2016/03/22 18:24:11 Update enum values in this file.
Mikus 2016/03/23 17:53:22 Done.
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->weights().EqualsValueForTesting(gfx::Font::WEIGHT_BOLD));
EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false));
render_text->SetText(WideToUTF16(cases[i]));
@@ -286,7 +287,7 @@ TEST_F(RenderTextTest, ApplyStyles) {
// 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));
+ render_text->ApplyWeight(gfx::Font::WEIGHT_BOLD, 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));
@@ -301,26 +302,30 @@ TEST_F(RenderTextTest, ApplyStyles) {
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));
+ std::vector<std::pair<size_t, gfx::Font::Weight>> expected_weight;
+ expected_weight.push_back(
+ std::pair<size_t, gfx::Font::Weight>(0, gfx::Font::WEIGHT_NORMAL));
+ expected_weight.push_back(
+ std::pair<size_t, gfx::Font::Weight>(2, gfx::Font::WEIGHT_BOLD));
+ expected_weight.push_back(
+ std::pair<size_t, gfx::Font::Weight>(5, gfx::Font::WEIGHT_NORMAL));
+ EXPECT_TRUE(render_text->weights().EqualsForTesting(expected_weight));
// Ensure that setting a value overrides the ranged values.
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));
+ render_text->SetWeight(gfx::Font::WEIGHT_NORMAL);
+ EXPECT_TRUE(
+ render_text->weights().EqualsValueForTesting(gfx::Font::WEIGHT_NORMAL));
// Apply a value over the text end and check the resulting breaks (INT_MAX
// should be used instead of the text length for 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));
+ render_text->ApplyWeight(gfx::Font::WEIGHT_BOLD, 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));
@@ -328,10 +333,12 @@ TEST_F(RenderTextTest, ApplyStyles) {
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));
- EXPECT_TRUE(render_text->styles()[BOLD].EqualsForTesting(expected_style_end));
+ std::vector<std::pair<size_t, gfx::Font::Weight>> expected_weight_end;
+ expected_weight_end.push_back(
+ std::pair<size_t, gfx::Font::Weight>(0, gfx::Font::WEIGHT_NORMAL));
+ expected_weight_end.push_back(
+ std::pair<size_t, gfx::Font::Weight>(2, gfx::Font::WEIGHT_BOLD));
+ EXPECT_TRUE(render_text->weights().EqualsForTesting(expected_weight_end));
// Ensure ranged values adjust to accommodate text length changes.
render_text->ApplyStyle(ITALIC, true, Range(0, 2));
@@ -1622,12 +1629,12 @@ TEST_F(RenderTextTest, StringSizeBoldWidth) {
EXPECT_GT(plain_width, 0);
// Apply a bold style and check that the new width is greater.
- render_text->SetStyle(BOLD, true);
+ render_text->SetWeight(gfx::Font::WEIGHT_BOLD);
const int bold_width = render_text->GetStringSize().width();
EXPECT_GT(bold_width, plain_width);
// Now, apply a plain style over the first word only.
- render_text->ApplyStyle(BOLD, false, Range(0, 5));
+ render_text->ApplyWeight(gfx::Font::WEIGHT_NORMAL, Range(0, 5));
const int plain_bold_width = render_text->GetStringSize().width();
EXPECT_GT(plain_bold_width, plain_width);
EXPECT_LT(plain_bold_width, bold_width);
@@ -2924,7 +2931,7 @@ TEST_F(RenderTextTest, StringFitsOwnWidth) {
const base::string16 kString = ASCIIToUTF16("www.example.com");
render_text->SetText(kString);
- render_text->ApplyStyle(BOLD, true, Range(0, 3));
+ render_text->ApplyWeight(gfx::Font::WEIGHT_BOLD, Range(0, 3));
render_text->SetElideBehavior(ELIDE_TAIL);
render_text->SetDisplayRect(Rect(0, 0, 500, 100));
@@ -3032,7 +3039,7 @@ TEST_F(RenderTextTest, TextDoesntClip) {
render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4));
render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6));
render_text->ApplyBaselineStyle(SUBSCRIPT, Range(7, 8));
- render_text->SetStyle(BOLD, true);
+ render_text->SetWeight(gfx::Font::WEIGHT_BOLD);
render_text->SetDisplayRect(
Rect(kTestSize, kTestSize, string_size.width(), string_size.height()));
// Allow the RenderText to paint outside of its display rect.

Powered by Google App Engine
This is Rietveld 408576698