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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tapted's comments and fixed tests Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 3976 matching lines...) Expand 10 before | Expand all | Expand 10 after
3987 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after 3987 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
3988 // checking, apply the override anyway to be explicit that it is suppressed. 3988 // checking, apply the override anyway to be explicit that it is suppressed.
3989 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3989 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3990 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering = 3990 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3991 FontRenderParams::SUBPIXEL_RENDERING_RGB; 3991 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3992 DrawVisualText(); 3992 DrawVisualText();
3993 #endif 3993 #endif
3994 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3994 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3995 } 3995 }
3996 3996
3997 // Verify GetDecoratedWordAtPoint returns the correct baseline point and 3997 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point
3998 // decorated word for an LTR string. 3998 // and decorated word for an LTR string.
3999 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_LTR) { 3999 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_LTR) {
4000 const base::string16 ltr = ASCIIToUTF16(" ab c "); 4000 const base::string16 ltr = ASCIIToUTF16(" ab c ");
4001 const int kWordOneStartIndex = 2; 4001 const int kWordOneStartIndex = 2;
4002 const int kWordTwoStartIndex = 6; 4002 const int kWordTwoStartIndex = 6;
4003 4003
4004 RenderText* render_text = GetRenderText(); 4004 RenderText* render_text = GetRenderText();
4005 render_text->SetDisplayRect(Rect(100, 30)); 4005 render_text->SetDisplayRect(Rect(100, 30));
4006 render_text->SetText(ltr); 4006 render_text->SetText(ltr);
4007 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3)); 4007 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3));
4008 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5)); 4008 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5));
4009 render_text->ApplyStyle(ITALIC, true, Range(3, 8)); 4009 render_text->ApplyStyle(ITALIC, true, Range(3, 8));
(...skipping 25 matching lines...) Expand all
4035 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, 4035 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL,
4036 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK)); 4036 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK));
4037 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4037 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4038 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4038 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4039 4039
4040 DecoratedText decorated_word; 4040 DecoratedText decorated_word;
4041 Point baseline_point; 4041 Point baseline_point;
4042 4042
4043 { 4043 {
4044 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4044 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4045 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4045 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4046 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4046 Point(-5, cursor_y), &decorated_word, &baseline_point));
4047 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4047 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4048 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4048 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4049 } 4049 }
4050 { 4050 {
4051 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4051 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4052 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4052 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4053 Point(105, cursor_y), &decorated_word, &baseline_point)); 4053 Point(105, cursor_y), &decorated_word, &baseline_point));
4054 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4054 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4055 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4055 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4056 } 4056 }
4057 4057
4058 for (size_t i = 0; i < render_text->text().length(); i++) { 4058 for (size_t i = 0; i < render_text->text().length(); i++) {
4059 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4059 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4060 // Query the decorated word using the origin of the i'th glyph's bounds. 4060 // Query the decorated word using the origin of the i'th glyph's bounds.
4061 const Point query = 4061 const Point query =
4062 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4062 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4063 .origin(); 4063 .origin();
4064 4064
4065 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4065 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4066 &baseline_point)); 4066 query, &decorated_word, &baseline_point));
4067 4067
4068 if (i < kWordTwoStartIndex) { 4068 if (i < kWordTwoStartIndex) {
4069 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4069 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4070 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4070 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4071 } else { 4071 } else {
4072 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4072 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4073 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4073 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4074 } 4074 }
4075 } 4075 }
4076 } 4076 }
4077 4077
4078 // Verify GetDecoratedWordAtPoint returns the correct baseline point and 4078 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point
4079 // and
4079 // decorated word for an RTL string. 4080 // decorated word for an RTL string.
4080 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) { 4081 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_RTL) {
4081 const base::string16 rtl = WideToUTF16( 4082 const base::string16 rtl = WideToUTF16(
4082 L" " 4083 L" "
4083 L"\x0634\x0632" 4084 L"\x0634\x0632"
4084 L" " 4085 L" "
4085 L"\x0634"); 4086 L"\x0634");
4086 const int kWordOneStartIndex = 1; 4087 const int kWordOneStartIndex = 1;
4087 const int kWordTwoStartIndex = 5; 4088 const int kWordTwoStartIndex = 5;
4088 4089
4089 RenderText* render_text = GetRenderText(); 4090 RenderText* render_text = GetRenderText();
4090 render_text->SetDisplayRect(Rect(100, 30)); 4091 render_text->SetDisplayRect(Rect(100, 30));
(...skipping 28 matching lines...) Expand all
4119 expected_word_2.attributes.push_back(CreateRangedAttribute( 4120 expected_word_2.attributes.push_back(CreateRangedAttribute(
4120 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK)); 4121 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK));
4121 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4122 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4122 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4123 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4123 4124
4124 DecoratedText decorated_word; 4125 DecoratedText decorated_word;
4125 Point baseline_point; 4126 Point baseline_point;
4126 4127
4127 { 4128 {
4128 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4129 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4129 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4130 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4130 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4131 Point(-5, cursor_y), &decorated_word, &baseline_point));
4131 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4132 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4132 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4133 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4133 } 4134 }
4134 { 4135 {
4135 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4136 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4136 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4137 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4137 Point(105, cursor_y), &decorated_word, &baseline_point)); 4138 Point(105, cursor_y), &decorated_word, &baseline_point));
4138 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4139 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4139 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4140 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4140 } 4141 }
4141 4142
4142 for (size_t i = 0; i < render_text->text().length(); i++) { 4143 for (size_t i = 0; i < render_text->text().length(); i++) {
4143 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4144 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4144 4145
4145 // Query the decorated word using the top right point of the i'th glyph's 4146 // Query the decorated word using the top right point of the i'th glyph's
4146 // bounds. 4147 // bounds.
4147 const Point query = 4148 const Point query =
4148 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4149 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4149 .top_right(); 4150 .top_right();
4150 4151
4151 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4152 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4152 &baseline_point)); 4153 query, &decorated_word, &baseline_point));
4153 if (i < kWordTwoStartIndex) { 4154 if (i < kWordTwoStartIndex) {
4154 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4155 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4155 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4156 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4156 } else { 4157 } else {
4157 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4158 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4158 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4159 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4159 } 4160 }
4160 } 4161 }
4161 } 4162 }
4162 4163
4163 // Verify the boolean return value of GetDecoratedWordAtPoint. 4164 // Verify the boolean return value of GetDecoratedWordAndBaselineAtPoint.
4164 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Return) { 4165 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_Return) {
4165 RenderText* render_text = GetRenderText(); 4166 RenderText* render_text = GetRenderText();
4166 render_text->SetText(ASCIIToUTF16("...")); 4167 render_text->SetText(ASCIIToUTF16("..."));
4167 4168
4168 DecoratedText decorated_word; 4169 DecoratedText decorated_word;
4169 Point baseline_point; 4170 Point baseline_point;
4170 4171
4171 // False should be returned, when the text does not contain any word. 4172 // False should be returned, when the text does not contain any word.
4172 Point query = 4173 Point query =
4173 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4174 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4174 .origin(); 4175 .origin();
4175 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4176 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint(
4176 &baseline_point)); 4177 query, &decorated_word, &baseline_point));
4177 4178
4178 render_text->SetText(ASCIIToUTF16("abc")); 4179 render_text->SetText(ASCIIToUTF16("abc"));
4179 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4180 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4180 .origin(); 4181 .origin();
4181 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4182 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4182 &baseline_point)); 4183 query, &decorated_word, &baseline_point));
4183 4184
4184 // False should be returned for obscured text. 4185 // False should be returned for obscured text.
4185 render_text->SetObscured(true); 4186 render_text->SetObscured(true);
4186 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4187 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4187 .origin(); 4188 .origin();
4188 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4189 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint(
4189 &baseline_point)); 4190 query, &decorated_word, &baseline_point));
4190 } 4191 }
4191 4192
4192 // Tests text selection made at end points of individual lines of multiline 4193 // Tests text selection made at end points of individual lines of multiline
4193 // text. 4194 // text.
4194 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) { 4195 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) {
4195 const wchar_t* const ltr = L"abc\n\ndef"; 4196 const wchar_t* const ltr = L"abc\n\ndef";
4196 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5"; 4197 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5";
4197 const int left_x = -100; 4198 const int left_x = -100;
4198 const int right_x = 200; 4199 const int right_x = 200;
4199 struct { 4200 struct {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4283 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4284 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4284 PrintRenderTextBackend()); 4285 PrintRenderTextBackend());
4285 #endif 4286 #endif
4286 4287
4287 INSTANTIATE_TEST_CASE_P(, 4288 INSTANTIATE_TEST_CASE_P(,
4288 RenderTextHarfBuzzTest, 4289 RenderTextHarfBuzzTest,
4289 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4290 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4290 PrintRenderTextBackend()); 4291 PrintRenderTextBackend());
4291 4292
4292 } // namespace gfx 4293 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698