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

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