OLD | NEW |
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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
11 | 11 |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #endif | 14 #endif |
15 | 15 |
| 16 #if defined(TOOLKIT_GTK) |
| 17 #include <gtk/gtk.h> |
| 18 #endif |
| 19 |
16 namespace gfx { | 20 namespace gfx { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 // Checks whether |range| contains |index|. This is not the same as calling | 24 // Checks whether |range| contains |index|. This is not the same as calling |
21 // |range.Contains(ui::Range(index))| - as that would return true when | 25 // |range.Contains(ui::Range(index))| - as that would return true when |
22 // |index| == |range.end()|. | 26 // |index| == |range.end()|. |
23 bool IndexInRange(const ui::Range& range, size_t index) { | 27 bool IndexInRange(const ui::Range& range, size_t index) { |
24 return index >= range.start() && index < range.end(); | 28 return index >= range.start() && index < range.end(); |
25 } | 29 } |
26 | 30 |
| 31 // A test utility function to set the application default text direction. |
| 32 void SetRTL(bool rtl) { |
| 33 // Override the current locale/direction. |
| 34 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en"); |
| 35 #if defined(TOOLKIT_GTK) |
| 36 // Do the same for GTK, which does not rely on the ICU default locale. |
| 37 gtk_widget_set_default_direction(rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR); |
| 38 #endif |
| 39 EXPECT_EQ(rtl, base::i18n::IsRTL()); |
| 40 } |
| 41 |
27 } // namespace | 42 } // namespace |
28 | 43 |
29 class RenderTextTest : public testing::Test { | 44 class RenderTextTest : public testing::Test { |
30 }; | 45 }; |
31 | 46 |
32 TEST_F(RenderTextTest, DefaultStyle) { | 47 TEST_F(RenderTextTest, DefaultStyle) { |
33 // Defaults to empty text with no styles. | 48 // Defaults to empty text with no styles. |
34 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 49 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
35 EXPECT_TRUE(render_text->text().empty()); | 50 EXPECT_TRUE(render_text->text().empty()); |
36 EXPECT_TRUE(render_text->style_ranges().empty()); | 51 EXPECT_TRUE(render_text->style_ranges().empty()); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 render_text->SetText(seuss); | 343 render_text->SetText(seuss); |
329 render_text->SetObscured(true); | 344 render_text->SetObscured(true); |
330 EXPECT_EQ(seuss, render_text->text()); | 345 EXPECT_EQ(seuss, render_text->text()); |
331 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); | 346 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); |
332 render_text->SetObscured(false); | 347 render_text->SetObscured(false); |
333 EXPECT_EQ(seuss, render_text->text()); | 348 EXPECT_EQ(seuss, render_text->text()); |
334 EXPECT_EQ(seuss, render_text->GetDisplayText()); | 349 EXPECT_EQ(seuss, render_text->GetDisplayText()); |
335 | 350 |
336 // TODO(benrg): No Windows implementation yet. | 351 // TODO(benrg): No Windows implementation yet. |
337 #if !defined(OS_WIN) | 352 #if !defined(OS_WIN) |
338 | |
339 render_text->SetObscured(true); | 353 render_text->SetObscured(true); |
340 | 354 |
341 // Surrogate pairs are counted as one code point. | 355 // Surrogate pairs are counted as one code point. |
342 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; | 356 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; |
343 render_text->SetText(invalid_surrogates); | 357 render_text->SetText(invalid_surrogates); |
344 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); | 358 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); |
345 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; | 359 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; |
346 render_text->SetText(valid_surrogates); | 360 render_text->SetText(valid_surrogates); |
347 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); | 361 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); |
348 EXPECT_EQ(0U, render_text->cursor_position()); | 362 EXPECT_EQ(0U, render_text->cursor_position()); |
349 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 363 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
350 EXPECT_EQ(2U, render_text->cursor_position()); | 364 EXPECT_EQ(2U, render_text->cursor_position()); |
351 | 365 |
352 // Cursoring is independent of the underlying characters when the text is | 366 // Cursoring is independent of the underlying characters when the text is |
353 // obscured. | 367 // obscured. |
354 const wchar_t* const texts[] = { | 368 const wchar_t* const texts[] = { |
355 L"hop on pop", // word boundaries | 369 L"hop on pop", // word boundaries |
356 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2 | 370 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2 |
357 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux | 371 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux |
358 L"\x5D0\x5D1" // pure RTL | 372 L"\x5D0\x5D1" // pure RTL |
359 }; | 373 }; |
360 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) { | 374 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) { |
361 string16 text = WideToUTF16(texts[i]); | 375 string16 text = WideToUTF16(texts[i]); |
362 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); | 376 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); |
363 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); | 377 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); |
364 } | 378 } |
365 #endif // !defined(OS_WIN) | 379 #endif // !defined(OS_WIN) |
366 } | 380 } |
367 | 381 |
| 382 TEST_F(RenderTextTest, GetTextDirection) { |
| 383 const bool was_rtl = base::i18n::IsRTL(); |
| 384 // Ensure that text direction is set by the first strong character direction. |
| 385 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
| 386 for (size_t i = 0; i < 2; ++i) { |
| 387 // Toggle the application default text direction (to try each direction). |
| 388 SetRTL(!base::i18n::IsRTL()); |
| 389 |
| 390 // Blank strings (and those without directionality) default to LTR. |
| 391 render_text->SetText(string16()); |
| 392 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection()); |
| 393 render_text->SetText(ASCIIToUTF16(" ")); |
| 394 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection()); |
| 395 |
| 396 // Pure LTR. |
| 397 render_text->SetText(ASCIIToUTF16("abc")); |
| 398 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection()); |
| 399 // LTR-RTL |
| 400 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
| 401 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection()); |
| 402 // LTR-RTL-LTR. |
| 403 render_text->SetText(WideToUTF16(L"a"L"\x05d1"L"b")); |
| 404 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection()); |
| 405 // Pure RTL. |
| 406 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
| 407 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection()); |
| 408 // RTL-LTR |
| 409 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); |
| 410 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection()); |
| 411 // RTL-LTR-RTL. |
| 412 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); |
| 413 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection()); |
| 414 } |
| 415 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
| 416 } |
| 417 |
368 void RunMoveCursorLeftRightTest(RenderText* render_text, | 418 void RunMoveCursorLeftRightTest(RenderText* render_text, |
369 const std::vector<SelectionModel>& expected, | 419 const std::vector<SelectionModel>& expected, |
370 VisualCursorDirection direction) { | 420 VisualCursorDirection direction) { |
371 for (size_t i = 0; i < expected.size(); ++i) { | 421 for (size_t i = 0; i < expected.size(); ++i) { |
372 EXPECT_EQ(expected[i], render_text->selection_model()); | 422 EXPECT_EQ(expected[i], render_text->selection_model()); |
373 render_text->MoveCursor(CHARACTER_BREAK, direction, false); | 423 render_text->MoveCursor(CHARACTER_BREAK, direction, false); |
374 } | 424 } |
375 // Check that cursoring is clamped at the line edge. | 425 // Check that cursoring is clamped at the line edge. |
376 EXPECT_EQ(expected.back(), render_text->selection_model()); | 426 EXPECT_EQ(expected.back(), render_text->selection_model()); |
377 // Check that it is the line edge. | 427 // Check that it is the line edge. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 502 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
453 } | 503 } |
454 | 504 |
455 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { | 505 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { |
456 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 506 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
457 // Pure RTL. | 507 // Pure RTL. |
458 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); | 508 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
459 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 509 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
460 std::vector<SelectionModel> expected; | 510 std::vector<SelectionModel> expected; |
461 | 511 |
462 #if defined(OS_LINUX) | |
463 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 512 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
464 #else | |
465 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | |
466 #endif | |
467 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 513 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
468 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 514 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
469 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 515 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
470 #if defined(OS_LINUX) | |
471 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 516 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
472 #else | |
473 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
474 #endif | |
475 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 517 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
476 | 518 |
477 expected.clear(); | 519 expected.clear(); |
478 | 520 |
479 #if defined(OS_LINUX) | |
480 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 521 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
481 #else | |
482 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
483 #endif | |
484 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 522 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
485 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 523 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
486 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 524 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
487 #if defined(OS_LINUX) | |
488 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 525 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
489 #else | |
490 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | |
491 #endif | |
492 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 526 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
493 } | 527 } |
494 | 528 |
495 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { | 529 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { |
496 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 530 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
497 // RTL-LTR | 531 // RTL-LTR |
498 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); | 532 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); |
499 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 533 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
500 std::vector<SelectionModel> expected; | 534 std::vector<SelectionModel> expected; |
501 #if defined(OS_LINUX) | |
502 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 535 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
503 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 536 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
504 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 537 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
505 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 538 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
506 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); | 539 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); |
507 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | 540 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); |
508 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 541 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
509 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 542 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
510 #else | |
511 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | |
512 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); | |
513 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); | |
514 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | |
515 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | |
516 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | |
517 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | |
518 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
519 #endif | |
520 | |
521 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 543 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
522 | 544 |
523 expected.clear(); | 545 expected.clear(); |
524 #if defined(OS_LINUX) | |
525 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | 546 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); |
526 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | 547 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); |
527 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); | 548 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); |
528 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); | 549 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); |
529 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 550 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
530 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 551 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
531 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 552 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
532 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 553 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
533 #else | |
534 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
535 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | |
536 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | |
537 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | |
538 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); | |
539 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); | |
540 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); | |
541 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); | |
542 #endif | |
543 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 554 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
544 } | 555 } |
545 | 556 |
546 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { | 557 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { |
547 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 558 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
548 // RTL-LTR-RTL. | 559 // RTL-LTR-RTL. |
549 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); | 560 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); |
550 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); | 561 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); |
551 std::vector<SelectionModel> expected; | 562 std::vector<SelectionModel> expected; |
552 #if defined(OS_LINUX) | |
553 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 563 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
554 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | 564 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); |
555 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | 565 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); |
556 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | 566 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); |
557 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 567 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
558 #else | |
559 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | |
560 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); | |
561 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); | |
562 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); | |
563 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
564 #endif | |
565 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); | 568 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); |
566 | 569 |
567 expected.clear(); | 570 expected.clear(); |
568 #if defined(OS_LINUX) | |
569 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | 571 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); |
570 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | 572 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); |
571 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | 573 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); |
572 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | 574 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); |
573 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | 575 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); |
574 #else | |
575 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); | |
576 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); | |
577 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); | |
578 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); | |
579 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); | |
580 #endif | |
581 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); | 576 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); |
582 } | 577 } |
583 | 578 |
584 // TODO(xji): temporarily disable in platform Win since the complex script | 579 // TODO(xji): temporarily disable in platform Win since the complex script |
585 // characters turned into empty square due to font regression. So, not able | 580 // characters turned into empty square due to font regression. So, not able |
586 // to test 2 characters belong to the same grapheme. | 581 // to test 2 characters belong to the same grapheme. |
587 #if defined(OS_LINUX) | 582 #if defined(OS_LINUX) |
588 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { | 583 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { |
589 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 584 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
590 | 585 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); | 694 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); |
700 | 695 |
701 struct { | 696 struct { |
702 string16 text; | 697 string16 text; |
703 base::i18n::TextDirection expected_text_direction; | 698 base::i18n::TextDirection expected_text_direction; |
704 } cases[] = { | 699 } cases[] = { |
705 { string16(), base::i18n::LEFT_TO_RIGHT }, | 700 { string16(), base::i18n::LEFT_TO_RIGHT }, |
706 { kLatin, base::i18n::LEFT_TO_RIGHT }, | 701 { kLatin, base::i18n::LEFT_TO_RIGHT }, |
707 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT }, | 702 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT }, |
708 { kHindiLatin, base::i18n::LEFT_TO_RIGHT }, | 703 { kHindiLatin, base::i18n::LEFT_TO_RIGHT }, |
709 #if defined(OS_LINUX) | |
710 // On Linux, the whole string is displayed RTL, rather than individual runs. | |
711 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT }, | 704 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT }, |
712 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, | 705 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, |
713 #else | |
714 { kRTLGrapheme, base::i18n::LEFT_TO_RIGHT }, | |
715 { kHebrewLatin, base::i18n::LEFT_TO_RIGHT }, | |
716 #endif | |
717 }; | 706 }; |
718 | 707 |
719 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete | 708 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete |
720 // font support for some scripts - http://crbug.com/106450 | 709 // font support for some scripts - http://crbug.com/106450 |
721 #if defined(OS_WIN) | 710 #if defined(OS_WIN) |
722 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 711 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
723 return; | 712 return; |
724 #endif | 713 #endif |
725 | 714 |
726 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 715 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 // Ensure that the text will pan to fill its expanding display rectangle. | 1169 // Ensure that the text will pan to fill its expanding display rectangle. |
1181 render_text->SetDisplayRect(Rect(width - 5, 1)); | 1170 render_text->SetDisplayRect(Rect(width - 5, 1)); |
1182 EXPECT_EQ(render_text->display_rect().width() - 1, | 1171 EXPECT_EQ(render_text->display_rect().width() - 1, |
1183 render_text->GetUpdatedCursorBounds().x()); | 1172 render_text->GetUpdatedCursorBounds().x()); |
1184 | 1173 |
1185 // Ensure that a sufficiently large display rectangle shows all the text. | 1174 // Ensure that a sufficiently large display rectangle shows all the text. |
1186 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1175 render_text->SetDisplayRect(Rect(width + 10, 1)); |
1187 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); | 1176 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); |
1188 } | 1177 } |
1189 | 1178 |
1190 // TODO(asvitkine): This test fails on desktop Linux. http://crbug.com/134009 | |
1191 #if !defined(OS_LINUX) || defined(OS_CHROMEOS) | |
1192 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { | 1179 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { |
1193 // Set the locale to Hebrew for RTL UI. | 1180 // Set the application default text direction to RTL. |
1194 std::string locale = l10n_util::GetApplicationLocale(""); | 1181 const bool was_rtl = base::i18n::IsRTL(); |
1195 base::i18n::SetICUDefaultLocale("he"); | 1182 SetRTL(true); |
1196 | 1183 |
1197 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); | 1184 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); |
1198 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); | 1185 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); |
1199 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); | 1186 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); |
1200 int width = render_text->GetStringSize().width(); | 1187 int width = render_text->GetStringSize().width(); |
1201 ASSERT_GT(width, 10); | 1188 ASSERT_GT(width, 10); |
1202 | 1189 |
1203 // Ensure that the cursor is placed at the width of its preceding text. | 1190 // Ensure that the cursor is placed at the width of its preceding text. |
1204 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1191 render_text->SetDisplayRect(Rect(width + 10, 1)); |
1205 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1192 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1224 |
1238 // Ensure that the text will pan to fill its expanding display rectangle. | 1225 // Ensure that the text will pan to fill its expanding display rectangle. |
1239 render_text->SetDisplayRect(Rect(width - 5, 1)); | 1226 render_text->SetDisplayRect(Rect(width - 5, 1)); |
1240 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); | 1227 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); |
1241 | 1228 |
1242 // Ensure that a sufficiently large display rectangle shows all the text. | 1229 // Ensure that a sufficiently large display rectangle shows all the text. |
1243 render_text->SetDisplayRect(Rect(width + 10, 1)); | 1230 render_text->SetDisplayRect(Rect(width + 10, 1)); |
1244 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1231 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
1245 render_text->GetUpdatedCursorBounds().x()); | 1232 render_text->GetUpdatedCursorBounds().x()); |
1246 | 1233 |
1247 // Reset locale. | 1234 // Reset the application default text direction to LTR. |
1248 base::i18n::SetICUDefaultLocale(locale); | 1235 SetRTL(was_rtl); |
| 1236 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
1249 } | 1237 } |
1250 #endif // !defined(OS_LINUX) || defined(OS_CHROMEOS) | |
1251 | 1238 |
1252 } // namespace gfx | 1239 } // namespace gfx |
OLD | NEW |