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

Side by Side Diff: ios/chrome/browser/ui/util/manual_text_framer_unittest.mm

Issue 2912863005: Use MDCTypography instead of MDFRobotoFontLoader directly. (Closed)
Patch Set: Tentative fix for ManualTextFramerTest Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ios/chrome/browser/ui/util/manual_text_framer.h" 5 #include "ios/chrome/browser/ui/util/manual_text_framer.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #import "ios/chrome/browser/ui/util/core_text_util.h" 9 #import "ios/chrome/browser/ui/util/core_text_util.h"
10 #import "ios/chrome/browser/ui/util/text_frame.h" 10 #import "ios/chrome/browser/ui/util/text_frame.h"
11 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gtest_mac.h" 13 #include "testing/gtest_mac.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support." 18 #error "This file requires ARC support."
19 #endif 19 #endif
20 20
21 namespace { 21 namespace {
22 // Copy of ManualTextFramer's alignment function. 22 void ExpectNearPoint(CGFloat value1, CGFloat value2) {
23 enum class AlignmentFunction : short { CEIL = 0, FLOOR }; 23 EXPECT_NEAR(value1, value2, 1);
24 CGFloat AlignValueToPixel(CGFloat value, AlignmentFunction function) {
25 static CGFloat scale = [[UIScreen mainScreen] scale];
26 return function == AlignmentFunction::CEIL ? ceil(value * scale) / scale
27 : floor(value * scale) / scale;
28 } 24 }
29 25
30 class ManualTextFramerTest : public PlatformTest { 26 class ManualTextFramerTest : public PlatformTest {
31 protected: 27 protected:
32 ManualTextFramerTest() { 28 ManualTextFramerTest() {
33 attributes_ = [[NSMutableDictionary alloc] init]; 29 attributes_ = [[NSMutableDictionary alloc] init];
34 string_ = [[NSMutableAttributedString alloc] init]; 30 string_ = [[NSMutableAttributedString alloc] init];
35 } 31 }
36 32
37 NSString* text() { return [string_ string]; } 33 NSString* text() { return [string_ string]; }
38 NSRange text_range() { return NSMakeRange(0, [string_ length]); } 34 NSRange text_range() { return NSMakeRange(0, [string_ length]); }
39 id<TextFrame> text_frame() { return static_cast<id<TextFrame>>(text_frame_); } 35 id<TextFrame> text_frame() { return static_cast<id<TextFrame>>(text_frame_); }
40 36
41 void SetText(NSString* text) { 37 void SetText(NSString* text) {
42 DCHECK(text.length); 38 DCHECK(text.length);
43 [[string_ mutableString] setString:text]; 39 [[string_ mutableString] setString:text];
44 } 40 }
45 41
46 void FrameTextInBounds(CGRect bounds) { 42 void FrameTextInBounds(CGRect bounds) {
47 ManualTextFramer* manual_framer = 43 ManualTextFramer* manual_framer =
48 [[ManualTextFramer alloc] initWithString:string_ inBounds:bounds]; 44 [[ManualTextFramer alloc] initWithString:string_ inBounds:bounds];
49 [manual_framer frameText]; 45 [manual_framer frameText];
50 id frame = [manual_framer textFrame]; 46 id frame = [manual_framer textFrame];
51 text_frame_ = frame; 47 text_frame_ = frame;
52 } 48 }
53 49
54 UIFont* RobotoFontWithSize(CGFloat size) { 50 UIFont* TypographyFontWithSize(CGFloat size) {
55 return [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:size]; 51 return [[MDCTypography fontLoader] regularFontOfSize:size];
56 } 52 }
57 53
58 NSParagraphStyle* CreateParagraphStyle(CGFloat line_height, 54 NSParagraphStyle* CreateParagraphStyle(CGFloat line_height,
59 NSTextAlignment alignment, 55 NSTextAlignment alignment,
60 NSLineBreakMode line_break_mode) { 56 NSLineBreakMode line_break_mode) {
61 NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init]; 57 NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init];
62 style.alignment = alignment; 58 style.alignment = alignment;
63 style.lineBreakMode = line_break_mode; 59 style.lineBreakMode = line_break_mode;
64 style.minimumLineHeight = line_height; 60 style.minimumLineHeight = line_height;
65 style.maximumLineHeight = line_height; 61 style.maximumLineHeight = line_height;
(...skipping 15 matching lines...) Expand all
81 77
82 NSMutableDictionary* attributes_; 78 NSMutableDictionary* attributes_;
83 NSMutableAttributedString* string_; 79 NSMutableAttributedString* string_;
84 id<TextFrame> text_frame_; 80 id<TextFrame> text_frame_;
85 }; 81 };
86 82
87 // Tests that newline characters cause an attributed string to be laid out on 83 // Tests that newline characters cause an attributed string to be laid out on
88 // multiple lines. 84 // multiple lines.
89 TEST_F(ManualTextFramerTest, NewlineTest) { 85 TEST_F(ManualTextFramerTest, NewlineTest) {
90 SetText(@"line one\nline two\nline three"); 86 SetText(@"line one\nline two\nline three");
91 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 87 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
92 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 88 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
93 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 89 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
94 ApplyAttributesForRange(text_range()); 90 ApplyAttributesForRange(text_range());
95 CGRect bounds = CGRectMake(0, 0, 500, 500); 91 CGRect bounds = CGRectMake(0, 0, 500, 500);
96 FrameTextInBounds(bounds); 92 FrameTextInBounds(bounds);
97 CheckForLineCountAndFramedRange(3, text_range()); 93 CheckForLineCountAndFramedRange(3, text_range());
98 } 94 }
99 95
100 // Tests that strings with no spaces fail correctly. 96 // Tests that strings with no spaces fail correctly.
101 TEST_F(ManualTextFramerTest, NoSpacesText) { 97 TEST_F(ManualTextFramerTest, NoSpacesText) {
102 // "St. Mary's church in the hollow of the white hazel near the the rapid 98 // "St. Mary's church in the hollow of the white hazel near the the rapid
103 // whirlpool of Llantysilio of the red cave." 99 // whirlpool of Llantysilio of the red cave."
104 SetText( 100 SetText(
105 @"Llanfair­pwllgwyngyll­gogery­chwyrn­drobwll­llan­tysilio­gogo­goch"); 101 @"Llanfair­pwllgwyngyll­gogery­chwyrn­drobwll­llan­tysilio­gogo­goch");
106 attributes()[NSFontAttributeName] = RobotoFontWithSize(16.0); 102 attributes()[NSFontAttributeName] = TypographyFontWithSize(16.0);
107 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 103 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
108 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 104 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
109 ApplyAttributesForRange(text_range()); 105 ApplyAttributesForRange(text_range());
110 CGRect bounds = CGRectMake(0, 0, 200, 60); 106 CGRect bounds = CGRectMake(0, 0, 200, 60);
111 FrameTextInBounds(bounds); 107 FrameTextInBounds(bounds);
112 CheckForLineCountAndFramedRange(0, NSMakeRange(0, 0)); 108 CheckForLineCountAndFramedRange(0, NSMakeRange(0, 0));
113 } 109 }
114 110
115 // Tests that multiple newlines are accounted for. Only the first three 111 // Tests that multiple newlines are accounted for. Only the first three
116 // newlines should be added to |lines_|. 112 // newlines should be added to |lines_|.
117 TEST_F(ManualTextFramerTest, MultipleNewlineTest) { 113 TEST_F(ManualTextFramerTest, MultipleNewlineTest) {
118 SetText(@"\n\n\ntext"); 114 SetText(@"\n\n\ntext");
119 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 115 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
120 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 116 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
121 ApplyAttributesForRange(text_range()); 117 ApplyAttributesForRange(text_range());
122 CGRect bounds = CGRectMake(0, 0, 500, 60); 118 CGRect bounds = CGRectMake(0, 0, 500, 60);
123 FrameTextInBounds(bounds); 119 FrameTextInBounds(bounds);
124 CheckForLineCountAndFramedRange(3, NSMakeRange(0, 3)); 120 CheckForLineCountAndFramedRange(3, NSMakeRange(0, 3));
125 } 121 }
126 122
127 // Tests that the framed range for text that will be rendered with ligatures is 123 // Tests that the framed range for text that will be rendered with ligatures is
128 // corresponds with the actual range of the text. 124 // corresponds with the actual range of the text.
129 TEST_F(ManualTextFramerTest, LigatureTest) { 125 TEST_F(ManualTextFramerTest, LigatureTest) {
130 SetText(@"fffi"); 126 SetText(@"fffi");
131 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 127 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
132 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 128 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
133 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 129 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
134 ApplyAttributesForRange(text_range()); 130 ApplyAttributesForRange(text_range());
135 CGRect bounds = CGRectMake(0, 0, 500, 20); 131 CGRect bounds = CGRectMake(0, 0, 500, 20);
136 FrameTextInBounds(bounds); 132 FrameTextInBounds(bounds);
137 CheckForLineCountAndFramedRange(1, text_range()); 133 CheckForLineCountAndFramedRange(1, text_range());
138 } 134 }
139 135
140 // Tests that ManualTextFramer correctly frames Å 136 // Tests that ManualTextFramer correctly frames Å
141 TEST_F(ManualTextFramerTest, DiacriticTest) { 137 TEST_F(ManualTextFramerTest, DiacriticTest) {
142 SetText(@"A\u030A"); 138 SetText(@"A\u030A");
143 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 139 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
144 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 140 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
145 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 141 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
146 ApplyAttributesForRange(text_range()); 142 ApplyAttributesForRange(text_range());
147 CGRect bounds = CGRectMake(0, 0, 500, 20); 143 CGRect bounds = CGRectMake(0, 0, 500, 20);
148 FrameTextInBounds(bounds); 144 FrameTextInBounds(bounds);
149 CheckForLineCountAndFramedRange(1, text_range()); 145 CheckForLineCountAndFramedRange(1, text_range());
150 } 146 }
151 147
152 // String text, attributes, and bounds are chosen to match the "Terms of 148 // String text, attributes, and bounds are chosen to match the "Terms of
153 // Service" text in WelcomeToChromeView, as the text is not properly framed by 149 // Service" text in WelcomeToChromeView, as the text is not properly framed by
154 // CTFrameSetter. http://crbug.com/537212 150 // CTFrameSetter. http://crbug.com/537212
155 TEST_F(ManualTextFramerTest, TOSTextTest) { 151 TEST_F(ManualTextFramerTest, TOSTextTest) {
156 CGRect bounds = CGRectMake(0, 0, 300.0, 40.0); 152 CGRect bounds = CGRectMake(0, 0, 300.0, 40.0);
157 NSString* const kTOSLinkText = @"Terms of Service"; 153 NSString* const kTOSLinkText = @"Terms of Service";
158 NSString* const kTOSText = 154 NSString* const kTOSText =
159 @"By using this application, you agree to Chrome’s Terms of Service."; 155 @"By using this application, you agree to Chrome’s Terms of Service.";
160 SetText(kTOSText); 156 SetText(kTOSText);
161 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 157 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
162 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 158 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
163 20.0, NSTextAlignmentCenter, NSLineBreakByTruncatingTail); 159 20.0, NSTextAlignmentCenter, NSLineBreakByTruncatingTail);
164 attributes()[NSForegroundColorAttributeName] = [UIColor blackColor]; 160 attributes()[NSForegroundColorAttributeName] = [UIColor blackColor];
165 ApplyAttributesForRange(text_range()); 161 ApplyAttributesForRange(text_range());
166 attributes()[NSForegroundColorAttributeName] = [UIColor blueColor]; 162 attributes()[NSForegroundColorAttributeName] = [UIColor blueColor];
167 ApplyAttributesForRange([kTOSText rangeOfString:kTOSLinkText]); 163 ApplyAttributesForRange([kTOSText rangeOfString:kTOSLinkText]);
168 FrameTextInBounds(bounds); 164 FrameTextInBounds(bounds);
169 CheckForLineCountAndFramedRange(2, text_range()); 165 CheckForLineCountAndFramedRange(2, text_range());
170 } 166 }
171 167
172 // Tests that the origin of a left-aligned single line is correct. 168 // Tests that the origin of a left-aligned single line is correct.
173 TEST_F(ManualTextFramerTest, SimpleOriginTest) { 169 TEST_F(ManualTextFramerTest, SimpleOriginTest) {
174 SetText(@"test"); 170 SetText(@"test");
175 UIFont* font = RobotoFontWithSize(14.0); 171 UIFont* font = TypographyFontWithSize(14.0);
176 attributes()[NSFontAttributeName] = font; 172 attributes()[NSFontAttributeName] = font;
177 CGFloat line_height = 20.0; 173 CGFloat line_height = 20.0;
178 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 174 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
179 line_height, NSTextAlignmentLeft, NSLineBreakByWordWrapping); 175 line_height, NSTextAlignmentLeft, NSLineBreakByWordWrapping);
180 ApplyAttributesForRange(text_range()); 176 ApplyAttributesForRange(text_range());
181 CGRect bounds = CGRectMake(0, 0, 500, 21); 177 CGRect bounds = CGRectMake(0, 0, 500, 21);
182 FrameTextInBounds(bounds); 178 FrameTextInBounds(bounds);
183 CheckForLineCountAndFramedRange(1, text_range()); 179 CheckForLineCountAndFramedRange(1, text_range());
184 FramedLine* line = [text_frame().lines firstObject]; 180 FramedLine* line = [text_frame().lines firstObject];
185 EXPECT_EQ(0, line.origin.x); 181 EXPECT_EQ(0, line.origin.x);
186 EXPECT_EQ( 182 ExpectNearPoint(CGRectGetHeight(bounds) - line_height - font.descender,
187 AlignValueToPixel(CGRectGetHeight(bounds) - line_height - font.descender, 183 line.origin.y);
188 AlignmentFunction::FLOOR),
189 line.origin.y);
190 } 184 }
191 185
192 // Tests that lines that are laid out in RTL are right aligned. 186 // Tests that lines that are laid out in RTL are right aligned.
193 TEST_F(ManualTextFramerTest, OriginRTLTest) { 187 TEST_F(ManualTextFramerTest, OriginRTLTest) {
194 SetText(@"\u0641\u064e\u0628\u064e\u0642\u064e\u064a\u0652\u062a\u064f\u0020" 188 SetText(@"\u0641\u064e\u0628\u064e\u0642\u064e\u064a\u0652\u062a\u064f\u0020"
195 @"\u0645\u064f\u062a\u064e\u0627\u0628\u0650\u0639\u064e\u0627\u064b" 189 @"\u0645\u064f\u062a\u064e\u0627\u0628\u0650\u0639\u064e\u0627\u064b"
196 @"\u0020\u0028\u0634\u064f\u063a\u0652\u0644\u0650\u064a\u0029\u0020" 190 @"\u0020\u0028\u0634\u064f\u063a\u0652\u0644\u0650\u064a\u0029\u0020"
197 @"\u0644\u064e\u0639\u064e\u0644\u064e\u0643\u0650\u0020\u062a\u064e" 191 @"\u0644\u064e\u0639\u064e\u0644\u064e\u0643\u0650\u0020\u062a\u064e"
198 @"\u062a\u064e\u0639\u064e\u0644\u0651\u064e\u0645\u064e\u0020\u0627" 192 @"\u062a\u064e\u0639\u064e\u0644\u0651\u064e\u0645\u064e\u0020\u0627"
199 @"\u0644\u062d\u0650\u0631\u0652\u0635\u064e\u0020\u0639\u064e\u0644" 193 @"\u0644\u062d\u0650\u0631\u0652\u0635\u064e\u0020\u0639\u064e\u0644"
200 @"\u064e\u0649\u0020\u0627\u0644\u0648\u064e\u0642\u0652\u062a\u0650" 194 @"\u064e\u0649\u0020\u0627\u0644\u0648\u064e\u0642\u0652\u062a\u0650"
201 @"\u0020\u002e\u0020\u0641\u064e\u0627\u0644\u062d\u064e\u064a\u064e" 195 @"\u0020\u002e\u0020\u0641\u064e\u0627\u0644\u062d\u064e\u064a\u064e"
202 @"\u0627\u0629\u064f"); 196 @"\u0627\u0629\u064f");
203 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 197 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
204 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 198 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
205 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 199 20.0, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
206 ApplyAttributesForRange(text_range()); 200 ApplyAttributesForRange(text_range());
207 CGRect bounds = CGRectMake(0, 0, 100.0, 60.0); 201 CGRect bounds = CGRectMake(0, 0, 100.0, 60.0);
208 FrameTextInBounds(bounds); 202 FrameTextInBounds(bounds);
209 CheckForLineCountAndFramedRange(3, text_range()); 203 CheckForLineCountAndFramedRange(3, text_range());
210 for (FramedLine* line in text_frame().lines) { 204 for (FramedLine* line in text_frame().lines) {
211 CGFloat line_width = 205 ExpectNearPoint(
212 AlignValueToPixel(core_text_util::GetTrimmedLineWidth(line.line), 206 CGRectGetMaxX(bounds),
213 AlignmentFunction::CEIL); 207 line.origin.x + core_text_util::GetTrimmedLineWidth(line.line));
214 EXPECT_EQ(CGRectGetMaxX(bounds), line.origin.x + line_width);
215 } 208 }
216 } 209 }
217 210
218 TEST_F(ManualTextFramerTest, CJKLineBreakTest) { 211 TEST_F(ManualTextFramerTest, CJKLineBreakTest) {
219 // Example from our strings. Framer will put “触摸搜索” on one line, and then 212 // Example from our strings. Framer will put “触摸搜索” on one line, and then
220 // fail to frame the second. 213 // fail to frame the second.
221 // clang-format off 214 // clang-format off
222 SetText(@"“触摸搜索”会将所选字词和当前页面(作为上下文)一起发送给 Google 搜索。" 215 SetText(@"“触摸搜索”会将所选字词和当前页面(作为上下文)一起发送给 Google 搜索。"
223 @"您可以在设置中停用此功能。"); 216 @"您可以在设置中停用此功能。");
224 // clang-format on 217 // clang-format on
225 attributes()[NSFontAttributeName] = RobotoFontWithSize(16.0); 218 attributes()[NSFontAttributeName] = TypographyFontWithSize(16.0);
226 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 219 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
227 16 * 1.15, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 220 16 * 1.15, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
228 ApplyAttributesForRange(text_range()); 221 ApplyAttributesForRange(text_range());
229 CGRect bounds = CGRectMake(0, 0, 300.0, 65.0); 222 CGRect bounds = CGRectMake(0, 0, 300.0, 65.0);
230 FrameTextInBounds(bounds); 223 FrameTextInBounds(bounds);
231 CheckForLineCountAndFramedRange(3, NSMakeRange(0, 53)); 224 CheckForLineCountAndFramedRange(3, NSMakeRange(0, 53));
232 225
233 // Example without any space-ish characters: 226 // Example without any space-ish characters:
234 // clang-format off
235 SetText(@"会将所选字词和当前页面(作为上下文)一起发送给Google搜索。" 227 SetText(@"会将所选字词和当前页面(作为上下文)一起发送给Google搜索。"
236 @"您可以在设置中停用此功能。"); 228 @"您可以在设置中停用此功能。");
237 // clang-format on 229 attributes()[NSFontAttributeName] = TypographyFontWithSize(16.0);
238 attributes()[NSFontAttributeName] = RobotoFontWithSize(16.0);
239 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 230 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
240 16 * 1.15, NSTextAlignmentNatural, NSLineBreakByWordWrapping); 231 16 * 1.15, NSTextAlignmentNatural, NSLineBreakByWordWrapping);
241 ApplyAttributesForRange(text_range()); 232 ApplyAttributesForRange(text_range());
242 FrameTextInBounds(bounds); 233 FrameTextInBounds(bounds);
243 CheckForLineCountAndFramedRange(2, NSMakeRange(0, 45)); 234 CheckForLineCountAndFramedRange(2, NSMakeRange(0, 45));
244 } 235 }
245 236
246 // Tests that paragraphs with NSTextAlignmentCenter are actually centered. 237 // Tests that paragraphs with NSTextAlignmentCenter are actually centered.
247 TEST_F(ManualTextFramerTest, CenterAlignedTest) { 238 TEST_F(ManualTextFramerTest, CenterAlignedTest) {
248 SetText(@"xxxx\nyyy\nwww"); 239 SetText(@"xxxx\nyyy\nwww");
249 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 240 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
250 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 241 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
251 20.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping); 242 20.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping);
252 ApplyAttributesForRange(text_range()); 243 ApplyAttributesForRange(text_range());
253 CGRect bounds = CGRectMake(0, 0, 200.0, 60.0); 244 CGRect bounds = CGRectMake(0, 0, 200.0, 60.0);
254 FrameTextInBounds(bounds); 245 FrameTextInBounds(bounds);
255 CheckForLineCountAndFramedRange(3, text_range()); 246 CheckForLineCountAndFramedRange(3, text_range());
256 for (FramedLine* line in text_frame().lines) { 247 for (FramedLine* line in text_frame().lines) {
257 CGFloat line_width = 248 ExpectNearPoint(CGRectGetMidX(bounds) -
258 AlignValueToPixel(core_text_util::GetTrimmedLineWidth(line.line), 249 0.5 * core_text_util::GetTrimmedLineWidth(line.line),
259 AlignmentFunction::CEIL); 250 line.origin.x);
260 EXPECT_EQ(AlignValueToPixel(CGRectGetMidX(bounds) - 0.5 * line_width,
261 AlignmentFunction::FLOOR),
262 line.origin.x);
263 } 251 }
264 } 252 }
265 253
266 // Tests that words with a large line height will not be framed if they don't 254 // Tests that words with a large line height will not be framed if they don't
267 // fit in the bounding height. 255 // fit in the bounding height.
268 TEST_F(ManualTextFramerTest, LargeLineHeightTest) { 256 TEST_F(ManualTextFramerTest, LargeLineHeightTest) {
269 SetText(@"the last word is very LARGE"); 257 SetText(@"the last word is very LARGE");
270 attributes()[NSFontAttributeName] = RobotoFontWithSize(14.0); 258 attributes()[NSFontAttributeName] = TypographyFontWithSize(14.0);
271 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 259 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
272 20.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping); 260 20.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping);
273 ApplyAttributesForRange(text_range()); 261 ApplyAttributesForRange(text_range());
274 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle( 262 attributes()[NSParagraphStyleAttributeName] = CreateParagraphStyle(
275 500.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping); 263 500.0, NSTextAlignmentCenter, NSLineBreakByWordWrapping);
276 ApplyAttributesForRange(NSMakeRange(22, 5)); // "LARGE" 264 ApplyAttributesForRange(NSMakeRange(22, 5)); // "LARGE"
277 CGRect bounds = CGRectMake(0, 0, 500, 20.0); 265 CGRect bounds = CGRectMake(0, 0, 500, 20.0);
278 FrameTextInBounds(bounds); 266 FrameTextInBounds(bounds);
279 CheckForLineCountAndFramedRange(1, NSMakeRange(0, 22)); 267 CheckForLineCountAndFramedRange(1, NSMakeRange(0, 22));
280 } 268 }
(...skipping 11 matching lines...) Expand all
292 "\u062A\u0639\u0637\u064A\u0644\u0020\u0647\u0630\u0647\u0020\u0627" 280 "\u062A\u0639\u0637\u064A\u0644\u0020\u0647\u0630\u0647\u0020\u0627"
293 "\u0644\u062E\u062F\u0645\u0627\u062A\u002E"); 281 "\u0644\u062E\u062F\u0645\u0627\u062A\u002E");
294 attributes()[NSFontAttributeName] = [UIFont systemFontOfSize:20.0]; 282 attributes()[NSFontAttributeName] = [UIFont systemFontOfSize:20.0];
295 ApplyAttributesForRange(text_range()); 283 ApplyAttributesForRange(text_range());
296 CGRect bounds = CGRectMake(0, 0, 500, 100); 284 CGRect bounds = CGRectMake(0, 0, 500, 100);
297 FrameTextInBounds(bounds); 285 FrameTextInBounds(bounds);
298 CheckForLineCountAndFramedRange(2, text_range()); 286 CheckForLineCountAndFramedRange(2, text_range());
299 } 287 }
300 288
301 } // namespace 289 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tools_menu/tools_menu_view_item.mm ('k') | ios/chrome/browser/ui/util/text_region_mapper_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698