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

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