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

Side by Side Diff: ui/base/text/text_elider_unittest.cc

Issue 10386016: Modify ui::ElideRectangleText() to honor trailing newlines. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« base/string_util.cc ('K') | « ui/base/text/text_elider.cc ('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 // Unit tests for eliding and formatting utility functions. 5 // Unit tests for eliding and formatting utility functions.
6 6
7 #include "ui/base/text/text_elider.h" 7 #include "ui/base/text/text_elider.h"
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 { "Test Test", test_width, line_height * 2, false, "Test|Test" }, 523 { "Test Test", test_width, line_height * 2, false, "Test|Test" },
524 { "Test Test", test_width, line_height * 3, false, "Test|Test" }, 524 { "Test Test", test_width, line_height * 3, false, "Test|Test" },
525 { "Test Test", test_width * 2, line_height * 2, false, "Test|Test" }, 525 { "Test Test", test_width * 2, line_height * 2, false, "Test|Test" },
526 { "Test Test", test_width * 3, line_height, false, "Test Test" }, 526 { "Test Test", test_width * 3, line_height, false, "Test Test" },
527 { "Test\nTest", test_width * 3, line_height * 2, false, "Test|Test" }, 527 { "Test\nTest", test_width * 3, line_height * 2, false, "Test|Test" },
528 { "Te\nst Te", test_width, line_height * 3, false, "Te|st|Te" }, 528 { "Te\nst Te", test_width, line_height * 3, false, "Te|st|Te" },
529 { "\nTest", test_width, line_height * 2, false, "|Test" }, 529 { "\nTest", test_width, line_height * 2, false, "|Test" },
530 { "\nTest", test_width, line_height, true, "" }, 530 { "\nTest", test_width, line_height, true, "" },
531 { "\n\nTest", test_width, line_height * 3, false, "||Test" }, 531 { "\n\nTest", test_width, line_height * 3, false, "||Test" },
532 { "\n\nTest", test_width, line_height * 2, true, "|" }, 532 { "\n\nTest", test_width, line_height * 2, true, "|" },
533 { "Test\n", 2 * test_width, line_height * 5, false, "Test|" },
534 { "Test\n\n", 2 * test_width, line_height * 5, false, "Test||" },
535 { "Test\n\n\n", 2 * test_width, line_height * 5, false, "Test|||" },
536 { "Test\nTest\n\n", 2 * test_width, line_height * 5, false, "Test|Test||" },
537 { "Test\n\nTest\n", 2 * test_width, line_height * 5, false, "Test||Test|" },
538 { "Test\n\n\nTest", 2 * test_width, line_height * 5, false, "Test|||Test" },
539 { "Te ", test_width, line_height, false, "Te" },
540 { "Te Te Test", test_width, 3 * line_height, false, "Te|Te|Test" },
533 }; 541 };
534 542
535 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 543 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
536 std::vector<string16> lines; 544 std::vector<string16> lines;
537 EXPECT_EQ(cases[i].truncated, 545 EXPECT_EQ(cases[i].truncated,
538 ElideRectangleText(UTF8ToUTF16(cases[i].input), 546 ElideRectangleText(UTF8ToUTF16(cases[i].input),
539 font, 547 font,
540 cases[i].available_pixel_width, 548 cases[i].available_pixel_width,
541 cases[i].available_pixel_height, 549 cases[i].available_pixel_height,
542 TRUNCATE_LONG_WORDS, 550 TRUNCATE_LONG_WORDS,
543 &lines)); 551 &lines));
544 if (cases[i].output) 552 if (cases[i].output) {
545 EXPECT_EQ(cases[i].output, UTF16ToUTF8(JoinString(lines, '|'))); 553 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
546 else 554 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
547 EXPECT_TRUE(lines.empty()); 555 } else {
556 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
557 }
548 } 558 }
549 } 559 }
550 560
551 TEST(TextEliderTest, ElideRectangleTextPunctuation) { 561 TEST(TextEliderTest, ElideRectangleTextPunctuation) {
552 const gfx::Font font; 562 const gfx::Font font;
553 const int line_height = font.GetHeight(); 563 const int line_height = font.GetHeight();
554 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test")); 564 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test"));
555 const int test_t_width = font.GetStringWidth(ASCIIToUTF16("Test T")); 565 const int test_t_width = font.GetStringWidth(ASCIIToUTF16("Test T"));
556 566
557 struct TestData { 567 struct TestData {
(...skipping 14 matching lines...) Expand all
572 std::vector<string16> lines; 582 std::vector<string16> lines;
573 const WordWrapBehavior wrap_behavior = 583 const WordWrapBehavior wrap_behavior =
574 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); 584 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS);
575 EXPECT_EQ(cases[i].truncated, 585 EXPECT_EQ(cases[i].truncated,
576 ElideRectangleText(UTF8ToUTF16(cases[i].input), 586 ElideRectangleText(UTF8ToUTF16(cases[i].input),
577 font, 587 font,
578 cases[i].available_pixel_width, 588 cases[i].available_pixel_width,
579 cases[i].available_pixel_height, 589 cases[i].available_pixel_height,
580 wrap_behavior, 590 wrap_behavior,
581 &lines)); 591 &lines));
582 if (cases[i].output) 592 if (cases[i].output) {
583 EXPECT_EQ(cases[i].output, UTF16ToUTF8(JoinString(lines, '|'))); 593 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
584 else 594 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
585 EXPECT_TRUE(lines.empty()); 595 } else {
596 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
597 }
586 } 598 }
587 } 599 }
588 600
589 TEST(TextEliderTest, ElideRectangleTextLongWords) { 601 TEST(TextEliderTest, ElideRectangleTextLongWords) {
590 const gfx::Font font; 602 const gfx::Font font;
591 const int kAvailableHeight = 1000; 603 const int kAvailableHeight = 1000;
592 const string16 kElidedTesting = UTF8ToUTF16(std::string("Tes") + kEllipsis); 604 const string16 kElidedTesting = UTF8ToUTF16(std::string("Tes") + kEllipsis);
593 const int elided_width = font.GetStringWidth(kElidedTesting); 605 const int elided_width = font.GetStringWidth(kElidedTesting);
594 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test")); 606 const int test_width = font.GetStringWidth(ASCIIToUTF16("Test"));
595 607
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 643 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
632 std::vector<string16> lines; 644 std::vector<string16> lines;
633 ElideRectangleText(UTF8ToUTF16(cases[i].input), 645 ElideRectangleText(UTF8ToUTF16(cases[i].input),
634 font, 646 font,
635 cases[i].available_pixel_width, 647 cases[i].available_pixel_width,
636 kAvailableHeight, 648 kAvailableHeight,
637 cases[i].wrap_behavior, 649 cases[i].wrap_behavior,
638 &lines); 650 &lines);
639 std::string expected_output(cases[i].output); 651 std::string expected_output(cases[i].output);
640 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); 652 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis);
641 EXPECT_EQ(expected_output, UTF16ToUTF8(JoinString(lines, '|'))); 653 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
654 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!";
642 } 655 }
643 } 656 }
644 657
645 TEST(TextEliderTest, ElideRectangleString) { 658 TEST(TextEliderTest, ElideRectangleString) {
646 struct TestData { 659 struct TestData {
647 const char* input; 660 const char* input;
648 int max_rows; 661 int max_rows;
649 int max_cols; 662 int max_cols;
650 bool result; 663 bool result;
651 const char* output; 664 const char* output;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 873
861 // Test adds ... at right spot when there is not enough room to break at a 874 // Test adds ... at right spot when there is not enough room to break at a
862 // word boundary. 875 // word boundary.
863 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11))); 876 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 11)));
864 877
865 // Test completely truncates string if break is on initial whitespace. 878 // Test completely truncates string if break is on initial whitespace.
866 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2))); 879 EXPECT_EQ(L"\x2026", UTF16ToWide(TruncateString(ASCIIToUTF16(" "), 2)));
867 } 880 }
868 881
869 } // namespace ui 882 } // namespace ui
OLDNEW
« base/string_util.cc ('K') | « ui/base/text/text_elider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698