| OLD | NEW |
| 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 #import <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "ios/chrome/browser/ui/util/text_region_mapper.h" | 8 #include "ios/chrome/browser/ui/util/text_region_mapper.h" |
| 9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 9 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 class TextRegionMapperTest : public PlatformTest { | 19 class TextRegionMapperTest : public PlatformTest { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 TEST_F(TextRegionMapperTest, CJKTest) { | 113 TEST_F(TextRegionMapperTest, CJKTest) { |
| 114 CGRect bounds = CGRectMake(0, 0, 345, 65); | 114 CGRect bounds = CGRectMake(0, 0, 345, 65); |
| 115 // clang-format off | 115 // clang-format off |
| 116 NSString* CJKString = | 116 NSString* CJKString = |
| 117 @"“触摸搜索”会将所选字词和当前页面(作为上下文)一起发送给 Google 搜索。" | 117 @"“触摸搜索”会将所选字词和当前页面(作为上下文)一起发送给 Google 搜索。" |
| 118 @"您可以在设置中停用此功能。"; | 118 @"您可以在设置中停用此功能。"; |
| 119 // clang-format on | 119 // clang-format on |
| 120 NSMutableDictionary* attributes = [NSMutableDictionary | 120 NSMutableDictionary* attributes = [NSMutableDictionary |
| 121 dictionaryWithDictionary:AttributesForTextAlignment(NSTextAlignmentLeft)]; | 121 dictionaryWithDictionary:AttributesForTextAlignment(NSTextAlignmentLeft)]; |
| 122 attributes[NSFontAttributeName] = | 122 attributes[NSFontAttributeName] = [MDCTypography subheadFont]; |
| 123 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]; | |
| 124 NSAttributedString* string = | 123 NSAttributedString* string = |
| 125 [[NSAttributedString alloc] initWithString:CJKString | 124 [[NSAttributedString alloc] initWithString:CJKString |
| 126 attributes:attributes]; | 125 attributes:attributes]; |
| 127 InitMapper(string, bounds); | 126 InitMapper(string, bounds); |
| 128 | 127 |
| 129 NSRange range = NSMakeRange(0, 6); // "“触摸搜索”". | 128 NSRange range = NSMakeRange(0, 6); // "“触摸搜索”". |
| 130 NSArray* rects = [_textMapper rectsForRange:range]; | 129 NSArray* rects = [_textMapper rectsForRange:range]; |
| 131 ASSERT_EQ(1UL, [rects count]); | 130 ASSERT_EQ(1UL, [rects count]); |
| 132 } | 131 } |
| 133 | 132 |
| 134 /* | 133 /* |
| 135 Further unit tests should cover additional cases: | 134 Further unit tests should cover additional cases: |
| 136 - In several languages. | 135 - In several languages. |
| 137 - Range split across line break == two rects | 136 - Range split across line break == two rects |
| 138 - Bidi text with text range across scripts gets two rects. | 137 - Bidi text with text range across scripts gets two rects. |
| 139 - Various string attributions. | 138 - Various string attributions. |
| 140 - Isolate buggy CoreText case. | 139 - Isolate buggy CoreText case. |
| 141 */ | 140 */ |
| OLD | NEW |