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

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

Issue 384953003: RenderText: handle center-aligned text in UpdateCachedBoundsAndOffset() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added test Created 6 years, 5 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
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.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 #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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 }; 1555 };
1556 1556
1557 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(large_content_cases); i++) { 1557 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(large_content_cases); i++) {
1558 render_text->SetHorizontalAlignment(large_content_cases[i].alignment); 1558 render_text->SetHorizontalAlignment(large_content_cases[i].alignment);
1559 render_text->SetDisplayOffset(large_content_cases[i].offset); 1559 render_text->SetDisplayOffset(large_content_cases[i].offset);
1560 EXPECT_EQ(large_content_cases[i].expected_offset, 1560 EXPECT_EQ(large_content_cases[i].expected_offset,
1561 render_text->GetUpdatedDisplayOffset().x()); 1561 render_text->GetUpdatedDisplayOffset().x());
1562 } 1562 }
1563 } 1563 }
1564 1564
1565 TEST_F(RenderTextTest, DisplayOffsetForCenteredTextChangingAtEnds) {
1566 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
1567 render_text->SetText(ASCIIToUTF16("abcdefghij"));
1568 render_text->SetFontList(FontList("Arial, 13px"));
msw 2014/07/16 21:55:54 nit: can you avoid setting the font?
mohsen 2014/07/16 23:36:21 Sure, Done. That was what I saw other tests do.
1569 render_text->SetHorizontalAlignment(ALIGN_CENTER);
1570
1571 const Size display_size(render_text->GetContentWidth() / 2,
1572 render_text->font_list().GetHeight());
1573 render_text->SetDisplayRect(Rect(display_size));
1574
1575 // Move cursor to the beginning of text and check the offset.
msw 2014/07/16 21:55:54 nit: "Move the cursor" here and at line 1588.
mohsen 2014/07/16 23:36:21 Done.
1576 render_text->SetCursorPosition(0);
1577 int expected_offset =
msw 2014/07/16 21:55:54 nit: inline the |expected_offset| calculations int
mohsen 2014/07/16 23:36:21 Done.
1578 (render_text->GetContentWidth() - display_size.width()) / 2;
1579 EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x());
msw 2014/07/16 21:55:54 Hmm, is there a better way of verifying the intend
mohsen 2014/07/16 23:36:21 The intended outcome is that no extra space should
msw 2014/07/16 23:51:59 I think glyph bounds would be good indicator and e
1580
1581 // Make text shorter (by removing a character), put the cursor at the
msw 2014/07/16 21:55:54 nit: "Make the text" here and at line 1594.
mohsen 2014/07/16 23:36:21 Done.
1582 // beginning, and check the offset.
1583 render_text->SetText(render_text->text().substr(1));
1584 render_text->SetCursorPosition(0);
1585 expected_offset = (render_text->GetContentWidth() - display_size.width()) / 2;
1586 EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x());
1587
1588 // Move cursor to the end of text and check the offset.
1589 render_text->SetCursorPosition(render_text->text().length());
1590 expected_offset =
1591 (display_size.width() - render_text->GetContentWidth() - 1) / 2;
1592 EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x());
1593
1594 // Make text shorter (by removing a character), put cursor at the end, and
msw 2014/07/16 21:55:54 Instead of setting the text and cursor (which comp
mohsen 2014/07/16 23:36:21 Done, it's cleaner and more to the point of the te
1595 // check the offset.
1596 render_text->SetText(render_text->text().substr(1));
1597 render_text->SetCursorPosition(render_text->text().length());
1598 expected_offset =
1599 (display_size.width() - render_text->GetContentWidth() - 1) / 2;
1600 EXPECT_EQ(expected_offset, render_text->GetUpdatedDisplayOffset().x());
1601 }
1602
1565 TEST_F(RenderTextTest, SameFontForParentheses) { 1603 TEST_F(RenderTextTest, SameFontForParentheses) {
1566 struct { 1604 struct {
1567 const base::char16 left_char; 1605 const base::char16 left_char;
1568 const base::char16 right_char; 1606 const base::char16 right_char;
1569 } punctuation_pairs[] = { 1607 } punctuation_pairs[] = {
1570 { '(', ')' }, 1608 { '(', ')' },
1571 { '{', '}' }, 1609 { '{', '}' },
1572 { '<', '>' }, 1610 { '<', '>' },
1573 }; 1611 };
1574 struct { 1612 struct {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { 2146 for (size_t i = 0; i < arraysize(kTestStrings); ++i) {
2109 render_text->SetText(WideToUTF16(kTestStrings[i])); 2147 render_text->SetText(WideToUTF16(kTestStrings[i]));
2110 render_text->EnsureLayout(); 2148 render_text->EnsureLayout();
2111 2149
2112 for (size_t j = 0; j < render_text->text().length(); ++j) 2150 for (size_t j = 0; j < render_text->text().length(); ++j)
2113 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); 2151 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty());
2114 } 2152 }
2115 } 2153 }
2116 2154
2117 } // namespace gfx 2155 } // namespace gfx
OLDNEW
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698