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

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

Issue 112063003: Implement eliding/truncating at end in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments (Patch Set 4) Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/text_elider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText()); 393 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText());
394 render_text->RenderText::SetObscuredRevealIndex(2); 394 render_text->RenderText::SetObscuredRevealIndex(2);
395 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText()); 395 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText());
396 render_text->RenderText::SetObscuredRevealIndex(5); 396 render_text->RenderText::SetObscuredRevealIndex(5);
397 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; 397 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0};
398 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); 398 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText());
399 render_text->RenderText::SetObscuredRevealIndex(6); 399 render_text->RenderText::SetObscuredRevealIndex(6);
400 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); 400 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText());
401 } 401 }
402 402
403 TEST_F(RenderTextTest, ElidedText) {
404 // TODO(skanuj) : Add more test cases for following
405 // - RenderText styles.
406 // - Cross interaction of truncate, elide and obscure.
407 // - ElideText tests from text_elider.cc.
408 struct {
409 const wchar_t* text;
410 const wchar_t* layout_text;
411 } cases[] = {
412 // Strings shorter than the elision width should be laid out in full.
413 { L"" , L"" },
msw 2013/12/13 03:20:05 I actually wanted the opposite of this, but it's n
414 { kWeak , kWeak },
415 { kLtr , kLtr },
416 { kLtrRtl , kLtrRtl },
417 { kLtrRtlLtr , kLtrRtlLtr },
418 { kRtl , kRtl },
419 { kRtlLtr , kRtlLtr },
420 { kRtlLtrRtl , kRtlLtrRtl },
421 // Strings as long as the elision width should be laid out in full.
422 { L"012ab", L"012ab" },
423 // Long strings should be elided with an ellipsis appended at the end.
424 { L"012" L"abc" , L"012a\x2026" },
425 { L"012" L"ab" L"\x5d0\x5d1" , L"012a\x2026" },
426 { L"012" L"a" L"\x5d1" L"b" , L"012a\x2026" },
427 { L"01" L"\x5d0\x5d1\x5d2" L"ab" , L"01\x5d0\x5d1\x2026" },
428 { L"ab" L"\x5d0\x5d1\x5d2" L"ab" , L"ab\x5d0\x5d1\x2026\x200f" },
429 // Surrogate pairs should be elided reasonably enough.
430 { L"0123\x0915\x093f" L"abcd" , L"0123\x0915\x2026" },
431 { L"0\x05e9\x05bc\x05c1\x05b8" , L"0\x05e9\x05bc\x05c1\x05b8" },
432 { L"0\x05e9\x05bc\x05c1\x05b8" L"ab" , L"0\x05e9\x05bc\x2026" },
433 { L"01\x05e9\x05bc\x05c1\x05b8" L"ab" , L"01\x05e9\x2026" },
434 { L"012\x05e9\x05bc\x05c1\x05b8" L"ab" , L"012\x2026" },
435 { L"012\xF0\x9D\x84\x9E" , L"012\xF0\x2026" },
436 };
437
438 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance());
439 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
440 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100));
441
442 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
443 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
444 render_text->SetElideBehavior(gfx::ELIDE_AT_END);
445 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
446 expected_render_text->SetText(WideToUTF16(cases[i].layout_text));
447 render_text->SetDisplayRect(
448 gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100));
449 render_text->SetText(WideToUTF16(cases[i].text));
450 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text());
451 EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText())
452 << "->For case " << i << ": " << cases[i].text << "\n";
453 expected_render_text->SetText(base::string16());
454 }
455 }
456
457 TEST_F(RenderTextTest, ElidedObscuredText) {
458 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance());
459 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
460 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100));
461 expected_render_text->SetText(WideToUTF16(L"**\x2026"));
462
463 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
464 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
465 render_text->SetElideBehavior(gfx::ELIDE_AT_END);
466 render_text->SetDisplayRect(
467 gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100));
468 render_text->SetObscured(true);
469 render_text->SetText(WideToUTF16(L"abcdef"));
470 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
471 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText());
472 }
473
403 TEST_F(RenderTextTest, TruncatedText) { 474 TEST_F(RenderTextTest, TruncatedText) {
404 struct { 475 struct {
405 const wchar_t* text; 476 const wchar_t* text;
406 const wchar_t* layout_text; 477 const wchar_t* layout_text;
407 } cases[] = { 478 } cases[] = {
408 // Strings shorter than the truncation length should be laid out in full. 479 // Strings shorter than the truncation length should be laid out in full.
409 { L"", L"" }, 480 { L"", L"" },
410 { kWeak, kWeak }, 481 { kWeak, kWeak },
411 { kLtr, kLtr }, 482 { kLtr, kLtr },
412 { kLtrRtl, kLtrRtl }, 483 { kLtrRtl, kLtrRtl },
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 render_text->SetText(WideToUTF16(L"x \x25B6 y")); 1866 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
1796 render_text->EnsureLayout(); 1867 render_text->EnsureLayout();
1797 ASSERT_EQ(3U, render_text->runs_.size()); 1868 ASSERT_EQ(3U, render_text->runs_.size());
1798 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); 1869 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range);
1799 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); 1870 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range);
1800 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); 1871 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range);
1801 } 1872 }
1802 #endif // defined(OS_WIN) 1873 #endif // defined(OS_WIN)
1803 1874
1804 } // namespace gfx 1875 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/text_elider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698