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

Side by Side Diff: ios/chrome/browser/ui/first_run/first_run_util_unittest.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <UIKit/UIKit.h>
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "ios/chrome/browser/ui/first_run/first_run_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace {
12
13 TEST(UICommonTest, TestFixOrphanWord) {
14 NSString* englishString =
15 @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempus"
16 " dignissim congue. Morbi pulvinar vitae purus at mollis. Sed laoreet "
17 "euismod neque, eget laoreet nisi porttitor sed.";
18 NSString* englishStringWithOrphan =
19 @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempus"
20 " dignissim congue. Morbi pulvinar vitae purus at mollis. Sed laoreet "
21 "euismod neque, eget laoreet nisi.";
22 // TODO(crbug.com/675342): clang_format does a poor job here. Remove when
23 // fixed in clang_format.
24 // clang-format off
25 NSString* chineseString =
26 @"那只敏捷的棕色狐狸跃过那只懒狗。那只敏捷的棕色狐狸跃过那只懒狗。"
27 "那只敏捷的棕色狐狸跃过那只懒狗。那只敏捷的棕色狐狸跃过那只懒狗。"
28 "那只敏捷的棕色狐狸跃过那只懒狗。那只敏捷的棕色狐狸跃过那只懒狗。";
29 NSString* chineseStringWithOrphan =
30 @"那只敏捷的棕色狐狸跃过那只懒狗。那只敏捷的棕色狐狸跃过那只懒狗。"
31 "那只敏捷的棕色狐狸跃过那只懒狗。快速狐狸";
32 // clang-format on
33
34 base::scoped_nsobject<UILabel> label(
35 [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 500)]);
36 [label setText:englishString];
37 ios_internal::FixOrphanWord(label);
38 NSRange range = [[label text] rangeOfString:@"\n"];
39 // Check that the label's text does not contain a newline.
40 EXPECT_EQ(NSNotFound, static_cast<NSInteger>(range.location));
41
42 [label setText:englishStringWithOrphan];
43 ios_internal::FixOrphanWord(label);
44 range = [[label text] rangeOfString:@"\n"];
45 // Check that the label's text contains a newline.
46 EXPECT_NE(NSNotFound, static_cast<NSInteger>(range.location));
47
48 // Check the words after the newline.
49 NSString* wordsAfterNewline =
50 [[label text] substringFromIndex:(range.location + range.length)];
51 EXPECT_TRUE([@"laoreet nisi." isEqualToString:wordsAfterNewline]);
52
53 [label setText:chineseString];
54 ios_internal::FixOrphanWord(label);
55 range = [[label text] rangeOfString:@"\n"];
56 // Check that the label's text does not contain a newline.
57 EXPECT_EQ(NSNotFound, static_cast<NSInteger>(range.location));
58
59 [label setText:chineseStringWithOrphan];
60 ios_internal::FixOrphanWord(label);
61 range = [[label text] rangeOfString:@"\n"];
62 // Check that the label's text contains a newline.
63 ASSERT_NE(NSNotFound, static_cast<NSInteger>(range.location));
64
65 // Check the words after the newline.
66 wordsAfterNewline =
67 [[label text] substringFromIndex:(range.location + range.length)];
68 EXPECT_TRUE([@"快速狐狸" isEqualToString:wordsAfterNewline]);
69 }
70 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/first_run/first_run_util.mm ('k') | ios/chrome/browser/ui/first_run/static_file_view_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698