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

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

Issue 312233003: Add fade eliding for Views Labels; related cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refine alignment check; minor additional cleanup. Created 6 years, 6 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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/text_constants.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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x2026\x200E" , true }, 439 { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x2026\x200E" , true },
440 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , true }, 440 { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , true },
441 }; 441 };
442 442
443 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); 443 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance());
444 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); 444 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
445 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100)); 445 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100));
446 446
447 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 447 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
448 render_text->SetFontList(FontList("serif, Sans serif, 12px")); 448 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
449 render_text->SetElideBehavior(ELIDE_AT_END); 449 render_text->SetElideBehavior(ELIDE_TAIL);
450 450
451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
452 // Compute expected width 452 // Compute expected width
453 expected_render_text->SetText(WideToUTF16(cases[i].layout_text)); 453 expected_render_text->SetText(WideToUTF16(cases[i].layout_text));
454 int expected_width = expected_render_text->GetContentWidth(); 454 int expected_width = expected_render_text->GetContentWidth();
455 455
456 base::string16 input = WideToUTF16(cases[i].text); 456 base::string16 input = WideToUTF16(cases[i].text);
457 // Extend the input text to ensure that it is wider than the layout_text, 457 // Extend the input text to ensure that it is wider than the layout_text,
458 // and so it will get elided. 458 // and so it will get elided.
459 if (cases[i].elision_expected) 459 if (cases[i].elision_expected)
(...skipping 10 matching lines...) Expand all
470 } 470 }
471 471
472 TEST_F(RenderTextTest, ElidedObscuredText) { 472 TEST_F(RenderTextTest, ElidedObscuredText) {
473 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); 473 scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance());
474 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); 474 expected_render_text->SetFontList(FontList("serif, Sans serif, 12px"));
475 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100)); 475 expected_render_text->SetDisplayRect(Rect(0, 0, 9999, 100));
476 expected_render_text->SetText(WideToUTF16(L"**\x2026")); 476 expected_render_text->SetText(WideToUTF16(L"**\x2026"));
477 477
478 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 478 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
479 render_text->SetFontList(FontList("serif, Sans serif, 12px")); 479 render_text->SetFontList(FontList("serif, Sans serif, 12px"));
480 render_text->SetElideBehavior(ELIDE_AT_END); 480 render_text->SetElideBehavior(ELIDE_TAIL);
481 render_text->SetDisplayRect( 481 render_text->SetDisplayRect(
482 Rect(0, 0, expected_render_text->GetContentWidth(), 100)); 482 Rect(0, 0, expected_render_text->GetContentWidth(), 100));
483 render_text->SetObscured(true); 483 render_text->SetObscured(true);
484 render_text->SetText(WideToUTF16(L"abcdef")); 484 render_text->SetText(WideToUTF16(L"abcdef"));
485 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); 485 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text());
486 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText()); 486 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText());
487 } 487 }
488 488
489 TEST_F(RenderTextTest, TruncatedText) { 489 TEST_F(RenderTextTest, TruncatedText) {
490 struct { 490 struct {
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 render_text->SetText(WideToUTF16(L"x \x25B6 y")); 1918 render_text->SetText(WideToUTF16(L"x \x25B6 y"));
1919 render_text->EnsureLayout(); 1919 render_text->EnsureLayout();
1920 ASSERT_EQ(3U, render_text->runs_.size()); 1920 ASSERT_EQ(3U, render_text->runs_.size());
1921 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range); 1921 EXPECT_EQ(Range(0, 2), render_text->runs_[0]->range);
1922 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range); 1922 EXPECT_EQ(Range(2, 3), render_text->runs_[1]->range);
1923 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range); 1923 EXPECT_EQ(Range(3, 5), render_text->runs_[2]->range);
1924 } 1924 }
1925 #endif // defined(OS_WIN) 1925 #endif // defined(OS_WIN)
1926 1926
1927 } // namespace gfx 1927 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/text_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698