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 <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 Loading... | |
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) { | |
msw
2013/12/12 19:28:29
I think this test might be too fragile with hard-c
Anuj
2013/12/13 01:23:50
Done.
| |
404 // TODO(skanuj) : Add more test cases, possibly covering styles. | |
405 // To add more test cases, add a new case with large expected width. | |
406 // Uncomment the log statements below and find the actual width for | |
407 // layout_text, and update the test case. | |
408 struct { | |
409 const wchar_t* text; | |
410 const wchar_t* layout_text; | |
411 const int width; | |
412 } cases[] = { | |
413 // Strings shorter than the elision width should be laid out in full. | |
414 { L"", L"" , 30}, | |
msw
2013/12/12 19:28:29
nit: align the comments after the preceding entry:
Anuj
2013/12/13 01:23:50
Didn't understand.
msw
2013/12/13 01:56:08
D'oh I meant "align the commas", so that the comma
Anuj
2013/12/13 02:23:45
Done.
| |
415 { kWeak, kWeak , 30}, | |
416 { kLtr, kLtr , 30}, | |
417 { kLtrRtl, kLtrRtl , 30}, | |
418 { kLtrRtlLtr, kLtrRtlLtr , 30}, | |
419 { kRtl, kRtl , 30}, | |
420 { kRtlLtr, kRtlLtr , 30}, | |
421 { kRtlLtrRtl, kRtlLtrRtl , 30}, | |
422 // Strings as long as the elision width should be laid out in full. | |
423 { L"012ab", L"012ab" , 40}, | |
424 // Long strings should be elided with an ellipsis appended at the end. | |
425 { L"012" L"abc", L"012a\x2026" , 44}, | |
msw
2013/12/12 19:28:29
nit: align the strings within each commented secti
Anuj
2013/12/13 01:23:50
For the record, I find this column formatting insa
msw
2013/12/13 01:56:08
I think it makes reading test cases easier :)
Anuj
2013/12/13 02:23:45
Looks like I have some motivation to hack on clang
| |
426 { L"012" L"ab" L"\x5d0\x5d1", L"012a\x2026" , 44}, | |
427 { L"012" L"a" L"\x5d1" L"b", L"012a\x2026" , 44}, | |
428 { L"01" L"\x5d0\x5d1\x5d2" L"ab", L"01\x5d0\x5d1\x2026" , 37}, | |
429 { L"ab" L"\x5d0\x5d1\x5d2" L"ab", L"ab\x5d0\x5d1\x2026\x200f" , 39}, | |
430 // Surrogate pairs should be elided reasonably enough. | |
431 { L"0123\x0915\x093f" L"abcd", L"0123\x0915\x2026" , 50}, | |
432 { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8" , 14}, | |
433 { L"0\x05e9\x05bc\x05c1\x05b8" L"ab", L"0\x05e9\x05bc\x2026" , 26}, | |
434 { L"01\x05e9\x05bc\x05c1\x05b8" L"ab", L"01\x05e9\x2026" , 32}, | |
435 { L"012\x05e9\x05bc\x05c1\x05b8" L"ab", L"012\x2026" , 37}, | |
436 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , 44}, | |
437 }; | |
438 | |
439 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
440 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
441 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
442 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | |
443 render_text->SetDisplayRect(gfx::Rect(0, 0, cases[i].width, 100)); | |
444 render_text->SetText(WideToUTF16(cases[i].text)); | |
445 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); | |
446 EXPECT_LE(render_text->GetContentWidth(), cases[i].width) | |
447 << "->For case " << i << ": " << cases[i].text << "\n"; | |
448 EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText()) | |
449 << "->For case " << i << ": " << cases[i].text << "\n"; | |
450 render_text->SetText(base::string16()); | |
msw
2013/12/12 19:28:29
Why is this needed?
Anuj
2013/12/13 01:23:50
To clear the layout text.
| |
451 | |
452 // render_text->SetDisplayRect(gfx::Rect(0, 0, 9000, 100)); | |
453 // render_text->SetText(WideToUTF16(cases[i].layout_text)); | |
454 // LOG(ERROR) << "Expected ContentWidth:" << render_text->GetContentWidth() | |
455 // << " case: " << i << ": " << render_text->GetLayoutText(); | |
456 // render_text->SetText(base::string16()); | |
457 } | |
458 } | |
459 | |
460 TEST_F(RenderTextTest, ElidedObscuredText) { | |
461 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
462 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
463 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
464 render_text->SetDisplayRect(gfx::Rect(0, 0, 30, 100)); | |
msw
2013/12/12 19:28:29
Ditto here, consider using the width of L"**\x2026
Anuj
2013/12/13 01:23:50
Done.
| |
465 render_text->SetObscured(true); | |
466 render_text->SetText(WideToUTF16(L"abcdef")); | |
467 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); | |
468 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText()); | |
469 } | |
470 | |
403 TEST_F(RenderTextTest, TruncatedText) { | 471 TEST_F(RenderTextTest, TruncatedText) { |
404 struct { | 472 struct { |
405 const wchar_t* text; | 473 const wchar_t* text; |
406 const wchar_t* layout_text; | 474 const wchar_t* layout_text; |
407 } cases[] = { | 475 } cases[] = { |
408 // Strings shorter than the truncation length should be laid out in full. | 476 // Strings shorter than the truncation length should be laid out in full. |
409 { L"", L"" }, | 477 { L"", L"" }, |
410 { kWeak, kWeak }, | 478 { kWeak, kWeak }, |
411 { kLtr, kLtr }, | 479 { kLtr, kLtr }, |
412 { kLtrRtl, kLtrRtl }, | 480 { kLtrRtl, kLtrRtl }, |
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1795 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1863 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
1796 render_text->EnsureLayout(); | 1864 render_text->EnsureLayout(); |
1797 ASSERT_EQ(3U, render_text->runs_.size()); | 1865 ASSERT_EQ(3U, render_text->runs_.size()); |
1798 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1866 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
1799 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1867 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
1800 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1868 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
1801 } | 1869 } |
1802 #endif // defined(OS_WIN) | 1870 #endif // defined(OS_WIN) |
1803 | 1871 |
1804 } // namespace gfx | 1872 } // namespace gfx |
OLD | NEW |