Chromium Code Reviews| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText()); | 394 EXPECT_EQ(valid_expect_0_and_1, render_text->GetLayoutText()); |
| 395 render_text->RenderText::SetObscuredRevealIndex(2); | 395 render_text->RenderText::SetObscuredRevealIndex(2); |
| 396 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText()); | 396 EXPECT_EQ(ASCIIToUTF16("*h***"), render_text->GetLayoutText()); |
| 397 render_text->RenderText::SetObscuredRevealIndex(5); | 397 render_text->RenderText::SetObscuredRevealIndex(5); |
| 398 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; | 398 const char16 valid_expect_5_and_6[] = {'*', '*', '*', '*', 0xD800, 0xDC00, 0}; |
| 399 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); | 399 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
| 400 render_text->RenderText::SetObscuredRevealIndex(6); | 400 render_text->RenderText::SetObscuredRevealIndex(6); |
| 401 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); | 401 EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 TEST_F(RenderTextTest, ElidedText) { | |
| 405 // TODO(skanuj) : Add more test cases for following | |
| 406 // - RenderText styles. | |
| 407 // - Cross interaction of truncate, elide and obscure. | |
| 408 // - ElideText tests from text_elider.cc. | |
| 409 struct { | |
| 410 const wchar_t* text; | |
| 411 const wchar_t* layout_text; | |
| 412 } cases[] = { | |
| 413 // Strings shorter than the elision width should be laid out in full. | |
| 414 { L"" , L"" }, | |
| 415 { kWeak , kWeak }, | |
| 416 { kLtr , kLtr }, | |
| 417 { kLtrRtl , kLtrRtl }, | |
| 418 { kLtrRtlLtr , kLtrRtlLtr }, | |
| 419 { kRtl , kRtl }, | |
| 420 { kRtlLtr , kRtlLtr }, | |
| 421 { kRtlLtrRtl , kRtlLtrRtl }, | |
| 422 // Strings as long as the elision width should be laid out in full. | |
| 423 { L"012ab", L"012ab" }, | |
| 424 // Long strings should be elided with an ellipsis appended at the end. | |
| 425 { L"012" L"abc" , L"012a\x2026" }, | |
|
msw
2013/12/13 20:46:34
nit: When you re-land, you can remove all the pref
Anuj
2013/12/13 21:05:59
Why does that matter? 012 is just some random stri
msw
2013/12/13 21:17:10
It's just a nit, but I asked to keep the test simp
| |
| 426 { L"012" L"ab" L"\x5d0\x5d1" , L"012a\x2026" }, | |
| 427 { L"012" L"a" L"\x5d1" L"b" , L"012a\x2026" }, | |
| 428 { L"01" L"\x5d0\x5d1\x5d2" L"ab" , L"01\x5d0\x5d1\x2026" }, | |
| 429 { L"ab" L"\x5d0\x5d1\x5d2" L"ab" , L"ab\x5d0\x5d1\x2026\x200f" }, | |
| 430 // Surrogate pairs should be elided reasonably enough. | |
| 431 { L"0123\x0915\x093f" L"abcd" , L"0123\x0915\x2026" }, | |
|
msw
2013/12/13 20:46:34
Hmm, I missed this in the original review. In the
Anuj
2013/12/13 21:05:59
I am a native speaker of Hindi (script devanagari)
| |
| 432 { L"0\x05e9\x05bc\x05c1\x05b8" , L"0\x05e9\x05bc\x05c1\x05b8" }, | |
| 433 { L"0\x05e9\x05bc\x05c1\x05b8" L"ab" , L"0\x05e9\x05bc\x2026" }, | |
| 434 { L"01\x05e9\x05bc\x05c1\x05b8" L"ab" , L"01\x05e9\x2026" }, | |
| 435 { L"012\x05e9\x05bc\x05c1\x05b8" L"ab" , L"012\x2026" }, | |
| 436 { L"012\xF0\x9D\x84\x9E" , L"012\xF0\x2026" }, | |
|
msw
2013/12/13 20:46:34
Oddly, I don't remember why this failing test case
Anuj
2013/12/13 21:05:59
I think I will be cautious :)
| |
| 437 }; | |
| 438 | |
| 439 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); | |
| 440 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
| 441 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); | |
| 442 | |
| 443 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
| 444 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
| 445 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
| 446 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | |
| 447 expected_render_text->SetText(WideToUTF16(cases[i].layout_text)); | |
| 448 render_text->SetDisplayRect( | |
| 449 gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100)); | |
| 450 render_text->SetText(WideToUTF16(cases[i].text)); | |
| 451 EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); | |
| 452 EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText()) | |
| 453 << "->For case " << i << ": " << cases[i].text << "\n"; | |
| 454 expected_render_text->SetText(base::string16()); | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 TEST_F(RenderTextTest, ElidedObscuredText) { | |
| 459 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); | |
| 460 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
| 461 expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); | |
| 462 expected_render_text->SetText(WideToUTF16(L"**\x2026")); | |
| 463 | |
| 464 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
| 465 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | |
| 466 render_text->SetElideBehavior(gfx::ELIDE_AT_END); | |
| 467 render_text->SetDisplayRect( | |
| 468 gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100)); | |
| 469 render_text->SetObscured(true); | |
| 470 render_text->SetText(WideToUTF16(L"abcdef")); | |
| 471 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); | |
| 472 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText()); | |
| 473 } | |
| 474 | |
| 475 TEST_F(RenderTextTest, TruncatedText) { | 404 TEST_F(RenderTextTest, TruncatedText) { |
| 476 struct { | 405 struct { |
| 477 const wchar_t* text; | 406 const wchar_t* text; |
| 478 const wchar_t* layout_text; | 407 const wchar_t* layout_text; |
| 479 } cases[] = { | 408 } cases[] = { |
| 480 // Strings shorter than the truncation length should be laid out in full. | 409 // Strings shorter than the truncation length should be laid out in full. |
| 481 { L"", L"" }, | 410 { L"", L"" }, |
| 482 { kWeak, kWeak }, | 411 { kWeak, kWeak }, |
| 483 { kLtr, kLtr }, | 412 { kLtr, kLtr }, |
| 484 { kLtrRtl, kLtrRtl }, | 413 { kLtrRtl, kLtrRtl }, |
| (...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1869 render_text->SetText(WideToUTF16(L"x \x25B6 y")); | 1798 render_text->SetText(WideToUTF16(L"x \x25B6 y")); |
| 1870 render_text->EnsureLayout(); | 1799 render_text->EnsureLayout(); |
| 1871 ASSERT_EQ(3U, render_text->runs_.size()); | 1800 ASSERT_EQ(3U, render_text->runs_.size()); |
| 1872 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); | 1801 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); |
| 1873 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); | 1802 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); |
| 1874 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); | 1803 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); |
| 1875 } | 1804 } |
| 1876 #endif // defined(OS_WIN) | 1805 #endif // defined(OS_WIN) |
| 1877 | 1806 |
| 1878 } // namespace gfx | 1807 } // namespace gfx |
| OLD | NEW |