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

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

Issue 2688883002: Revert [MacViews] Implemented text context menu (Closed)
Patch Set: 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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/strings/ui_strings.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3981 matching lines...) Expand 10 before | Expand all | Expand 10 after
3992 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after 3992 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
3993 // checking, apply the override anyway to be explicit that it is suppressed. 3993 // checking, apply the override anyway to be explicit that it is suppressed.
3994 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3994 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3995 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering = 3995 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3996 FontRenderParams::SUBPIXEL_RENDERING_RGB; 3996 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3997 DrawVisualText(); 3997 DrawVisualText();
3998 #endif 3998 #endif
3999 EXPECT_FALSE(GetRendererPaint().isLCDRenderText()); 3999 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
4000 } 4000 }
4001 4001
4002 // Verify GetDecoratedTextAndBaselineForRange returns the correct baseline 4002 // Verify GetDecoratedWordAtPoint returns the correct baseline point and
4003 // point and decorated word. 4003 // decorated word for an LTR string.
4004 TEST_P(RenderTextHarfBuzzTest, GetDecoratedTextAndBaselineForRange) { 4004 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_LTR) {
4005 const base::string16 text = ASCIIToUTF16("yellow boxfish");
4006 const Range kWordOneRange = Range(0, 6);
4007 const Range kWordTwoRange = Range(7, 14);
4008 const Range kTextRange = Range(0, 14);
4009
4010 RenderText* render_text = GetRenderText();
4011 render_text->SetDisplayRect(Rect(100, 30));
4012 render_text->SetText(text);
4013 render_text->ApplyWeight(Font::Weight::NORMAL, kWordOneRange);
4014 render_text->ApplyWeight(Font::Weight::SEMIBOLD, kWordTwoRange);
4015 render_text->ApplyStyle(UNDERLINE, true, kWordOneRange);
4016 render_text->ApplyStyle(STRIKE, true, Range(6, 7));
4017 render_text->ApplyStyle(ITALIC, true, kWordTwoRange);
4018
4019 const std::vector<RenderText::FontSpan> font_spans =
4020 render_text->GetFontSpansForTesting();
4021 DecoratedText decorated_text;
4022 Point baseline_point;
4023
4024 // Tests the range of the first word.
4025 DecoratedText expected_text_1;
4026 expected_text_1.text = ASCIIToUTF16("yellow");
4027 for (size_t i = 0; i < expected_text_1.text.length(); i++) {
4028 expected_text_1.attributes.push_back(CreateRangedAttribute(
4029 font_spans, i, i, Font::Weight::NORMAL, UNDERLINE_MASK));
4030 }
4031
4032 const Rect left_glyph_1 =
4033 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false);
4034
4035 EXPECT_TRUE(render_text->GetDecoratedTextAndBaselineForRange(
4036 kWordOneRange, &decorated_text, &baseline_point));
4037 VerifyDecoratedWordsAreEqual(expected_text_1, decorated_text);
4038 EXPECT_TRUE(left_glyph_1.Contains(baseline_point));
4039
4040 // Tests the range of the second word.
4041 DecoratedText expected_text_2;
4042 expected_text_2.text = ASCIIToUTF16("boxfish");
4043 for (size_t i = 0; i < expected_text_2.text.length(); i++) {
4044 expected_text_2.attributes.push_back(CreateRangedAttribute(
4045 font_spans, i, i, Font::Weight::SEMIBOLD, ITALIC_MASK));
4046 }
4047
4048 const Rect left_glyph_2 = render_text->GetCursorBounds(
4049 SelectionModel(kWordTwoRange.start(), CURSOR_FORWARD), false);
4050
4051 EXPECT_TRUE(render_text->GetDecoratedTextAndBaselineForRange(
4052 kWordTwoRange, &decorated_text, &baseline_point));
4053 VerifyDecoratedWordsAreEqual(expected_text_2, decorated_text);
4054 EXPECT_TRUE(left_glyph_2.Contains(baseline_point));
4055
4056 // Tests the range of the entire text.
4057 DecoratedText expected_text_3;
4058 expected_text_3.text = ASCIIToUTF16("yellow boxfish");
4059 expected_text_3.attributes.insert(expected_text_3.attributes.begin(),
4060 expected_text_1.attributes.begin(),
4061 expected_text_1.attributes.end());
4062
4063 expected_text_3.attributes.push_back(CreateRangedAttribute(
4064 font_spans, 6, 6, Font::Weight::NORMAL, STRIKE_MASK));
4065
4066 for (size_t i = kWordTwoRange.start(); i < kWordTwoRange.end(); i++) {
4067 expected_text_3.attributes.push_back(CreateRangedAttribute(
4068 font_spans, i, i, Font::Weight::SEMIBOLD, ITALIC_MASK));
4069 }
4070
4071 EXPECT_TRUE(render_text->GetDecoratedTextAndBaselineForRange(
4072 kTextRange, &decorated_text, &baseline_point));
4073 VerifyDecoratedWordsAreEqual(expected_text_3, decorated_text);
4074 EXPECT_TRUE(left_glyph_1.Contains(baseline_point));
4075 }
4076
4077 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point
4078 // and decorated word for an LTR string.
4079 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_LTR) {
4080 const base::string16 ltr = ASCIIToUTF16(" ab c "); 4005 const base::string16 ltr = ASCIIToUTF16(" ab c ");
4081 const int kWordOneStartIndex = 2; 4006 const int kWordOneStartIndex = 2;
4082 const int kWordTwoStartIndex = 6; 4007 const int kWordTwoStartIndex = 6;
4083 4008
4084 RenderText* render_text = GetRenderText(); 4009 RenderText* render_text = GetRenderText();
4085 render_text->SetDisplayRect(Rect(100, 30)); 4010 render_text->SetDisplayRect(Rect(100, 30));
4086 render_text->SetText(ltr); 4011 render_text->SetText(ltr);
4087 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3)); 4012 render_text->ApplyWeight(Font::Weight::SEMIBOLD, Range(0, 3));
4088 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5)); 4013 render_text->ApplyStyle(UNDERLINE, true, Range(1, 5));
4089 render_text->ApplyStyle(ITALIC, true, Range(3, 8)); 4014 render_text->ApplyStyle(ITALIC, true, Range(3, 8));
(...skipping 25 matching lines...) Expand all
4115 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, 4040 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL,
4116 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK)); 4041 ITALIC_MASK | DIAGONAL_STRIKE_MASK | STRIKE_MASK));
4117 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4042 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4118 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4043 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4119 4044
4120 DecoratedText decorated_word; 4045 DecoratedText decorated_word;
4121 Point baseline_point; 4046 Point baseline_point;
4122 4047
4123 { 4048 {
4124 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4049 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4125 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4050 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4126 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4051 Point(-5, cursor_y), &decorated_word, &baseline_point));
4127 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4052 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4128 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4053 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4129 } 4054 }
4130 { 4055 {
4131 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4056 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4132 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4057 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4133 Point(105, cursor_y), &decorated_word, &baseline_point)); 4058 Point(105, cursor_y), &decorated_word, &baseline_point));
4134 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4059 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4135 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4060 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4136 } 4061 }
4137 4062
4138 for (size_t i = 0; i < render_text->text().length(); i++) { 4063 for (size_t i = 0; i < render_text->text().length(); i++) {
4139 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4064 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4140 // Query the decorated word using the origin of the i'th glyph's bounds. 4065 // Query the decorated word using the origin of the i'th glyph's bounds.
4141 const Point query = 4066 const Point query =
4142 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4067 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4143 .origin(); 4068 .origin();
4144 4069
4145 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4070 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word,
4146 query, &decorated_word, &baseline_point)); 4071 &baseline_point));
4147 4072
4148 if (i < kWordTwoStartIndex) { 4073 if (i < kWordTwoStartIndex) {
4149 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4074 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4150 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4075 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4151 } else { 4076 } else {
4152 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4077 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4153 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4078 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4154 } 4079 }
4155 } 4080 }
4156 } 4081 }
4157 4082
4158 // Verify GetDecoratedWordAndBaselineAtPoint returns the correct baseline point 4083 // Verify GetDecoratedWordAtPoint returns the correct baseline point and
4159 // and
4160 // decorated word for an RTL string. 4084 // decorated word for an RTL string.
4161 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_RTL) { 4085 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_RTL) {
4162 const base::string16 rtl = WideToUTF16( 4086 const base::string16 rtl = WideToUTF16(
4163 L" " 4087 L" "
4164 L"\x0634\x0632" 4088 L"\x0634\x0632"
4165 L" " 4089 L" "
4166 L"\x0634"); 4090 L"\x0634");
4167 const int kWordOneStartIndex = 1; 4091 const int kWordOneStartIndex = 1;
4168 const int kWordTwoStartIndex = 5; 4092 const int kWordTwoStartIndex = 5;
4169 4093
4170 RenderText* render_text = GetRenderText(); 4094 RenderText* render_text = GetRenderText();
4171 render_text->SetDisplayRect(Rect(100, 30)); 4095 render_text->SetDisplayRect(Rect(100, 30));
(...skipping 28 matching lines...) Expand all
4200 expected_word_2.attributes.push_back(CreateRangedAttribute( 4124 expected_word_2.attributes.push_back(CreateRangedAttribute(
4201 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK)); 4125 font_spans, 0, kWordTwoStartIndex, Font::Weight::NORMAL, UNDERLINE_MASK));
4202 const Rect left_glyph_word_2 = render_text->GetCursorBounds( 4126 const Rect left_glyph_word_2 = render_text->GetCursorBounds(
4203 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false); 4127 SelectionModel(kWordTwoStartIndex, CURSOR_FORWARD), false);
4204 4128
4205 DecoratedText decorated_word; 4129 DecoratedText decorated_word;
4206 Point baseline_point; 4130 Point baseline_point;
4207 4131
4208 { 4132 {
4209 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds")); 4133 SCOPED_TRACE(base::StringPrintf("Query to the left of text bounds"));
4210 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4134 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4211 Point(-5, cursor_y), &decorated_word, &baseline_point)); 4135 Point(-5, cursor_y), &decorated_word, &baseline_point));
4212 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4136 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4213 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4137 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4214 } 4138 }
4215 { 4139 {
4216 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds")); 4140 SCOPED_TRACE(base::StringPrintf("Query to the right of text bounds"));
4217 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4141 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4218 Point(105, cursor_y), &decorated_word, &baseline_point)); 4142 Point(105, cursor_y), &decorated_word, &baseline_point));
4219 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4143 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4220 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4144 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4221 } 4145 }
4222 4146
4223 for (size_t i = 0; i < render_text->text().length(); i++) { 4147 for (size_t i = 0; i < render_text->text().length(); i++) {
4224 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i)); 4148 SCOPED_TRACE(base::StringPrintf("Case[%" PRIuS "]", i));
4225 4149
4226 // Query the decorated word using the top right point of the i'th glyph's 4150 // Query the decorated word using the top right point of the i'th glyph's
4227 // bounds. 4151 // bounds.
4228 const Point query = 4152 const Point query =
4229 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false) 4153 render_text->GetCursorBounds(SelectionModel(i, CURSOR_FORWARD), false)
4230 .top_right(); 4154 .top_right();
4231 4155
4232 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4156 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word,
4233 query, &decorated_word, &baseline_point)); 4157 &baseline_point));
4234 if (i < kWordTwoStartIndex) { 4158 if (i < kWordTwoStartIndex) {
4235 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4159 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4236 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4160 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4237 } else { 4161 } else {
4238 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4162 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4239 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4163 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4240 } 4164 }
4241 } 4165 }
4242 } 4166 }
4243 4167
4244 // Test that GetDecoratedWordAndBaselineAtPoint behaves correctly for multiline 4168 // Test that GetDecoratedWordAtPoint behaves correctly for multiline text.
4245 // text. 4169 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Multiline) {
4246 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_Multiline) {
4247 const base::string16 text = ASCIIToUTF16("a b\n..\ncd."); 4170 const base::string16 text = ASCIIToUTF16("a b\n..\ncd.");
4248 const size_t kWordOneIndex = 0; // Index of character 'a'. 4171 const size_t kWordOneIndex = 0; // Index of character 'a'.
4249 const size_t kWordTwoIndex = 2; // Index of character 'b'. 4172 const size_t kWordTwoIndex = 2; // Index of character 'b'.
4250 const size_t kWordThreeIndex = 7; // Index of character 'c'. 4173 const size_t kWordThreeIndex = 7; // Index of character 'c'.
4251 4174
4252 // Set up render text. 4175 // Set up render text.
4253 RenderText* render_text = GetRenderText(); 4176 RenderText* render_text = GetRenderText();
4254 render_text->SetMultiline(true); 4177 render_text->SetMultiline(true);
4255 render_text->SetDisplayRect(Rect(500, 500)); 4178 render_text->SetDisplayRect(Rect(500, 500));
4256 render_text->SetText(text); 4179 render_text->SetText(text);
(...skipping 29 matching lines...) Expand all
4286 expected_word_3.attributes.push_back(CreateRangedAttribute( 4209 expected_word_3.attributes.push_back(CreateRangedAttribute(
4287 font_spans, 1, kWordThreeIndex + 1, Font::Weight::NORMAL, ITALIC_MASK)); 4210 font_spans, 1, kWordThreeIndex + 1, Font::Weight::NORMAL, ITALIC_MASK));
4288 4211
4289 const Rect left_glyph_word_3 = 4212 const Rect left_glyph_word_3 =
4290 GetSubstringBoundsUnion(Range(kWordThreeIndex, kWordThreeIndex + 1)); 4213 GetSubstringBoundsUnion(Range(kWordThreeIndex, kWordThreeIndex + 1));
4291 4214
4292 DecoratedText decorated_word; 4215 DecoratedText decorated_word;
4293 Point baseline_point; 4216 Point baseline_point;
4294 { 4217 {
4295 // Query to the left of the first line. 4218 // Query to the left of the first line.
4296 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4219 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4297 Point(-5, GetCursorYForTesting(0)), &decorated_word, &baseline_point)); 4220 Point(-5, GetCursorYForTesting(0)), &decorated_word, &baseline_point));
4298 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word); 4221 VerifyDecoratedWordsAreEqual(expected_word_1, decorated_word);
4299 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point)); 4222 EXPECT_TRUE(left_glyph_word_1.Contains(baseline_point));
4300 } 4223 }
4301 { 4224 {
4302 // Query on the second line. 4225 // Query on the second line.
4303 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4226 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4304 Point(5, GetCursorYForTesting(1)), &decorated_word, &baseline_point)); 4227 Point(5, GetCursorYForTesting(1)), &decorated_word, &baseline_point));
4305 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word); 4228 VerifyDecoratedWordsAreEqual(expected_word_2, decorated_word);
4306 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point)); 4229 EXPECT_TRUE(left_glyph_word_2.Contains(baseline_point));
4307 } 4230 }
4308 { 4231 {
4309 // Query at the center point of the character 'c'. 4232 // Query at the center point of the character 'c'.
4310 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4233 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4311 left_glyph_word_3.CenterPoint(), &decorated_word, &baseline_point)); 4234 left_glyph_word_3.CenterPoint(), &decorated_word, &baseline_point));
4312 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); 4235 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word);
4313 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); 4236 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point));
4314 } 4237 }
4315 { 4238 {
4316 // Query to the right of the third line. 4239 // Query to the right of the third line.
4317 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4240 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(
4318 Point(505, GetCursorYForTesting(2)), &decorated_word, &baseline_point)); 4241 Point(505, GetCursorYForTesting(2)), &decorated_word, &baseline_point));
4319 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word); 4242 VerifyDecoratedWordsAreEqual(expected_word_3, decorated_word);
4320 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point)); 4243 EXPECT_TRUE(left_glyph_word_3.Contains(baseline_point));
4321 } 4244 }
4322 } 4245 }
4323 4246
4324 // Verify the boolean return value of GetDecoratedWordAndBaselineAtPoint. 4247 // Verify the boolean return value of GetDecoratedWordAtPoint.
4325 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAndBaselineAtPoint_Return) { 4248 TEST_P(RenderTextHarfBuzzTest, GetDecoratedWordAtPoint_Return) {
4326 RenderText* render_text = GetRenderText(); 4249 RenderText* render_text = GetRenderText();
4327 render_text->SetText(ASCIIToUTF16("...")); 4250 render_text->SetText(ASCIIToUTF16("..."));
4328 4251
4329 DecoratedText decorated_word; 4252 DecoratedText decorated_word;
4330 Point baseline_point; 4253 Point baseline_point;
4331 4254
4332 // False should be returned, when the text does not contain any word. 4255 // False should be returned, when the text does not contain any word.
4333 Point query = 4256 Point query =
4334 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4257 render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4335 .origin(); 4258 .origin();
4336 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint( 4259 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word,
4337 query, &decorated_word, &baseline_point)); 4260 &baseline_point));
4338 4261
4339 render_text->SetText(ASCIIToUTF16("abc")); 4262 render_text->SetText(ASCIIToUTF16("abc"));
4340 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4263 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4341 .origin(); 4264 .origin();
4342 EXPECT_TRUE(render_text->GetDecoratedWordAndBaselineAtPoint( 4265 EXPECT_TRUE(render_text->GetDecoratedWordAtPoint(query, &decorated_word,
4343 query, &decorated_word, &baseline_point)); 4266 &baseline_point));
4344 4267
4345 // False should be returned for obscured text. 4268 // False should be returned for obscured text.
4346 render_text->SetObscured(true); 4269 render_text->SetObscured(true);
4347 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false) 4270 query = render_text->GetCursorBounds(SelectionModel(0, CURSOR_FORWARD), false)
4348 .origin(); 4271 .origin();
4349 EXPECT_FALSE(render_text->GetDecoratedWordAndBaselineAtPoint( 4272 EXPECT_FALSE(render_text->GetDecoratedWordAtPoint(query, &decorated_word,
4350 query, &decorated_word, &baseline_point)); 4273 &baseline_point));
4351 } 4274 }
4352 4275
4353 // Tests text selection made at end points of individual lines of multiline 4276 // Tests text selection made at end points of individual lines of multiline
4354 // text. 4277 // text.
4355 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) { 4278 TEST_P(RenderTextHarfBuzzTest, LineEndSelections) {
4356 const wchar_t* const ltr = L"abc\n\ndef"; 4279 const wchar_t* const ltr = L"abc\n\ndef";
4357 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5"; 4280 const wchar_t* const rtl = L"\x5d0\x5d1\x5d2\n\n\x5d3\x5d4\x5d5";
4358 const int left_x = -100; 4281 const int left_x = -100;
4359 const int right_x = 200; 4282 const int right_x = 200;
4360 struct { 4283 struct {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4444 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4367 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4445 PrintRenderTextBackend()); 4368 PrintRenderTextBackend());
4446 #endif 4369 #endif
4447 4370
4448 INSTANTIATE_TEST_CASE_P(, 4371 INSTANTIATE_TEST_CASE_P(,
4449 RenderTextHarfBuzzTest, 4372 RenderTextHarfBuzzTest,
4450 ::testing::Values(RENDER_TEXT_HARFBUZZ), 4373 ::testing::Values(RENDER_TEXT_HARFBUZZ),
4451 PrintRenderTextBackend()); 4374 PrintRenderTextBackend());
4452 4375
4453 } // namespace gfx 4376 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/strings/ui_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698