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

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

Issue 2251893004: Use parameterized tests to test multiple render text implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@selection_direction
Patch Set: Created 4 years, 4 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
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_mac.h ('k') | no next file » | 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 namespace test { 55 namespace test {
56 56
57 class RenderTextTestApi { 57 class RenderTextTestApi {
58 public: 58 public:
59 RenderTextTestApi(RenderText* render_text) : render_text_(render_text) {} 59 RenderTextTestApi(RenderText* render_text) : render_text_(render_text) {}
60 60
61 static SkPaint& GetRendererPaint(internal::SkiaTextRenderer* renderer) { 61 static SkPaint& GetRendererPaint(internal::SkiaTextRenderer* renderer) {
62 return renderer->paint_; 62 return renderer->paint_;
63 } 63 }
64 64
65 static internal::TextRunList* GetHarfbuzzRunList( 65 // Callers should ensure that the associated RenderText object is a
66 RenderTextHarfBuzz* harfbuzz) { 66 // RenderTextHarfBuzz instance.
67 return harfbuzz->GetRunList(); 67 internal::TextRunList* GetHarfBuzzRunList() {
68 RenderTextHarfBuzz* render_text =
69 static_cast<RenderTextHarfBuzz*>(render_text_);
70 return render_text->GetRunList();
68 } 71 }
69 72
70 void DrawVisualText(internal::SkiaTextRenderer* renderer) { 73 void DrawVisualText(internal::SkiaTextRenderer* renderer) {
71 render_text_->EnsureLayout(); 74 render_text_->EnsureLayout();
72 render_text_->DrawVisualText(renderer); 75 render_text_->DrawVisualText(renderer);
73 } 76 }
74 77
75 private: 78 private:
76 RenderText* render_text_; 79 RenderText* render_text_;
77 80
78 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi); 81 DISALLOW_COPY_AND_ASSIGN(RenderTextTestApi);
79 }; 82 };
80 83
81 } // namespace test 84 } // namespace test
82 85
83 namespace { 86 namespace {
84 87
88 // An enum specifying the different RenderText implementations to be tested.
89 enum RenderTextBackend {
90 RENDER_TEXT_HARFBUZZ,
91 RENDER_TEXT_MAC,
92 };
93
94 // Parameterised test name generator for tests depending on RenderTextBackend.
95 struct PrintRenderTextBackend {
96 template <class ParamType>
97 std::string operator()(const testing::TestParamInfo<ParamType>& info) const {
98 switch (info.param) {
99 case RENDER_TEXT_HARFBUZZ:
100 return "RenderTextHarfBuzz";
101 case RENDER_TEXT_MAC:
102 return "RenderTextMac";
103 }
104 NOTREACHED();
105 return std::string();
106 }
107 };
108
85 // Various weak, LTR, RTL, and Bidi string cases with three characters each. 109 // Various weak, LTR, RTL, and Bidi string cases with three characters each.
86 const wchar_t kWeak[] = L" . "; 110 const wchar_t kWeak[] = L" . ";
87 const wchar_t kLtr[] = L"abc"; 111 const wchar_t kLtr[] = L"abc";
88 const wchar_t kRtl[] = L"\x5d0\x5d1\x5d2"; 112 const wchar_t kRtl[] = L"\x5d0\x5d1\x5d2";
89 const wchar_t kLtrRtl[] = L"a" L"\x5d0\x5d1"; 113 const wchar_t kLtrRtl[] = L"a" L"\x5d0\x5d1";
90 const wchar_t kLtrRtlLtr[] = L"a" L"\x5d1" L"b"; 114 const wchar_t kLtrRtlLtr[] = L"a" L"\x5d1" L"b";
91 const wchar_t kRtlLtr[] = L"\x5d0\x5d1" L"a"; 115 const wchar_t kRtlLtr[] = L"\x5d0\x5d1" L"a";
92 const wchar_t kRtlLtrRtl[] = L"\x5d0" L"a" L"\x5d1"; 116 const wchar_t kRtlLtrRtl[] = L"\x5d0" L"a" L"\x5d1";
93 117
94 // Checks whether |range| contains |index|. This is not the same as calling 118 // Checks whether |range| contains |index|. This is not the same as calling
(...skipping 26 matching lines...) Expand all
121 SCOPED_TRACE(base::StringPrintf( 145 SCOPED_TRACE(base::StringPrintf(
122 "BreakType-%d VisualCursorDirection-%d SelectionBehavior-%d Case-%d.", 146 "BreakType-%d VisualCursorDirection-%d SelectionBehavior-%d Case-%d.",
123 break_type, direction, selection_behavior, static_cast<int>(i))); 147 break_type, direction, selection_behavior, static_cast<int>(i)));
124 148
125 render_text->MoveCursor(break_type, direction, selection_behavior); 149 render_text->MoveCursor(break_type, direction, selection_behavior);
126 EXPECT_EQ(expected->at(i), render_text->selection()); 150 EXPECT_EQ(expected->at(i), render_text->selection());
127 } 151 }
128 expected->clear(); 152 expected->clear();
129 } 153 }
130 154
131 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
132 #if !defined(OS_MACOSX)
133 // Ensure cursor movement in the specified |direction| yields |expected| values. 155 // Ensure cursor movement in the specified |direction| yields |expected| values.
134 void RunMoveCursorLeftRightTest(RenderText* render_text, 156 void RunMoveCursorLeftRightTest(RenderText* render_text,
135 const std::vector<SelectionModel>& expected, 157 const std::vector<SelectionModel>& expected,
136 VisualCursorDirection direction) { 158 VisualCursorDirection direction) {
137 for (size_t i = 0; i < expected.size(); ++i) { 159 for (size_t i = 0; i < expected.size(); ++i) {
138 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.", 160 SCOPED_TRACE(base::StringPrintf("Going %s; expected value index %d.",
139 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i))); 161 direction == CURSOR_LEFT ? "left" : "right", static_cast<int>(i)));
140 EXPECT_EQ(expected[i], render_text->selection_model()); 162 EXPECT_EQ(expected[i], render_text->selection_model());
141 render_text->MoveCursor(CHARACTER_BREAK, direction, SELECTION_NONE); 163 render_text->MoveCursor(CHARACTER_BREAK, direction, SELECTION_NONE);
142 } 164 }
143 // Check that cursoring is clamped at the line edge. 165 // Check that cursoring is clamped at the line edge.
144 EXPECT_EQ(expected.back(), render_text->selection_model()); 166 EXPECT_EQ(expected.back(), render_text->selection_model());
145 // Check that it is the line edge. 167 // Check that it is the line edge.
146 render_text->MoveCursor(LINE_BREAK, direction, SELECTION_NONE); 168 render_text->MoveCursor(LINE_BREAK, direction, SELECTION_NONE);
147 EXPECT_EQ(expected.back(), render_text->selection_model()); 169 EXPECT_EQ(expected.back(), render_text->selection_model());
148 } 170 }
149 #endif // !defined(OS_MACOSX)
150 171
151 // The class which records the drawing operations so that the test case can 172 // The class which records the drawing operations so that the test case can
152 // verify where exactly the glyphs are drawn. 173 // verify where exactly the glyphs are drawn.
153 class TestSkiaTextRenderer : public internal::SkiaTextRenderer { 174 class TestSkiaTextRenderer : public internal::SkiaTextRenderer {
154 public: 175 public:
155 struct TextLog { 176 struct TextLog {
156 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {} 177 TextLog() : glyph_count(0u), color(SK_ColorTRANSPARENT) {}
157 PointF origin; 178 PointF origin;
158 size_t glyph_count; 179 size_t glyph_count;
159 SkColor color; 180 SkColor color;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 277
257 private: 278 private:
258 const wchar_t* string_; 279 const wchar_t* string_;
259 const SkColor* buffer_; 280 const SkColor* buffer_;
260 int stride_; 281 int stride_;
261 int row_count_; 282 int row_count_;
262 283
263 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer); 284 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer);
264 }; 285 };
265 286
266 // Helper to run the same test expectations on all RenderText backends.
267 class RenderTextAllBackends {
268 public:
269 RenderTextAllBackends() : renderer_(&canvas_), current_(nullptr) {}
270
271 bool Advance() {
272 if (!current_) {
273 current_ = &render_text_harfbuzz_;
274 return true;
275 }
276 #if defined(OS_MACOSX)
277 if (current_ == &render_text_harfbuzz_) {
278 current_ = &render_text_mac_;
279 return true;
280 }
281 #endif
282
283 return false;
284 }
285
286 const char* GetName() const {
287 return current_ == &render_text_harfbuzz_ ? "Harfbuzz" : "Mac";
288 }
289
290 RenderText* operator->() {
291 return current_;
292 }
293
294 void DrawVisualText() {
295 test::RenderTextTestApi test_api(current_);
296 test_api.DrawVisualText(&renderer_);
297 }
298
299 void GetTextLogAndReset(std::vector<TestSkiaTextRenderer::TextLog>* log) {
300 renderer_.GetTextLogAndReset(log);
301 }
302
303 SkPaint& paint() {
304 return test::RenderTextTestApi::GetRendererPaint(&renderer_);
305 }
306
307 internal::TextRunList* GetHarfbuzzRunList() {
308 return test::RenderTextTestApi::GetHarfbuzzRunList(&render_text_harfbuzz_);
309 }
310
311 private:
312 Canvas canvas_;
313 TestSkiaTextRenderer renderer_;
314 RenderText* current_;
315
316 RenderTextHarfBuzz render_text_harfbuzz_;
317 #if defined(OS_MACOSX)
318 RenderTextMac render_text_mac_;
319 #endif
320
321 DISALLOW_COPY_AND_ASSIGN(RenderTextAllBackends);
322 };
323
324 } // namespace 287 } // namespace
325 288
326 class RenderTextTest : public testing::Test { 289 // Test fixture class used to run parameterized tests on all RenderText
290 // implementations.
291 class RenderTextTestAll
msw 2016/08/25 03:02:19 nit: maybe just "RenderTextTest"?
karandeepb 2016/08/25 08:13:10 Done.
292 : public testing::Test,
293 public ::testing::WithParamInterface<RenderTextBackend> {
294 public:
295 RenderTextTestAll()
296 : render_text_(CreateRenderTextInstance()),
297 test_api_(new test::RenderTextTestApi(render_text_.get())),
298 renderer_(canvas()) {}
299
300 protected:
301 std::unique_ptr<RenderText> CreateRenderTextInstance() const {
302 std::unique_ptr<RenderText> render_text;
303 switch (GetParam()) {
304 case RENDER_TEXT_HARFBUZZ:
305 render_text.reset(new RenderTextHarfBuzz());
msw 2016/08/25 03:02:19 optional nit: return from within cases.
karandeepb 2016/08/25 08:13:10 Done.
306 break;
307
308 case RENDER_TEXT_MAC:
309 #if defined(OS_MACOSX)
310 render_text.reset(new RenderTextMac());
311 #else
312 NOTREACHED();
313 #endif
314 break;
315 }
316 return render_text;
317 }
318
319 SkPaint& GetRendererPaint() {
320 return test::RenderTextTestApi::GetRendererPaint(renderer());
321 }
322
323 void DrawVisualText() { test_api_->DrawVisualText(renderer()); }
324
325 internal::TextRunList* GetHarfBuzzRunList() {
326 DCHECK_EQ(RENDER_TEXT_HARFBUZZ, GetParam());
327 return test_api_->GetHarfBuzzRunList();
328 }
329
330 void ResetRenderTextInstance() {
331 render_text_ = CreateRenderTextInstance();
332 test_api_.reset(new test::RenderTextTestApi(GetRenderText()));
333 }
334
335 RenderText* GetRenderText() { return render_text_.get(); };
336
337 RenderTextHarfBuzz* GetRenderTextHarfBuzz() {
338 DCHECK_EQ(RENDER_TEXT_HARFBUZZ, GetParam());
339 return static_cast<RenderTextHarfBuzz*>(GetRenderText());
340 }
341
342 #if defined(OS_MACOSX)
343 RenderTextMac* GetRenderTextMac() {
344 DCHECK_EQ(RENDER_TEXT_MAC, GetParam());
345 return static_cast<RenderTextMac*>(GetRenderText());
346 }
347 #endif
348
349 Canvas* canvas() { return &canvas_; }
350 TestSkiaTextRenderer* renderer() { return &renderer_; }
351
327 private: 352 private:
353 std::unique_ptr<RenderText> render_text_;
354 std::unique_ptr<test::RenderTextTestApi> test_api_;
355 Canvas canvas_;
356 TestSkiaTextRenderer renderer_;
357
328 #if defined(OS_WIN) 358 #if defined(OS_WIN)
329 // Needed to bypass DCHECK in GetFallbackFont. 359 // Needed to bypass DCHECK in GetFallbackFont.
330 base::MessageLoopForUI message_loop_; 360 base::MessageLoopForUI message_loop_;
331 #endif 361 #endif
362
363 DISALLOW_COPY_AND_ASSIGN(RenderTextTestAll);
332 }; 364 };
333 365
334 TEST_F(RenderTextTest, DefaultStyles) { 366 // Test fixture class. Use for tests which are only to be run on
msw 2016/08/25 03:02:19 nit: s/on/for/ (be consistent with comment below)
karandeepb 2016/08/25 08:13:10 Done.
367 // RenderTextHarfBuzz.
368 class RenderTextHarfBuzzTest : public RenderTextTestAll {
369 public:
370 RenderTextHarfBuzzTest() {}
371
372 // Overridden from testing::Test:
373 void SetUp() override { DCHECK_EQ(RENDER_TEXT_HARFBUZZ, GetParam()); }
374
375 private:
376 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest);
377 };
378
379 // Test fixture class. Use for tests which are only to be run for RenderTextMac.
380 class RenderTextMacTest : public RenderTextTestAll {
381 public:
382 RenderTextMacTest() {}
383
384 // Overridden from testing::Test:
385 void SetUp() override { DCHECK_EQ(RENDER_TEXT_MAC, GetParam()); }
386
387 private:
388 DISALLOW_COPY_AND_ASSIGN(RenderTextMacTest);
389 };
390
391 TEST_P(RenderTextTestAll, DefaultStyles) {
335 // Check the default styles applied to new instances and adjusted text. 392 // Check the default styles applied to new instances and adjusted text.
336 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 393 RenderText* render_text = GetRenderText();
337 EXPECT_TRUE(render_text->text().empty()); 394 EXPECT_TRUE(render_text->text().empty());
338 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; 395 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
339 for (size_t i = 0; i < arraysize(cases); ++i) { 396 for (size_t i = 0; i < arraysize(cases); ++i) {
340 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); 397 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK));
341 EXPECT_TRUE( 398 EXPECT_TRUE(
342 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); 399 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE));
343 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) 400 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
344 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false)); 401 EXPECT_TRUE(render_text->styles()[style].EqualsValueForTesting(false));
345 render_text->SetText(WideToUTF16(cases[i])); 402 render_text->SetText(WideToUTF16(cases[i]));
346 } 403 }
347 } 404 }
348 405
349 TEST_F(RenderTextTest, SetStyles) { 406 TEST_P(RenderTextTestAll, SetStyles) {
350 // Ensure custom default styles persist across setting and clearing text. 407 // Ensure custom default styles persist across setting and clearing text.
351 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 408 RenderText* render_text = GetRenderText();
352 const SkColor color = SK_ColorRED; 409 const SkColor color = SK_ColorRED;
353 render_text->SetColor(color); 410 render_text->SetColor(color);
354 render_text->SetBaselineStyle(SUPERSCRIPT); 411 render_text->SetBaselineStyle(SUPERSCRIPT);
355 render_text->SetWeight(Font::Weight::BOLD); 412 render_text->SetWeight(Font::Weight::BOLD);
356 render_text->SetStyle(UNDERLINE, false); 413 render_text->SetStyle(UNDERLINE, false);
357 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; 414 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" };
358 for (size_t i = 0; i < arraysize(cases); ++i) { 415 for (size_t i = 0; i < arraysize(cases); ++i) {
359 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); 416 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color));
360 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); 417 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT));
361 EXPECT_TRUE( 418 EXPECT_TRUE(
362 render_text->weights().EqualsValueForTesting(Font::Weight::BOLD)); 419 render_text->weights().EqualsValueForTesting(Font::Weight::BOLD));
363 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); 420 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false));
364 render_text->SetText(WideToUTF16(cases[i])); 421 render_text->SetText(WideToUTF16(cases[i]));
365 422
366 // Ensure custom default styles can be applied after text has been set. 423 // Ensure custom default styles can be applied after text has been set.
367 if (i == 1) 424 if (i == 1)
368 render_text->SetStyle(STRIKE, true); 425 render_text->SetStyle(STRIKE, true);
369 if (i >= 1) 426 if (i >= 1)
370 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true)); 427 EXPECT_TRUE(render_text->styles()[STRIKE].EqualsValueForTesting(true));
371 } 428 }
372 } 429 }
373 430
374 TEST_F(RenderTextTest, ApplyStyles) { 431 TEST_P(RenderTextTestAll, ApplyStyles) {
375 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 432 RenderText* render_text = GetRenderText();
376 render_text->SetText(ASCIIToUTF16("012345678")); 433 render_text->SetText(ASCIIToUTF16("012345678"));
377 434
378 // Apply a ranged color and style and check the resulting breaks. 435 // Apply a ranged color and style and check the resulting breaks.
379 render_text->ApplyColor(SK_ColorRED, Range(1, 4)); 436 render_text->ApplyColor(SK_ColorRED, Range(1, 4));
380 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4)); 437 render_text->ApplyBaselineStyle(SUPERIOR, Range(2, 4));
381 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, 5)); 438 render_text->ApplyWeight(Font::Weight::BOLD, Range(2, 5));
382 std::vector<std::pair<size_t, SkColor> > expected_color; 439 std::vector<std::pair<size_t, SkColor> > expected_color;
383 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK)); 440 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorBLACK));
384 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED)); 441 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorRED));
385 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK)); 442 expected_color.push_back(std::pair<size_t, SkColor>(4, SK_ColorBLACK));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 509 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
453 render_text->ApplyStyle(ITALIC, false, Range(0, 1)); 510 render_text->ApplyStyle(ITALIC, false, Range(0, 1));
454 render_text->SetText(ASCIIToUTF16("0123456")); 511 render_text->SetText(ASCIIToUTF16("0123456"));
455 expected_italic.begin()->second = false; 512 expected_italic.begin()->second = false;
456 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 513 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
457 render_text->ApplyStyle(ITALIC, true, Range(2, 4)); 514 render_text->ApplyStyle(ITALIC, true, Range(2, 4));
458 render_text->SetText(ASCIIToUTF16("012345678")); 515 render_text->SetText(ASCIIToUTF16("012345678"));
459 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic)); 516 EXPECT_TRUE(render_text->styles()[ITALIC].EqualsForTesting(expected_italic));
460 517
461 // TODO(tmoniuszko): Enable when RenderTextMac::IsValidCursorIndex is 518 // TODO(tmoniuszko): Enable when RenderTextMac::IsValidCursorIndex is
462 // implemented. 519 // implemented.
msw 2016/08/25 03:02:19 optional nit: cite http://crbug.com/131618
karandeepb 2016/08/25 08:13:10 Done.
463 #if !defined(OS_MACOSX) 520 if (GetParam() != RENDER_TEXT_MAC) {
464 // Styles shouldn't be changed mid-grapheme. 521 // Styles shouldn't be changed mid-grapheme.
465 render_text->SetText(WideToUTF16( 522 render_text->SetText(
466 L"0" L"\x0915\x093f" L"1" L"\x0915\x093f" L"2")); 523 WideToUTF16(L"0"
467 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5)); 524 L"\x0915\x093f"
468 std::vector<std::pair<size_t, bool> > expected_underline; 525 L"1"
469 expected_underline.push_back(std::pair<size_t, bool>(0, false)); 526 L"\x0915\x093f"
470 expected_underline.push_back(std::pair<size_t, bool>(1, true)); 527 L"2"));
471 expected_underline.push_back(std::pair<size_t, bool>(6, false)); 528 render_text->ApplyStyle(UNDERLINE, true, Range(2, 5));
472 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsForTesting( 529 std::vector<std::pair<size_t, bool>> expected_underline;
473 expected_underline)); 530 expected_underline.push_back(std::pair<size_t, bool>(0, false));
474 #endif // !defined(OS_MACOSX) 531 expected_underline.push_back(std::pair<size_t, bool>(1, true));
532 expected_underline.push_back(std::pair<size_t, bool>(6, false));
533 EXPECT_TRUE(
534 render_text->styles()[UNDERLINE].EqualsForTesting(expected_underline));
535 }
475 } 536 }
476 537
477 TEST_F(RenderTextTest, AppendTextKeepsStyles) { 538 TEST_P(RenderTextTestAll, AppendTextKeepsStyles) {
478 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 539 RenderText* render_text = GetRenderText();
479 // Setup basic functionality. 540 // Setup basic functionality.
480 render_text->SetText(ASCIIToUTF16("abc")); 541 render_text->SetText(ASCIIToUTF16("abc"));
481 render_text->ApplyColor(SK_ColorRED, Range(0, 1)); 542 render_text->ApplyColor(SK_ColorRED, Range(0, 1));
482 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); 543 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
483 render_text->ApplyStyle(UNDERLINE, true, Range(2, 3)); 544 render_text->ApplyStyle(UNDERLINE, true, Range(2, 3));
484 // Verify basic functionality. 545 // Verify basic functionality.
485 std::vector<std::pair<size_t, SkColor>> expected_color; 546 std::vector<std::pair<size_t, SkColor>> expected_color;
486 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED)); 547 expected_color.push_back(std::pair<size_t, SkColor>(0, SK_ColorRED));
487 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorBLACK)); 548 expected_color.push_back(std::pair<size_t, SkColor>(1, SK_ColorBLACK));
488 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color)); 549 EXPECT_TRUE(render_text->colors().EqualsForTesting(expected_color));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 render_text->selection_model()); 592 render_text->selection_model());
532 } 593 }
533 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, selection_behavior); 594 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, selection_behavior);
534 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD), 595 EXPECT_EQ(SelectionModel(Range(select ? 0 : len, len), CURSOR_FORWARD),
535 render_text->selection_model()); 596 render_text->selection_model());
536 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, selection_behavior); 597 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, selection_behavior);
537 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); 598 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
538 } 599 }
539 600
540 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 601 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
541 #if !defined(OS_MACOSX) 602 TEST_P(RenderTextHarfBuzzTest, ObscuredText) {
542 TEST_F(RenderTextTest, ObscuredText) {
543 const base::string16 seuss = ASCIIToUTF16("hop on pop"); 603 const base::string16 seuss = ASCIIToUTF16("hop on pop");
544 const base::string16 no_seuss = ASCIIToUTF16("**********"); 604 const base::string16 no_seuss = ASCIIToUTF16("**********");
545 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 605 RenderText* render_text = GetRenderText();
546 606
547 // GetLayoutText() returns asterisks when the obscured bit is set. 607 // GetLayoutText() returns asterisks when the obscured bit is set.
548 render_text->SetText(seuss); 608 render_text->SetText(seuss);
549 render_text->SetObscured(true); 609 render_text->SetObscured(true);
550 EXPECT_EQ(seuss, render_text->text()); 610 EXPECT_EQ(seuss, render_text->text());
551 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); 611 EXPECT_EQ(no_seuss, render_text->GetDisplayText());
552 render_text->SetObscured(false); 612 render_text->SetObscured(false);
553 EXPECT_EQ(seuss, render_text->text()); 613 EXPECT_EQ(seuss, render_text->text());
554 EXPECT_EQ(seuss, render_text->GetDisplayText()); 614 EXPECT_EQ(seuss, render_text->GetDisplayText());
555 615
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 static_cast<int>(render_text->GetGlyphBounds(0U).length())); 650 static_cast<int>(render_text->GetGlyphBounds(0U).length()));
591 651
592 // Cursoring is independent of underlying characters when text is obscured. 652 // Cursoring is independent of underlying characters when text is obscured.
593 const wchar_t* const texts[] = { 653 const wchar_t* const texts[] = {
594 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, 654 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl,
595 L"hop on pop", // Check LTR word boundaries. 655 L"hop on pop", // Check LTR word boundaries.
596 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. 656 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries.
597 }; 657 };
598 for (size_t i = 0; i < arraysize(texts); ++i) { 658 for (size_t i = 0; i < arraysize(texts); ++i) {
599 base::string16 text = WideToUTF16(texts[i]); 659 base::string16 text = WideToUTF16(texts[i]);
600 TestVisualCursorMotionInObscuredField(render_text.get(), text, 660 TestVisualCursorMotionInObscuredField(render_text, text, SELECTION_NONE);
601 SELECTION_NONE); 661 TestVisualCursorMotionInObscuredField(render_text, text, SELECTION_RETAIN);
602 TestVisualCursorMotionInObscuredField(render_text.get(), text,
603 SELECTION_RETAIN);
604 } 662 }
605 } 663 }
606 #endif // !defined(OS_MACOSX)
607 664
608 TEST_F(RenderTextTest, RevealObscuredText) { 665 TEST_P(RenderTextTestAll, RevealObscuredText) {
609 const base::string16 seuss = ASCIIToUTF16("hop on pop"); 666 const base::string16 seuss = ASCIIToUTF16("hop on pop");
610 const base::string16 no_seuss = ASCIIToUTF16("**********"); 667 const base::string16 no_seuss = ASCIIToUTF16("**********");
611 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 668 RenderText* render_text = GetRenderText();
612 669
613 render_text->SetText(seuss); 670 render_text->SetText(seuss);
614 render_text->SetObscured(true); 671 render_text->SetObscured(true);
615 EXPECT_EQ(seuss, render_text->text()); 672 EXPECT_EQ(seuss, render_text->text());
616 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); 673 EXPECT_EQ(no_seuss, render_text->GetDisplayText());
617 674
618 // Valid reveal index and new revealed index clears previous one. 675 // Valid reveal index and new revealed index clears previous one.
619 render_text->RenderText::SetObscuredRevealIndex(0); 676 render_text->RenderText::SetObscuredRevealIndex(0);
620 EXPECT_EQ(ASCIIToUTF16("h*********"), render_text->GetDisplayText()); 677 EXPECT_EQ(ASCIIToUTF16("h*********"), render_text->GetDisplayText());
621 render_text->RenderText::SetObscuredRevealIndex(1); 678 render_text->RenderText::SetObscuredRevealIndex(1);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 render_text->RenderText::SetObscuredRevealIndex(2); 729 render_text->RenderText::SetObscuredRevealIndex(2);
673 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetDisplayText()); 730 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetDisplayText());
674 render_text->RenderText::SetObscuredRevealIndex(5); 731 render_text->RenderText::SetObscuredRevealIndex(5);
675 const base::char16 valid_expect_5_and_6[] = 732 const base::char16 valid_expect_5_and_6[] =
676 {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; 733 {'*', '*', '*', '*', 0xD800, 0xDC00, 0};
677 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); 734 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText());
678 render_text->RenderText::SetObscuredRevealIndex(6); 735 render_text->RenderText::SetObscuredRevealIndex(6);
679 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText()); 736 EXPECT_EQ(valid_expect_5_and_6, render_text->GetDisplayText());
680 } 737 }
681 738
682 TEST_F(RenderTextTest, ObscuredEmoji) { 739 TEST_P(RenderTextTestAll, ObscuredEmoji) {
683 // Ensures text itemization doesn't crash on obscured multi-char glyphs. 740 // Ensures text itemization doesn't crash on obscured multi-char glyphs.
684 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 741 RenderText* render_text = GetRenderText();
685 render_text->SetObscured(true); 742 render_text->SetObscured(true);
686 Canvas canvas;
687 // Test the "Grinning face with smiling eyes" character followed by 'y'. 743 // Test the "Grinning face with smiling eyes" character followed by 'y'.
688 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x98\x81y")); 744 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x98\x81y"));
689 render_text->Draw(&canvas); 745 render_text->Draw(canvas());
690 // Test two "Camera" characters in a row. 746 // Test two "Camera" characters in a row.
691 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x93\xB7\xF0\x9F\x93\xB7")); 747 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x93\xB7\xF0\x9F\x93\xB7"));
692 render_text->Draw(&canvas); 748 render_text->Draw(canvas());
693 } 749 }
694 750
695 // TODO(PORT): Fails for RenderTextMac. 751 // TODO(PORT): Fails for RenderTextMac.
752 // Crashes on Mac with RenderTextHarfBuzz. See http://crbug.com/640068.
696 #if !defined(OS_MACOSX) 753 #if !defined(OS_MACOSX)
697 754
698 TEST_F(RenderTextTest, ElidedText) { 755 TEST_P(RenderTextTestAll, ElidedText) {
699 // TODO(skanuj) : Add more test cases for following 756 // TODO(skanuj) : Add more test cases for following
700 // - RenderText styles. 757 // - RenderText styles.
701 // - Cross interaction of truncate, elide and obscure. 758 // - Cross interaction of truncate, elide and obscure.
702 // - ElideText tests from text_elider.cc. 759 // - ElideText tests from text_elider.cc.
703 struct { 760 struct {
704 const wchar_t* text; 761 const wchar_t* text;
705 const wchar_t* display_text; 762 const wchar_t* display_text;
706 const bool elision_expected; 763 const bool elision_expected;
707 } cases[] = { 764 } cases[] = {
708 // Strings shorter than the elision width should be laid out in full. 765 // Strings shorter than the elision width should be laid out in full.
(...skipping 28 matching lines...) Expand all
737 // U+05E9 U+05BC U+05C1 U+05B8 forms a four-character compound glyph. Again, 794 // U+05E9 U+05BC U+05C1 U+05B8 forms a four-character compound glyph. Again,
738 // it should be either fully elided, or not elided at all. If completely 795 // it should be either fully elided, or not elided at all. If completely
739 // elided, an LTR Mark (U+200E) should be added. 796 // elided, an LTR Mark (U+200E) should be added.
740 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8", false }, 797 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8", false },
741 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x2026\x200E" , true }, 798 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x2026\x200E" , true },
742 { L"01\x05e9\x05bc\x05c1\x05b8", L"01\x2026\x200E" , true }, 799 { L"01\x05e9\x05bc\x05c1\x05b8", L"01\x2026\x200E" , true },
743 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x2026\x200E" , true }, 800 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x2026\x200E" , true },
744 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , true }, 801 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , true },
745 }; 802 };
746 803
747 std::unique_ptr<RenderText> expected_render_text( 804 std::unique_ptr<RenderText> expected_render_text(CreateRenderTextInstance());
748 RenderText::CreateInstance());
749 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); 805 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
750 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100)); 806 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100));
751 807
752 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 808 RenderText* render_text = GetRenderText();
753 render_text->SetFontList(FontList("serif, Sans serif, 12px")); 809 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
754 render_text->SetElideBehavior(ELIDE_TAIL); 810 render_text->SetElideBehavior(ELIDE_TAIL);
755 811
756 for (size_t i = 0; i < arraysize(cases); i++) { 812 for (size_t i = 0; i < arraysize(cases); i++) {
757 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "] '%ls'", i, 813 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "] '%ls'", i,
758 cases[i].text)); 814 cases[i].text));
759 815
760 // Compute expected width 816 // Compute expected width
761 expected_render_text->SetText(WideToUTF16(cases[i].display_text)); 817 expected_render_text->SetText(WideToUTF16(cases[i].display_text));
762 int expected_width = expected_render_text->GetContentWidth(); 818 int expected_width = expected_render_text->GetContentWidth();
763 819
764 base::string16 input = WideToUTF16(cases[i].text); 820 base::string16 input = WideToUTF16(cases[i].text);
765 // Extend the input text to ensure that it is wider than the display_text, 821 // Extend the input text to ensure that it is wider than the display_text,
766 // and so it will get elided. 822 // and so it will get elided.
767 if (cases[i].elision_expected) 823 if (cases[i].elision_expected)
768 input.append(WideToUTF16(L" MMMMMMMMMMM")); 824 input.append(WideToUTF16(L" MMMMMMMMMMM"));
769 render_text->SetText(input); 825 render_text->SetText(input);
770 render_text->SetDisplayRect(Rect(0, 0, expected_width, 100)); 826 render_text->SetDisplayRect(Rect(0, 0, expected_width, 100));
771 EXPECT_EQ(input, render_text->text()); 827 EXPECT_EQ(input, render_text->text());
772 EXPECT_EQ(WideToUTF16(cases[i].display_text), 828 EXPECT_EQ(WideToUTF16(cases[i].display_text),
773 render_text->GetDisplayText()); 829 render_text->GetDisplayText());
774 expected_render_text->SetText(base::string16()); 830 expected_render_text->SetText(base::string16());
775 } 831 }
776 } 832 }
777 833
778 TEST_F(RenderTextTest, ElidedObscuredText) { 834 TEST_P(RenderTextTestAll, ElidedObscuredText) {
779 std::unique_ptr<RenderText> expected_render_text( 835 std::unique_ptr<RenderText> expected_render_text(CreateRenderTextInstance());
780 RenderText::CreateInstance());
781 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); 836 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
782 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100)); 837 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100));
783 expected_render_text->SetText(WideToUTF16(L"**\x2026")); 838 expected_render_text->SetText(WideToUTF16(L"**\x2026"));
784 839
785 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 840 RenderText* render_text = GetRenderText();
786 render_text->SetFontList(FontList("serif, Sans serif, 12px")); 841 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
787 render_text->SetElideBehavior(ELIDE_TAIL); 842 render_text->SetElideBehavior(ELIDE_TAIL);
788 render_text->SetDisplayRect( 843 render_text->SetDisplayRect(
789 Rect(0, 0, expected_render_text->GetContentWidth(), 100)); 844 Rect(0, 0, expected_render_text->GetContentWidth(), 100));
790 render_text->SetObscured(true); 845 render_text->SetObscured(true);
791 render_text->SetText(WideToUTF16(L"abcdef")); 846 render_text->SetText(WideToUTF16(L"abcdef"));
792 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); 847 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
793 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); 848 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText());
794 } 849 }
850 #endif // !defined(OS_MACOSX)
msw 2016/08/25 03:02:19 nit: add a blank line above this.
karandeepb 2016/08/25 08:13:10 Done.
795 851
796 TEST_F(RenderTextTest, MultilineElide) { 852 // TODO(PORT): Fails for RenderTextMac.
msw 2016/08/25 03:02:19 optional nit: cite a bug?
karandeepb 2016/08/25 08:13:10 Can't find a relevant bug. This was just copied fr
797 std::unique_ptr<RenderText> render_text(new RenderTextHarfBuzz); 853 TEST_P(RenderTextHarfBuzzTest, MultilineElide) {
854 RenderText* render_text = GetRenderText();
798 base::string16 input_text; 855 base::string16 input_text;
799 // Aim for 3 lines of text. 856 // Aim for 3 lines of text.
800 for (int i = 0; i < 20; ++i) 857 for (int i = 0; i < 20; ++i)
801 input_text.append(ASCIIToUTF16("hello world ")); 858 input_text.append(ASCIIToUTF16("hello world "));
802 render_text->SetText(input_text); 859 render_text->SetText(input_text);
803 // Apply a style that tweaks the layout to make sure elision is calculated 860 // Apply a style that tweaks the layout to make sure elision is calculated
804 // with these styles. This can expose a behavior in layout where text is 861 // with these styles. This can expose a behavior in layout where text is
805 // slightly different width. This must be done after |SetText()|. 862 // slightly different width. This must be done after |SetText()|.
806 render_text->ApplyWeight(Font::Weight::BOLD, Range(1, 20)); 863 render_text->ApplyWeight(Font::Weight::BOLD, Range(1, 20));
807 render_text->ApplyStyle(ITALIC, true, Range(1, 20)); 864 render_text->ApplyStyle(ITALIC, true, Range(1, 20));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 EXPECT_EQ(input_text, render_text->GetDisplayText()); 896 EXPECT_EQ(input_text, render_text->GetDisplayText());
840 897
841 // And put it back. 898 // And put it back.
842 render_text->SetMaxLines(3); 899 render_text->SetMaxLines(3);
843 render_text->GetStringSize(); 900 render_text->GetStringSize();
844 EXPECT_LT(actual_text.size(), input_text.size()); 901 EXPECT_LT(actual_text.size(), input_text.size());
845 EXPECT_EQ(actual_text, input_text.substr(0, actual_text.size() - 1) + 902 EXPECT_EQ(actual_text, input_text.substr(0, actual_text.size() - 1) +
846 base::string16(kEllipsisUTF16)); 903 base::string16(kEllipsisUTF16));
847 } 904 }
848 905
849 #endif // !defined(OS_MACOSX) 906 TEST_P(RenderTextTestAll, ElidedEmail) {
850 907 RenderText* render_text = GetRenderText();
851 TEST_F(RenderTextTest, ElidedEmail) {
852 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
853 render_text->SetText(ASCIIToUTF16("test@example.com")); 908 render_text->SetText(ASCIIToUTF16("test@example.com"));
854 const Size size = render_text->GetStringSize(); 909 const Size size = render_text->GetStringSize();
855 910
856 const base::string16 long_email = 911 const base::string16 long_email =
857 ASCIIToUTF16("longemailaddresstest@example.com"); 912 ASCIIToUTF16("longemailaddresstest@example.com");
858 render_text->SetText(long_email); 913 render_text->SetText(long_email);
859 render_text->SetElideBehavior(ELIDE_EMAIL); 914 render_text->SetElideBehavior(ELIDE_EMAIL);
860 render_text->SetDisplayRect(Rect(size)); 915 render_text->SetDisplayRect(Rect(size));
861 EXPECT_GE(size.width(), render_text->GetStringSize().width()); 916 EXPECT_GE(size.width(), render_text->GetStringSize().width());
862 EXPECT_GT(long_email.size(), render_text->GetDisplayText().size()); 917 EXPECT_GT(long_email.size(), render_text->GetDisplayText().size());
863 } 918 }
864 919
865 TEST_F(RenderTextTest, TruncatedText) { 920 TEST_P(RenderTextTestAll, TruncatedText) {
866 struct { 921 struct {
867 const wchar_t* text; 922 const wchar_t* text;
868 const wchar_t* display_text; 923 const wchar_t* display_text;
869 } cases[] = { 924 } cases[] = {
870 // Strings shorter than the truncation length should be laid out in full. 925 // Strings shorter than the truncation length should be laid out in full.
871 { L"", L"" }, 926 { L"", L"" },
872 { kWeak, kWeak }, 927 { kWeak, kWeak },
873 { kLtr, kLtr }, 928 { kLtr, kLtr },
874 { kLtrRtl, kLtrRtl }, 929 { kLtrRtl, kLtrRtl },
875 { kLtrRtlLtr, kLtrRtlLtr }, 930 { kLtrRtlLtr, kLtrRtlLtr },
(...skipping 14 matching lines...) Expand all
890 // Surrogate pairs should be truncated reasonably enough. 945 // Surrogate pairs should be truncated reasonably enough.
891 { L"0123\x0915\x093f", L"0123\x2026" }, 946 { L"0123\x0915\x093f", L"0123\x2026" },
892 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8" }, 947 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8" },
893 { L"01\x05e9\x05bc\x05c1\x05b8", L"01\x05e9\x05bc\x2026" }, 948 { L"01\x05e9\x05bc\x05c1\x05b8", L"01\x05e9\x05bc\x2026" },
894 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x05e9\x2026" }, 949 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x05e9\x2026" },
895 { L"0123\x05e9\x05bc\x05c1\x05b8", L"0123\x2026" }, 950 { L"0123\x05e9\x05bc\x05c1\x05b8", L"0123\x2026" },
896 { L"01234\x05e9\x05bc\x05c1\x05b8", L"0123\x2026" }, 951 { L"01234\x05e9\x05bc\x05c1\x05b8", L"0123\x2026" },
897 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" }, 952 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" },
898 }; 953 };
899 954
900 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 955 RenderText* render_text = GetRenderText();
901 render_text->set_truncate_length(5); 956 render_text->set_truncate_length(5);
902 for (size_t i = 0; i < arraysize(cases); i++) { 957 for (size_t i = 0; i < arraysize(cases); i++) {
903 render_text->SetText(WideToUTF16(cases[i].text)); 958 render_text->SetText(WideToUTF16(cases[i].text));
904 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); 959 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text());
905 EXPECT_EQ(WideToUTF16(cases[i].display_text), render_text->GetDisplayText()) 960 EXPECT_EQ(WideToUTF16(cases[i].display_text), render_text->GetDisplayText())
906 << "For case " << i << ": " << cases[i].text; 961 << "For case " << i << ": " << cases[i].text;
907 } 962 }
908 } 963 }
909 964
910 TEST_F(RenderTextTest, TruncatedObscuredText) { 965 TEST_P(RenderTextTestAll, TruncatedObscuredText) {
911 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 966 RenderText* render_text = GetRenderText();
912 render_text->set_truncate_length(3); 967 render_text->set_truncate_length(3);
913 render_text->SetObscured(true); 968 render_text->SetObscured(true);
914 render_text->SetText(WideToUTF16(L"abcdef")); 969 render_text->SetText(WideToUTF16(L"abcdef"));
915 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); 970 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
916 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); 971 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText());
917 } 972 }
918 973
919 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 974 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
920 #if !defined(OS_MACOSX) 975 TEST_P(RenderTextHarfBuzzTest, TruncatedCursorMovementLTR) {
921 TEST_F(RenderTextTest, TruncatedCursorMovementLTR) { 976 RenderText* render_text = GetRenderText();
922 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
923 render_text->set_truncate_length(2); 977 render_text->set_truncate_length(2);
924 render_text->SetText(WideToUTF16(L"abcd")); 978 render_text->SetText(WideToUTF16(L"abcd"));
925 979
926 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); 980 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
927 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 981 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
928 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); 982 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model());
929 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); 983 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
930 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); 984 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
931 985
932 std::vector<SelectionModel> expected; 986 std::vector<SelectionModel> expected;
933 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 987 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
934 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 988 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
935 // The cursor hops over the ellipsis and elided text to the line end. 989 // The cursor hops over the ellipsis and elided text to the line end.
936 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 990 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
937 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 991 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
938 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 992 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
939 993
940 expected.clear(); 994 expected.clear();
941 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 995 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
942 // The cursor hops over the elided text to preceeding text. 996 // The cursor hops over the elided text to preceeding text.
943 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 997 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
944 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 998 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
945 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 999 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
946 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1000 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
947 } 1001 }
948 1002
949 TEST_F(RenderTextTest, TruncatedCursorMovementRTL) { 1003 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
950 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1004 TEST_P(RenderTextHarfBuzzTest, TruncatedCursorMovementRTL) {
1005 RenderText* render_text = GetRenderText();
951 render_text->set_truncate_length(2); 1006 render_text->set_truncate_length(2);
952 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3")); 1007 render_text->SetText(WideToUTF16(L"\x5d0\x5d1\x5d2\x5d3"));
953 1008
954 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); 1009 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
955 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); 1010 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
956 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model()); 1011 EXPECT_EQ(SelectionModel(4, CURSOR_FORWARD), render_text->selection_model());
957 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1012 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
958 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model()); 1013 EXPECT_EQ(SelectionModel(0, CURSOR_BACKWARD), render_text->selection_model());
959 1014
960 std::vector<SelectionModel> expected; 1015 std::vector<SelectionModel> expected;
961 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1016 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
962 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1017 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
963 // The cursor hops over the ellipsis and elided text to the line end. 1018 // The cursor hops over the ellipsis and elided text to the line end.
964 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 1019 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
965 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 1020 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
966 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1021 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
967 1022
968 expected.clear(); 1023 expected.clear();
969 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 1024 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
970 // The cursor hops over the elided text to preceeding text. 1025 // The cursor hops over the elided text to preceeding text.
971 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1026 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
972 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1027 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
973 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1028 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
974 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1029 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
975 } 1030 }
976 #endif // !defined(OS_MACOSX)
977 1031
978 TEST_F(RenderTextTest, MoveCursor_Character) { 1032 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
979 std::unique_ptr<RenderText> render_text( 1033 TEST_P(RenderTextHarfBuzzTest, MoveCursor_Character) {
980 RenderText::CreateInstanceForEditing()); 1034 RenderText* render_text = GetRenderText();
981 render_text->SetText(WideToUTF16(L"123 456 789")); 1035 render_text->SetText(WideToUTF16(L"123 456 789"));
982 std::vector<Range> expected; 1036 std::vector<Range> expected;
983 1037
984 // SELECTION_NONE. 1038 // SELECTION_NONE.
985 render_text->SelectRange(Range(6)); 1039 render_text->SelectRange(Range(6));
986 1040
987 // Move right twice. 1041 // Move right twice.
988 expected.push_back(Range(7)); 1042 expected.push_back(Range(7));
989 expected.push_back(Range(8)); 1043 expected.push_back(Range(8));
990 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1044 RunMoveCursorTestAndClearExpectations(
991 CURSOR_RIGHT, SELECTION_NONE, 1045 render_text, CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected);
992 &expected);
993 1046
994 // Move left twice. 1047 // Move left twice.
995 expected.push_back(Range(7)); 1048 expected.push_back(Range(7));
996 expected.push_back(Range(6)); 1049 expected.push_back(Range(6));
997 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1050 RunMoveCursorTestAndClearExpectations(render_text, CHARACTER_BREAK,
998 CURSOR_LEFT, SELECTION_NONE, &expected); 1051 CURSOR_LEFT, SELECTION_NONE, &expected);
999 1052
1000 // SELECTION_CARET. 1053 // SELECTION_CARET.
1001 render_text->SelectRange(Range(6)); 1054 render_text->SelectRange(Range(6));
1002 expected.push_back(Range(6, 7)); 1055 expected.push_back(Range(6, 7));
1003 1056
1004 // Move right. 1057 // Move right.
1005 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1058 RunMoveCursorTestAndClearExpectations(
1006 CURSOR_RIGHT, SELECTION_CARET, 1059 render_text, CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected);
1007 &expected);
1008 1060
1009 // Move left twice. 1061 // Move left twice.
1010 expected.push_back(Range(6)); 1062 expected.push_back(Range(6));
1011 expected.push_back(Range(6, 5)); 1063 expected.push_back(Range(6, 5));
1012 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1064 RunMoveCursorTestAndClearExpectations(
1013 CURSOR_LEFT, SELECTION_CARET, 1065 render_text, CHARACTER_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected);
1014 &expected);
1015 1066
1016 // SELECTION_RETAIN. 1067 // SELECTION_RETAIN.
1017 render_text->SelectRange(Range(6)); 1068 render_text->SelectRange(Range(6));
1018 1069
1019 // Move right. 1070 // Move right.
1020 expected.push_back(Range(6, 7)); 1071 expected.push_back(Range(6, 7));
1021 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1072 RunMoveCursorTestAndClearExpectations(
1022 CURSOR_RIGHT, SELECTION_RETAIN, 1073 render_text, CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected);
1023 &expected);
1024 1074
1025 // Move left twice. 1075 // Move left twice.
1026 expected.push_back(Range(6)); 1076 expected.push_back(Range(6));
1027 expected.push_back(Range(6, 5)); 1077 expected.push_back(Range(6, 5));
1028 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1078 RunMoveCursorTestAndClearExpectations(
1029 CURSOR_LEFT, SELECTION_RETAIN, 1079 render_text, CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected);
1030 &expected);
1031 1080
1032 // SELECTION_EXTEND. 1081 // SELECTION_EXTEND.
1033 render_text->SelectRange(Range(6)); 1082 render_text->SelectRange(Range(6));
1034 1083
1035 // Move right. 1084 // Move right.
1036 expected.push_back(Range(6, 7)); 1085 expected.push_back(Range(6, 7));
1037 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1086 RunMoveCursorTestAndClearExpectations(
1038 CURSOR_RIGHT, SELECTION_EXTEND, 1087 render_text, CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected);
1039 &expected);
1040 1088
1041 // Move left twice. 1089 // Move left twice.
1042 expected.push_back(Range(7, 6)); 1090 expected.push_back(Range(7, 6));
1043 expected.push_back(Range(7, 5)); 1091 expected.push_back(Range(7, 5));
1044 RunMoveCursorTestAndClearExpectations(render_text.get(), CHARACTER_BREAK, 1092 RunMoveCursorTestAndClearExpectations(
1045 CURSOR_LEFT, SELECTION_EXTEND, 1093 render_text, CHARACTER_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected);
1046 &expected);
1047 } 1094 }
1048 1095
1049 TEST_F(RenderTextTest, MoveCursor_Word) { 1096 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1050 std::unique_ptr<RenderText> render_text( 1097 TEST_P(RenderTextHarfBuzzTest, MoveCursor_Word) {
1051 RenderText::CreateInstanceForEditing()); 1098 RenderText* render_text = GetRenderText();
1052 render_text->SetText(WideToUTF16(L"123 456 789")); 1099 render_text->SetText(WideToUTF16(L"123 456 789"));
1053 std::vector<Range> expected; 1100 std::vector<Range> expected;
1054 1101
1055 // SELECTION_NONE. 1102 // SELECTION_NONE.
1056 render_text->SelectRange(Range(6)); 1103 render_text->SelectRange(Range(6));
1057 1104
1058 // Move left twice. 1105 // Move left twice.
1059 expected.push_back(Range(4)); 1106 expected.push_back(Range(4));
1060 expected.push_back(Range(0)); 1107 expected.push_back(Range(0));
1061 RunMoveCursorTestAndClearExpectations(render_text.get(), WORD_BREAK, 1108 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1062 CURSOR_LEFT, SELECTION_NONE, &expected); 1109 SELECTION_NONE, &expected);
1063 1110
1064 // Move right twice. 1111 // Move right twice.
1065 expected.push_back(Range(3)); 1112 expected.push_back(Range(3));
1066 expected.push_back(Range(7)); 1113 expected.push_back(Range(7));
1067 RunMoveCursorTestAndClearExpectations( 1114 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_RIGHT,
msw 2016/08/25 03:02:19 nit: consistent arg wrapping for these calls acros
karandeepb 2016/08/25 08:13:10 I guess this is how clang format likes it.
1068 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); 1115 SELECTION_NONE, &expected);
1069 1116
1070 // SELECTION_CARET. 1117 // SELECTION_CARET.
1071 render_text->SelectRange(Range(6)); 1118 render_text->SelectRange(Range(6));
1072 1119
1073 // Move left. 1120 // Move left.
1074 expected.push_back(Range(6, 4)); 1121 expected.push_back(Range(6, 4));
1075 RunMoveCursorTestAndClearExpectations( 1122 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1076 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); 1123 SELECTION_CARET, &expected);
1077 1124
1078 // Move right twice. 1125 // Move right twice.
1079 expected.push_back(Range(6)); 1126 expected.push_back(Range(6));
1080 expected.push_back(Range(6, 7)); 1127 expected.push_back(Range(6, 7));
1081 RunMoveCursorTestAndClearExpectations( 1128 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_RIGHT,
1082 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); 1129 SELECTION_CARET, &expected);
1083 1130
1084 // Move left. 1131 // Move left.
1085 expected.push_back(Range(6)); 1132 expected.push_back(Range(6));
1086 RunMoveCursorTestAndClearExpectations( 1133 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1087 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); 1134 SELECTION_CARET, &expected);
1088 1135
1089 // SELECTION_RETAIN. 1136 // SELECTION_RETAIN.
1090 render_text->SelectRange(Range(6)); 1137 render_text->SelectRange(Range(6));
1091 1138
1092 // Move left. 1139 // Move left.
1093 expected.push_back(Range(6, 4)); 1140 expected.push_back(Range(6, 4));
1094 RunMoveCursorTestAndClearExpectations( 1141 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1095 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); 1142 SELECTION_RETAIN, &expected);
1096 1143
1097 // Move right twice. 1144 // Move right twice.
1098 expected.push_back(Range(6, 7)); 1145 expected.push_back(Range(6, 7));
1099 expected.push_back(Range(6, 11)); 1146 expected.push_back(Range(6, 11));
1100 RunMoveCursorTestAndClearExpectations( 1147 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_RIGHT,
1101 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); 1148 SELECTION_RETAIN, &expected);
1102 1149
1103 // Move left. 1150 // Move left.
1104 expected.push_back(Range(6, 8)); 1151 expected.push_back(Range(6, 8));
1105 RunMoveCursorTestAndClearExpectations( 1152 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1106 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); 1153 SELECTION_RETAIN, &expected);
1107 1154
1108 // SELECTION_EXTEND. 1155 // SELECTION_EXTEND.
1109 render_text->SelectRange(Range(6)); 1156 render_text->SelectRange(Range(6));
1110 1157
1111 // Move left. 1158 // Move left.
1112 expected.push_back(Range(6, 4)); 1159 expected.push_back(Range(6, 4));
1113 RunMoveCursorTestAndClearExpectations( 1160 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1114 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); 1161 SELECTION_EXTEND, &expected);
1115 1162
1116 // Move right twice. 1163 // Move right twice.
1117 expected.push_back(Range(4, 7)); 1164 expected.push_back(Range(4, 7));
1118 expected.push_back(Range(4, 11)); 1165 expected.push_back(Range(4, 11));
1119 RunMoveCursorTestAndClearExpectations( 1166 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_RIGHT,
1120 render_text.get(), WORD_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); 1167 SELECTION_EXTEND, &expected);
1121 1168
1122 // Move left. 1169 // Move left.
1123 expected.push_back(Range(4, 8)); 1170 expected.push_back(Range(4, 8));
1124 RunMoveCursorTestAndClearExpectations( 1171 RunMoveCursorTestAndClearExpectations(render_text, WORD_BREAK, CURSOR_LEFT,
1125 render_text.get(), WORD_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); 1172 SELECTION_EXTEND, &expected);
1126 } 1173 }
1127 1174
1128 TEST_F(RenderTextTest, MoveCursor_Line) { 1175 TEST_P(RenderTextTestAll, MoveCursor_Line) {
1129 std::unique_ptr<RenderText> render_text( 1176 RenderText* render_text = GetRenderText();
1130 RenderText::CreateInstanceForEditing());
1131 render_text->SetText(WideToUTF16(L"123 456 789")); 1177 render_text->SetText(WideToUTF16(L"123 456 789"));
1132 std::vector<Range> expected; 1178 std::vector<Range> expected;
1133 1179
1134 // SELECTION_NONE. 1180 // SELECTION_NONE.
1135 render_text->SelectRange(Range(6)); 1181 render_text->SelectRange(Range(6));
1136 1182
1137 // Move right twice. 1183 // Move right twice.
1138 expected.push_back(Range(11)); 1184 expected.push_back(Range(11));
1139 expected.push_back(Range(11)); 1185 expected.push_back(Range(11));
1140 RunMoveCursorTestAndClearExpectations( 1186 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1141 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE, &expected); 1187 SELECTION_NONE, &expected);
1142 1188
1143 // Move left twice. 1189 // Move left twice.
1144 expected.push_back(Range(0)); 1190 expected.push_back(Range(0));
1145 expected.push_back(Range(0)); 1191 expected.push_back(Range(0));
1146 RunMoveCursorTestAndClearExpectations(render_text.get(), LINE_BREAK, 1192 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
1147 CURSOR_LEFT, SELECTION_NONE, &expected); 1193 SELECTION_NONE, &expected);
1148 1194
1149 // SELECTION_CARET. 1195 // SELECTION_CARET.
1150 render_text->SelectRange(Range(6)); 1196 render_text->SelectRange(Range(6));
1151 1197
1152 // Move right. 1198 // Move right.
1153 expected.push_back(Range(6, 11)); 1199 expected.push_back(Range(6, 11));
1154 RunMoveCursorTestAndClearExpectations( 1200 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1155 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); 1201 SELECTION_CARET, &expected);
1156 1202
1157 // Move left twice. 1203 // Move left twice.
1158 expected.push_back(Range(6)); 1204 expected.push_back(Range(6));
1159 expected.push_back(Range(6, 0)); 1205 expected.push_back(Range(6, 0));
1160 RunMoveCursorTestAndClearExpectations( 1206 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
1161 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_CARET, &expected); 1207 SELECTION_CARET, &expected);
1162 1208
1163 // Move right. 1209 // Move right.
1164 expected.push_back(Range(6)); 1210 expected.push_back(Range(6));
1165 RunMoveCursorTestAndClearExpectations( 1211 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1166 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_CARET, &expected); 1212 SELECTION_CARET, &expected);
1167 1213
1168 // SELECTION_RETAIN. 1214 // SELECTION_RETAIN.
1169 render_text->SelectRange(Range(6)); 1215 render_text->SelectRange(Range(6));
1170 1216
1171 // Move right. 1217 // Move right.
1172 expected.push_back(Range(6, 11)); 1218 expected.push_back(Range(6, 11));
1173 RunMoveCursorTestAndClearExpectations( 1219 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1174 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); 1220 SELECTION_RETAIN, &expected);
1175 1221
1176 // Move left twice. 1222 // Move left twice.
1177 expected.push_back(Range(6, 0)); 1223 expected.push_back(Range(6, 0));
1178 expected.push_back(Range(6, 0)); 1224 expected.push_back(Range(6, 0));
1179 RunMoveCursorTestAndClearExpectations( 1225 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
1180 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_RETAIN, &expected); 1226 SELECTION_RETAIN, &expected);
1181 1227
1182 // Move right. 1228 // Move right.
1183 expected.push_back(Range(6, 11)); 1229 expected.push_back(Range(6, 11));
1184 RunMoveCursorTestAndClearExpectations( 1230 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1185 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_RETAIN, &expected); 1231 SELECTION_RETAIN, &expected);
1186 1232
1187 // SELECTION_EXTEND. 1233 // SELECTION_EXTEND.
1188 render_text->SelectRange(Range(6)); 1234 render_text->SelectRange(Range(6));
1189 1235
1190 // Move right. 1236 // Move right.
1191 expected.push_back(Range(6, 11)); 1237 expected.push_back(Range(6, 11));
1192 RunMoveCursorTestAndClearExpectations( 1238 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1193 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); 1239 SELECTION_EXTEND, &expected);
1194 1240
1195 // Move left twice. 1241 // Move left twice.
1196 expected.push_back(Range(11, 0)); 1242 expected.push_back(Range(11, 0));
1197 expected.push_back(Range(11, 0)); 1243 expected.push_back(Range(11, 0));
1198 RunMoveCursorTestAndClearExpectations( 1244 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
1199 render_text.get(), LINE_BREAK, CURSOR_LEFT, SELECTION_EXTEND, &expected); 1245 SELECTION_EXTEND, &expected);
1200 1246
1201 // Move right. 1247 // Move right.
1202 expected.push_back(Range(0, 11)); 1248 expected.push_back(Range(0, 11));
1203 RunMoveCursorTestAndClearExpectations( 1249 RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
1204 render_text.get(), LINE_BREAK, CURSOR_RIGHT, SELECTION_EXTEND, &expected); 1250 SELECTION_EXTEND, &expected);
1205 } 1251 }
1206 1252
1207 TEST_F(RenderTextTest, GetDisplayTextDirection) { 1253 TEST_P(RenderTextTestAll, GetDisplayTextDirection) {
1208 struct { 1254 struct {
1209 const wchar_t* text; 1255 const wchar_t* text;
1210 const base::i18n::TextDirection text_direction; 1256 const base::i18n::TextDirection text_direction;
1211 } cases[] = { 1257 } cases[] = {
1212 // Blank strings and those with no/weak directionality default to LTR. 1258 // Blank strings and those with no/weak directionality default to LTR.
1213 { L"", base::i18n::LEFT_TO_RIGHT }, 1259 { L"", base::i18n::LEFT_TO_RIGHT },
1214 { kWeak, base::i18n::LEFT_TO_RIGHT }, 1260 { kWeak, base::i18n::LEFT_TO_RIGHT },
1215 // Strings that begin with strong LTR characters. 1261 // Strings that begin with strong LTR characters.
1216 { kLtr, base::i18n::LEFT_TO_RIGHT }, 1262 { kLtr, base::i18n::LEFT_TO_RIGHT },
1217 { kLtrRtl, base::i18n::LEFT_TO_RIGHT }, 1263 { kLtrRtl, base::i18n::LEFT_TO_RIGHT },
1218 { kLtrRtlLtr, base::i18n::LEFT_TO_RIGHT }, 1264 { kLtrRtlLtr, base::i18n::LEFT_TO_RIGHT },
1219 // Strings that begin with strong RTL characters. 1265 // Strings that begin with strong RTL characters.
1220 { kRtl, base::i18n::RIGHT_TO_LEFT }, 1266 { kRtl, base::i18n::RIGHT_TO_LEFT },
1221 { kRtlLtr, base::i18n::RIGHT_TO_LEFT }, 1267 { kRtlLtr, base::i18n::RIGHT_TO_LEFT },
1222 { kRtlLtrRtl, base::i18n::RIGHT_TO_LEFT }, 1268 { kRtlLtrRtl, base::i18n::RIGHT_TO_LEFT },
1223 }; 1269 };
1224 1270
1225 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1271 RenderText* render_text = GetRenderText();
1226 const bool was_rtl = base::i18n::IsRTL(); 1272 const bool was_rtl = base::i18n::IsRTL();
1227 1273
1228 for (size_t i = 0; i < 2; ++i) { 1274 for (size_t i = 0; i < 2; ++i) {
1229 // Toggle the application default text direction (to try each direction). 1275 // Toggle the application default text direction (to try each direction).
1230 SetRTL(!base::i18n::IsRTL()); 1276 SetRTL(!base::i18n::IsRTL());
1231 const base::i18n::TextDirection ui_direction = base::i18n::IsRTL() ? 1277 const base::i18n::TextDirection ui_direction = base::i18n::IsRTL() ?
1232 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; 1278 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT;
1233 1279
1234 // Ensure that directionality modes yield the correct text directions. 1280 // Ensure that directionality modes yield the correct text directions.
1235 for (size_t j = 0; j < arraysize(cases); j++) { 1281 for (size_t j = 0; j < arraysize(cases); j++) {
(...skipping 15 matching lines...) Expand all
1251 1297
1252 // Ensure that text changes update the direction for DIRECTIONALITY_FROM_TEXT. 1298 // Ensure that text changes update the direction for DIRECTIONALITY_FROM_TEXT.
1253 render_text->SetDirectionalityMode(DIRECTIONALITY_FROM_TEXT); 1299 render_text->SetDirectionalityMode(DIRECTIONALITY_FROM_TEXT);
1254 render_text->SetText(WideToUTF16(kLtr)); 1300 render_text->SetText(WideToUTF16(kLtr));
1255 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::LEFT_TO_RIGHT); 1301 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::LEFT_TO_RIGHT);
1256 render_text->SetText(WideToUTF16(kRtl)); 1302 render_text->SetText(WideToUTF16(kRtl));
1257 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::RIGHT_TO_LEFT); 1303 EXPECT_EQ(render_text->GetDisplayTextDirection(), base::i18n::RIGHT_TO_LEFT);
1258 } 1304 }
1259 1305
1260 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 1306 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1261 #if !defined(OS_MACOSX) 1307 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInLtr) {
1262 TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) { 1308 RenderText* render_text = GetRenderText();
1263 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
1264
1265 // Pure LTR. 1309 // Pure LTR.
1266 render_text->SetText(ASCIIToUTF16("abc")); 1310 render_text->SetText(ASCIIToUTF16("abc"));
1267 // |expected| saves the expected SelectionModel when moving cursor from left 1311 // |expected| saves the expected SelectionModel when moving cursor from left
1268 // to right. 1312 // to right.
1269 std::vector<SelectionModel> expected; 1313 std::vector<SelectionModel> expected;
1270 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1314 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1271 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1315 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1272 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1316 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1273 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1317 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1274 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1318 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1275 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1319 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1276 1320
1277 expected.clear(); 1321 expected.clear();
1278 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1322 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1279 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1323 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1280 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1324 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1281 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1325 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1282 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1326 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1283 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1327 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1284 } 1328 }
1285 1329
1286 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtl) { 1330 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1287 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1331 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInLtrRtl) {
1332 RenderText* render_text = GetRenderText();
1288 // LTR-RTL 1333 // LTR-RTL
1289 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 1334 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
1290 // The last one is the expected END position. 1335 // The last one is the expected END position.
1291 std::vector<SelectionModel> expected; 1336 std::vector<SelectionModel> expected;
1292 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1337 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1293 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1338 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1294 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1339 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1295 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1340 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1296 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); 1341 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
1297 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 1342 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
1298 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1343 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1299 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 1344 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
1300 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1345 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1301 1346
1302 expected.clear(); 1347 expected.clear();
1303 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 1348 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
1304 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 1349 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
1305 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); 1350 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
1306 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); 1351 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
1307 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1352 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1308 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1353 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1309 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1354 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1310 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1355 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1311 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1356 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1312 } 1357 }
1313 1358
1314 TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtlLtr) { 1359 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1315 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1360 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInLtrRtlLtr) {
1361 RenderText* render_text = GetRenderText();
1316 // LTR-RTL-LTR. 1362 // LTR-RTL-LTR.
1317 render_text->SetText(WideToUTF16(L"a" L"\x05d1" L"b")); 1363 render_text->SetText(WideToUTF16(L"a" L"\x05d1" L"b"));
1318 std::vector<SelectionModel> expected; 1364 std::vector<SelectionModel> expected;
1319 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1365 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1320 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1366 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1321 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1367 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1322 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1368 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1323 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1369 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1324 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1370 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1325 1371
1326 expected.clear(); 1372 expected.clear();
1327 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1373 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1328 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1374 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1329 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1375 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1330 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1376 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1331 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1377 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1332 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1378 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1333 } 1379 }
1334 1380
1335 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { 1381 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1336 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1382 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInRtl) {
1383 RenderText* render_text = GetRenderText();
1337 // Pure RTL. 1384 // Pure RTL.
1338 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); 1385 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
1339 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1386 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1340 std::vector<SelectionModel> expected; 1387 std::vector<SelectionModel> expected;
1341 1388
1342 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1389 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1343 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1390 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1344 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1391 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1345 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1392 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1346 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1393 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1347 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1394 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1348 1395
1349 expected.clear(); 1396 expected.clear();
1350 1397
1351 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1398 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1352 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1399 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1353 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1400 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1354 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1401 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1355 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1402 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1356 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1403 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1357 } 1404 }
1358 1405
1359 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { 1406 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1360 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1407 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInRtlLtr) {
1408 RenderText* render_text = GetRenderText();
1361 // RTL-LTR 1409 // RTL-LTR
1362 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc")); 1410 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2" L"abc"));
1363 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1411 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1364 std::vector<SelectionModel> expected; 1412 std::vector<SelectionModel> expected;
1365 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1413 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1366 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1414 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1367 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1415 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1368 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1416 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1369 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); 1417 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
1370 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 1418 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
1371 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1419 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1372 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 1420 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
1373 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1421 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1374 1422
1375 expected.clear(); 1423 expected.clear();
1376 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 1424 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
1377 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 1425 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
1378 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); 1426 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
1379 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); 1427 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
1380 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1428 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1381 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1429 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1382 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1430 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1383 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1431 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1384 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1432 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1385 } 1433 }
1386 1434
1387 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { 1435 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1388 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1436 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightInRtlLtrRtl) {
1437 RenderText* render_text = GetRenderText();
1389 // RTL-LTR-RTL. 1438 // RTL-LTR-RTL.
1390 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1")); 1439 render_text->SetText(WideToUTF16(L"\x05d0" L"a" L"\x05d1"));
1391 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1440 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1392 std::vector<SelectionModel> expected; 1441 std::vector<SelectionModel> expected;
1393 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1442 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1394 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 1443 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
1395 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 1444 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
1396 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 1445 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
1397 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1446 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1398 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 1447 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_LEFT);
1399 1448
1400 expected.clear(); 1449 expected.clear();
1401 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 1450 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
1402 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 1451 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
1403 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 1452 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
1404 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 1453 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
1405 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 1454 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
1406 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 1455 RunMoveCursorLeftRightTest(render_text, expected, CURSOR_RIGHT);
1407 } 1456 }
1408 1457
1409 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { 1458 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1410 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1459 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRight_ComplexScript) {
1411 1460 RenderText* render_text = GetRenderText();
1412 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); 1461 render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"));
1413 EXPECT_EQ(0U, render_text->cursor_position()); 1462 EXPECT_EQ(0U, render_text->cursor_position());
1414 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1463 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1415 EXPECT_EQ(2U, render_text->cursor_position()); 1464 EXPECT_EQ(2U, render_text->cursor_position());
1416 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1465 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1417 EXPECT_EQ(4U, render_text->cursor_position()); 1466 EXPECT_EQ(4U, render_text->cursor_position());
1418 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1467 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1419 EXPECT_EQ(5U, render_text->cursor_position()); 1468 EXPECT_EQ(5U, render_text->cursor_position());
1420 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1469 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1421 EXPECT_EQ(5U, render_text->cursor_position()); 1470 EXPECT_EQ(5U, render_text->cursor_position());
1422 1471
1423 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1472 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1424 EXPECT_EQ(4U, render_text->cursor_position()); 1473 EXPECT_EQ(4U, render_text->cursor_position());
1425 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1474 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1426 EXPECT_EQ(2U, render_text->cursor_position()); 1475 EXPECT_EQ(2U, render_text->cursor_position());
1427 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1476 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1428 EXPECT_EQ(0U, render_text->cursor_position()); 1477 EXPECT_EQ(0U, render_text->cursor_position());
1429 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1478 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1430 EXPECT_EQ(0U, render_text->cursor_position()); 1479 EXPECT_EQ(0U, render_text->cursor_position());
1431 } 1480 }
1432 1481
1433 TEST_F(RenderTextTest, MoveCursorLeftRight_MeiryoUILigatures) { 1482 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1434 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1483 // Crashes on Mac with RenderTextHarfBuzz. See http://crbug.com/640068.
1484 #if !defined(OS_MACOSX)
1485 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRight_MeiryoUILigatures) {
1486 RenderText* render_text = GetRenderText();
1435 // Meiryo UI uses single-glyph ligatures for 'ff' and 'ffi', but each letter 1487 // Meiryo UI uses single-glyph ligatures for 'ff' and 'ffi', but each letter
1436 // (code point) has unique bounds, so mid-glyph cursoring should be possible. 1488 // (code point) has unique bounds, so mid-glyph cursoring should be possible.
1437 render_text->SetFontList(FontList("Meiryo UI, 12px")); 1489 render_text->SetFontList(FontList("Meiryo UI, 12px"));
1438 render_text->SetText(WideToUTF16(L"ff ffi")); 1490 render_text->SetText(WideToUTF16(L"ff ffi"));
1439 EXPECT_EQ(0U, render_text->cursor_position()); 1491 EXPECT_EQ(0U, render_text->cursor_position());
1440 for (size_t i = 0; i < render_text->text().length(); ++i) { 1492 for (size_t i = 0; i < render_text->text().length(); ++i) {
1441 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1493 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1442 EXPECT_EQ(i + 1, render_text->cursor_position()); 1494 EXPECT_EQ(i + 1, render_text->cursor_position());
1443 } 1495 }
1444 EXPECT_EQ(6U, render_text->cursor_position()); 1496 EXPECT_EQ(6U, render_text->cursor_position());
1445 } 1497 }
1498 #endif // !defined(OS_MACOSX)
1446 1499
1447 TEST_F(RenderTextTest, GraphemePositions) { 1500 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1501 TEST_P(RenderTextHarfBuzzTest, GraphemePositions) {
1448 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme. 1502 // LTR 2-character grapheme, LTR abc, LTR 2-character grapheme.
1449 const base::string16 kText1 = 1503 const base::string16 kText1 =
1450 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f"); 1504 WideToUTF16(L"\x0915\x093f" L"abc" L"\x0915\x093f");
1451 1505
1452 // LTR ab, LTR 2-character grapheme, LTR cd. 1506 // LTR ab, LTR 2-character grapheme, LTR cd.
1453 const base::string16 kText2 = WideToUTF16(L"ab" L"\x0915\x093f" L"cd"); 1507 const base::string16 kText2 = WideToUTF16(L"ab" L"\x0915\x093f" L"cd");
1454 1508
1455 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as 1509 // The below is 'MUSICAL SYMBOL G CLEF', which is represented in UTF-16 as
1456 // two characters forming the surrogate pair 0x0001D11E. 1510 // two characters forming the surrogate pair 0x0001D11E.
1457 const std::string kSurrogate = "\xF0\x9D\x84\x9E"; 1511 const std::string kSurrogate = "\xF0\x9D\x84\x9E";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 { kText3, 7, 6, 6 }, 1551 { kText3, 7, 6, 6 },
1498 { kText3, 50, 6, 6 }, 1552 { kText3, 50, 6, 6 },
1499 }; 1553 };
1500 1554
1501 #if defined(OS_WIN) 1555 #if defined(OS_WIN)
1502 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450 1556 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450
1503 if (base::win::GetVersion() < base::win::VERSION_VISTA) 1557 if (base::win::GetVersion() < base::win::VERSION_VISTA)
1504 return; 1558 return;
1505 #endif 1559 #endif
1506 1560
1507 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1561 RenderText* render_text = GetRenderText();
1508 for (size_t i = 0; i < arraysize(cases); i++) { 1562 for (size_t i = 0; i < arraysize(cases); i++) {
1509 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); 1563 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i));
1510 render_text->SetText(cases[i].text); 1564 render_text->SetText(cases[i].text);
1511 1565
1512 size_t next = render_text->IndexOfAdjacentGrapheme(cases[i].index, 1566 size_t next = render_text->IndexOfAdjacentGrapheme(cases[i].index,
1513 CURSOR_FORWARD); 1567 CURSOR_FORWARD);
1514 EXPECT_EQ(cases[i].expected_next, next); 1568 EXPECT_EQ(cases[i].expected_next, next);
1515 EXPECT_TRUE(render_text->IsValidCursorIndex(next)); 1569 EXPECT_TRUE(render_text->IsValidCursorIndex(next));
1516 1570
1517 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index, 1571 size_t previous = render_text->IndexOfAdjacentGrapheme(cases[i].index,
1518 CURSOR_BACKWARD); 1572 CURSOR_BACKWARD);
1519 EXPECT_EQ(cases[i].expected_previous, previous); 1573 EXPECT_EQ(cases[i].expected_previous, previous);
1520 EXPECT_TRUE(render_text->IsValidCursorIndex(previous)); 1574 EXPECT_TRUE(render_text->IsValidCursorIndex(previous));
1521 } 1575 }
1522 } 1576 }
1523 1577
1524 TEST_F(RenderTextTest, MidGraphemeSelectionBounds) { 1578 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1579 TEST_P(RenderTextHarfBuzzTest, MidGraphemeSelectionBounds) {
1525 #if defined(OS_WIN) 1580 #if defined(OS_WIN)
1526 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450 1581 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450
1527 if (base::win::GetVersion() < base::win::VERSION_VISTA) 1582 if (base::win::GetVersion() < base::win::VERSION_VISTA)
1528 return; 1583 return;
1529 #endif 1584 #endif
1530 1585
1531 // Test that selection bounds may be set amid multi-character graphemes. 1586 // Test that selection bounds may be set amid multi-character graphemes.
1532 const base::string16 kHindi = WideToUTF16(L"\x0915\x093f"); 1587 const base::string16 kHindi = WideToUTF16(L"\x0915\x093f");
1533 const base::string16 kThai = WideToUTF16(L"\x0e08\x0e33"); 1588 const base::string16 kThai = WideToUTF16(L"\x0e08\x0e33");
1534 const base::string16 cases[] = { kHindi, kThai }; 1589 const base::string16 cases[] = { kHindi, kThai };
1535 1590
1536 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1591 RenderText* render_text = GetRenderText();
1537 for (size_t i = 0; i < arraysize(cases); i++) { 1592 for (size_t i = 0; i < arraysize(cases); i++) {
1538 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i)); 1593 SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i));
1539 render_text->SetText(cases[i]); 1594 render_text->SetText(cases[i]);
1540 EXPECT_TRUE(render_text->IsValidLogicalIndex(1)); 1595 EXPECT_TRUE(render_text->IsValidLogicalIndex(1));
1541 EXPECT_FALSE(render_text->IsValidCursorIndex(1)); 1596 EXPECT_FALSE(render_text->IsValidCursorIndex(1));
1542 EXPECT_TRUE(render_text->SelectRange(Range(2, 1))); 1597 EXPECT_TRUE(render_text->SelectRange(Range(2, 1)));
1543 EXPECT_EQ(Range(2, 1), render_text->selection()); 1598 EXPECT_EQ(Range(2, 1), render_text->selection());
1544 EXPECT_EQ(1U, render_text->cursor_position()); 1599 EXPECT_EQ(1U, render_text->cursor_position());
1545 // Although selection bounds may be set within a multi-character grapheme, 1600 // Although selection bounds may be set within a multi-character grapheme,
1546 // cursor movement (e.g. via arrow key) should avoid those indices. 1601 // cursor movement (e.g. via arrow key) should avoid those indices.
1547 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1602 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1548 EXPECT_EQ(0U, render_text->cursor_position()); 1603 EXPECT_EQ(0U, render_text->cursor_position());
1549 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1604 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1550 EXPECT_EQ(2U, render_text->cursor_position()); 1605 EXPECT_EQ(2U, render_text->cursor_position());
1551 } 1606 }
1552 } 1607 }
1553 1608
1554 TEST_F(RenderTextTest, FindCursorPosition) { 1609 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1610 TEST_P(RenderTextHarfBuzzTest, FindCursorPosition) {
1555 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl }; 1611 const wchar_t* kTestStrings[] = { kLtrRtl, kLtrRtlLtr, kRtlLtr, kRtlLtrRtl };
1556 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1612 RenderText* render_text = GetRenderText();
1557 render_text->SetDisplayRect(Rect(0, 0, 100, 20)); 1613 render_text->SetDisplayRect(Rect(0, 0, 100, 20));
1558 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 1614 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
1559 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i)); 1615 SCOPED_TRACE(base::StringPrintf("Testing case[%" PRIuS "]", i));
1560 render_text->SetText(WideToUTF16(kTestStrings[i])); 1616 render_text->SetText(WideToUTF16(kTestStrings[i]));
1561 for(size_t j = 0; j < render_text->text().length(); ++j) { 1617 for (size_t j = 0; j < render_text->text().length(); ++j) {
1562 const Range range(render_text->GetGlyphBounds(j)); 1618 const Range range(render_text->GetGlyphBounds(j));
1563 // Test a point just inside the leading edge of the glyph bounds. 1619 // Test a point just inside the leading edge of the glyph bounds.
1564 int x = range.is_reversed() ? range.GetMax() - 1 : range.GetMin() + 1; 1620 int x = range.is_reversed() ? range.GetMax() - 1 : range.GetMin() + 1;
1565 EXPECT_EQ(j, render_text->FindCursorPosition(Point(x, 0)).caret_pos()); 1621 EXPECT_EQ(j, render_text->FindCursorPosition(Point(x, 0)).caret_pos());
1566 } 1622 }
1567 } 1623 }
1568 } 1624 }
1569 #endif // !defined(OS_MACOSX)
1570 1625
1571 TEST_F(RenderTextTest, EdgeSelectionModels) { 1626 TEST_P(RenderTextTestAll, EdgeSelectionModels) {
1572 // Simple Latin text. 1627 // Simple Latin text.
1573 const base::string16 kLatin = WideToUTF16(L"abc"); 1628 const base::string16 kLatin = WideToUTF16(L"abc");
1574 // LTR 2-character grapheme. 1629 // LTR 2-character grapheme.
1575 const base::string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f"); 1630 const base::string16 kLTRGrapheme = WideToUTF16(L"\x0915\x093f");
1576 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme. 1631 // LTR 2-character grapheme, LTR a, LTR 2-character grapheme.
1577 const base::string16 kHindiLatin = 1632 const base::string16 kHindiLatin =
1578 WideToUTF16(L"\x0915\x093f" L"a" L"\x0915\x093f"); 1633 WideToUTF16(L"\x0915\x093f" L"a" L"\x0915\x093f");
1579 // RTL 2-character grapheme. 1634 // RTL 2-character grapheme.
1580 const base::string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8"); 1635 const base::string16 kRTLGrapheme = WideToUTF16(L"\x05e0\x05b8");
1581 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme. 1636 // RTL 2-character grapheme, LTR a, RTL 2-character grapheme.
(...skipping 11 matching lines...) Expand all
1593 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT }, 1648 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT },
1594 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, 1649 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT },
1595 }; 1650 };
1596 1651
1597 #if defined(OS_WIN) 1652 #if defined(OS_WIN)
1598 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450 1653 // TODO(msw): XP fails due to lack of font support: http://crbug.com/106450
1599 if (base::win::GetVersion() < base::win::VERSION_VISTA) 1654 if (base::win::GetVersion() < base::win::VERSION_VISTA)
1600 return; 1655 return;
1601 #endif 1656 #endif
1602 1657
1603 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1658 RenderText* render_text = GetRenderText();
1604 for (size_t i = 0; i < arraysize(cases); i++) { 1659 for (size_t i = 0; i < arraysize(cases); i++) {
1605 render_text->SetText(cases[i].text); 1660 render_text->SetText(cases[i].text);
1606 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT); 1661 bool ltr = (cases[i].expected_text_direction == base::i18n::LEFT_TO_RIGHT);
1607 1662
1608 SelectionModel start_edge = 1663 SelectionModel start_edge =
1609 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT); 1664 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT);
1610 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD)); 1665 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD));
1611 1666
1612 SelectionModel end_edge = 1667 SelectionModel end_edge =
1613 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT); 1668 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT);
1614 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD)); 1669 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD));
1615 } 1670 }
1616 } 1671 }
1617 1672
1618 TEST_F(RenderTextTest, SelectAll) { 1673 TEST_P(RenderTextTestAll, SelectAll) {
1619 const wchar_t* const cases[] = 1674 const wchar_t* const cases[] =
1620 { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl }; 1675 { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl };
1621 1676
1622 // Ensure that SelectAll respects the |reversed| argument regardless of 1677 // Ensure that SelectAll respects the |reversed| argument regardless of
1623 // application locale and text content directionality. 1678 // application locale and text content directionality.
1624 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1679 RenderText* render_text = GetRenderText();
1625 const SelectionModel expected_reversed(Range(3, 0), CURSOR_FORWARD); 1680 const SelectionModel expected_reversed(Range(3, 0), CURSOR_FORWARD);
1626 const SelectionModel expected_forwards(Range(0, 3), CURSOR_BACKWARD); 1681 const SelectionModel expected_forwards(Range(0, 3), CURSOR_BACKWARD);
1627 const bool was_rtl = base::i18n::IsRTL(); 1682 const bool was_rtl = base::i18n::IsRTL();
1628 1683
1629 for (size_t i = 0; i < 2; ++i) { 1684 for (size_t i = 0; i < 2; ++i) {
1630 SetRTL(!base::i18n::IsRTL()); 1685 SetRTL(!base::i18n::IsRTL());
1631 // Test that an empty string produces an empty selection model. 1686 // Test that an empty string produces an empty selection model.
1632 render_text->SetText(base::string16()); 1687 render_text->SetText(base::string16());
1633 EXPECT_EQ(render_text->selection_model(), SelectionModel()); 1688 EXPECT_EQ(render_text->selection_model(), SelectionModel());
1634 1689
1635 // Test the weak, LTR, RTL, and Bidi string cases. 1690 // Test the weak, LTR, RTL, and Bidi string cases.
1636 for (size_t j = 0; j < arraysize(cases); j++) { 1691 for (size_t j = 0; j < arraysize(cases); j++) {
1637 render_text->SetText(WideToUTF16(cases[j])); 1692 render_text->SetText(WideToUTF16(cases[j]));
1638 render_text->SelectAll(false); 1693 render_text->SelectAll(false);
1639 EXPECT_EQ(render_text->selection_model(), expected_forwards); 1694 EXPECT_EQ(render_text->selection_model(), expected_forwards);
1640 render_text->SelectAll(true); 1695 render_text->SelectAll(true);
1641 EXPECT_EQ(render_text->selection_model(), expected_reversed); 1696 EXPECT_EQ(render_text->selection_model(), expected_reversed);
1642 } 1697 }
1643 } 1698 }
1644 1699
1645 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 1700 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
1646 } 1701 }
1647 1702
1648 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 1703 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1649 #if !defined(OS_MACOSX) 1704 TEST_P(RenderTextHarfBuzzTest, MoveCursorLeftRightWithSelection) {
1650 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { 1705 RenderText* render_text = GetRenderText();
1651 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance());
1652 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 1706 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
1653 // Left arrow on select ranging (6, 4). 1707 // Left arrow on select ranging (6, 4).
1654 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1708 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1655 EXPECT_EQ(Range(6), render_text->selection()); 1709 EXPECT_EQ(Range(6), render_text->selection());
1656 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1710 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1657 EXPECT_EQ(Range(4), render_text->selection()); 1711 EXPECT_EQ(Range(4), render_text->selection());
1658 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1712 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1659 EXPECT_EQ(Range(5), render_text->selection()); 1713 EXPECT_EQ(Range(5), render_text->selection());
1660 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1714 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1661 EXPECT_EQ(Range(6), render_text->selection()); 1715 EXPECT_EQ(Range(6), render_text->selection());
(...skipping 17 matching lines...) Expand all
1679 EXPECT_EQ(Range(5), render_text->selection()); 1733 EXPECT_EQ(Range(5), render_text->selection());
1680 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1734 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1681 EXPECT_EQ(Range(4), render_text->selection()); 1735 EXPECT_EQ(Range(4), render_text->selection());
1682 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN); 1736 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN);
1683 EXPECT_EQ(Range(4, 5), render_text->selection()); 1737 EXPECT_EQ(Range(4, 5), render_text->selection());
1684 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN); 1738 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_RETAIN);
1685 EXPECT_EQ(Range(4, 6), render_text->selection()); 1739 EXPECT_EQ(Range(4, 6), render_text->selection());
1686 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1740 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1687 EXPECT_EQ(Range(4), render_text->selection()); 1741 EXPECT_EQ(Range(4), render_text->selection());
1688 } 1742 }
1689 #endif // !defined(OS_MACOSX)
1690 1743
1691 TEST_F(RenderTextTest, CenteredDisplayOffset) { 1744 TEST_P(RenderTextTestAll, CenteredDisplayOffset) {
1692 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1745 RenderText* render_text = GetRenderText();
1693 render_text->SetText(ASCIIToUTF16("abcdefghij")); 1746 render_text->SetText(ASCIIToUTF16("abcdefghij"));
1694 render_text->SetHorizontalAlignment(ALIGN_CENTER); 1747 render_text->SetHorizontalAlignment(ALIGN_CENTER);
1695 1748
1696 const int kEnlargement = 10; 1749 const int kEnlargement = 10;
1697 const int content_width = render_text->GetContentWidth(); 1750 const int content_width = render_text->GetContentWidth();
1698 Rect display_rect(0, 0, content_width / 2, 1751 Rect display_rect(0, 0, content_width / 2,
1699 render_text->font_list().GetHeight()); 1752 render_text->font_list().GetHeight());
1700 render_text->SetDisplayRect(display_rect); 1753 render_text->SetDisplayRect(display_rect);
1701 1754
1702 // Move the cursor to the beginning of the text and, by checking the cursor 1755 // Move the cursor to the beginning of the text and, by checking the cursor
1703 // bounds, make sure no empty space is to the left of the text. 1756 // bounds, make sure no empty space is to the left of the text.
1704 render_text->SetCursorPosition(0); 1757 render_text->SetCursorPosition(0);
1705 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x()); 1758 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x());
1706 1759
1707 // Widen the display rect and, by checking the cursor bounds, make sure no 1760 // Widen the display rect and, by checking the cursor bounds, make sure no
1708 // empty space is introduced to the left of the text. 1761 // empty space is introduced to the left of the text.
1709 display_rect.Inset(0, 0, -kEnlargement, 0); 1762 display_rect.Inset(0, 0, -kEnlargement, 0);
1710 render_text->SetDisplayRect(display_rect); 1763 render_text->SetDisplayRect(display_rect);
1711 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x()); 1764 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x());
1712 1765
1713 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 1766 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1714 #if !defined(OS_MACOSX) 1767 if (GetParam() != RENDER_TEXT_MAC) {
1715 // Move the cursor to the end of the text and, by checking the cursor bounds, 1768 // Move the cursor to the end of the text and, by checking the cursor
1716 // make sure no empty space is to the right of the text. 1769 // bounds, make sure no empty space is to the right of the text.
1717 render_text->SetCursorPosition(render_text->text().length()); 1770 render_text->SetCursorPosition(render_text->text().length());
1718 EXPECT_EQ(display_rect.right(), 1771 EXPECT_EQ(display_rect.right(),
1719 render_text->GetUpdatedCursorBounds().right()); 1772 render_text->GetUpdatedCursorBounds().right());
1720 1773
1721 // Widen the display rect and, by checking the cursor bounds, make sure no 1774 // Widen the display rect and, by checking the cursor bounds, make sure no
1722 // empty space is introduced to the right of the text. 1775 // empty space is introduced to the right of the text.
1723 display_rect.Inset(0, 0, -kEnlargement, 0); 1776 display_rect.Inset(0, 0, -kEnlargement, 0);
1724 render_text->SetDisplayRect(display_rect); 1777 render_text->SetDisplayRect(display_rect);
1725 EXPECT_EQ(display_rect.right(), 1778 EXPECT_EQ(display_rect.right(),
1726 render_text->GetUpdatedCursorBounds().right()); 1779 render_text->GetUpdatedCursorBounds().right());
1727 #endif // !defined(OS_MACOSX) 1780 }
1728 } 1781 }
1729 1782
1730 void MoveLeftRightByWordVerifier(RenderText* render_text, 1783 void MoveLeftRightByWordVerifier(RenderText* render_text,
1731 const wchar_t* str) { 1784 const wchar_t* str) {
1732 render_text->SetText(WideToUTF16(str)); 1785 render_text->SetText(WideToUTF16(str));
1733 1786
1734 // Test moving by word from left ro right. 1787 // Test moving by word from left ro right.
1735 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); 1788 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
1736 bool first_word = true; 1789 bool first_word = true;
1737 while (true) { 1790 while (true) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 render_text->MoveCursorTo(start); 1836 render_text->MoveCursorTo(start);
1784 for (int k = 0; k < j; ++k) 1837 for (int k = 0; k < j; ++k)
1785 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); 1838 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
1786 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); 1839 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE);
1787 EXPECT_EQ(end, render_text->selection_model()); 1840 EXPECT_EQ(end, render_text->selection_model());
1788 } 1841 }
1789 } 1842 }
1790 } 1843 }
1791 1844
1792 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 1845 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1793 #if !defined(OS_MACOSX)
1794 // TODO(msw): Make these work on Windows. 1846 // TODO(msw): Make these work on Windows.
msw 2016/08/25 03:02:19 optional nit: cite http://crbug.com/196326
karandeepb 2016/08/25 08:13:10 Done.
1795 #if !defined(OS_WIN) 1847 #if !defined(OS_WIN)
1796 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { 1848 TEST_P(RenderTextHarfBuzzTest, MoveLeftRightByWordInBidiText) {
1797 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1849 RenderText* render_text = GetRenderText();
1798
1799 // For testing simplicity, each word is a 3-character word. 1850 // For testing simplicity, each word is a 3-character word.
1800 std::vector<const wchar_t*> test; 1851 std::vector<const wchar_t*> test;
1801 test.push_back(L"abc"); 1852 test.push_back(L"abc");
1802 test.push_back(L"abc def"); 1853 test.push_back(L"abc def");
1803 test.push_back(L"\x05E1\x05E2\x05E3"); 1854 test.push_back(L"\x05E1\x05E2\x05E3");
1804 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"); 1855 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6");
1805 test.push_back(L"abc \x05E1\x05E2\x05E3"); 1856 test.push_back(L"abc \x05E1\x05E2\x05E3");
1806 test.push_back(L"abc def \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"); 1857 test.push_back(L"abc def \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6");
1807 test.push_back(L"abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6" 1858 test.push_back(L"abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"
1808 L" \x05E7\x05E8\x05E9"); 1859 L" \x05E7\x05E8\x05E9");
1809 1860
1810 test.push_back(L"abc \x05E1\x05E2\x05E3 hij"); 1861 test.push_back(L"abc \x05E1\x05E2\x05E3 hij");
1811 test.push_back(L"abc def \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 hij opq"); 1862 test.push_back(L"abc def \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 hij opq");
1812 test.push_back(L"abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6" 1863 test.push_back(L"abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"
1813 L" \x05E7\x05E8\x05E9" L" opq rst uvw"); 1864 L" \x05E7\x05E8\x05E9" L" opq rst uvw");
1814 1865
1815 test.push_back(L"\x05E1\x05E2\x05E3 abc"); 1866 test.push_back(L"\x05E1\x05E2\x05E3 abc");
1816 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 abc def"); 1867 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 abc def");
1817 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 \x05E7\x05E8\x05E9" 1868 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6 \x05E7\x05E8\x05E9"
1818 L" abc def hij"); 1869 L" abc def hij");
1819 1870
1820 test.push_back(L"\x05D1\x05D2\x05D3 abc \x05E1\x05E2\x05E3"); 1871 test.push_back(L"\x05D1\x05D2\x05D3 abc \x05E1\x05E2\x05E3");
1821 test.push_back(L"\x05D1\x05D2\x05D3 \x05D4\x05D5\x05D6 abc def" 1872 test.push_back(L"\x05D1\x05D2\x05D3 \x05D4\x05D5\x05D6 abc def"
1822 L" \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"); 1873 L" \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6");
1823 test.push_back(L"\x05D1\x05D2\x05D3 \x05D4\x05D5\x05D6 \x05D7\x05D8\x05D9" 1874 test.push_back(L"\x05D1\x05D2\x05D3 \x05D4\x05D5\x05D6 \x05D7\x05D8\x05D9"
1824 L" abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6" 1875 L" abc def hij \x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"
1825 L" \x05E7\x05E8\x05E9"); 1876 L" \x05E7\x05E8\x05E9");
1826 1877
1827 for (size_t i = 0; i < test.size(); ++i) 1878 for (size_t i = 0; i < test.size(); ++i)
1828 MoveLeftRightByWordVerifier(render_text.get(), test[i]); 1879 MoveLeftRightByWordVerifier(render_text, test[i]);
1829 } 1880 }
1830 1881
1831 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText_TestEndOfText) { 1882 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1832 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1883 TEST_P(RenderTextHarfBuzzTest, MoveLeftRightByWordInBidiText_TestEndOfText) {
1884 RenderText* render_text = GetRenderText();
1833 1885
1834 render_text->SetText(WideToUTF16(L"ab\x05E1")); 1886 render_text->SetText(WideToUTF16(L"ab\x05E1"));
1835 // Moving the cursor by word from "abC|" to the left should return "|abC". 1887 // Moving the cursor by word from "abC|" to the left should return "|abC".
1836 // But since end of text is always treated as a word break, it returns 1888 // But since end of text is always treated as a word break, it returns
1837 // position "ab|C". 1889 // position "ab|C".
1838 // TODO(xji): Need to make it work as expected. 1890 // TODO(xji): Need to make it work as expected.
1839 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1891 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1840 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); 1892 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE);
1841 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); 1893 // EXPECT_EQ(SelectionModel(), render_text->selection_model());
1842 1894
(...skipping 11 matching lines...) Expand all
1854 1906
1855 // Moving the cursor by word from "|aCB" to the right should return "aCB|". 1907 // Moving the cursor by word from "|aCB" to the right should return "aCB|".
1856 // But since end of text is always treated as a word break, it returns 1908 // But since end of text is always treated as a word break, it returns
1857 // position "a|CB". 1909 // position "a|CB".
1858 // TODO(xji): Need to make it work as expected. 1910 // TODO(xji): Need to make it work as expected.
1859 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); 1911 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
1860 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1912 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1861 // EXPECT_EQ(SelectionModel(), render_text->selection_model()); 1913 // EXPECT_EQ(SelectionModel(), render_text->selection_model());
1862 } 1914 }
1863 1915
1864 TEST_F(RenderTextTest, MoveLeftRightByWordInTextWithMultiSpaces) { 1916 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1865 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1917 TEST_P(RenderTextHarfBuzzTest, MoveLeftRightByWordInTextWithMultiSpaces) {
1918 RenderText* render_text = GetRenderText();
1866 render_text->SetText(WideToUTF16(L"abc def")); 1919 render_text->SetText(WideToUTF16(L"abc def"));
1867 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); 1920 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD));
1868 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1921 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1869 EXPECT_EQ(11U, render_text->cursor_position()); 1922 EXPECT_EQ(11U, render_text->cursor_position());
1870 1923
1871 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); 1924 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD));
1872 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); 1925 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE);
1873 EXPECT_EQ(0U, render_text->cursor_position()); 1926 EXPECT_EQ(0U, render_text->cursor_position());
1874 } 1927 }
1875 #endif // !defined(OS_WIN) 1928 #endif // !defined(OS_WIN)
1876 1929
1877 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { 1930 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
1878 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1931 TEST_P(RenderTextHarfBuzzTest, MoveLeftRightByWordInChineseText) {
1932 RenderText* render_text = GetRenderText();
1879 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); 1933 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9"));
1880 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE); 1934 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
1881 EXPECT_EQ(0U, render_text->cursor_position()); 1935 EXPECT_EQ(0U, render_text->cursor_position());
1882 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1936 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1883 EXPECT_EQ(2U, render_text->cursor_position()); 1937 EXPECT_EQ(2U, render_text->cursor_position());
1884 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1938 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1885 EXPECT_EQ(3U, render_text->cursor_position()); 1939 EXPECT_EQ(3U, render_text->cursor_position());
1886 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1940 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1887 EXPECT_EQ(5U, render_text->cursor_position()); 1941 EXPECT_EQ(5U, render_text->cursor_position());
1888 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1942 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1889 EXPECT_EQ(6U, render_text->cursor_position()); 1943 EXPECT_EQ(6U, render_text->cursor_position());
1890 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE); 1944 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
1891 EXPECT_EQ(6U, render_text->cursor_position()); 1945 EXPECT_EQ(6U, render_text->cursor_position());
1892 } 1946 }
1893 #endif // !defined(OS_MACOSX)
1894 1947
1895 TEST_F(RenderTextTest, StringSizeSanity) { 1948 TEST_P(RenderTextTestAll, StringSizeSanity) {
1896 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1949 RenderText* render_text = GetRenderText();
1897 render_text->SetText(UTF8ToUTF16("Hello World")); 1950 render_text->SetText(UTF8ToUTF16("Hello World"));
1898 const Size string_size = render_text->GetStringSize(); 1951 const Size string_size = render_text->GetStringSize();
1899 EXPECT_GT(string_size.width(), 0); 1952 EXPECT_GT(string_size.width(), 0);
1900 EXPECT_GT(string_size.height(), 0); 1953 EXPECT_GT(string_size.height(), 0);
1901 } 1954 }
1902 1955
1903 TEST_F(RenderTextTest, StringSizeLongStrings) { 1956 TEST_P(RenderTextTestAll, StringSizeLongStrings) {
1904 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1957 RenderText* render_text = GetRenderText();
1905 Size previous_string_size; 1958 Size previous_string_size;
1906 for (size_t length = 10; length < 1000000; length *= 10) { 1959 for (size_t length = 10; length < 1000000; length *= 10) {
1907 render_text->SetText(base::string16(length, 'a')); 1960 render_text->SetText(base::string16(length, 'a'));
1908 const Size string_size = render_text->GetStringSize(); 1961 const Size string_size = render_text->GetStringSize();
1909 EXPECT_GT(string_size.width(), previous_string_size.width()); 1962 EXPECT_GT(string_size.width(), previous_string_size.width());
1910 EXPECT_GT(string_size.height(), 0); 1963 EXPECT_GT(string_size.height(), 0);
1911 previous_string_size = string_size; 1964 previous_string_size = string_size;
1912 } 1965 }
1913 } 1966 }
1914 1967
1915 // TODO(asvitkine): This test fails because PlatformFontMac uses point font 1968 TEST_P(RenderTextTestAll, StringSizeEmptyString) {
1916 // sizes instead of pixel sizes like other implementations.
1917 #if !defined(OS_MACOSX)
1918 TEST_F(RenderTextTest, StringSizeEmptyString) {
1919 // Ascent and descent of Arial and Symbol are different on most platforms. 1969 // Ascent and descent of Arial and Symbol are different on most platforms.
1920 const FontList font_list("Arial,Symbol, 16px"); 1970 const FontList font_list("Arial,Symbol, 16px");
1921 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 1971 RenderText* render_text = GetRenderText();
1922 render_text->SetFontList(font_list); 1972 render_text->SetFontList(font_list);
1923 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight())); 1973 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight()));
1924 1974
1925 // The empty string respects FontList metrics for non-zero height 1975 // The empty string respects FontList metrics for non-zero height
1926 // and baseline. 1976 // and baseline.
1927 render_text->SetText(base::string16()); 1977 render_text->SetText(base::string16());
1928 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 1978 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height());
1929 EXPECT_EQ(0, render_text->GetStringSize().width()); 1979 EXPECT_EQ(0, render_text->GetStringSize().width());
1930 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 1980 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1931 1981
1932 render_text->SetText(UTF8ToUTF16(" ")); 1982 render_text->SetText(UTF8ToUTF16(" "));
1933 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 1983 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height());
1934 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 1984 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1935 } 1985 }
1936 #endif // !defined(OS_MACOSX)
1937 1986
1938 TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { 1987 TEST_P(RenderTextTestAll, StringSizeRespectsFontListMetrics) {
1939 // Check that Arial and Symbol have different font metrics. 1988 // Check that Arial and Symbol have different font metrics.
1940 Font arial_font("Arial", 16); 1989 Font arial_font("Arial", 16);
1941 ASSERT_EQ("arial", 1990 ASSERT_EQ("arial",
1942 base::ToLowerASCII(arial_font.GetActualFontNameForTesting())); 1991 base::ToLowerASCII(arial_font.GetActualFontNameForTesting()));
1943 Font symbol_font("Symbol", 16); 1992 Font symbol_font("Symbol", 16);
1944 ASSERT_EQ("symbol", 1993 ASSERT_EQ("symbol",
1945 base::ToLowerASCII(symbol_font.GetActualFontNameForTesting())); 1994 base::ToLowerASCII(symbol_font.GetActualFontNameForTesting()));
1946 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight()); 1995 EXPECT_NE(arial_font.GetHeight(), symbol_font.GetHeight());
1947 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline()); 1996 EXPECT_NE(arial_font.GetBaseline(), symbol_font.GetBaseline());
1948 // "a" should be rendered with Arial, not with Symbol. 1997 // "a" should be rendered with Arial, not with Symbol.
1949 const char* arial_font_text = "a"; 1998 const char* arial_font_text = "a";
1950 // "®" (registered trademark symbol) should be rendered with Symbol, 1999 // "®" (registered trademark symbol) should be rendered with Symbol,
1951 // not with Arial. 2000 // not with Arial.
1952 const char* symbol_font_text = "\xC2\xAE"; 2001 const char* symbol_font_text = "\xC2\xAE";
1953 2002
1954 Font smaller_font = arial_font; 2003 Font smaller_font = arial_font;
1955 Font larger_font = symbol_font; 2004 Font larger_font = symbol_font;
1956 const char* smaller_font_text = arial_font_text; 2005 const char* smaller_font_text = arial_font_text;
1957 const char* larger_font_text = symbol_font_text; 2006 const char* larger_font_text = symbol_font_text;
1958 if (symbol_font.GetHeight() < arial_font.GetHeight() && 2007 if (symbol_font.GetHeight() < arial_font.GetHeight() &&
1959 symbol_font.GetBaseline() < arial_font.GetBaseline()) { 2008 symbol_font.GetBaseline() < arial_font.GetBaseline()) {
1960 std::swap(smaller_font, larger_font); 2009 std::swap(smaller_font, larger_font);
1961 std::swap(smaller_font_text, larger_font_text); 2010 std::swap(smaller_font_text, larger_font_text);
1962 } 2011 }
1963 ASSERT_LT(smaller_font.GetHeight(), larger_font.GetHeight()); 2012 ASSERT_LT(smaller_font.GetHeight(), larger_font.GetHeight());
1964 ASSERT_LT(smaller_font.GetBaseline(), larger_font.GetBaseline()); 2013 ASSERT_LT(smaller_font.GetBaseline(), larger_font.GetBaseline());
1965 2014
1966 // Check |smaller_font_text| is rendered with the smaller font. 2015 // Check |smaller_font_text| is rendered with the smaller font.
1967 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2016 RenderText* render_text = GetRenderText();
1968 render_text->SetText(UTF8ToUTF16(smaller_font_text)); 2017 render_text->SetText(UTF8ToUTF16(smaller_font_text));
1969 render_text->SetFontList(FontList(smaller_font)); 2018 render_text->SetFontList(FontList(smaller_font));
1970 render_text->SetDisplayRect(Rect(0, 0, 0, 2019 render_text->SetDisplayRect(Rect(0, 0, 0,
1971 render_text->font_list().GetHeight())); 2020 render_text->font_list().GetHeight()));
1972 EXPECT_EQ(smaller_font.GetHeight(), render_text->GetStringSize().height()); 2021 EXPECT_EQ(smaller_font.GetHeight(), render_text->GetStringSize().height());
1973 EXPECT_EQ(smaller_font.GetBaseline(), render_text->GetBaseline()); 2022 EXPECT_EQ(smaller_font.GetBaseline(), render_text->GetBaseline());
1974 2023
1975 // Layout the same text with mixed fonts. The text should be rendered with 2024 // Layout the same text with mixed fonts. The text should be rendered with
1976 // the smaller font, but the height and baseline are determined with the 2025 // the smaller font, but the height and baseline are determined with the
1977 // metrics of the font list, which is equal to the larger font. 2026 // metrics of the font list, which is equal to the larger font.
1978 std::vector<Font> fonts; 2027 std::vector<Font> fonts;
1979 fonts.push_back(smaller_font); // The primary font is the smaller font. 2028 fonts.push_back(smaller_font); // The primary font is the smaller font.
1980 fonts.push_back(larger_font); 2029 fonts.push_back(larger_font);
1981 const FontList font_list(fonts); 2030 const FontList font_list(fonts);
1982 render_text->SetFontList(font_list); 2031 render_text->SetFontList(font_list);
1983 render_text->SetDisplayRect(Rect(0, 0, 0, 2032 render_text->SetDisplayRect(Rect(0, 0, 0,
1984 render_text->font_list().GetHeight())); 2033 render_text->font_list().GetHeight()));
1985 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height()); 2034 EXPECT_LT(smaller_font.GetHeight(), render_text->GetStringSize().height());
1986 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline()); 2035 EXPECT_LT(smaller_font.GetBaseline(), render_text->GetBaseline());
1987 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height()); 2036 EXPECT_EQ(font_list.GetHeight(), render_text->GetStringSize().height());
1988 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline()); 2037 EXPECT_EQ(font_list.GetBaseline(), render_text->GetBaseline());
1989 } 2038 }
1990 2039
1991 TEST_F(RenderTextTest, MinLineHeight) { 2040 TEST_P(RenderTextTestAll, MinLineHeight) {
1992 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2041 RenderText* render_text = GetRenderText();
1993
1994 render_text->SetText(ASCIIToUTF16("Hello!")); 2042 render_text->SetText(ASCIIToUTF16("Hello!"));
1995 SizeF default_size = render_text->GetStringSizeF(); 2043 SizeF default_size = render_text->GetStringSizeF();
1996 ASSERT_NE(0, default_size.height()); 2044 ASSERT_NE(0, default_size.height());
1997 ASSERT_NE(0, default_size.width()); 2045 ASSERT_NE(0, default_size.width());
1998 2046
1999 render_text->SetMinLineHeight(default_size.height() / 2); 2047 render_text->SetMinLineHeight(default_size.height() / 2);
2000 EXPECT_EQ(default_size.ToString(), render_text->GetStringSizeF().ToString()); 2048 EXPECT_EQ(default_size.ToString(), render_text->GetStringSizeF().ToString());
2001 2049
2002 render_text->SetMinLineHeight(default_size.height() * 2); 2050 render_text->SetMinLineHeight(default_size.height() * 2);
2003 SizeF taller_size = render_text->GetStringSizeF(); 2051 SizeF taller_size = render_text->GetStringSizeF();
2004 EXPECT_EQ(default_size.height() * 2, taller_size.height()); 2052 EXPECT_EQ(default_size.height() * 2, taller_size.height());
2005 EXPECT_EQ(default_size.width(), taller_size.width()); 2053 EXPECT_EQ(default_size.width(), taller_size.width());
2006 } 2054 }
2007 2055
2008 TEST_F(RenderTextTest, SetFontList) { 2056 TEST_P(RenderTextTestAll, SetFontList) {
2009 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2057 RenderText* render_text = GetRenderText();
2010 render_text->SetFontList(FontList("Arial,Symbol, 13px")); 2058 render_text->SetFontList(FontList("Arial,Symbol, 13px"));
2011 const std::vector<Font>& fonts = render_text->font_list().GetFonts(); 2059 const std::vector<Font>& fonts = render_text->font_list().GetFonts();
2012 ASSERT_EQ(2U, fonts.size()); 2060 ASSERT_EQ(2U, fonts.size());
2013 EXPECT_EQ("Arial", fonts[0].GetFontName()); 2061 EXPECT_EQ("Arial", fonts[0].GetFontName());
2014 EXPECT_EQ("Symbol", fonts[1].GetFontName()); 2062 EXPECT_EQ("Symbol", fonts[1].GetFontName());
2015 EXPECT_EQ(13, render_text->font_list().GetFontSize()); 2063 EXPECT_EQ(13, render_text->font_list().GetFontSize());
2016 } 2064 }
2017 2065
2018 // http://crbug/624513 2066 // http://crbug/624513
2019 #if defined(OS_WIN) 2067 #if !defined(OS_WIN)
2020 #define MAYBE_StringSizeBoldWidth DISABLED_StringSizeBoldWidth 2068 TEST_P(RenderTextTestAll, StringSizeBoldWidth) {
2021 #else
2022 #define MAYBE_StringSizeBoldWidth StringSizeBoldWidth
2023 #endif
2024 TEST_F(RenderTextTest, MAYBE_StringSizeBoldWidth) {
2025 // TODO(mboc): Add some unittests for other weights (currently not 2069 // TODO(mboc): Add some unittests for other weights (currently not
2026 // implemented because of test system font configuration). 2070 // implemented because of test system font configuration).
2027 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2071 RenderText* render_text = GetRenderText();
2028 render_text->SetText(UTF8ToUTF16("Hello World")); 2072 render_text->SetText(UTF8ToUTF16("Hello World"));
2029 2073
2030 const int plain_width = render_text->GetStringSize().width(); 2074 const int plain_width = render_text->GetStringSize().width();
2031 EXPECT_GT(plain_width, 0); 2075 EXPECT_GT(plain_width, 0);
2032 2076
2033 // Apply a bold style and check that the new width is greater. 2077 // Apply a bold style and check that the new width is greater.
2034 render_text->SetWeight(Font::Weight::BOLD); 2078 render_text->SetWeight(Font::Weight::BOLD);
2035 const int bold_width = render_text->GetStringSize().width(); 2079 const int bold_width = render_text->GetStringSize().width();
2036 EXPECT_GT(bold_width, plain_width); 2080 EXPECT_GT(bold_width, plain_width);
2037 2081
2038 #if defined(OS_WIN) 2082 #if defined(OS_WIN)
2039 render_text->SetWeight(Font::Weight::SEMIBOLD); 2083 render_text->SetWeight(Font::Weight::SEMIBOLD);
2040 const int semibold_width = render_text->GetStringSize().width(); 2084 const int semibold_width = render_text->GetStringSize().width();
2041 EXPECT_GT(bold_width, semibold_width); 2085 EXPECT_GT(bold_width, semibold_width);
2042 #endif 2086 #endif
2043 2087
2044 // Now, apply a plain style over the first word only. 2088 // Now, apply a plain style over the first word only.
2045 render_text->ApplyWeight(Font::Weight::NORMAL, Range(0, 5)); 2089 render_text->ApplyWeight(Font::Weight::NORMAL, Range(0, 5));
2046 const int plain_bold_width = render_text->GetStringSize().width(); 2090 const int plain_bold_width = render_text->GetStringSize().width();
2047 EXPECT_GT(plain_bold_width, plain_width); 2091 EXPECT_GT(plain_bold_width, plain_width);
2048 EXPECT_LT(plain_bold_width, bold_width); 2092 EXPECT_LT(plain_bold_width, bold_width);
2049 } 2093 }
2094 #endif // !defined(OS_WIN)
2050 2095
2051 TEST_F(RenderTextTest, StringSizeHeight) { 2096 TEST_P(RenderTextTestAll, StringSizeHeight) {
2052 base::string16 cases[] = { 2097 base::string16 cases[] = {
2053 WideToUTF16(L"Hello World!"), // English 2098 WideToUTF16(L"Hello World!"), // English
2054 WideToUTF16(L"\x6328\x62f6"), // Japanese 2099 WideToUTF16(L"\x6328\x62f6"), // Japanese
2055 WideToUTF16(L"\x0915\x093f"), // Hindi 2100 WideToUTF16(L"\x0915\x093f"), // Hindi
2056 WideToUTF16(L"\x05e0\x05b8"), // Hebrew 2101 WideToUTF16(L"\x05e0\x05b8"), // Hebrew
2057 }; 2102 };
2058 2103
2059 const FontList default_font_list; 2104 const FontList default_font_list;
2060 const FontList& larger_font_list = default_font_list.DeriveWithSizeDelta(24); 2105 const FontList& larger_font_list = default_font_list.DeriveWithSizeDelta(24);
2061 EXPECT_GT(larger_font_list.GetHeight(), default_font_list.GetHeight()); 2106 EXPECT_GT(larger_font_list.GetHeight(), default_font_list.GetHeight());
2062 2107
2063 for (size_t i = 0; i < arraysize(cases); i++) { 2108 for (size_t i = 0; i < arraysize(cases); i++) {
2064 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2109 ResetRenderTextInstance();
2110 RenderText* render_text = GetRenderText();
2065 render_text->SetFontList(default_font_list); 2111 render_text->SetFontList(default_font_list);
2066 render_text->SetText(cases[i]); 2112 render_text->SetText(cases[i]);
2067 2113
2068 const int height1 = render_text->GetStringSize().height(); 2114 const int height1 = render_text->GetStringSize().height();
2069 EXPECT_GT(height1, 0); 2115 EXPECT_GT(height1, 0);
2070 2116
2071 // Check that setting the larger font increases the height. 2117 // Check that setting the larger font increases the height.
2072 render_text->SetFontList(larger_font_list); 2118 render_text->SetFontList(larger_font_list);
2073 const int height2 = render_text->GetStringSize().height(); 2119 const int height2 = render_text->GetStringSize().height();
2074 EXPECT_GT(height2, height1); 2120 EXPECT_GT(height2, height1);
2075 } 2121 }
2076 } 2122 }
2077 2123
2078 TEST_F(RenderTextTest, GetBaselineSanity) { 2124 TEST_P(RenderTextTestAll, GetBaselineSanity) {
2079 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2125 RenderText* render_text = GetRenderText();
2080 render_text->SetText(UTF8ToUTF16("Hello World")); 2126 render_text->SetText(UTF8ToUTF16("Hello World"));
2081 const int baseline = render_text->GetBaseline(); 2127 const int baseline = render_text->GetBaseline();
2082 EXPECT_GT(baseline, 0); 2128 EXPECT_GT(baseline, 0);
2083 } 2129 }
2084 2130
2085 TEST_F(RenderTextTest, CursorBoundsInReplacementMode) { 2131 TEST_P(RenderTextTestAll, CursorBoundsInReplacementMode) {
2086 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2132 RenderText* render_text = GetRenderText();
2087 render_text->SetText(ASCIIToUTF16("abcdefg")); 2133 render_text->SetText(ASCIIToUTF16("abcdefg"));
2088 render_text->SetDisplayRect(Rect(100, 17)); 2134 render_text->SetDisplayRect(Rect(100, 17));
2089 SelectionModel sel_b(1, CURSOR_FORWARD); 2135 SelectionModel sel_b(1, CURSOR_FORWARD);
2090 SelectionModel sel_c(2, CURSOR_FORWARD); 2136 SelectionModel sel_c(2, CURSOR_FORWARD);
2091 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false); 2137 Rect cursor_around_b = render_text->GetCursorBounds(sel_b, false);
2092 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true); 2138 Rect cursor_before_b = render_text->GetCursorBounds(sel_b, true);
2093 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true); 2139 Rect cursor_before_c = render_text->GetCursorBounds(sel_c, true);
2094 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x()); 2140 EXPECT_EQ(cursor_around_b.x(), cursor_before_b.x());
2095 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x()); 2141 EXPECT_EQ(cursor_around_b.right(), cursor_before_c.x());
2096 } 2142 }
2097 2143
2098 TEST_F(RenderTextTest, GetTextOffset) { 2144 TEST_P(RenderTextTestAll, GetTextOffset) {
2099 // The default horizontal text offset differs for LTR and RTL, and is only set 2145 // The default horizontal text offset differs for LTR and RTL, and is only set
2100 // when the RenderText object is created. This test will check the default in 2146 // when the RenderText object is created. This test will check the default in
2101 // LTR mode, and the next test will check the RTL default. 2147 // LTR mode, and the next test will check the RTL default.
2102 const bool was_rtl = base::i18n::IsRTL(); 2148 const bool was_rtl = base::i18n::IsRTL();
2103 SetRTL(false); 2149 SetRTL(false);
2104 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2150
2151 // Reset the render text instance since the locale was changed.
2152 ResetRenderTextInstance();
2153 RenderText* render_text = GetRenderText();
2154
2105 render_text->SetText(ASCIIToUTF16("abcdefg")); 2155 render_text->SetText(ASCIIToUTF16("abcdefg"));
2106 render_text->SetFontList(FontList("Arial, 13px")); 2156 render_text->SetFontList(FontList("Arial, 13px"));
2107 2157
2108 // Set display area's size equal to the font size. 2158 // Set display area's size equal to the font size.
2109 const Size font_size(render_text->GetContentWidth(), 2159 const Size font_size(render_text->GetContentWidth(),
2110 render_text->font_list().GetHeight()); 2160 render_text->font_list().GetHeight());
2111 Rect display_rect(font_size); 2161 Rect display_rect(font_size);
2112 render_text->SetDisplayRect(display_rect); 2162 render_text->SetDisplayRect(display_rect);
2113 2163
2114 Vector2d offset = render_text->GetLineOffset(0); 2164 Vector2d offset = render_text->GetLineOffset(0);
(...skipping 24 matching lines...) Expand all
2139 render_text->SetDisplayRect(display_rect); 2189 render_text->SetDisplayRect(display_rect);
2140 const Vector2d prev_offset = render_text->GetLineOffset(0); 2190 const Vector2d prev_offset = render_text->GetLineOffset(0);
2141 display_rect.Inset(0, 0, 0, -2 * kEnlargementY); 2191 display_rect.Inset(0, 0, 0, -2 * kEnlargementY);
2142 render_text->SetDisplayRect(display_rect); 2192 render_text->SetDisplayRect(display_rect);
2143 offset = render_text->GetLineOffset(0); 2193 offset = render_text->GetLineOffset(0);
2144 EXPECT_EQ(prev_offset.y() + kEnlargementY, offset.y()); 2194 EXPECT_EQ(prev_offset.y() + kEnlargementY, offset.y());
2145 2195
2146 SetRTL(was_rtl); 2196 SetRTL(was_rtl);
2147 } 2197 }
2148 2198
2149 TEST_F(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL) { 2199 TEST_P(RenderTextTestAll, GetTextOffsetHorizontalDefaultInRTL) {
2150 // This only checks the default horizontal alignment in RTL mode; all other 2200 // This only checks the default horizontal alignment in RTL mode; all other
2151 // GetLineOffset(0) attributes are checked by the test above. 2201 // GetLineOffset(0) attributes are checked by the test above.
2152 const bool was_rtl = base::i18n::IsRTL(); 2202 const bool was_rtl = base::i18n::IsRTL();
2153 SetRTL(true); 2203 SetRTL(true);
2154 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2204
2205 // Reset the render text instance since the locale was changed.
2206 ResetRenderTextInstance();
2207 RenderText* render_text = GetRenderText();
2208
2155 render_text->SetText(ASCIIToUTF16("abcdefg")); 2209 render_text->SetText(ASCIIToUTF16("abcdefg"));
2156 render_text->SetFontList(FontList("Arial, 13px")); 2210 render_text->SetFontList(FontList("Arial, 13px"));
2157 const int kEnlargement = 2; 2211 const int kEnlargement = 2;
2158 const Size font_size(render_text->GetContentWidth() + kEnlargement, 2212 const Size font_size(render_text->GetContentWidth() + kEnlargement,
2159 render_text->GetStringSize().height()); 2213 render_text->GetStringSize().height());
2160 Rect display_rect(font_size); 2214 Rect display_rect(font_size);
2161 render_text->SetDisplayRect(display_rect); 2215 render_text->SetDisplayRect(display_rect);
2162 Vector2d offset = render_text->GetLineOffset(0); 2216 Vector2d offset = render_text->GetLineOffset(0);
2163 EXPECT_EQ(kEnlargement, offset.x()); 2217 EXPECT_EQ(kEnlargement, offset.x());
2164 SetRTL(was_rtl); 2218 SetRTL(was_rtl);
2165 } 2219 }
2166 2220
2167 TEST_F(RenderTextTest, SetDisplayOffset) { 2221 TEST_P(RenderTextTestAll, SetDisplayOffset) {
2168 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2222 RenderText* render_text = GetRenderText();
2169 render_text->SetText(ASCIIToUTF16("abcdefg")); 2223 render_text->SetText(ASCIIToUTF16("abcdefg"));
2170 render_text->SetFontList(FontList("Arial, 13px")); 2224 render_text->SetFontList(FontList("Arial, 13px"));
2171 2225
2172 const Size font_size(render_text->GetContentWidth(), 2226 const Size font_size(render_text->GetContentWidth(),
2173 render_text->font_list().GetHeight()); 2227 render_text->font_list().GetHeight());
2174 const int kEnlargement = 10; 2228 const int kEnlargement = 10;
2175 2229
2176 // Set display width |kEnlargement| pixels greater than content width and test 2230 // Set display width |kEnlargement| pixels greater than content width and test
2177 // different possible situations. In this case the only possible display 2231 // different possible situations. In this case the only possible display
2178 // offset is zero. 2232 // offset is zero.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 }; 2285 };
2232 2286
2233 for (size_t i = 0; i < arraysize(large_content_cases); i++) { 2287 for (size_t i = 0; i < arraysize(large_content_cases); i++) {
2234 render_text->SetHorizontalAlignment(large_content_cases[i].alignment); 2288 render_text->SetHorizontalAlignment(large_content_cases[i].alignment);
2235 render_text->SetDisplayOffset(large_content_cases[i].offset); 2289 render_text->SetDisplayOffset(large_content_cases[i].offset);
2236 EXPECT_EQ(large_content_cases[i].expected_offset, 2290 EXPECT_EQ(large_content_cases[i].expected_offset,
2237 render_text->GetUpdatedDisplayOffset().x()); 2291 render_text->GetUpdatedDisplayOffset().x());
2238 } 2292 }
2239 } 2293 }
2240 2294
2241 TEST_F(RenderTextTest, SameFontForParentheses) { 2295 TEST_P(RenderTextTestAll, SameFontForParentheses) {
2242 struct { 2296 struct {
2243 const base::char16 left_char; 2297 const base::char16 left_char;
2244 const base::char16 right_char; 2298 const base::char16 right_char;
2245 } punctuation_pairs[] = { 2299 } punctuation_pairs[] = {
2246 { '(', ')' }, 2300 { '(', ')' },
2247 { '{', '}' }, 2301 { '{', '}' },
2248 { '<', '>' }, 2302 { '<', '>' },
2249 }; 2303 };
2250 struct { 2304 struct {
2251 base::string16 text; 2305 base::string16 text;
(...skipping 18 matching lines...) Expand all
2270 { WideToUTF16(L"Hello World(\x0915\x093f)Hello World") }, 2324 { WideToUTF16(L"Hello World(\x0915\x093f)Hello World") },
2271 2325
2272 // Hebrew(English) 2326 // Hebrew(English)
2273 { WideToUTF16(L"\x05e0\x05b8(a)") }, 2327 { WideToUTF16(L"\x05e0\x05b8(a)") },
2274 // Hebrew(English)Hebrew 2328 // Hebrew(English)Hebrew
2275 { WideToUTF16(L"\x05e0\x05b8(a)\x05e0\x05b8") }, 2329 { WideToUTF16(L"\x05e0\x05b8(a)\x05e0\x05b8") },
2276 // English(Hebrew)English 2330 // English(Hebrew)English
2277 { WideToUTF16(L"Hello World(\x05e0\x05b8)Hello World") }, 2331 { WideToUTF16(L"Hello World(\x05e0\x05b8)Hello World") },
2278 }; 2332 };
2279 2333
2280 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2334 RenderText* render_text = GetRenderText();
2281 for (size_t i = 0; i < arraysize(cases); ++i) { 2335 for (size_t i = 0; i < arraysize(cases); ++i) {
2282 base::string16 text = cases[i].text; 2336 base::string16 text = cases[i].text;
2283 const size_t start_paren_char_index = text.find('('); 2337 const size_t start_paren_char_index = text.find('(');
2284 ASSERT_NE(base::string16::npos, start_paren_char_index); 2338 ASSERT_NE(base::string16::npos, start_paren_char_index);
2285 const size_t end_paren_char_index = text.find(')'); 2339 const size_t end_paren_char_index = text.find(')');
2286 ASSERT_NE(base::string16::npos, end_paren_char_index); 2340 ASSERT_NE(base::string16::npos, end_paren_char_index);
2287 2341
2288 for (size_t j = 0; j < arraysize(punctuation_pairs); ++j) { 2342 for (size_t j = 0; j < arraysize(punctuation_pairs); ++j) {
2289 text[start_paren_char_index] = punctuation_pairs[j].left_char; 2343 text[start_paren_char_index] = punctuation_pairs[j].left_char;
2290 text[end_paren_char_index] = punctuation_pairs[j].right_char; 2344 text[end_paren_char_index] = punctuation_pairs[j].right_char;
(...skipping 17 matching lines...) Expand all
2308 const Font& end_font = spans[end_paren_span_index].first; 2362 const Font& end_font = spans[end_paren_span_index].first;
2309 EXPECT_EQ(start_font.GetFontName(), end_font.GetFontName()); 2363 EXPECT_EQ(start_font.GetFontName(), end_font.GetFontName());
2310 EXPECT_EQ(start_font.GetFontSize(), end_font.GetFontSize()); 2364 EXPECT_EQ(start_font.GetFontSize(), end_font.GetFontSize());
2311 EXPECT_EQ(start_font.GetStyle(), end_font.GetStyle()); 2365 EXPECT_EQ(start_font.GetStyle(), end_font.GetStyle());
2312 } 2366 }
2313 } 2367 }
2314 } 2368 }
2315 2369
2316 // Make sure the caret width is always >=1 so that the correct 2370 // Make sure the caret width is always >=1 so that the correct
2317 // caret is drawn at high DPI. crbug.com/164100. 2371 // caret is drawn at high DPI. crbug.com/164100.
2318 TEST_F(RenderTextTest, CaretWidth) { 2372 TEST_P(RenderTextTestAll, CaretWidth) {
2319 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2373 RenderText* render_text = GetRenderText();
2320 render_text->SetText(ASCIIToUTF16("abcdefg")); 2374 render_text->SetText(ASCIIToUTF16("abcdefg"));
2321 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1); 2375 EXPECT_GE(render_text->GetUpdatedCursorBounds().width(), 1);
2322 } 2376 }
2323 2377
2324 TEST_F(RenderTextTest, SelectWord) { 2378 TEST_P(RenderTextTestAll, SelectWord) {
2325 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2379 RenderText* render_text = GetRenderText();
2326 render_text->SetText(ASCIIToUTF16(" foo a.bc.d bar")); 2380 render_text->SetText(ASCIIToUTF16(" foo a.bc.d bar"));
2327 2381
2328 struct { 2382 struct {
2329 size_t cursor; 2383 size_t cursor;
2330 size_t selection_start; 2384 size_t selection_start;
2331 size_t selection_end; 2385 size_t selection_end;
2332 } cases[] = { 2386 } cases[] = {
2333 { 0, 0, 1 }, 2387 { 0, 0, 1 },
2334 { 1, 1, 4 }, 2388 { 1, 1, 4 },
2335 { 2, 1, 4 }, 2389 { 2, 1, 4 },
(...skipping 15 matching lines...) Expand all
2351 2405
2352 for (size_t i = 0; i < arraysize(cases); ++i) { 2406 for (size_t i = 0; i < arraysize(cases); ++i) {
2353 render_text->SetCursorPosition(cases[i].cursor); 2407 render_text->SetCursorPosition(cases[i].cursor);
2354 render_text->SelectWord(); 2408 render_text->SelectWord();
2355 EXPECT_EQ(Range(cases[i].selection_start, cases[i].selection_end), 2409 EXPECT_EQ(Range(cases[i].selection_start, cases[i].selection_end),
2356 render_text->selection()); 2410 render_text->selection());
2357 } 2411 }
2358 } 2412 }
2359 2413
2360 // Make sure the last word is selected when the cursor is at text.length(). 2414 // Make sure the last word is selected when the cursor is at text.length().
2361 TEST_F(RenderTextTest, LastWordSelected) { 2415 TEST_P(RenderTextTestAll, LastWordSelected) {
2362 const std::string kTestURL1 = "http://www.google.com"; 2416 const std::string kTestURL1 = "http://www.google.com";
2363 const std::string kTestURL2 = "http://www.google.com/something/"; 2417 const std::string kTestURL2 = "http://www.google.com/something/";
2364 2418
2365 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2419 RenderText* render_text = GetRenderText();
2366 2420
2367 render_text->SetText(ASCIIToUTF16(kTestURL1)); 2421 render_text->SetText(ASCIIToUTF16(kTestURL1));
2368 render_text->SetCursorPosition(kTestURL1.length()); 2422 render_text->SetCursorPosition(kTestURL1.length());
2369 render_text->SelectWord(); 2423 render_text->SelectWord();
2370 EXPECT_EQ(ASCIIToUTF16("com"), GetSelectedText(render_text.get())); 2424 EXPECT_EQ(ASCIIToUTF16("com"), GetSelectedText(render_text));
2371 EXPECT_FALSE(render_text->selection().is_reversed()); 2425 EXPECT_FALSE(render_text->selection().is_reversed());
2372 2426
2373 render_text->SetText(ASCIIToUTF16(kTestURL2)); 2427 render_text->SetText(ASCIIToUTF16(kTestURL2));
2374 render_text->SetCursorPosition(kTestURL2.length()); 2428 render_text->SetCursorPosition(kTestURL2.length());
2375 render_text->SelectWord(); 2429 render_text->SelectWord();
2376 EXPECT_EQ(ASCIIToUTF16("/"), GetSelectedText(render_text.get())); 2430 EXPECT_EQ(ASCIIToUTF16("/"), GetSelectedText(render_text));
2377 EXPECT_FALSE(render_text->selection().is_reversed()); 2431 EXPECT_FALSE(render_text->selection().is_reversed());
2378 } 2432 }
2379 2433
2380 // When given a non-empty selection, SelectWord should expand the selection to 2434 // When given a non-empty selection, SelectWord should expand the selection to
2381 // nearest word boundaries. 2435 // nearest word boundaries.
2382 TEST_F(RenderTextTest, SelectMultipleWords) { 2436 TEST_P(RenderTextTestAll, SelectMultipleWords) {
2383 const std::string kTestURL = "http://www.google.com"; 2437 const std::string kTestURL = "http://www.google.com";
2384 2438
2385 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2439 RenderText* render_text = GetRenderText();
2386 2440
2387 render_text->SetText(ASCIIToUTF16(kTestURL)); 2441 render_text->SetText(ASCIIToUTF16(kTestURL));
2388 render_text->SelectRange(Range(16, 20)); 2442 render_text->SelectRange(Range(16, 20));
2389 render_text->SelectWord(); 2443 render_text->SelectWord();
2390 EXPECT_EQ(ASCIIToUTF16("google.com"), GetSelectedText(render_text.get())); 2444 EXPECT_EQ(ASCIIToUTF16("google.com"), GetSelectedText(render_text));
2391 EXPECT_FALSE(render_text->selection().is_reversed()); 2445 EXPECT_FALSE(render_text->selection().is_reversed());
2392 2446
2393 // SelectWord should preserve the selection direction. 2447 // SelectWord should preserve the selection direction.
2394 render_text->SelectRange(Range(20, 16)); 2448 render_text->SelectRange(Range(20, 16));
2395 render_text->SelectWord(); 2449 render_text->SelectWord();
2396 EXPECT_EQ(ASCIIToUTF16("google.com"), GetSelectedText(render_text.get())); 2450 EXPECT_EQ(ASCIIToUTF16("google.com"), GetSelectedText(render_text));
2397 EXPECT_TRUE(render_text->selection().is_reversed()); 2451 EXPECT_TRUE(render_text->selection().is_reversed());
2398 } 2452 }
2399 2453
2400 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 2454 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618
2401 #if !defined(OS_MACOSX) 2455 TEST_P(RenderTextHarfBuzzTest, DisplayRectShowsCursorLTR) {
2402 TEST_F(RenderTextTest, DisplayRectShowsCursorLTR) {
2403 ASSERT_FALSE(base::i18n::IsRTL()); 2456 ASSERT_FALSE(base::i18n::IsRTL());
2404 ASSERT_FALSE(base::i18n::ICUIsRTL()); 2457 ASSERT_FALSE(base::i18n::ICUIsRTL());
2405 2458
2406 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2459 RenderText* render_text = GetRenderText();
2407 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); 2460 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));
2408 render_text->MoveCursorTo(SelectionModel(render_text->text().length(), 2461 render_text->MoveCursorTo(SelectionModel(render_text->text().length(),
2409 CURSOR_FORWARD)); 2462 CURSOR_FORWARD));
2410 int width = render_text->GetStringSize().width(); 2463 int width = render_text->GetStringSize().width();
2411 ASSERT_GT(width, 10); 2464 ASSERT_GT(width, 10);
2412 2465
2413 // Ensure that the cursor is placed at the width of its preceding text. 2466 // Ensure that the cursor is placed at the width of its preceding text.
2414 render_text->SetDisplayRect(Rect(width + 10, 1)); 2467 render_text->SetDisplayRect(Rect(width + 10, 1));
2415 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 2468 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
2416 2469
(...skipping 29 matching lines...) Expand all
2446 2499
2447 // Ensure that the text will pan to fill its expanding display rectangle. 2500 // Ensure that the text will pan to fill its expanding display rectangle.
2448 render_text->SetDisplayRect(Rect(width - 5, 1)); 2501 render_text->SetDisplayRect(Rect(width - 5, 1));
2449 EXPECT_EQ(render_text->display_rect().width(), 2502 EXPECT_EQ(render_text->display_rect().width(),
2450 render_text->GetUpdatedCursorBounds().right()); 2503 render_text->GetUpdatedCursorBounds().right());
2451 2504
2452 // Ensure that a sufficiently large display rectangle shows all the text. 2505 // Ensure that a sufficiently large display rectangle shows all the text.
2453 render_text->SetDisplayRect(Rect(width + 10, 1)); 2506 render_text->SetDisplayRect(Rect(width + 10, 1));
2454 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 2507 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
2455 } 2508 }
2456 #endif // !defined(OS_MACOSX)
2457 2509
2458 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { 2510 TEST_P(RenderTextTestAll, DisplayRectShowsCursorRTL) {
2459 // Set the application default text direction to RTL. 2511 // Set the application default text direction to RTL.
2460 const bool was_rtl = base::i18n::IsRTL(); 2512 const bool was_rtl = base::i18n::IsRTL();
2461 SetRTL(true); 2513 SetRTL(true);
2462 2514
2463 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2515 // Reset the render text instance since the locale was changed.
2516 ResetRenderTextInstance();
2517 RenderText* render_text = GetRenderText();
2464 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); 2518 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));
2465 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); 2519 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
2466 int width = render_text->GetStringSize().width(); 2520 int width = render_text->GetStringSize().width();
2467 ASSERT_GT(width, 10); 2521 ASSERT_GT(width, 10);
2468 2522
2469 // Ensure that the cursor is placed at the width of its preceding text. 2523 // Ensure that the cursor is placed at the width of its preceding text.
2470 render_text->SetDisplayRect(Rect(width + 10, 1)); 2524 render_text->SetDisplayRect(Rect(width + 10, 1));
2471 EXPECT_EQ(render_text->display_rect().width() - width - 1, 2525 EXPECT_EQ(render_text->display_rect().width() - width - 1,
2472 render_text->GetUpdatedCursorBounds().x()); 2526 render_text->GetUpdatedCursorBounds().x());
2473 2527
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 render_text->SetDisplayRect(Rect(width + 10, 1)); 2563 render_text->SetDisplayRect(Rect(width + 10, 1));
2510 EXPECT_EQ(render_text->display_rect().width() - width - 1, 2564 EXPECT_EQ(render_text->display_rect().width() - width - 1,
2511 render_text->GetUpdatedCursorBounds().x()); 2565 render_text->GetUpdatedCursorBounds().x());
2512 2566
2513 // Reset the application default text direction to LTR. 2567 // Reset the application default text direction to LTR.
2514 SetRTL(was_rtl); 2568 SetRTL(was_rtl);
2515 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 2569 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
2516 } 2570 }
2517 2571
2518 // Changing colors between or inside ligated glyphs should not break shaping. 2572 // Changing colors between or inside ligated glyphs should not break shaping.
2519 TEST_F(RenderTextTest, SelectionKeepsLigatures) { 2573 TEST_P(RenderTextTestAll, SelectionKeepsLigatures) {
2520 const wchar_t* kTestStrings[] = { L"\x644\x623", L"\x633\x627" }; 2574 const wchar_t* kTestStrings[] = { L"\x644\x623", L"\x633\x627" };
2521 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 2575 RenderText* render_text = GetRenderText();
2522 render_text->set_selection_color(SK_ColorRED); 2576 render_text->set_selection_color(SK_ColorRED);
2523 Canvas canvas;
2524 2577
2525 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2578 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2526 render_text->SetText(WideToUTF16(kTestStrings[i])); 2579 render_text->SetText(WideToUTF16(kTestStrings[i]));
2527 const int expected_width = render_text->GetStringSize().width(); 2580 const int expected_width = render_text->GetStringSize().width();
2528 render_text->MoveCursorTo(SelectionModel(Range(0, 1), CURSOR_FORWARD)); 2581 render_text->MoveCursorTo(SelectionModel(Range(0, 1), CURSOR_FORWARD));
2529 EXPECT_EQ(expected_width, render_text->GetStringSize().width()); 2582 EXPECT_EQ(expected_width, render_text->GetStringSize().width());
2530 // Drawing the text should not DCHECK or crash; see http://crbug.com/262119 2583 // Drawing the text should not DCHECK or crash; see http://crbug.com/262119
2531 render_text->Draw(&canvas); 2584 render_text->Draw(canvas());
2532 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); 2585 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
2533 } 2586 }
2534 } 2587 }
2535 2588
2536 // Ensure strings wrap onto multiple lines for a small available width. 2589 // Ensure strings wrap onto multiple lines for a small available width.
2537 TEST_F(RenderTextTest, Multiline_MinWidth) { 2590 TEST_P(RenderTextHarfBuzzTest, Multiline_MinWidth) {
2538 const wchar_t* kTestStrings[] = { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, 2591 const wchar_t* kTestStrings[] = { kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl,
2539 kRtlLtr, kRtlLtrRtl }; 2592 kRtlLtr, kRtlLtrRtl };
2540 2593
2541 RenderTextHarfBuzz render_text; 2594 RenderText* render_text = GetRenderText();
2542 render_text.SetDisplayRect(Rect(1, 1000)); 2595 render_text->SetDisplayRect(Rect(1, 1000));
2543 render_text.SetMultiline(true); 2596 render_text->SetMultiline(true);
2544 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS); 2597 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS);
2545 Canvas canvas;
2546 2598
2547 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2599 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2548 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2600 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2549 render_text.SetText(WideToUTF16(kTestStrings[i])); 2601 render_text->SetText(WideToUTF16(kTestStrings[i]));
2550 render_text.Draw(&canvas); 2602 render_text->Draw(canvas());
2551 EXPECT_GT(render_text.lines_.size(), 1U); 2603 EXPECT_GT(render_text->lines_.size(), 1U);
2552 } 2604 }
2553 } 2605 }
2554 2606
2555 // Ensure strings wrap onto multiple lines for a normal available width. 2607 // Ensure strings wrap onto multiple lines for a normal available width.
2556 TEST_F(RenderTextTest, Multiline_NormalWidth) { 2608 TEST_P(RenderTextHarfBuzzTest, Multiline_NormalWidth) {
2557 const struct { 2609 const struct {
2558 const wchar_t* const text; 2610 const wchar_t* const text;
2559 const Range first_line_char_range; 2611 const Range first_line_char_range;
2560 const Range second_line_char_range; 2612 const Range second_line_char_range;
2561 bool is_ltr; 2613 bool is_ltr;
2562 } kTestStrings[] = { 2614 } kTestStrings[] = {
2563 { L"abc defg hijkl", Range(0, 9), Range(9, 14), true }, 2615 { L"abc defg hijkl", Range(0, 9), Range(9, 14), true },
2564 { L"qwertyzxcvbn", Range(0, 10), Range(10, 12), true }, 2616 { L"qwertyzxcvbn", Range(0, 10), Range(10, 12), true },
2565 { L"\x0627\x0644\x0644\x063A\x0629 " 2617 { L"\x0627\x0644\x0644\x063A\x0629 "
2566 L"\x0627\x0644\x0639\x0631\x0628\x064A\x0629", 2618 L"\x0627\x0644\x0639\x0631\x0628\x064A\x0629",
2567 Range(0, 6), Range(6, 13), false }, 2619 Range(0, 6), Range(6, 13), false },
2568 { L"\x062A\x0641\x0627\x062D \x05EA\x05E4\x05D5\x05D6\x05D9" 2620 { L"\x062A\x0641\x0627\x062D \x05EA\x05E4\x05D5\x05D6\x05D9"
2569 L"\x05DA\x05DB\x05DD", Range(0, 5), Range(5, 13), false } 2621 L"\x05DA\x05DB\x05DD", Range(0, 5), Range(5, 13), false }
2570 }; 2622 };
2571 2623
2572 RenderTextHarfBuzz render_text; 2624 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2625
2573 // Specify the fixed width for characters to suppress the possible variations 2626 // Specify the fixed width for characters to suppress the possible variations
2574 // of linebreak results. 2627 // of linebreak results.
2575 render_text.set_glyph_width_for_test(5); 2628 render_text->set_glyph_width_for_test(5);
2576 render_text.SetDisplayRect(Rect(50, 1000)); 2629 render_text->SetDisplayRect(Rect(50, 1000));
2577 render_text.SetMultiline(true); 2630 render_text->SetMultiline(true);
2578 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS); 2631 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS);
2579 render_text.SetHorizontalAlignment(ALIGN_TO_HEAD); 2632 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD);
2580
2581 Canvas canvas;
2582 TestSkiaTextRenderer renderer(&canvas);
2583 2633
2584 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2634 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2585 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2635 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2586 render_text.SetText(WideToUTF16(kTestStrings[i].text)); 2636 render_text->SetText(WideToUTF16(kTestStrings[i].text));
2587 render_text.EnsureLayout(); 2637 DrawVisualText();
2588 render_text.DrawVisualText(&renderer);
2589 2638
2590 ASSERT_EQ(2U, render_text.lines_.size()); 2639 ASSERT_EQ(2U, render_text->lines_.size());
2591 ASSERT_EQ(1U, render_text.lines_[0].segments.size()); 2640 ASSERT_EQ(1U, render_text->lines_[0].segments.size());
2592 EXPECT_EQ(kTestStrings[i].first_line_char_range, 2641 EXPECT_EQ(kTestStrings[i].first_line_char_range,
2593 render_text.lines_[0].segments[0].char_range); 2642 render_text->lines_[0].segments[0].char_range);
2594 ASSERT_EQ(1U, render_text.lines_[1].segments.size()); 2643 ASSERT_EQ(1U, render_text->lines_[1].segments.size());
2595 EXPECT_EQ(kTestStrings[i].second_line_char_range, 2644 EXPECT_EQ(kTestStrings[i].second_line_char_range,
2596 render_text.lines_[1].segments[0].char_range); 2645 render_text->lines_[1].segments[0].char_range);
2597 2646
2598 std::vector<TestSkiaTextRenderer::TextLog> text_log; 2647 std::vector<TestSkiaTextRenderer::TextLog> text_log;
2599 renderer.GetTextLogAndReset(&text_log); 2648 renderer()->GetTextLogAndReset(&text_log);
2600 ASSERT_EQ(2U, text_log.size()); 2649 ASSERT_EQ(2U, text_log.size());
2601 // NOTE: this expectation compares the character length and glyph counts, 2650 // NOTE: this expectation compares the character length and glyph counts,
2602 // which isn't always equal. This is okay only because all the test 2651 // which isn't always equal. This is okay only because all the test
2603 // strings are simple (like, no compound characters nor UTF16-surrogate 2652 // strings are simple (like, no compound characters nor UTF16-surrogate
2604 // pairs). Be careful in case more complicated test strings are added. 2653 // pairs). Be careful in case more complicated test strings are added.
2605 EXPECT_EQ(kTestStrings[i].first_line_char_range.length(), 2654 EXPECT_EQ(kTestStrings[i].first_line_char_range.length(),
2606 text_log[0].glyph_count); 2655 text_log[0].glyph_count);
2607 EXPECT_EQ(kTestStrings[i].second_line_char_range.length(), 2656 EXPECT_EQ(kTestStrings[i].second_line_char_range.length(),
2608 text_log[1].glyph_count); 2657 text_log[1].glyph_count);
2609 EXPECT_LT(text_log[0].origin.y(), text_log[1].origin.y()); 2658 EXPECT_LT(text_log[0].origin.y(), text_log[1].origin.y());
2610 if (kTestStrings[i].is_ltr) { 2659 if (kTestStrings[i].is_ltr) {
2611 EXPECT_EQ(0, text_log[0].origin.x()); 2660 EXPECT_EQ(0, text_log[0].origin.x());
2612 EXPECT_EQ(0, text_log[1].origin.x()); 2661 EXPECT_EQ(0, text_log[1].origin.x());
2613 } else { 2662 } else {
2614 EXPECT_LT(0, text_log[0].origin.x()); 2663 EXPECT_LT(0, text_log[0].origin.x());
2615 EXPECT_LT(0, text_log[1].origin.x()); 2664 EXPECT_LT(0, text_log[1].origin.x());
2616 } 2665 }
2617 } 2666 }
2618 } 2667 }
2619 2668
2620 // Ensure strings don't wrap onto multiple lines for a sufficient available 2669 // Ensure strings don't wrap onto multiple lines for a sufficient available
2621 // width. 2670 // width.
2622 TEST_F(RenderTextTest, Multiline_SufficientWidth) { 2671 TEST_P(RenderTextHarfBuzzTest, Multiline_SufficientWidth) {
2623 const wchar_t* kTestStrings[] = { L"", L" ", L".", L" . ", L"abc", L"a b c", 2672 const wchar_t* kTestStrings[] = { L"", L" ", L".", L" . ", L"abc", L"a b c",
2624 L"\x62E\x628\x632", L"\x62E \x628 \x632" }; 2673 L"\x62E\x628\x632", L"\x62E \x628 \x632" };
2625 2674
2626 RenderTextHarfBuzz render_text; 2675 RenderText* render_text = GetRenderText();
2627 render_text.SetDisplayRect(Rect(1000, 1000)); 2676 render_text->SetDisplayRect(Rect(1000, 1000));
2628 render_text.SetMultiline(true); 2677 render_text->SetMultiline(true);
2629 Canvas canvas;
2630 2678
2631 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2679 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2632 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2680 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2633 render_text.SetText(WideToUTF16(kTestStrings[i])); 2681 render_text->SetText(WideToUTF16(kTestStrings[i]));
2634 render_text.Draw(&canvas); 2682 render_text->Draw(canvas());
2635 EXPECT_EQ(1U, render_text.lines_.size()); 2683 EXPECT_EQ(1U, render_text->lines_.size());
2636 } 2684 }
2637 } 2685 }
2638 2686
2639 TEST_F(RenderTextTest, Multiline_Newline) { 2687 TEST_P(RenderTextHarfBuzzTest, Multiline_Newline) {
2640 const struct { 2688 const struct {
2641 const wchar_t* const text; 2689 const wchar_t* const text;
2642 const size_t lines_count; 2690 const size_t lines_count;
2643 // Ranges of the characters on each line preceding the newline. 2691 // Ranges of the characters on each line preceding the newline.
2644 const Range line_char_ranges[3]; 2692 const Range line_char_ranges[3];
2645 } kTestStrings[] = { 2693 } kTestStrings[] = {
2646 {L"abc\ndef", 2ul, { Range(0, 3), Range(4, 7), Range::InvalidRange() } }, 2694 {L"abc\ndef", 2ul, { Range(0, 3), Range(4, 7), Range::InvalidRange() } },
2647 {L"a \n b ", 2ul, { Range(0, 2), Range(3, 6), Range::InvalidRange() } }, 2695 {L"a \n b ", 2ul, { Range(0, 2), Range(3, 6), Range::InvalidRange() } },
2648 {L"ab\n", 2ul, { Range(0, 2), Range(), Range::InvalidRange() } }, 2696 {L"ab\n", 2ul, { Range(0, 2), Range(), Range::InvalidRange() } },
2649 {L"a\n\nb", 3ul, { Range(0, 1), Range(), Range(3, 4) } }, 2697 {L"a\n\nb", 3ul, { Range(0, 1), Range(), Range(3, 4) } },
2650 {L"\nab", 2ul, { Range(), Range(1, 3), Range::InvalidRange() } }, 2698 {L"\nab", 2ul, { Range(), Range(1, 3), Range::InvalidRange() } },
2651 {L"\n", 2ul, { Range(), Range(), Range::InvalidRange() } }, 2699 {L"\n", 2ul, { Range(), Range(), Range::InvalidRange() } },
2652 }; 2700 };
2653 2701
2654 RenderTextHarfBuzz render_text; 2702 RenderText* render_text = GetRenderText();
2655 render_text.SetDisplayRect(Rect(200, 1000)); 2703 render_text->SetDisplayRect(Rect(200, 1000));
2656 render_text.SetMultiline(true); 2704 render_text->SetMultiline(true);
2657 Canvas canvas;
2658 2705
2659 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2706 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2660 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2707 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2661 render_text.SetText(WideToUTF16(kTestStrings[i].text)); 2708 render_text->SetText(WideToUTF16(kTestStrings[i].text));
2662 render_text.Draw(&canvas); 2709 render_text->Draw(canvas());
2663 EXPECT_EQ(kTestStrings[i].lines_count, render_text.lines_.size()); 2710 EXPECT_EQ(kTestStrings[i].lines_count, render_text->lines_.size());
2664 if (kTestStrings[i].lines_count != render_text.lines_.size()) 2711 if (kTestStrings[i].lines_count != render_text->lines_.size())
2665 continue; 2712 continue;
2666 2713
2667 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) { 2714 for (size_t j = 0; j < kTestStrings[i].lines_count; ++j) {
2668 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j)); 2715 SCOPED_TRACE(base::StringPrintf("Line %" PRIuS "", j));
2669 // There might be multiple segments in one line. Merge all the segments 2716 // There might be multiple segments in one line. Merge all the segments
2670 // ranges in the same line. 2717 // ranges in the same line.
2671 const size_t segment_size = render_text.lines()[j].segments.size(); 2718 const size_t segment_size = render_text->lines()[j].segments.size();
2672 Range line_range; 2719 Range line_range;
2673 if (segment_size > 0) 2720 if (segment_size > 0)
2674 line_range = Range( 2721 line_range =
2675 render_text.lines()[j].segments[0].char_range.start(), 2722 Range(render_text->lines()[j].segments[0].char_range.start(),
2676 render_text.lines()[j].segments[segment_size - 1].char_range.end()); 2723 render_text->lines()[j]
2724 .segments[segment_size - 1]
2725 .char_range.end());
2677 EXPECT_EQ(kTestStrings[i].line_char_ranges[j], line_range); 2726 EXPECT_EQ(kTestStrings[i].line_char_ranges[j], line_range);
2678 } 2727 }
2679 } 2728 }
2680 } 2729 }
2681 2730
2682 // Make sure that multiline mode ignores elide behavior. 2731 // Make sure that multiline mode ignores elide behavior.
2683 TEST_F(RenderTextTest, Multiline_IgnoreElide) { 2732 TEST_P(RenderTextHarfBuzzTest, Multiline_IgnoreElide) {
2684 const wchar_t kTestString[] = 2733 const wchar_t kTestString[] =
2685 L"very very very long string xxxxxxxxxxxxxxxxxxxxxxxxxx"; 2734 L"very very very long string xxxxxxxxxxxxxxxxxxxxxxxxxx";
2686 const wchar_t kEllipsis[] = L"\x2026"; 2735 const wchar_t kEllipsis[] = L"\x2026";
2687 2736
2688 RenderTextHarfBuzz render_text; 2737 RenderText* render_text = GetRenderText();
2689 render_text.SetElideBehavior(ELIDE_TAIL); 2738 render_text->SetElideBehavior(ELIDE_TAIL);
2690 render_text.SetDisplayRect(Rect(20, 1000)); 2739 render_text->SetDisplayRect(Rect(20, 1000));
2691 render_text.SetText(base::WideToUTF16(kTestString)); 2740 render_text->SetText(base::WideToUTF16(kTestString));
2692 EXPECT_NE(base::string16::npos, 2741 EXPECT_NE(base::string16::npos,
2693 render_text.GetDisplayText().find(base::WideToUTF16(kEllipsis))); 2742 render_text->GetDisplayText().find(base::WideToUTF16(kEllipsis)));
2694 2743
2695 render_text.SetMultiline(true); 2744 render_text->SetMultiline(true);
2696 EXPECT_EQ(base::string16::npos, 2745 EXPECT_EQ(base::string16::npos,
2697 render_text.GetDisplayText().find(base::WideToUTF16(kEllipsis))); 2746 render_text->GetDisplayText().find(base::WideToUTF16(kEllipsis)));
2698 } 2747 }
2699 2748
2700 TEST_F(RenderTextTest, Multiline_NewlineCharacterReplacement) { 2749 TEST_P(RenderTextHarfBuzzTest, Multiline_NewlineCharacterReplacement) {
2701 const wchar_t* kTestStrings[] = { 2750 const wchar_t* kTestStrings[] = {
2702 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", 2751 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",
2703 }; 2752 };
2704 2753
2705 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2754 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2706 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2755 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2707 RenderTextHarfBuzz render_text; 2756 ResetRenderTextInstance();
2708 render_text.SetDisplayRect(Rect(200, 1000)); 2757 RenderText* render_text = GetRenderText();
2709 render_text.SetText(WideToUTF16(kTestStrings[i])); 2758 render_text->SetDisplayRect(Rect(200, 1000));
2759 render_text->SetText(WideToUTF16(kTestStrings[i]));
2710 2760
2711 base::string16 display_text = render_text.GetDisplayText(); 2761 base::string16 display_text = render_text->GetDisplayText();
2712 // If RenderText is not multiline, the newline characters are replaced 2762 // If RenderText is not multiline, the newline characters are replaced
2713 // by symbols, therefore the character should be changed. 2763 // by symbols, therefore the character should be changed.
2714 EXPECT_NE(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); 2764 EXPECT_NE(WideToUTF16(kTestStrings[i]), render_text->GetDisplayText());
2715 2765
2716 // Setting multiline will fix this, the newline characters will be back 2766 // Setting multiline will fix this, the newline characters will be back
2717 // to the original text. 2767 // to the original text.
2718 render_text.SetMultiline(true); 2768 render_text->SetMultiline(true);
2719 EXPECT_EQ(WideToUTF16(kTestStrings[i]), render_text.GetDisplayText()); 2769 EXPECT_EQ(WideToUTF16(kTestStrings[i]), render_text->GetDisplayText());
2720 } 2770 }
2721 } 2771 }
2722 2772
2723 // Ensure horizontal alignment works in multiline mode. 2773 // Ensure horizontal alignment works in multiline mode.
2724 TEST_F(RenderTextTest, Multiline_HorizontalAlignment) { 2774 TEST_P(RenderTextHarfBuzzTest, Multiline_HorizontalAlignment) {
2725 const struct { 2775 const struct {
2726 const wchar_t* const text; 2776 const wchar_t* const text;
2727 const HorizontalAlignment alignment; 2777 const HorizontalAlignment alignment;
2728 } kTestStrings[] = { 2778 } kTestStrings[] = {
2729 { L"abcdefghij\nhijkl", ALIGN_LEFT }, 2779 { L"abcdefghij\nhijkl", ALIGN_LEFT },
2730 { L"nhijkl\nabcdefghij", ALIGN_LEFT }, 2780 { L"nhijkl\nabcdefghij", ALIGN_LEFT },
2731 // hebrew, 2nd line shorter 2781 // hebrew, 2nd line shorter
2732 { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3", 2782 { L"\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7\n\x5d0\x5d1\x5d2\x5d3",
2733 ALIGN_RIGHT }, 2783 ALIGN_RIGHT },
2734 // hebrew, 2nd line longer 2784 // hebrew, 2nd line longer
2735 { L"\x5d0\x5d1\x5d2\x5d3\n\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7", 2785 { L"\x5d0\x5d1\x5d2\x5d3\n\x5d0\x5d1\x5d2\x5d3\x5d4\x5d5\x5d6\x5d7",
2736 ALIGN_RIGHT }, 2786 ALIGN_RIGHT },
2737 // arabic, 2nd line shorter 2787 // arabic, 2nd line shorter
2738 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664", 2788 { L"\x62a\x62b\x62c\x62d\x62e\x62f\x630\n\x660\x661\x662\x663\x664",
2739 ALIGN_RIGHT }, 2789 ALIGN_RIGHT },
2740 // arabic, 2nd line longer 2790 // arabic, 2nd line longer
2741 { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630", 2791 { L"\x660\x661\x662\x663\x664\n\x62a\x62b\x62c\x62d\x62e\x62f\x630",
2742 ALIGN_RIGHT }, 2792 ALIGN_RIGHT },
2743 }; 2793 };
2744 const int kGlyphSize = 5; 2794 const int kGlyphSize = 5;
2745 RenderTextHarfBuzz render_text; 2795 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2746 render_text.SetHorizontalAlignment(ALIGN_TO_HEAD); 2796 render_text->SetHorizontalAlignment(ALIGN_TO_HEAD);
2747 render_text.set_glyph_width_for_test(kGlyphSize); 2797 render_text->set_glyph_width_for_test(kGlyphSize);
2748 render_text.SetDisplayRect(Rect(100, 1000)); 2798 render_text->SetDisplayRect(Rect(100, 1000));
2749 render_text.SetMultiline(true); 2799 render_text->SetMultiline(true);
2750 2800
2751 Canvas canvas;
2752 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2801 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2753 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i, 2802 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "] %ls", i,
2754 kTestStrings[i].text)); 2803 kTestStrings[i].text));
2755 render_text.SetText(WideToUTF16(kTestStrings[i].text)); 2804 render_text->SetText(WideToUTF16(kTestStrings[i].text));
2756 render_text.Draw(&canvas); 2805 render_text->Draw(canvas());
2757 ASSERT_LE(2u, render_text.lines().size()); 2806 ASSERT_LE(2u, render_text->lines().size());
2758 if (kTestStrings[i].alignment == ALIGN_LEFT) { 2807 if (kTestStrings[i].alignment == ALIGN_LEFT) {
2759 EXPECT_EQ(0, render_text.GetAlignmentOffset(0).x()); 2808 EXPECT_EQ(0, render_text->GetAlignmentOffset(0).x());
2760 EXPECT_EQ(0, render_text.GetAlignmentOffset(1).x()); 2809 EXPECT_EQ(0, render_text->GetAlignmentOffset(1).x());
2761 } else { 2810 } else {
2762 std::vector<base::string16> lines = base::SplitString( 2811 std::vector<base::string16> lines = base::SplitString(
2763 base::WideToUTF16(kTestStrings[i].text), 2812 base::WideToUTF16(kTestStrings[i].text),
2764 base::string16(1, '\n'), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 2813 base::string16(1, '\n'), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
2765 ASSERT_EQ(2u, lines.size()); 2814 ASSERT_EQ(2u, lines.size());
2766 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize; 2815 int difference = (lines[0].length() - lines[1].length()) * kGlyphSize;
2767 EXPECT_EQ(render_text.GetAlignmentOffset(0).x() + difference, 2816 EXPECT_EQ(render_text->GetAlignmentOffset(0).x() + difference,
2768 render_text.GetAlignmentOffset(1).x()); 2817 render_text->GetAlignmentOffset(1).x());
2769 } 2818 }
2770 } 2819 }
2771 } 2820 }
2772 2821
2773 TEST_F(RenderTextTest, Multiline_WordWrapBehavior) { 2822 TEST_P(RenderTextHarfBuzzTest, Multiline_WordWrapBehavior) {
2774 const int kGlyphSize = 5; 2823 const int kGlyphSize = 5;
2775 const struct { 2824 const struct {
2776 const WordWrapBehavior behavior; 2825 const WordWrapBehavior behavior;
2777 const size_t num_lines; 2826 const size_t num_lines;
2778 const Range char_ranges[4]; 2827 const Range char_ranges[4];
2779 } kTestScenarios[] = { 2828 } kTestScenarios[] = {
2780 { IGNORE_LONG_WORDS, 3u, 2829 { IGNORE_LONG_WORDS, 3u,
2781 { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } }, 2830 { Range(0, 4), Range(4, 11), Range(11, 14), Range::InvalidRange() } },
2782 { TRUNCATE_LONG_WORDS, 3u, 2831 { TRUNCATE_LONG_WORDS, 3u,
2783 { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } }, 2832 { Range(0, 4), Range(4, 8), Range(11, 14), Range::InvalidRange() } },
2784 { WRAP_LONG_WORDS, 4u, 2833 { WRAP_LONG_WORDS, 4u,
2785 { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } }, 2834 { Range(0, 4), Range(4, 8), Range(8, 11), Range(11, 14) } },
2786 // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now. 2835 // TODO(mukai): implement ELIDE_LONG_WORDS. It's not used right now.
2787 }; 2836 };
2788 RenderTextHarfBuzz render_text; 2837 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2789 render_text.SetMultiline(true); 2838 render_text->SetMultiline(true);
2790 render_text.SetText(ASCIIToUTF16("foo fooooo foo")); 2839 render_text->SetText(ASCIIToUTF16("foo fooooo foo"));
2791 render_text.set_glyph_width_for_test(kGlyphSize); 2840 render_text->set_glyph_width_for_test(kGlyphSize);
2792 render_text.SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); 2841 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0));
2793
2794 Canvas canvas;
2795 2842
2796 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { 2843 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) {
2797 SCOPED_TRACE(base::StringPrintf( 2844 SCOPED_TRACE(base::StringPrintf(
2798 "kTestScenarios[%" PRIuS "] %d", i, kTestScenarios[i].behavior)); 2845 "kTestScenarios[%" PRIuS "] %d", i, kTestScenarios[i].behavior));
2799 render_text.SetWordWrapBehavior(kTestScenarios[i].behavior); 2846 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior);
2800 render_text.Draw(&canvas); 2847 render_text->Draw(canvas());
2801 2848
2802 ASSERT_EQ(kTestScenarios[i].num_lines, render_text.lines().size()); 2849 ASSERT_EQ(kTestScenarios[i].num_lines, render_text->lines().size());
2803 for (size_t j = 0; j < render_text.lines().size(); ++j) { 2850 for (size_t j = 0; j < render_text->lines().size(); ++j) {
2804 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); 2851 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
2805 EXPECT_EQ(kTestScenarios[i].char_ranges[j], 2852 EXPECT_EQ(kTestScenarios[i].char_ranges[j],
2806 render_text.lines()[j].segments[0].char_range); 2853 render_text->lines()[j].segments[0].char_range);
2807 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, 2854 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize,
2808 render_text.lines()[j].size.width()); 2855 render_text->lines()[j].size.width());
2809 } 2856 }
2810 } 2857 }
2811 } 2858 }
2812 2859
2813 TEST_F(RenderTextTest, Multiline_LineBreakerBehavior) { 2860 TEST_P(RenderTextHarfBuzzTest, Multiline_LineBreakerBehavior) {
2814 const int kGlyphSize = 5; 2861 const int kGlyphSize = 5;
2815 const struct { 2862 const struct {
2816 const wchar_t* const text; 2863 const wchar_t* const text;
2817 const WordWrapBehavior behavior; 2864 const WordWrapBehavior behavior;
2818 const Range char_ranges[3]; 2865 const Range char_ranges[3];
2819 } kTestScenarios[] = { 2866 } kTestScenarios[] = {
2820 { L"a single run", IGNORE_LONG_WORDS, 2867 { L"a single run", IGNORE_LONG_WORDS,
2821 {Range(0, 2), Range(2, 9), Range(9, 12) } }, 2868 {Range(0, 2), Range(2, 9), Range(9, 12) } },
2822 // 3 words: "That's ", ""good". ", "aaa" and 7 runs: "That", "'", "s ", 2869 // 3 words: "That's ", ""good". ", "aaa" and 7 runs: "That", "'", "s ",
2823 // """, "good", "". ", "aaa". They all mixed together. 2870 // """, "good", "". ", "aaa". They all mixed together.
(...skipping 14 matching lines...) Expand all
2838 { L"a \"good\" one.", TRUNCATE_LONG_WORDS, 2885 { L"a \"good\" one.", TRUNCATE_LONG_WORDS,
2839 {Range(0, 2), Range(2, 6), Range(9, 13) } }, 2886 {Range(0, 2), Range(2, 6), Range(9, 13) } },
2840 { L"asingleword", WRAP_LONG_WORDS, 2887 { L"asingleword", WRAP_LONG_WORDS,
2841 {Range(0, 4), Range(4, 8), Range(8, 11) } }, 2888 {Range(0, 4), Range(4, 8), Range(8, 11) } },
2842 { L"That's good", WRAP_LONG_WORDS, 2889 { L"That's good", WRAP_LONG_WORDS,
2843 {Range(0, 4), Range(4, 7), Range(7, 11) } }, 2890 {Range(0, 4), Range(4, 7), Range(7, 11) } },
2844 { L"That's \"g\".", WRAP_LONG_WORDS, 2891 { L"That's \"g\".", WRAP_LONG_WORDS,
2845 {Range(0, 4), Range(4, 7), Range(7, 11) } }, 2892 {Range(0, 4), Range(4, 7), Range(7, 11) } },
2846 }; 2893 };
2847 2894
2848 RenderTextHarfBuzz render_text; 2895 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2849 render_text.SetMultiline(true); 2896 render_text->SetMultiline(true);
2850 render_text.set_glyph_width_for_test(kGlyphSize); 2897 render_text->set_glyph_width_for_test(kGlyphSize);
2851 render_text.SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0)); 2898 render_text->SetDisplayRect(Rect(0, 0, kGlyphSize * 4, 0));
2852
2853 Canvas canvas;
2854 2899
2855 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { 2900 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) {
2856 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2901 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2857 render_text.SetText(WideToUTF16(kTestScenarios[i].text)); 2902 render_text->SetText(WideToUTF16(kTestScenarios[i].text));
2858 render_text.SetWordWrapBehavior(kTestScenarios[i].behavior); 2903 render_text->SetWordWrapBehavior(kTestScenarios[i].behavior);
2859 render_text.Draw(&canvas); 2904 render_text->Draw(canvas());
2860 2905
2861 ASSERT_EQ(3u, render_text.lines().size()); 2906 ASSERT_EQ(3u, render_text->lines().size());
2862 for (size_t j = 0; j < render_text.lines().size(); ++j) { 2907 for (size_t j = 0; j < render_text->lines().size(); ++j) {
2863 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); 2908 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
2864 // Merge all the segments ranges in the same line. 2909 // Merge all the segments ranges in the same line.
2865 size_t segment_size = render_text.lines()[j].segments.size(); 2910 size_t segment_size = render_text->lines()[j].segments.size();
2866 Range line_range; 2911 Range line_range;
2867 if (segment_size > 0) 2912 if (segment_size > 0)
2868 line_range = Range( 2913 line_range =
2869 render_text.lines()[j].segments[0].char_range.start(), 2914 Range(render_text->lines()[j].segments[0].char_range.start(),
2870 render_text.lines()[j].segments[segment_size - 1].char_range.end()); 2915 render_text->lines()[j]
2916 .segments[segment_size - 1]
2917 .char_range.end());
2871 EXPECT_EQ(kTestScenarios[i].char_ranges[j], line_range); 2918 EXPECT_EQ(kTestScenarios[i].char_ranges[j], line_range);
2872 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize, 2919 EXPECT_EQ(kTestScenarios[i].char_ranges[j].length() * kGlyphSize,
2873 render_text.lines()[j].size.width()); 2920 render_text->lines()[j].size.width());
2874 } 2921 }
2875 } 2922 }
2876 } 2923 }
2877 2924
2878 // Test that Surrogate pairs or combining character sequences do not get 2925 // Test that Surrogate pairs or combining character sequences do not get
2879 // separated by line breaking. 2926 // separated by line breaking.
2880 TEST_F(RenderTextTest, Multiline_SurrogatePairsOrCombiningChars) { 2927 TEST_P(RenderTextHarfBuzzTest, Multiline_SurrogatePairsOrCombiningChars) {
2881 RenderTextHarfBuzz render_text; 2928 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2882 render_text.SetMultiline(true); 2929 render_text->SetMultiline(true);
2883 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS); 2930 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS);
2884 2931
2885 // Below is 'MUSICAL SYMBOL G CLEF' (U+1D11E), which is represented in UTF-16 2932 // Below is 'MUSICAL SYMBOL G CLEF' (U+1D11E), which is represented in UTF-16
2886 // as two code units forming a surrogate pair: 0xD834 0xDD1E. 2933 // as two code units forming a surrogate pair: 0xD834 0xDD1E.
2887 const base::char16 kSurrogate[] = {0xD834, 0xDD1E, 0}; 2934 const base::char16 kSurrogate[] = {0xD834, 0xDD1E, 0};
2888 const base::string16 text_surrogate(kSurrogate); 2935 const base::string16 text_surrogate(kSurrogate);
2889 const int kSurrogateWidth = 2936 const int kSurrogateWidth =
2890 GetStringWidth(kSurrogate, render_text.font_list()); 2937 GetStringWidth(kSurrogate, render_text->font_list());
2891 2938
2892 // Below is a Devanagari two-character combining sequence U+0921 U+093F. The 2939 // Below is a Devanagari two-character combining sequence U+0921 U+093F. The
2893 // sequence forms a single display character and should not be separated. 2940 // sequence forms a single display character and should not be separated.
2894 const base::char16 kCombiningChars[] = {0x921, 0x93F, 0}; 2941 const base::char16 kCombiningChars[] = {0x921, 0x93F, 0};
2895 const base::string16 text_combining(kCombiningChars); 2942 const base::string16 text_combining(kCombiningChars);
2896 const int kCombiningCharsWidth = 2943 const int kCombiningCharsWidth =
2897 GetStringWidth(kCombiningChars, render_text.font_list()); 2944 GetStringWidth(kCombiningChars, render_text->font_list());
2898 2945
2899 const struct { 2946 const struct {
2900 const base::string16 text; 2947 const base::string16 text;
2901 const int display_width; 2948 const int display_width;
2902 const Range char_ranges[3]; 2949 const Range char_ranges[3];
2903 } kTestScenarios[] = { 2950 } kTestScenarios[] = {
2904 { text_surrogate + text_surrogate + text_surrogate, 2951 { text_surrogate + text_surrogate + text_surrogate,
2905 kSurrogateWidth / 2 * 3, 2952 kSurrogateWidth / 2 * 3,
2906 { Range(0, 2), Range(2, 4), Range(4, 6) } }, 2953 { Range(0, 2), Range(2, 4), Range(4, 6) } },
2907 { text_surrogate + UTF8ToUTF16(" ") + kCombiningChars, 2954 { text_surrogate + UTF8ToUTF16(" ") + kCombiningChars,
2908 std::min(kSurrogateWidth, kCombiningCharsWidth) / 2, 2955 std::min(kSurrogateWidth, kCombiningCharsWidth) / 2,
2909 { Range(0, 2), Range(2, 3), Range(3, 5) } }, 2956 { Range(0, 2), Range(2, 3), Range(3, 5) } },
2910 }; 2957 };
2911 2958
2912 Canvas canvas;
2913
2914 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) { 2959 for (size_t i = 0; i < arraysize(kTestScenarios); ++i) {
2915 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 2960 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2916 render_text.SetText(kTestScenarios[i].text); 2961 render_text->SetText(kTestScenarios[i].text);
2917 render_text.SetDisplayRect(Rect(0, 0, kTestScenarios[i].display_width, 0)); 2962 render_text->SetDisplayRect(Rect(0, 0, kTestScenarios[i].display_width, 0));
2918 render_text.Draw(&canvas); 2963 render_text->Draw(canvas());
2919 2964
2920 ASSERT_EQ(3u, render_text.lines().size()); 2965 ASSERT_EQ(3u, render_text->lines().size());
2921 for (size_t j = 0; j < render_text.lines().size(); ++j) { 2966 for (size_t j = 0; j < render_text->lines().size(); ++j) {
2922 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); 2967 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
2923 // There is only one segment in each line. 2968 // There is only one segment in each line.
2924 EXPECT_EQ(kTestScenarios[i].char_ranges[j], 2969 EXPECT_EQ(kTestScenarios[i].char_ranges[j],
2925 render_text.lines()[j].segments[0].char_range); 2970 render_text->lines()[j].segments[0].char_range);
2926 } 2971 }
2927 } 2972 }
2928 } 2973 }
2929 2974
2930 // Test that Zero width characters have the correct line breaking behavior. 2975 // Test that Zero width characters have the correct line breaking behavior.
2931 TEST_F(RenderTextTest, Multiline_ZeroWidthChars) { 2976 TEST_P(RenderTextHarfBuzzTest, Multiline_ZeroWidthChars) {
2932 RenderTextHarfBuzz render_text; 2977 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2933 render_text.SetMultiline(true); 2978 render_text->SetMultiline(true);
2934 render_text.SetWordWrapBehavior(WRAP_LONG_WORDS); 2979 render_text->SetWordWrapBehavior(WRAP_LONG_WORDS);
2935 2980
2936 const base::char16 kZeroWidthSpace = {0x200B}; 2981 const base::char16 kZeroWidthSpace = {0x200B};
2937 const base::string16 text(UTF8ToUTF16("test") + kZeroWidthSpace + 2982 const base::string16 text(UTF8ToUTF16("test") + kZeroWidthSpace +
2938 UTF8ToUTF16("\n") + kZeroWidthSpace + 2983 UTF8ToUTF16("\n") + kZeroWidthSpace +
2939 UTF8ToUTF16("test.")); 2984 UTF8ToUTF16("test."));
2940 const int kTestWidth = 2985 const int kTestWidth =
2941 GetStringWidth(UTF8ToUTF16("test"), render_text.font_list()); 2986 GetStringWidth(UTF8ToUTF16("test"), render_text->font_list());
2942 const Range char_ranges[3] = {Range(0, 5), Range(6, 11), Range(11, 12)}; 2987 const Range char_ranges[3] = {Range(0, 5), Range(6, 11), Range(11, 12)};
2943 2988
2944 Canvas canvas; 2989 render_text->SetText(text);
2945 render_text.SetText(text); 2990 render_text->SetDisplayRect(Rect(0, 0, kTestWidth, 0));
2946 render_text.SetDisplayRect(Rect(0, 0, kTestWidth, 0)); 2991 render_text->Draw(canvas());
2947 render_text.Draw(&canvas);
2948 2992
2949 ASSERT_EQ(3u, render_text.lines().size()); 2993 ASSERT_EQ(3u, render_text->lines().size());
2950 for (size_t j = 0; j < render_text.lines().size(); ++j) { 2994 for (size_t j = 0; j < render_text->lines().size(); ++j) {
2951 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j)); 2995 SCOPED_TRACE(base::StringPrintf("%" PRIuS "-th line", j));
2952 int segment_size = render_text.lines()[j].segments.size(); 2996 int segment_size = render_text->lines()[j].segments.size();
2953 ASSERT_GT(segment_size, 0); 2997 ASSERT_GT(segment_size, 0);
2954 Range line_range( 2998 Range line_range(
2955 render_text.lines()[j].segments[0].char_range.start(), 2999 render_text->lines()[j].segments[0].char_range.start(),
2956 render_text.lines()[j].segments[segment_size - 1].char_range.end()); 3000 render_text->lines()[j].segments[segment_size - 1].char_range.end());
2957 EXPECT_EQ(char_ranges[j], line_range); 3001 EXPECT_EQ(char_ranges[j], line_range);
2958 } 3002 }
2959 } 3003 }
2960 3004
2961 TEST_F(RenderTextTest, NewlineWithoutMultilineFlag) { 3005 TEST_P(RenderTextHarfBuzzTest, NewlineWithoutMultilineFlag) {
2962 const wchar_t* kTestStrings[] = { 3006 const wchar_t* kTestStrings[] = {
2963 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n", 3007 L"abc\ndef", L"a \n b ", L"ab\n", L"a\n\nb", L"\nab", L"\n",
2964 }; 3008 };
2965 3009
2966 RenderTextHarfBuzz render_text; 3010 RenderText* render_text = GetRenderText();
2967 render_text.SetDisplayRect(Rect(200, 1000)); 3011 render_text->SetDisplayRect(Rect(200, 1000));
2968 Canvas canvas;
2969 3012
2970 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 3013 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2971 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 3014 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
2972 render_text.SetText(WideToUTF16(kTestStrings[i])); 3015 render_text->SetText(WideToUTF16(kTestStrings[i]));
2973 render_text.Draw(&canvas); 3016 render_text->Draw(canvas());
2974 3017
2975 EXPECT_EQ(1U, render_text.lines_.size()); 3018 EXPECT_EQ(1U, render_text->lines_.size());
2976 } 3019 }
2977 } 3020 }
2978 3021
2979 // Make sure the horizontal positions of runs in a line (left-to-right for 3022 // Make sure the horizontal positions of runs in a line (left-to-right for
2980 // LTR languages and right-to-left for RTL languages). 3023 // LTR languages and right-to-left for RTL languages).
2981 TEST_F(RenderTextTest, HarfBuzz_HorizontalPositions) { 3024 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_HorizontalPositions) {
2982 const struct { 3025 const struct {
2983 const wchar_t* const text; 3026 const wchar_t* const text;
2984 const Range first_run_char_range; 3027 const Range first_run_char_range;
2985 const Range second_run_char_range; 3028 const Range second_run_char_range;
2986 bool is_rtl; 3029 bool is_rtl;
2987 } kTestStrings[] = { 3030 } kTestStrings[] = {
2988 { L"abc\x3042\x3044\x3046\x3048\x304A", Range(0, 3), Range(3, 8), false }, 3031 { L"abc\x3042\x3044\x3046\x3048\x304A", Range(0, 3), Range(3, 8), false },
2989 { L"\x062A\x0641\x0627\x062D" 3032 { L"\x062A\x0641\x0627\x062D"
2990 L"\x05EA\x05E4\x05D5\x05D6\x05D9\x05DA\x05DB\x05DD", 3033 L"\x05EA\x05E4\x05D5\x05D6\x05D9\x05DA\x05DB\x05DD",
2991 Range(0, 4), Range(4, 12), true }, 3034 Range(0, 4), Range(4, 12), true },
2992 }; 3035 };
2993 3036
2994 RenderTextHarfBuzz render_text; 3037 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
2995 Canvas canvas;
2996 TestSkiaTextRenderer renderer(&canvas);
2997 3038
2998 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 3039 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2999 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i)); 3040 SCOPED_TRACE(base::StringPrintf("kTestStrings[%" PRIuS "]", i));
3000 render_text.SetText(WideToUTF16(kTestStrings[i].text)); 3041 render_text->SetText(WideToUTF16(kTestStrings[i].text));
3001 3042
3002 render_text.EnsureLayout(); 3043 render_text->EnsureLayout();
3003 const internal::TextRunList* run_list = render_text.GetRunList(); 3044 const internal::TextRunList* run_list = render_text->GetRunList();
3004 ASSERT_EQ(2U, run_list->runs().size()); 3045 ASSERT_EQ(2U, run_list->runs().size());
3005 EXPECT_EQ(kTestStrings[i].first_run_char_range, run_list->runs()[0]->range); 3046 EXPECT_EQ(kTestStrings[i].first_run_char_range, run_list->runs()[0]->range);
3006 EXPECT_EQ(kTestStrings[i].second_run_char_range, 3047 EXPECT_EQ(kTestStrings[i].second_run_char_range,
3007 run_list->runs()[1]->range); 3048 run_list->runs()[1]->range);
3008 // If it's RTL, the visual order is reversed. 3049 // If it's RTL, the visual order is reversed.
3009 if (kTestStrings[i].is_rtl) { 3050 if (kTestStrings[i].is_rtl) {
3010 EXPECT_EQ(1U, run_list->logical_to_visual(0)); 3051 EXPECT_EQ(1U, run_list->logical_to_visual(0));
3011 EXPECT_EQ(0U, run_list->logical_to_visual(1)); 3052 EXPECT_EQ(0U, run_list->logical_to_visual(1));
3012 } else { 3053 } else {
3013 EXPECT_EQ(0U, run_list->logical_to_visual(0)); 3054 EXPECT_EQ(0U, run_list->logical_to_visual(0));
3014 EXPECT_EQ(1U, run_list->logical_to_visual(1)); 3055 EXPECT_EQ(1U, run_list->logical_to_visual(1));
3015 } 3056 }
3016 3057
3017 render_text.DrawVisualText(&renderer); 3058 render_text->DrawVisualText(renderer());
3018 3059
3019 std::vector<TestSkiaTextRenderer::TextLog> text_log; 3060 std::vector<TestSkiaTextRenderer::TextLog> text_log;
3020 renderer.GetTextLogAndReset(&text_log); 3061 renderer()->GetTextLogAndReset(&text_log);
3021 3062
3022 EXPECT_EQ(2U, text_log.size()); 3063 EXPECT_EQ(2U, text_log.size());
3023 3064
3024 // Verifies the DrawText happens in the visual order and left-to-right. 3065 // Verifies the DrawText happens in the visual order and left-to-right.
3025 // If the text is RTL, the logically first run should be drawn at last. 3066 // If the text is RTL, the logically first run should be drawn at last.
3026 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(0)]->glyph_count, 3067 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(0)]->glyph_count,
3027 text_log[0].glyph_count); 3068 text_log[0].glyph_count);
3028 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(1)]->glyph_count, 3069 EXPECT_EQ(run_list->runs()[run_list->logical_to_visual(1)]->glyph_count,
3029 text_log[1].glyph_count); 3070 text_log[1].glyph_count);
3030 EXPECT_LT(text_log[0].origin.x(), text_log[1].origin.x()); 3071 EXPECT_LT(text_log[0].origin.x(), text_log[1].origin.x());
3031 } 3072 }
3032 } 3073 }
3033 3074
3034 // Test TextRunHarfBuzz's cluster finding logic. 3075 // Test TextRunHarfBuzz's cluster finding logic.
3035 TEST_F(RenderTextTest, HarfBuzz_Clusters) { 3076 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_Clusters) {
3036 struct { 3077 struct {
3037 uint32_t glyph_to_char[4]; 3078 uint32_t glyph_to_char[4];
3038 Range chars[4]; 3079 Range chars[4];
3039 Range glyphs[4]; 3080 Range glyphs[4];
3040 bool is_rtl; 3081 bool is_rtl;
3041 } cases[] = { 3082 } cases[] = {
3042 { // From string "A B C D" to glyphs "a b c d". 3083 { // From string "A B C D" to glyphs "a b c d".
3043 { 0, 1, 2, 3 }, 3084 { 0, 1, 2, 3 },
3044 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) }, 3085 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
3045 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) }, 3086 { Range(0, 1), Range(1, 2), Range(2, 3), Range(3, 4) },
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3081 Range glyphs; 3122 Range glyphs;
3082 run.GetClusterAt(j, &chars, &glyphs); 3123 run.GetClusterAt(j, &chars, &glyphs);
3083 EXPECT_EQ(cases[i].chars[j], chars); 3124 EXPECT_EQ(cases[i].chars[j], chars);
3084 EXPECT_EQ(cases[i].glyphs[j], glyphs); 3125 EXPECT_EQ(cases[i].glyphs[j], glyphs);
3085 EXPECT_EQ(cases[i].glyphs[j], run.CharRangeToGlyphRange(chars)); 3126 EXPECT_EQ(cases[i].glyphs[j], run.CharRangeToGlyphRange(chars));
3086 } 3127 }
3087 } 3128 }
3088 } 3129 }
3089 3130
3090 // Ensure that graphemes with multiple code points do not get split. 3131 // Ensure that graphemes with multiple code points do not get split.
3091 TEST_F(RenderTextTest, HarfBuzz_SubglyphGraphemeCases) { 3132 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemeCases) {
3092 const wchar_t* cases[] = { 3133 const wchar_t* cases[] = {
3093 // "A" with a combining umlaut, followed by a "B". 3134 // "A" with a combining umlaut, followed by a "B".
3094 L"A\x0308" L"B", 3135 L"A\x0308" L"B",
3095 // Devanagari biconsonantal conjunct "ki", followed by an "a". 3136 // Devanagari biconsonantal conjunct "ki", followed by an "a".
3096 L"\x0915\x093f\x0905", 3137 L"\x0915\x093f\x0905",
3097 // Thai consonant and vowel pair "cho chan" + "sara am", followed by Thai 3138 // Thai consonant and vowel pair "cho chan" + "sara am", followed by Thai
3098 // digit 0. 3139 // digit 0.
3099 L"\x0e08\x0e33\x0E50", 3140 L"\x0e08\x0e33\x0E50",
3100 }; 3141 };
3101 3142
3102 RenderTextHarfBuzz render_text; 3143 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3103 3144
3104 for (size_t i = 0; i < arraysize(cases); ++i) { 3145 for (size_t i = 0; i < arraysize(cases); ++i) {
3105 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i)); 3146 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS, i));
3106 3147
3107 base::string16 text = WideToUTF16(cases[i]); 3148 base::string16 text = WideToUTF16(cases[i]);
3108 render_text.SetText(text); 3149 render_text->SetText(text);
3109 render_text.EnsureLayout(); 3150 render_text->EnsureLayout();
3110 internal::TextRunList* run_list = render_text.GetRunList(); 3151 internal::TextRunList* run_list = render_text->GetRunList();
3111 ASSERT_EQ(1U, run_list->size()); 3152 ASSERT_EQ(1U, run_list->size());
3112 internal::TextRunHarfBuzz* run = run_list->runs()[0]; 3153 internal::TextRunHarfBuzz* run = run_list->runs()[0];
3113 3154
3114 base::i18n::BreakIterator* iter = render_text.grapheme_iterator_.get(); 3155 base::i18n::BreakIterator* iter = render_text->grapheme_iterator_.get();
3115 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0); 3156 auto first_grapheme_bounds = run->GetGraphemeBounds(iter, 0);
3116 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1)); 3157 EXPECT_EQ(first_grapheme_bounds, run->GetGraphemeBounds(iter, 1));
3117 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2); 3158 auto second_grapheme_bounds = run->GetGraphemeBounds(iter, 2);
3118 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start()); 3159 EXPECT_EQ(first_grapheme_bounds.end(), second_grapheme_bounds.start());
3119 } 3160 }
3120 } 3161 }
3121 3162
3122 // Test the partition of a multi-grapheme cluster into grapheme ranges. 3163 // Test the partition of a multi-grapheme cluster into grapheme ranges.
3123 TEST_F(RenderTextTest, HarfBuzz_SubglyphGraphemePartition) { 3164 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_SubglyphGraphemePartition) {
3124 struct { 3165 struct {
3125 uint32_t glyph_to_char[2]; 3166 uint32_t glyph_to_char[2];
3126 Range bounds[4]; 3167 Range bounds[4];
3127 bool is_rtl; 3168 bool is_rtl;
3128 } cases[] = { 3169 } cases[] = {
3129 { // From string "A B C D" to glyphs "a bcd". 3170 { // From string "A B C D" to glyphs "a bcd".
3130 { 0, 1 }, 3171 { 0, 1 },
3131 { Range(0, 10), Range(10, 13), Range(13, 17), Range(17, 20) }, 3172 { Range(0, 10), Range(10, 13), Range(13, 17), Range(17, 20) },
3132 false 3173 false
3133 }, 3174 },
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 run.positions[j].set(j * 10, 0); 3209 run.positions[j].set(j * 10, 0);
3169 3210
3170 for (size_t j = 0; j < 4; ++j) { 3211 for (size_t j = 0; j < 4; ++j) {
3171 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j)); 3212 SCOPED_TRACE(base::StringPrintf("Case %" PRIuS ", char %" PRIuS, i, j));
3172 EXPECT_EQ(cases[i].bounds[j], 3213 EXPECT_EQ(cases[i].bounds[j],
3173 run.GetGraphemeBounds(iter.get(), j).Round()); 3214 run.GetGraphemeBounds(iter.get(), j).Round());
3174 } 3215 }
3175 } 3216 }
3176 } 3217 }
3177 3218
3178 TEST_F(RenderTextTest, HarfBuzz_RunDirection) { 3219 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_RunDirection) {
3179 RenderTextHarfBuzz render_text; 3220 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3180 const base::string16 mixed = WideToUTF16( 3221 const base::string16 mixed = WideToUTF16(
3181 L"\x05D0\x05D1" 3222 L"\x05D0\x05D1"
3182 L"1234" 3223 L"1234"
3183 L"\x05D2\x05D3" 3224 L"\x05D2\x05D3"
3184 L"abc"); 3225 L"abc");
3185 render_text.SetText(mixed); 3226 render_text->SetText(mixed);
3186 3227
3187 // Get the run list for both display directions. 3228 // Get the run list for both display directions.
3188 render_text.SetDirectionalityMode(DIRECTIONALITY_FORCE_LTR); 3229 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_LTR);
3189 render_text.EnsureLayout(); 3230 render_text->EnsureLayout();
3190 internal::TextRunList* run_list = render_text.GetRunList(); 3231 internal::TextRunList* run_list = render_text->GetRunList();
3191 ASSERT_EQ(4U, run_list->size()); 3232 ASSERT_EQ(4U, run_list->size());
3192 EXPECT_TRUE(run_list->runs()[0]->is_rtl); 3233 EXPECT_TRUE(run_list->runs()[0]->is_rtl);
3193 EXPECT_FALSE(run_list->runs()[1]->is_rtl); 3234 EXPECT_FALSE(run_list->runs()[1]->is_rtl);
3194 EXPECT_TRUE(run_list->runs()[2]->is_rtl); 3235 EXPECT_TRUE(run_list->runs()[2]->is_rtl);
3195 EXPECT_FALSE(run_list->runs()[3]->is_rtl); 3236 EXPECT_FALSE(run_list->runs()[3]->is_rtl);
3196 3237
3197 // The Latin letters should appear to the right of the other runs. 3238 // The Latin letters should appear to the right of the other runs.
3198 EXPECT_EQ(2U, run_list->logical_to_visual(0)); 3239 EXPECT_EQ(2U, run_list->logical_to_visual(0));
3199 EXPECT_EQ(1U, run_list->logical_to_visual(1)); 3240 EXPECT_EQ(1U, run_list->logical_to_visual(1));
3200 EXPECT_EQ(0U, run_list->logical_to_visual(2)); 3241 EXPECT_EQ(0U, run_list->logical_to_visual(2));
3201 EXPECT_EQ(3U, run_list->logical_to_visual(3)); 3242 EXPECT_EQ(3U, run_list->logical_to_visual(3));
3202 3243
3203 render_text.SetDirectionalityMode(DIRECTIONALITY_FORCE_RTL); 3244 render_text->SetDirectionalityMode(DIRECTIONALITY_FORCE_RTL);
3204 render_text.EnsureLayout(); 3245 render_text->EnsureLayout();
3205 run_list = render_text.GetRunList(); 3246 run_list = render_text->GetRunList();
3206 ASSERT_EQ(4U, run_list->size()); 3247 ASSERT_EQ(4U, run_list->size());
3207 EXPECT_TRUE(run_list->runs()[0]->is_rtl); 3248 EXPECT_TRUE(run_list->runs()[0]->is_rtl);
3208 EXPECT_FALSE(run_list->runs()[1]->is_rtl); 3249 EXPECT_FALSE(run_list->runs()[1]->is_rtl);
3209 EXPECT_TRUE(run_list->runs()[2]->is_rtl); 3250 EXPECT_TRUE(run_list->runs()[2]->is_rtl);
3210 EXPECT_FALSE(run_list->runs()[3]->is_rtl); 3251 EXPECT_FALSE(run_list->runs()[3]->is_rtl);
3211 3252
3212 // The Latin letters should appear to the left of the other runs. 3253 // The Latin letters should appear to the left of the other runs.
3213 EXPECT_EQ(3U, run_list->logical_to_visual(0)); 3254 EXPECT_EQ(3U, run_list->logical_to_visual(0));
3214 EXPECT_EQ(2U, run_list->logical_to_visual(1)); 3255 EXPECT_EQ(2U, run_list->logical_to_visual(1));
3215 EXPECT_EQ(1U, run_list->logical_to_visual(2)); 3256 EXPECT_EQ(1U, run_list->logical_to_visual(2));
3216 EXPECT_EQ(0U, run_list->logical_to_visual(3)); 3257 EXPECT_EQ(0U, run_list->logical_to_visual(3));
3217 } 3258 }
3218 3259
3219 TEST_F(RenderTextTest, HarfBuzz_BreakRunsByUnicodeBlocks) { 3260 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByUnicodeBlocks) {
3220 RenderTextHarfBuzz render_text; 3261 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3221 3262
3222 // The '\x25B6' "play character" should break runs. http://crbug.com/278913 3263 // The '\x25B6' "play character" should break runs. http://crbug.com/278913
3223 render_text.SetText(WideToUTF16(L"x\x25B6y")); 3264 render_text->SetText(WideToUTF16(L"x\x25B6y"));
3224 render_text.EnsureLayout(); 3265 render_text->EnsureLayout();
3225 internal::TextRunList* run_list = render_text.GetRunList(); 3266 internal::TextRunList* run_list = render_text->GetRunList();
3226 ASSERT_EQ(3U, run_list->size()); 3267 ASSERT_EQ(3U, run_list->size());
3227 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); 3268 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range);
3228 EXPECT_EQ(Range(1, 2), run_list->runs()[1]->range); 3269 EXPECT_EQ(Range(1, 2), run_list->runs()[1]->range);
3229 EXPECT_EQ(Range(2, 3), run_list->runs()[2]->range); 3270 EXPECT_EQ(Range(2, 3), run_list->runs()[2]->range);
3230 3271
3231 render_text.SetText(WideToUTF16(L"x \x25B6 y")); 3272 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
3232 render_text.EnsureLayout(); 3273 render_text->EnsureLayout();
3233 run_list = render_text.GetRunList(); 3274 run_list = render_text->GetRunList();
3234 ASSERT_EQ(4U, run_list->size()); 3275 ASSERT_EQ(4U, run_list->size());
3235 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); 3276 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range);
3236 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); 3277 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range);
3237 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); 3278 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range);
3238 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); 3279 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range);
3239 } 3280 }
3240 3281
3241 TEST_F(RenderTextTest, HarfBuzz_BreakRunsByEmoji) { 3282 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByEmoji) {
3242 RenderTextHarfBuzz render_text; 3283 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3243 3284
3244 // \xF0\x9F\x98\x81 (U+1F601) is smile icon emoji. \xE2\x9C\xA8 (U+2728) is 3285 // \xF0\x9F\x98\x81 (U+1F601) is smile icon emoji. \xE2\x9C\xA8 (U+2728) is
3245 // a sparkle icon. Both can be drawn with color emoji fonts, so runs should be 3286 // a sparkle icon. Both can be drawn with color emoji fonts, so runs should be
3246 // separated. See crbug.com/448909 3287 // separated. See crbug.com/448909
3247 render_text.SetText(UTF8ToUTF16("x\xF0\x9F\x98\x81y\xE2\x9C\xA8")); 3288 render_text->SetText(UTF8ToUTF16("x\xF0\x9F\x98\x81y\xE2\x9C\xA8"));
3248 render_text.EnsureLayout(); 3289 render_text->EnsureLayout();
3249 internal::TextRunList* run_list = render_text.GetRunList(); 3290 internal::TextRunList* run_list = render_text->GetRunList();
3250 ASSERT_EQ(4U, run_list->size()); 3291 ASSERT_EQ(4U, run_list->size());
3251 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range); 3292 EXPECT_EQ(Range(0, 1), run_list->runs()[0]->range);
3252 // The length is 2 since U+1F601 is represented as a surrogate pair in UTF16. 3293 // The length is 2 since U+1F601 is represented as a surrogate pair in UTF16.
3253 EXPECT_EQ(Range(1, 3), run_list->runs()[1]->range); 3294 EXPECT_EQ(Range(1, 3), run_list->runs()[1]->range);
3254 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range); 3295 EXPECT_EQ(Range(3, 4), run_list->runs()[2]->range);
3255 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range); 3296 EXPECT_EQ(Range(4, 5), run_list->runs()[3]->range);
3256 } 3297 }
3257 3298
3258 TEST_F(RenderTextTest, HarfBuzz_BreakRunsByAscii) { 3299 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_BreakRunsByAscii) {
3259 RenderTextHarfBuzz render_text; 3300 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3260 3301
3261 // \xF0\x9F\x90\xB1 (U+1F431) is a cat face. It should be put into a separate 3302 // \xF0\x9F\x90\xB1 (U+1F431) is a cat face. It should be put into a separate
3262 // run from the ASCII period character. 3303 // run from the ASCII period character.
3263 render_text.SetText(UTF8ToUTF16("\xF0\x9F\x90\xB1.")); 3304 render_text->SetText(UTF8ToUTF16("\xF0\x9F\x90\xB1."));
3264 render_text.EnsureLayout(); 3305 render_text->EnsureLayout();
3265 internal::TextRunList* run_list = render_text.GetRunList(); 3306 internal::TextRunList* run_list = render_text->GetRunList();
3266 ASSERT_EQ(2U, run_list->size()); 3307 ASSERT_EQ(2U, run_list->size());
3267 // U+1F431 is represented as a surrogate pair in UTF16. 3308 // U+1F431 is represented as a surrogate pair in UTF16.
3268 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range); 3309 EXPECT_EQ(Range(0, 2), run_list->runs()[0]->range);
3269 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range); 3310 EXPECT_EQ(Range(2, 3), run_list->runs()[1]->range);
3270 } 3311 }
3271 3312
3272 TEST_F(RenderTextTest, GlyphBounds) { 3313 TEST_P(RenderTextHarfBuzzTest, GlyphBounds) {
3273 const wchar_t* kTestStrings[] = { 3314 const wchar_t* kTestStrings[] = {
3274 L"asdf 1234 qwer", L"\x0647\x0654", L"\x0645\x0631\x062D\x0628\x0627" 3315 L"asdf 1234 qwer", L"\x0647\x0654", L"\x0645\x0631\x062D\x0628\x0627"
3275 }; 3316 };
3276 std::unique_ptr<RenderText> render_text(new RenderTextHarfBuzz); 3317 RenderText* render_text = GetRenderText();
3277 3318
3278 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 3319 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
3279 render_text->SetText(WideToUTF16(kTestStrings[i])); 3320 render_text->SetText(WideToUTF16(kTestStrings[i]));
3280 render_text->EnsureLayout(); 3321 render_text->EnsureLayout();
3281 3322
3282 for (size_t j = 0; j < render_text->text().length(); ++j) 3323 for (size_t j = 0; j < render_text->text().length(); ++j)
3283 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); 3324 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty());
3284 } 3325 }
3285 } 3326 }
3286 3327
3287 // Ensure that shaping with a non-existent font does not cause a crash. 3328 // Ensure that shaping with a non-existent font does not cause a crash.
3288 TEST_F(RenderTextTest, HarfBuzz_NonExistentFont) { 3329 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_NonExistentFont) {
3289 RenderTextHarfBuzz render_text; 3330 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3290 render_text.SetText(ASCIIToUTF16("test")); 3331 render_text->SetText(ASCIIToUTF16("test"));
3291 render_text.EnsureLayout(); 3332 render_text->EnsureLayout();
3292 internal::TextRunList* run_list = render_text.GetRunList(); 3333 internal::TextRunList* run_list = render_text->GetRunList();
3293 ASSERT_EQ(1U, run_list->size()); 3334 ASSERT_EQ(1U, run_list->size());
3294 internal::TextRunHarfBuzz* run = run_list->runs()[0]; 3335 internal::TextRunHarfBuzz* run = run_list->runs()[0];
3295 render_text.ShapeRunWithFont(render_text.text(), 3336 render_text->ShapeRunWithFont(render_text->text(),
3296 Font("TheFontThatDoesntExist", 13), 3337 Font("TheFontThatDoesntExist", 13),
3297 FontRenderParams(), run); 3338 FontRenderParams(), run);
3298 } 3339 }
3299 3340
3300 // Ensure an empty run returns sane values to queries. 3341 // Ensure an empty run returns sane values to queries.
3301 TEST_F(RenderTextTest, HarfBuzz_EmptyRun) { 3342 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_EmptyRun) {
3302 internal::TextRunHarfBuzz run((Font())); 3343 internal::TextRunHarfBuzz run((Font()));
3303 const base::string16 kString = ASCIIToUTF16("abcdefgh"); 3344 const base::string16 kString = ASCIIToUTF16("abcdefgh");
3304 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator( 3345 std::unique_ptr<base::i18n::BreakIterator> iter(new base::i18n::BreakIterator(
3305 kString, base::i18n::BreakIterator::BREAK_CHARACTER)); 3346 kString, base::i18n::BreakIterator::BREAK_CHARACTER));
3306 ASSERT_TRUE(iter->Init()); 3347 ASSERT_TRUE(iter->Init());
3307 3348
3308 run.range = Range(3, 8); 3349 run.range = Range(3, 8);
3309 run.glyph_count = 0; 3350 run.glyph_count = 0;
3310 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5))); 3351 EXPECT_EQ(Range(0, 0), run.CharRangeToGlyphRange(Range(4, 5)));
3311 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4).Round()); 3352 EXPECT_EQ(Range(0, 0), run.GetGraphemeBounds(iter.get(), 4).Round());
3312 Range chars; 3353 Range chars;
3313 Range glyphs; 3354 Range glyphs;
3314 run.GetClusterAt(4, &chars, &glyphs); 3355 run.GetClusterAt(4, &chars, &glyphs);
3315 EXPECT_EQ(Range(3, 8), chars); 3356 EXPECT_EQ(Range(3, 8), chars);
3316 EXPECT_EQ(Range(0, 0), glyphs); 3357 EXPECT_EQ(Range(0, 0), glyphs);
3317 } 3358 }
3318 3359
3319 // Ensure the line breaker doesn't compute the word's width bigger than the 3360 // Ensure the line breaker doesn't compute the word's width bigger than the
3320 // actual size. See http://crbug.com/470073 3361 // actual size. See http://crbug.com/470073
3321 TEST_F(RenderTextTest, HarfBuzz_WordWidthWithDiacritics) { 3362 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_WordWidthWithDiacritics) {
3322 RenderTextHarfBuzz render_text; 3363 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3323 const base::string16 kWord = WideToUTF16(L"\u0906\u092A\u0915\u0947 "); 3364 const base::string16 kWord = WideToUTF16(L"\u0906\u092A\u0915\u0947 ");
3324 render_text.SetText(kWord); 3365 render_text->SetText(kWord);
3325 const SizeF text_size = render_text.GetStringSizeF(); 3366 const SizeF text_size = render_text->GetStringSizeF();
3326 3367
3327 render_text.SetText(kWord + kWord); 3368 render_text->SetText(kWord + kWord);
3328 render_text.SetMultiline(true); 3369 render_text->SetMultiline(true);
3329 EXPECT_EQ(text_size.width() * 2, render_text.GetStringSizeF().width()); 3370 EXPECT_EQ(text_size.width() * 2, render_text->GetStringSizeF().width());
3330 EXPECT_EQ(text_size.height(), render_text.GetStringSizeF().height()); 3371 EXPECT_EQ(text_size.height(), render_text->GetStringSizeF().height());
3331 render_text.SetDisplayRect(Rect(0, 0, std::ceil(text_size.width()), 0)); 3372 render_text->SetDisplayRect(Rect(0, 0, std::ceil(text_size.width()), 0));
3332 EXPECT_NEAR(text_size.width(), render_text.GetStringSizeF().width(), 1.0f); 3373 EXPECT_NEAR(text_size.width(), render_text->GetStringSizeF().width(), 1.0f);
3333 EXPECT_EQ(text_size.height() * 2, render_text.GetStringSizeF().height()); 3374 EXPECT_EQ(text_size.height() * 2, render_text->GetStringSizeF().height());
3334 } 3375 }
3335 3376
3336 // Ensure a string fits in a display rect with a width equal to the string's. 3377 // Ensure a string fits in a display rect with a width equal to the string's.
3337 TEST_F(RenderTextTest, StringFitsOwnWidth) { 3378 TEST_P(RenderTextTestAll, StringFitsOwnWidth) {
3338 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 3379 RenderText* render_text = GetRenderText();
3339 const base::string16 kString = ASCIIToUTF16("www.example.com"); 3380 const base::string16 kString = ASCIIToUTF16("www.example.com");
3340 3381
3341 render_text->SetText(kString); 3382 render_text->SetText(kString);
3342 render_text->ApplyWeight(Font::Weight::BOLD, Range(0, 3)); 3383 render_text->ApplyWeight(Font::Weight::BOLD, Range(0, 3));
3343 render_text->SetElideBehavior(ELIDE_TAIL); 3384 render_text->SetElideBehavior(ELIDE_TAIL);
3344 3385
3345 render_text->SetDisplayRect(Rect(0, 0, 500, 100)); 3386 render_text->SetDisplayRect(Rect(0, 0, 500, 100));
3346 EXPECT_EQ(kString, render_text->GetDisplayText()); 3387 EXPECT_EQ(kString, render_text->GetDisplayText());
3347 render_text->SetDisplayRect(Rect(0, 0, render_text->GetContentWidth(), 100)); 3388 render_text->SetDisplayRect(Rect(0, 0, render_text->GetContentWidth(), 100));
3348 EXPECT_EQ(kString, render_text->GetDisplayText()); 3389 EXPECT_EQ(kString, render_text->GetDisplayText());
3349 } 3390 }
3350 3391
3351 // TODO(derat): Figure out why this fails on Windows: http://crbug.com/427184 3392 // TODO(derat): Figure out why this fails on Windows: http://crbug.com/427184
3352 #if !defined(OS_WIN) 3393 #if !defined(OS_WIN)
3353 // Ensure that RenderText examines all of the fonts in its FontList before 3394 // Ensure that RenderText examines all of the fonts in its FontList before
3354 // falling back to other fonts. 3395 // falling back to other fonts.
3355 TEST_F(RenderTextTest, HarfBuzz_FontListFallback) { 3396 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_FontListFallback) {
3356 // Double-check that the requested fonts are present. 3397 // Double-check that the requested fonts are present.
3357 FontList font_list("Arial, Symbol, 12px"); 3398 FontList font_list("Arial, Symbol, 12px");
3358 const std::vector<Font>& fonts = font_list.GetFonts(); 3399 const std::vector<Font>& fonts = font_list.GetFonts();
3359 ASSERT_EQ(2u, fonts.size()); 3400 ASSERT_EQ(2u, fonts.size());
3360 ASSERT_EQ("arial", 3401 ASSERT_EQ("arial",
3361 base::ToLowerASCII(fonts[0].GetActualFontNameForTesting())); 3402 base::ToLowerASCII(fonts[0].GetActualFontNameForTesting()));
3362 ASSERT_EQ("symbol", 3403 ASSERT_EQ("symbol",
3363 base::ToLowerASCII(fonts[1].GetActualFontNameForTesting())); 3404 base::ToLowerASCII(fonts[1].GetActualFontNameForTesting()));
3364 3405
3365 // "⊕" (CIRCLED PLUS) should be rendered with Symbol rather than falling back 3406 // "⊕" (CIRCLED PLUS) should be rendered with Symbol rather than falling back
3366 // to some other font that's present on the system. 3407 // to some other font that's present on the system.
3367 RenderTextHarfBuzz render_text; 3408 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3368 render_text.SetFontList(font_list); 3409 render_text->SetFontList(font_list);
3369 render_text.SetText(UTF8ToUTF16("\xE2\x8A\x95")); 3410 render_text->SetText(UTF8ToUTF16("\xE2\x8A\x95"));
3370 const std::vector<RenderText::FontSpan> spans = 3411 const std::vector<RenderText::FontSpan> spans =
3371 render_text.GetFontSpansForTesting(); 3412 render_text->GetFontSpansForTesting();
3372 ASSERT_EQ(static_cast<size_t>(1), spans.size()); 3413 ASSERT_EQ(static_cast<size_t>(1), spans.size());
3373 EXPECT_EQ("Symbol", spans[0].first.GetFontName()); 3414 EXPECT_EQ("Symbol", spans[0].first.GetFontName());
3374 } 3415 }
3375 #endif // !defined(OS_WIN) 3416 #endif // !defined(OS_WIN)
3376 3417
3377 // Ensure that the fallback fonts of the Uniscribe font are tried for shaping. 3418 // Ensure that the fallback fonts of the Uniscribe font are tried for shaping.
3378 #if defined(OS_WIN) 3419 #if defined(OS_WIN)
3379 TEST_F(RenderTextTest, HarfBuzz_UniscribeFallback) { 3420 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_UniscribeFallback) {
3380 RenderTextHarfBuzz render_text; 3421 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3381 PlatformFontWin* font_win = new PlatformFontWin("Meiryo", 12); 3422 PlatformFontWin* font_win = new PlatformFontWin("Meiryo", 12);
3382 // Japanese name for Meiryo. This name won't be found in the system's linked 3423 // Japanese name for Meiryo. This name won't be found in the system's linked
3383 // fonts, forcing RTHB to try the Uniscribe font and its fallbacks. 3424 // fonts, forcing RTHB to try the Uniscribe font and its fallbacks.
3384 font_win->font_ref_->font_name_ = WideToUTF8(L"\x30e1\x30a4\x30ea\x30aa"); 3425 font_win->font_ref_->font_name_ = WideToUTF8(L"\x30e1\x30a4\x30ea\x30aa");
3385 FontList font_list((Font(font_win))); 3426 FontList font_list((Font(font_win)));
3386 3427
3387 render_text.SetFontList(font_list); 3428 render_text->SetFontList(font_list);
3388 // Korean character "han". 3429 // Korean character "han".
3389 render_text.SetText(WideToUTF16(L"\xd55c")); 3430 render_text->SetText(WideToUTF16(L"\xd55c"));
3390 render_text.EnsureLayout(); 3431 render_text->EnsureLayout();
3391 internal::TextRunList* run_list = render_text.GetRunList(); 3432 internal::TextRunList* run_list = render_text->GetRunList();
3392 ASSERT_EQ(1U, run_list->size()); 3433 ASSERT_EQ(1U, run_list->size());
3393 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); 3434 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs());
3394 } 3435 }
3395 #endif // defined(OS_WIN) 3436 #endif // defined(OS_WIN)
3396 3437
3397 // Ensure that the fallback fonts offered by GetFallbackFonts() are 3438 // Ensure that the fallback fonts offered by GetFallbackFonts() are
3398 // tried. Note this test assumes the font "Arial" doesn't provide a unicode 3439 // tried. Note this test assumes the font "Arial" doesn't provide a unicode
3399 // glyph for a particular character, and that there exists a system fallback 3440 // glyph for a particular character, and that there exists a system fallback
3400 // font which does. 3441 // font which does.
3401 // TODO(msw): Fallback doesn't find a glyph on Linux. 3442 // TODO(msw): Fallback doesn't find a glyph on Linux.
3402 #if !defined(OS_LINUX) 3443 #if !defined(OS_LINUX)
3403 TEST_F(RenderTextTest, HarfBuzz_UnicodeFallback) { 3444 TEST_P(RenderTextHarfBuzzTest, HarfBuzz_UnicodeFallback) {
3404 RenderTextHarfBuzz render_text; 3445 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz();
3405 render_text.SetFontList(FontList("Arial, 12px")); 3446 render_text->SetFontList(FontList("Arial, 12px"));
3406 3447
3407 // Korean character "han". 3448 // Korean character "han".
3408 render_text.SetText(WideToUTF16(L"\xd55c")); 3449 render_text->SetText(WideToUTF16(L"\xd55c"));
3409 render_text.EnsureLayout(); 3450 render_text->EnsureLayout();
3410 internal::TextRunList* run_list = render_text.GetRunList(); 3451 internal::TextRunList* run_list = render_text->GetRunList();
3411 ASSERT_EQ(1U, run_list->size()); 3452 ASSERT_EQ(1U, run_list->size());
3412 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs()); 3453 EXPECT_EQ(0U, run_list->runs()[0]->CountMissingGlyphs());
3413 } 3454 }
3414 #endif // !defined(OS_LINUX) 3455 #endif // !defined(OS_LINUX)
3415 3456
3416 // http://crbug/624513 3457 // http://crbug/624513
3417 #if defined(OS_WIN) 3458 #if !defined(OS_WIN)
3418 #define MAYBE_TextDoesntClip DISABLED_TextDoesntClip
3419 #else
3420 #define MAYBE_TextDoesntClip TextDoesntClip
3421 #endif
3422 // Ensure that the width reported by RenderText is sufficient for drawing. Draws 3459 // Ensure that the width reported by RenderText is sufficient for drawing. Draws
3423 // to a canvas and checks if any pixel beyond the bounding rectangle is colored. 3460 // to a canvas and checks if any pixel beyond the bounding rectangle is colored.
3424 TEST_F(RenderTextTest, MAYBE_TextDoesntClip) { 3461 TEST_P(RenderTextTestAll, TextDoesntClip) {
3462 // Fails on Mac with RenderTextHarfBuzz. See http://crbug.com/640068.
3463 #if defined(OS_MACOSX)
3464 if (GetParam() == RENDER_TEXT_HARFBUZZ)
3465 return;
3466 #endif
3467
3425 const wchar_t* kTestStrings[] = { 3468 const wchar_t* kTestStrings[] = {
3426 L" ", 3469 L" ",
3427 // TODO(dschuyler): Underscores draw outside GetStringSize; 3470 // TODO(dschuyler): Underscores draw outside GetStringSize;
3428 // crbug.com/459812. This appears to be a preexisting issue that wasn't 3471 // crbug.com/459812. This appears to be a preexisting issue that wasn't
3429 // revealed by the prior unit tests. 3472 // revealed by the prior unit tests.
3430 // L"TEST_______", 3473 // L"TEST_______",
3431 L"TEST some stuff", 3474 L"TEST some stuff",
3432 L"WWWWWWWWWW", 3475 L"WWWWWWWWWW",
3433 L"gAXAXAXAXAXAXA", 3476 L"gAXAXAXAXAXAXA",
3434 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812. 3477 // TODO(dschuyler): A-Ring draws outside GetStringSize; crbug.com/459812.
3435 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5", 3478 // L"g\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5X\x00C5",
3436 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D" 3479 L"\x0647\x0654\x0647\x0654\x0647\x0654\x0647\x0654\x0645\x0631\x062D"
3437 L"\x0628\x0627"}; 3480 L"\x0628\x0627"};
3438 const Size kCanvasSize(300, 50); 3481 const Size kCanvasSize(300, 50);
3439 const int kTestSize = 10; 3482 const int kTestSize = 10;
3440 3483
3441 sk_sp<SkSurface> surface = 3484 sk_sp<SkSurface> surface =
3442 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); 3485 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height());
3443 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f); 3486 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f);
3444 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 3487 RenderText* render_text = GetRenderText();
3445 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3488 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3446 render_text->SetColor(SK_ColorBLACK); 3489 render_text->SetColor(SK_ColorBLACK);
3447 3490
3448 for (auto* string : kTestStrings) { 3491 for (auto* string : kTestStrings) {
3449 surface->getCanvas()->clear(SK_ColorWHITE); 3492 surface->getCanvas()->clear(SK_ColorWHITE);
3450 render_text->SetText(WideToUTF16(string)); 3493 render_text->SetText(WideToUTF16(string));
3451 const Size string_size = render_text->GetStringSize(); 3494 const Size string_size = render_text->GetStringSize();
3452 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2)); 3495 render_text->ApplyBaselineStyle(SUPERSCRIPT, Range(1, 2));
3453 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4)); 3496 render_text->ApplyBaselineStyle(SUPERIOR, Range(3, 4));
3454 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6)); 3497 render_text->ApplyBaselineStyle(INFERIOR, Range(5, 6));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 // TODO(dschuyler): On Mac text draws to right of GetStringSize. This 3558 // TODO(dschuyler): On Mac text draws to right of GetStringSize. This
3516 // appears to be a preexisting issue that wasn't revealed by the prior 3559 // appears to be a preexisting issue that wasn't revealed by the prior
3517 // unit tests. 3560 // unit tests.
3518 rect_buffer.EnsureSolidRect(SK_ColorWHITE, 3561 rect_buffer.EnsureSolidRect(SK_ColorWHITE,
3519 kTestSize + string_size.width(), kTestSize, 3562 kTestSize + string_size.width(), kTestSize,
3520 kTestSize, string_size.height()); 3563 kTestSize, string_size.height());
3521 #endif 3564 #endif
3522 } 3565 }
3523 } 3566 }
3524 } 3567 }
3568 #endif // !defined(OS_WIN)
3525 3569
3526 // Ensure that the text will clip to the display rect. Draws to a canvas and 3570 // Ensure that the text will clip to the display rect. Draws to a canvas and
3527 // checks whether any pixel beyond the bounding rectangle is colored. 3571 // checks whether any pixel beyond the bounding rectangle is colored.
3528 TEST_F(RenderTextTest, TextDoesClip) { 3572 TEST_P(RenderTextTestAll, TextDoesClip) {
3529 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"}; 3573 const wchar_t* kTestStrings[] = {L"TEST", L"W", L"WWWW", L"gAXAXWWWW"};
3530 const Size kCanvasSize(300, 50); 3574 const Size kCanvasSize(300, 50);
3531 const int kTestSize = 10; 3575 const int kTestSize = 10;
3532 3576
3533 sk_sp<SkSurface> surface = 3577 sk_sp<SkSurface> surface =
3534 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height()); 3578 SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height());
3535 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f); 3579 Canvas canvas(sk_ref_sp(surface->getCanvas()), 1.0f);
3536 std::unique_ptr<RenderText> render_text(RenderText::CreateInstance()); 3580 RenderText* render_text = GetRenderText();
3537 render_text->SetHorizontalAlignment(ALIGN_LEFT); 3581 render_text->SetHorizontalAlignment(ALIGN_LEFT);
3538 render_text->SetColor(SK_ColorBLACK); 3582 render_text->SetColor(SK_ColorBLACK);
3539 3583
3540 for (auto* string : kTestStrings) { 3584 for (auto* string : kTestStrings) {
3541 surface->getCanvas()->clear(SK_ColorWHITE); 3585 surface->getCanvas()->clear(SK_ColorWHITE);
3542 render_text->SetText(WideToUTF16(string)); 3586 render_text->SetText(WideToUTF16(string));
3543 const Size string_size = render_text->GetStringSize(); 3587 const Size string_size = render_text->GetStringSize();
3544 int fake_width = string_size.width() / 2; 3588 int fake_width = string_size.width() / 2;
3545 int fake_height = string_size.height() / 2; 3589 int fake_height = string_size.height() / 2;
3546 render_text->SetDisplayRect( 3590 render_text->SetDisplayRect(
(...skipping 25 matching lines...) Expand all
3572 } 3616 }
3573 { 3617 {
3574 SCOPED_TRACE("TextDoesClip Right Side"); 3618 SCOPED_TRACE("TextDoesClip Right Side");
3575 rect_buffer.EnsureSolidRect(SK_ColorWHITE, kTestSize + fake_width, 3619 rect_buffer.EnsureSolidRect(SK_ColorWHITE, kTestSize + fake_width,
3576 kTestSize, kTestSize, fake_height); 3620 kTestSize, kTestSize, fake_height);
3577 } 3621 }
3578 } 3622 }
3579 } 3623 }
3580 3624
3581 #if defined(OS_MACOSX) 3625 #if defined(OS_MACOSX)
3582 TEST_F(RenderTextTest, Mac_ElidedText) { 3626 TEST_P(RenderTextMacTest, Mac_ElidedText) {
3583 RenderTextMac render_text; 3627 RenderTextMac* render_text = GetRenderTextMac();
3584 base::string16 text(ASCIIToUTF16("This is an example.")); 3628 base::string16 text(ASCIIToUTF16("This is an example."));
3585 render_text.SetText(text); 3629 render_text->SetText(text);
3586 Size string_size = render_text.GetStringSize(); 3630 Size string_size = render_text->GetStringSize();
3587 render_text.SetDisplayRect(Rect(string_size)); 3631 render_text->SetDisplayRect(Rect(string_size));
3588 render_text.EnsureLayout(); 3632 render_text->EnsureLayout();
3589 // NOTE: Character and glyph counts are only comparable for simple text. 3633 // NOTE: Character and glyph counts are only comparable for simple text.
3590 EXPECT_EQ(text.size(), 3634 EXPECT_EQ(text.size(),
3591 static_cast<size_t>(CTLineGetGlyphCount(render_text.line_))); 3635 static_cast<size_t>(CTLineGetGlyphCount(render_text->line_)));
3592 3636
3593 render_text.SetElideBehavior(ELIDE_TAIL); 3637 render_text->SetElideBehavior(ELIDE_TAIL);
3594 string_size.set_width(string_size.width() / 2); 3638 string_size.set_width(string_size.width() / 2);
3595 render_text.SetDisplayRect(Rect(string_size)); 3639 render_text->SetDisplayRect(Rect(string_size));
3596 render_text.EnsureLayout(); 3640 render_text->EnsureLayout();
3597 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); 3641 CFIndex glyph_count = CTLineGetGlyphCount(render_text->line_);
3598 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); 3642 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count));
3599 EXPECT_NE(0, glyph_count); 3643 EXPECT_NE(0, glyph_count);
3600 } 3644 }
3601 #endif 3645 #endif // defined(OS_MACOSX)
3602 3646
3603 // Ensure color changes are picked up by the RenderText implementation. 3647 // Ensure color changes are picked up by the RenderText implementation.
3604 TEST_F(RenderTextTest, ColorChange) { 3648 TEST_P(RenderTextTestAll, ColorChange) {
3605 RenderTextAllBackends backend; 3649 RenderText* render_text = GetRenderText();
3650 render_text->SetText(ASCIIToUTF16("x"));
3651 DrawVisualText();
3606 3652
3607 while (backend.Advance()) { 3653 std::vector<TestSkiaTextRenderer::TextLog> text_log;
3608 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName()); 3654 renderer()->GetTextLogAndReset(&text_log);
3609 backend->SetText(ASCIIToUTF16("x")); 3655 EXPECT_EQ(1u, text_log.size());
3610 backend.DrawVisualText(); 3656 EXPECT_EQ(SK_ColorBLACK, text_log[0].color);
3611 3657
3612 std::vector<TestSkiaTextRenderer::TextLog> text_log; 3658 render_text->SetColor(SK_ColorRED);
3613 backend.GetTextLogAndReset(&text_log); 3659 DrawVisualText();
3614 EXPECT_EQ(1u, text_log.size()); 3660 renderer()->GetTextLogAndReset(&text_log);
3615 EXPECT_EQ(SK_ColorBLACK, text_log[0].color);
3616 3661
3617 backend->SetColor(SK_ColorRED); 3662 EXPECT_EQ(1u, text_log.size());
3618 backend.DrawVisualText(); 3663 EXPECT_EQ(SK_ColorRED, text_log[0].color);
3619 backend.GetTextLogAndReset(&text_log);
3620
3621 EXPECT_EQ(1u, text_log.size());
3622 EXPECT_EQ(SK_ColorRED, text_log[0].color);
3623 }
3624 } 3664 }
3625 3665
3626 // Ensure style information propagates to the typeface on the text renderer. 3666 // Ensure style information propagates to the typeface on the text renderer.
3627 TEST_F(RenderTextTest, StylePropagated) { 3667 TEST_P(RenderTextTestAll, StylePropagated) {
3628 RenderTextAllBackends backend; 3668 RenderText* render_text = GetRenderText();
3629
3630 // Default-constructed fonts on Mac are system fonts. These can have all kinds 3669 // Default-constructed fonts on Mac are system fonts. These can have all kinds
3631 // of weird weights and style, which are preserved by PlatformFontMac, but do 3670 // of weird weights and style, which are preserved by PlatformFontMac, but do
3632 // not map simply to a SkTypeface::Style (the full details in SkFontStyle is 3671 // not map simply to a SkTypeface::Style (the full details in SkFontStyle is
3633 // needed). They also vary depending on the OS version, so set a known font. 3672 // needed). They also vary depending on the OS version, so set a known font.
3634 FontList font_list(Font("Arial", 10)); 3673 FontList font_list(Font("Arial", 10));
3635 3674
3636 while (backend.Advance()) { 3675 render_text->SetText(ASCIIToUTF16("x"));
3637 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName()); 3676 render_text->SetFontList(font_list);
3638 backend->SetText(ASCIIToUTF16("x"));
3639 backend->SetFontList(font_list);
3640 3677
3641 backend.DrawVisualText(); 3678 DrawVisualText();
3642 EXPECT_EQ(SkTypeface::kNormal, backend.paint().getTypeface()->style()); 3679 EXPECT_EQ(SkTypeface::kNormal, GetRendererPaint().getTypeface()->style());
3643 3680
3644 backend->SetWeight(Font::Weight::BOLD); 3681 render_text->SetWeight(Font::Weight::BOLD);
3645 backend.DrawVisualText(); 3682 DrawVisualText();
3646 EXPECT_EQ(SkTypeface::kBold, backend.paint().getTypeface()->style()); 3683 EXPECT_EQ(SkTypeface::kBold, GetRendererPaint().getTypeface()->style());
3647 3684
3648 backend->SetStyle(TextStyle::ITALIC, true); 3685 render_text->SetStyle(TextStyle::ITALIC, true);
3649 backend.DrawVisualText(); 3686 DrawVisualText();
3650 EXPECT_EQ(SkTypeface::kBoldItalic, backend.paint().getTypeface()->style()); 3687 EXPECT_EQ(SkTypeface::kBoldItalic, GetRendererPaint().getTypeface()->style());
3651 3688
3652 backend->SetWeight(Font::Weight::NORMAL); 3689 render_text->SetWeight(Font::Weight::NORMAL);
3653 backend.DrawVisualText(); 3690 DrawVisualText();
3654 EXPECT_EQ(SkTypeface::kItalic, backend.paint().getTypeface()->style()); 3691 EXPECT_EQ(SkTypeface::kItalic, GetRendererPaint().getTypeface()->style());
3655 }
3656 } 3692 }
3657 3693
3658 // Ensure the painter adheres to RenderText::subpixel_rendering_suppressed(). 3694 // Ensure the painter adheres to RenderText::subpixel_rendering_suppressed().
3659 TEST_F(RenderTextTest, SubpixelRenderingSuppressed) { 3695 TEST_P(RenderTextTestAll, SubpixelRenderingSuppressed) {
3660 RenderTextAllBackends backend; 3696 RenderText* render_text = GetRenderText();
3697 render_text->SetText(ASCIIToUTF16("x"));
3661 3698
3662 while (backend.Advance()) { 3699 DrawVisualText();
3663 SCOPED_TRACE(testing::Message() << "backend: " << backend.GetName()); 3700 #if defined(OS_LINUX)
3664 backend->SetText(ASCIIToUTF16("x")); 3701 // On Linux, whether subpixel AA is supported is determined by the platform
3702 // FontConfig. Force it into a particular style after computing runs. Other
3703 // platforms use a known default FontRenderParams from a static local.
3704 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3705 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3706 DrawVisualText();
3707 #endif
3708 EXPECT_TRUE(GetRendererPaint().isLCDRenderText());
3665 3709
3666 backend.DrawVisualText(); 3710 render_text->set_subpixel_rendering_suppressed(true);
3667 #if defined(OS_LINUX) 3711 DrawVisualText();
3668 // On Linux, whether subpixel AA is supported is determined by the platform
3669 // FontConfig. Force it into a particular style after computing runs. Other
3670 // platforms use a known default FontRenderParams from a static local.
3671 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3672 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3673 backend.DrawVisualText();
3674 #endif
3675 EXPECT_TRUE(backend.paint().isLCDRenderText());
3676
3677 backend->set_subpixel_rendering_suppressed(true);
3678 backend.DrawVisualText();
3679 #if defined(OS_LINUX) 3712 #if defined(OS_LINUX)
3680 // For Linux, runs shouldn't be re-calculated, and the suppression of the 3713 // For Linux, runs shouldn't be re-calculated, and the suppression of the
3681 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after 3714 // SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
3682 // checking, apply the override anyway to be explicit that it is suppressed. 3715 // checking, apply the override anyway to be explicit that it is suppressed.
3683 EXPECT_FALSE(backend.paint().isLCDRenderText()); 3716 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3684 backend.GetHarfbuzzRunList()->runs()[0]->render_params.subpixel_rendering = 3717 GetHarfBuzzRunList()->runs()[0]->render_params.subpixel_rendering =
3685 FontRenderParams::SUBPIXEL_RENDERING_RGB; 3718 FontRenderParams::SUBPIXEL_RENDERING_RGB;
3686 backend.DrawVisualText(); 3719 DrawVisualText();
3687 #endif 3720 #endif
3688 EXPECT_FALSE(backend.paint().isLCDRenderText()); 3721 EXPECT_FALSE(GetRendererPaint().isLCDRenderText());
3689 }
3690 } 3722 }
3691 3723
3724 #if defined(OS_MACOSX)
3725 INSTANTIATE_TEST_CASE_P(,
msw 2016/08/25 03:02:19 nit: comment on empty first arg.
karandeepb 2016/08/25 08:13:10 Done.
3726 RenderTextTestAll,
3727 ::testing::Values(RENDER_TEXT_HARFBUZZ,
3728 RENDER_TEXT_MAC),
3729 PrintRenderTextBackend());
3730 INSTANTIATE_TEST_CASE_P(,
3731 RenderTextMacTest,
3732 ::testing::Values(RENDER_TEXT_MAC),
3733 PrintRenderTextBackend());
3734 #else
3735 INSTANTIATE_TEST_CASE_P(,
3736 RenderTextTestAll,
msw 2016/08/25 03:02:19 nit: the test logs print as "RenderTextTestAll.Tru
karandeepb 2016/08/25 08:13:10 For INSTANTIATE_TEST_CASE_P(prefix, test_case_name
msw 2016/08/25 15:20:37 Nice; thanks!
3737 ::testing::Values(RENDER_TEXT_HARFBUZZ),
3738 PrintRenderTextBackend());
3739 #endif
3740
3741 INSTANTIATE_TEST_CASE_P(,
3742 RenderTextHarfBuzzTest,
3743 ::testing::Values(RENDER_TEXT_HARFBUZZ),
3744 PrintRenderTextBackend());
3745
3692 } // namespace gfx 3746 } // namespace gfx
OLDNEW
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698