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

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 msw's comments, changed 2016 to 2017 Created 3 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 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 3980 matching lines...) Expand 10 before | Expand all | Expand 10 after
3991 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after 3991 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
3992 // checking, apply the override anyway to be explicit that it is suppressed. 3992 // checking, apply the override anyway to be explicit that it is suppressed.
3993 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3993 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3994 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering = 3994 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3995 FontRenderParams::SUBPIXEL_RENDERING_RGB; 3995 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3996 DrawVisualText(); 3996 DrawVisualText();
3997 #endif 3997 #endif
3998 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3998 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3999 } 3999 }
4000 4000
4001 // Verify GetDecoratedWordAtPoint returns the correct baseline point and 4001 // Verify GetDecoratedWordAndBaselineAtRange returns the correct baseline point
msw 2017/02/01 01:52:28 nit: GetDecoratedTextAndBaselineAtRange
spqchan 2017/02/02 20:35:05 Done.
4002 // decorated word for an LTR string. 4002 // and decorated word.
4003 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_LTR) { 4003 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtRange) {
msw 2017/02/01 01:52:28 nit: GetDecoratedTextAndBaselineAtRange
spqchan 2017/02/02 20:35:05 Done.
4004 const base::string16 text = ASCIIToUTF16("yellow boxfish");
4005 const Range kWordOneRange = Range(0, 6);
4006 const Range kWordTwoRange = Range(7, 14);
4007
4008 RenderText* render_text = GetRenderText();
4009 render_text->SetDisplayRect(Rect(100, 30));
4010 render_text->SetText(text);
4011 render_text->ApplyWeight(Font::Weight::NORMAL, kWordOneRange);
4012 render_text->ApplyWeight(Font::Weight::SEMIBOLD, kWordTwoRange);
4013 render_text->ApplyStyle(UNDERLINE, true, kWordOneRange);
4014 render_text->ApplyStyle(ITALIC, true, kWordTwoRange);
4015
4016 const std::vector<RenderText::FontSpan> font_spans =
4017 render_text->GetFontSpansForTesting();
4018
4019 DecoratedText expected_text_1;
4020 expected_text_1.text = ASCIIToUTF16("yellow");
4021 for (size_t i = 0; i < expected_text_1.text.length(); i++) {
msw 2017/02/01 01:52:28 Can you do this without a loop, like: expected_tex
spqchan 2017/02/02 20:35:05 No, it's weird like that. You need to apply an att
msw 2017/02/02 22:16:08 There are numerous other places in the code that c
4022 expected_text_1.attributes.push_back(CreateRangedAttribute(
4023 font_spans, i, i, Font::Weight::NORMAL, UNDERLINE_MASK));
4024 }
4025
4026 const Rect left_glyph_1 =
4027 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false);
4028
4029 DecoratedText decorated_text;
4030 Point baseline_point;
4031
4032 {
msw 2017/02/01 01:52:28 Remove this block if you're not using SCOPED_TRACE
spqchan 2017/02/02 20:35:05 Done.
4033 EXPECT_TRUE(render_text->GetDecoratedTextAndBaselineForRange(
4034 kWordOneRange, &decorated_text, &baseline_point));
4035 VerifyDecoratedWordsAreEqual(expected_text_1, decorated_text);
4036 EXPECT_TRUE(left_glyph_1.Contains(baseline_point));
4037 }
4038
4039 DecoratedText expected_text_2;
4040 expected_text_2.text = ASCIIToUTF16("boxfish");
msw 2017/02/01 01:52:28 It seems like the point of this new function is to
spqchan 2017/02/02 20:35:05 Sure thing, it now checks for both words
4041 for (size_t i = 0; i < expected_text_2.text.length(); i++) {
msw 2017/02/01 01:52:28 Can you do this without a loop, like: expected_tex
spqchan 2017/02/02 20:35:05 Ditto from above.
4042 expected_text_2.attributes.push_back(CreateRangedAttribute(
4043 font_spans, i, i, Font::Weight::SEMIBOLD, ITALIC_MASK));
4044 }
4045
4046 const Rect left_glyph_2 = render_text->GetCursorBounds(
4047 SelectionModel(kWordTwoRange.start(), CURSOR_FORWARD), false);
4048
4049 {
msw 2017/02/01 01:52:28 Remove this block if you're not using SCOPED_TRACE
spqchan 2017/02/02 20:35:05 Done.
4050 EXPECT_TRUE(render_text->GetDecoratedTextAndBaselineForRange(
4051 kWordTwoRange, &decorated_text, &baseline_point));
4052 VerifyDecoratedWordsAreEqual(expected_text_2, decorated_text);
4053 EXPECT_TRUE(left_glyph_2.Contains(baseline_point));
4054 }
4055 }
4056
4057 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point
4058 // and decorated word for an LTR string.
4059 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_LTR) {
4004 const base::string16 ltr = ASCIIToUTF16(" ab c "); 4060 const base::string16 ltr = ASCIIToUTF16(" ab c ");
4005 const int kWordOneStartIndex = 2; 4061 const int kWordOneStartIndex = 2;
4006 const int kWordTwoStartIndex = 6; 4062 const int kWordTwoStartIndex = 6;
4007 4063
4008 RenderText* render_text = GetRenderText(); 4064 RenderText* render_text = GetRenderText();
4009 render_text->SetDisplayRect(Rect(100, 30)); 4065 render_text->SetDisplayRect(Rect(100, 30));
4010 render_text->SetText(ltr); 4066 render_text->SetText(ltr);
4011 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3)); 4067 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3));
4012 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5)); 4068 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5));
4013 render_text->ApplyStyle(ITALIC, true, Range(3, 8)); 4069 render_text->ApplyStyle(ITALIC, true, Range(3, 8));
(...skipping 25 matching lines...) Expand all
4039 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, 4095 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL,
4040 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK)); 4096 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK));
4041 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4097 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4042 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4098 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4043 4099
4044 DecoratedText decorated_word; 4100 DecoratedText decorated_word;
4045 Point baseline_point; 4101 Point baseline_point;
4046 4102
4047 { 4103 {
4048 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4104 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4049 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4105 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4050 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4106 Point(-5, cursor_y), &decorated_word, &baseline_point));
4051 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4107 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4052 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4108 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4053 } 4109 }
4054 { 4110 {
4055 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4111 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4056 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4112 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4057 Point(105, cursor_y), &decorated_word, &baseline_point)); 4113 Point(105, cursor_y), &decorated_word, &baseline_point));
4058 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4114 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4059 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4115 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4060 } 4116 }
4061 4117
4062 for (size_t i = 0; i < render_text->text().length(); i++) { 4118 for (size_t i = 0; i < render_text->text().length(); i++) {
4063 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4119 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4064 // Query the decorated word using the origin of the i'th glyph's bounds. 4120 // Query the decorated word using the origin of the i'th glyph's bounds.
4065 const Point query = 4121 const Point query =
4066 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4122 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4067 .origin(); 4123 .origin();
4068 4124
4069 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4125 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4070 &baseline_point)); 4126 query, &decorated_word, &baseline_point));
4071 4127
4072 if (i < kWordTwoStartIndex) { 4128 if (i < kWordTwoStartIndex) {
4073 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4129 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4074 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4130 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4075 } else { 4131 } else {
4076 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4132 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4077 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4133 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4078 } 4134 }
4079 } 4135 }
4080 } 4136 }
4081 4137
4082 // Verify GetDecoratedWordAtPoint returns the correct baseline point and 4138 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point
4139 // and
4083 // decorated word for an RTL string. 4140 // decorated word for an RTL string.
4084 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) { 4141 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_RTL) {
4085 const base::string16 rtl = WideToUTF16( 4142 const base::string16 rtl = WideToUTF16(
4086 L" " 4143 L" "
4087 L"\x0634\x0632" 4144 L"\x0634\x0632"
4088 L" " 4145 L" "
4089 L"\x0634"); 4146 L"\x0634");
4090 const int kWordOneStartIndex = 1; 4147 const int kWordOneStartIndex = 1;
4091 const int kWordTwoStartIndex = 5; 4148 const int kWordTwoStartIndex = 5;
4092 4149
4093 RenderText* render_text = GetRenderText(); 4150 RenderText* render_text = GetRenderText();
4094 render_text->SetDisplayRect(Rect(100, 30)); 4151 render_text->SetDisplayRect(Rect(100, 30));
(...skipping 28 matching lines...) Expand all
4123 expected_word_2.attributes.push_back(CreateRangedAttribute( 4180 expected_word_2.attributes.push_back(CreateRangedAttribute(
4124 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK)); 4181 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK));
4125 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4182 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4126 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4183 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4127 4184
4128 DecoratedText decorated_word; 4185 DecoratedText decorated_word;
4129 Point baseline_point; 4186 Point baseline_point;
4130 4187
4131 { 4188 {
4132 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4189 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4133 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4190 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4134 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4191 Point(-5, cursor_y), &decorated_word, &baseline_point));
4135 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4192 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4136 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4193 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4137 } 4194 }
4138 { 4195 {
4139 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4196 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4140 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4197 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4141 Point(105, cursor_y), &decorated_word, &baseline_point)); 4198 Point(105, cursor_y), &decorated_word, &baseline_point));
4142 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4199 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4143 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4200 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4144 } 4201 }
4145 4202
4146 for (size_t i = 0; i < render_text->text().length(); i++) { 4203 for (size_t i = 0; i < render_text->text().length(); i++) {
4147 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4204 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4148 4205
4149 // Query the decorated word using the top right point of the i'th glyph's 4206 // Query the decorated word using the top right point of the i'th glyph's
4150 // bounds. 4207 // bounds.
4151 const Point query = 4208 const Point query =
4152 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4209 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4153 .top_right(); 4210 .top_right();
4154 4211
4155 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4212 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4156 &baseline_point)); 4213 query, &decorated_word, &baseline_point));
4157 if (i < kWordTwoStartIndex) { 4214 if (i < kWordTwoStartIndex) {
4158 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4215 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4159 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4216 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4160 } else { 4217 } else {
4161 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4218 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4162 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4219 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4163 } 4220 }
4164 } 4221 }
4165 } 4222 }
4166 4223
4167 // Test that GetDecoratedWordAtPoint behaves correctly for multiline text. 4224 // Test that GetDecoratedWordAndBaselineAtPoint behaves correctly for multiline
4168 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Multiline) { 4225 // text.
4226 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_Multiline) {
4169 const base::string16 text = ASCIIToUTF16("a b\n..\ncd."); 4227 const base::string16 text = ASCIIToUTF16("a b\n..\ncd.");
4170 const size_t kWordOneIndex = 0; // Index of character 'a'. 4228 const size_t kWordOneIndex = 0; // Index of character 'a'.
4171 const size_t kWordTwoIndex = 2; // Index of character 'b'. 4229 const size_t kWordTwoIndex = 2; // Index of character 'b'.
4172 const size_t kWordThreeIndex = 7; // Index of character 'c'. 4230 const size_t kWordThreeIndex = 7; // Index of character 'c'.
4173 4231
4174 // Set up render text. 4232 // Set up render text.
4175 RenderText* render_text = GetRenderText(); 4233 RenderText* render_text = GetRenderText();
4176 render_text->SetMultiline(true); 4234 render_text->SetMultiline(true);
4177 render_text->SetDisplayRect(Rect(500, 500)); 4235 render_text->SetDisplayRect(Rect(500, 500));
4178 render_text->SetText(text); 4236 render_text->SetText(text);
(...skipping 29 matching lines...) Expand all
4208 expected_word_3.attributes.push_back(CreateRangedAttribute( 4266 expected_word_3.attributes.push_back(CreateRangedAttribute(
4209 font_spans, 1, kWordThreeIndex + 1, Font::Weight::NORMAL, ITALIC_MASK)); 4267 font_spans, 1, kWordThreeIndex + 1, Font::Weight::NORMAL, ITALIC_MASK));
4210 4268
4211 const Rect left_glyph_word_3 = 4269 const Rect left_glyph_word_3 =
4212 GetSubstringBoundsUnion(Range(kWordThreeIndex, kWordThreeIndex + 1)); 4270 GetSubstringBoundsUnion(Range(kWordThreeIndex, kWordThreeIndex + 1));
4213 4271
4214 DecoratedText decorated_word; 4272 DecoratedText decorated_word;
4215 Point baseline_point; 4273 Point baseline_point;
4216 { 4274 {
4217 // Query to the left of the first line. 4275 // Query to the left of the first line.
4218 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4276 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4219 Point(-5, GetCursorYForTesting(0)), &decorated_word, &baseline_point)); 4277 Point(-5, GetCursorYForTesting(0)), &decorated_word, &baseline_point));
4220 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4278 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4221 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4279 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4222 } 4280 }
4223 { 4281 {
4224 // Query on the second line. 4282 // Query on the second line.
4225 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4283 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4226 Point(5, GetCursorYForTesting(1)), &decorated_word, &baseline_point)); 4284 Point(5, GetCursorYForTesting(1)), &decorated_word, &baseline_point));
4227 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4285 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4228 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4286 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4229 } 4287 }
4230 { 4288 {
4231 // Query at the center point of the character 'c'. 4289 // Query at the center point of the character 'c'.
4232 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4290 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4233 left_glyph_word_3.CenterPoint(), &decorated_word, &baseline_point)); 4291 left_glyph_word_3.CenterPoint(), &decorated_word, &baseline_point));
4234 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); 4292 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word);
4235 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); 4293 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point));
4236 } 4294 }
4237 { 4295 {
4238 // Query to the right of the third line. 4296 // Query to the right of the third line.
4239 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint( 4297 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4240 Point(505, GetCursorYForTesting(2)), &decorated_word, &baseline_point)); 4298 Point(505, GetCursorYForTesting(2)), &decorated_word, &baseline_point));
4241 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); 4299 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word);
4242 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); 4300 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point));
4243 } 4301 }
4244 } 4302 }
4245 4303
4246 // Verify the boolean return value of GetDecoratedWordAtPoint. 4304 // Verify the boolean return value of GetDecoratedWordAndBaselineAtPoint.
4247 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Return) { 4305 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_Return) {
4248 RenderText* render_text = GetRenderText(); 4306 RenderText* render_text = GetRenderText();
4249 render_text->SetText(ASCIIToUTF16("...")); 4307 render_text->SetText(ASCIIToUTF16("..."));
4250 4308
4251 DecoratedText decorated_word; 4309 DecoratedText decorated_word;
4252 Point baseline_point; 4310 Point baseline_point;
4253 4311
4254 // False should be returned, when the text does not contain any word. 4312 // False should be returned, when the text does not contain any word.
4255 Point query = 4313 Point query =
4256 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4314 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4257 .origin(); 4315 .origin();
4258 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4316 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint(
4259 &baseline_point)); 4317 query, &decorated_word, &baseline_point));
4260 4318
4261 render_text->SetText(ASCIIToUTF16("abc")); 4319 render_text->SetText(ASCIIToUTF16("abc"));
4262 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4320 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4263 .origin(); 4321 .origin();
4264 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4322 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint(
4265 &baseline_point)); 4323 query, &decorated_word, &baseline_point));
4266 4324
4267 // False should be returned for obscured text. 4325 // False should be returned for obscured text.
4268 render_text->SetObscured(true); 4326 render_text->SetObscured(true);
4269 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4327 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4270 .origin(); 4328 .origin();
4271 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word, 4329 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint(
4272 &baseline_point)); 4330 query, &decorated_word, &baseline_point));
4273 } 4331 }
4274 4332
4275 // Tests text selection made at end points of individual lines of multiline 4333 // Tests text selection made at end points of individual lines of multiline
4276 // text. 4334 // text.
4277 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) { 4335 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) {
4278 const wchar_t* const ltr = L"abc\n\ndef"; 4336 const wchar_t* const ltr = L"abc\n\ndef";
4279 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5"; 4337 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5";
4280 const int left_x = -100; 4338 const int left_x = -100;
4281 const int right_x = 200; 4339 const int right_x = 200;
4282 struct { 4340 struct {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4366 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4424 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4367 PrintRenderTextBackend()); 4425 PrintRenderTextBackend());
4368 #endif 4426 #endif
4369 4427
4370 INSTANTIATE_TEST_CASE_P(, 4428 INSTANTIATE_TEST_CASE_P(,
4371 RenderTextHarfBuzzTest, 4429 RenderTextHarfBuzzTest,
4372 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4430 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4373 PrintRenderTextBackend()); 4431 PrintRenderTextBackend());
4374 4432
4375 } // namespace gfx 4433 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698