Index: ios/chrome/browser/ui/util/core_text_util_unittest.mm |
diff --git a/ios/chrome/browser/ui/util/core_text_util_unittest.mm b/ios/chrome/browser/ui/util/core_text_util_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..30e281fa1c132a078bbc94364bc34307c2345f0d |
--- /dev/null |
+++ b/ios/chrome/browser/ui/util/core_text_util_unittest.mm |
@@ -0,0 +1,64 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/chrome/browser/ui/util/core_text_util.h" |
+ |
+#import "base/mac/scoped_nsobject.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/gtest_mac.h" |
+#include "testing/platform_test.h" |
+ |
+namespace { |
+ |
+// TODO(crbug.com/601772): Add tests for other core_text_util tests. |
+ |
+// Tests that the minimum line height attribute is reflected in GetLineHeight(). |
+TEST(CoreTextUtilTest, MinLineHeightText) { |
+ CGFloat min_line_height = 30.0; |
+ base::scoped_nsobject<NSMutableParagraphStyle> style( |
+ [[NSMutableParagraphStyle alloc] init]); |
+ [style setMinimumLineHeight:min_line_height]; |
+ base::scoped_nsobject<NSMutableAttributedString> str( |
+ [[NSMutableAttributedString alloc] |
+ initWithString:@"test" |
+ attributes:@{NSParagraphStyleAttributeName : style}]); |
+ ASSERT_EQ(min_line_height, |
+ core_text_util::GetLineHeight(str, NSMakeRange(0, [str length]))); |
+} |
+ |
+// Tests that the maximum line height attribute is reflected in GetLineHeight(). |
+TEST(CoreTextUtilTest, MaxLineHeightText) { |
+ CGFloat max_line_height = 10.0; |
+ base::scoped_nsobject<NSMutableParagraphStyle> style( |
+ [[NSMutableParagraphStyle alloc] init]); |
+ [style setMaximumLineHeight:max_line_height]; |
+ base::scoped_nsobject<NSMutableAttributedString> str( |
+ [[NSMutableAttributedString alloc] |
+ initWithString:@"test" |
+ attributes:@{NSParagraphStyleAttributeName : style}]); |
+ ASSERT_EQ(max_line_height, |
+ core_text_util::GetLineHeight(str, NSMakeRange(0, [str length]))); |
+} |
+ |
+// Tests that the line height multiple attribute is reflected in |
+// GetLineHeight(). |
+TEST(CoreTextUtilTest, LineHeightMultipleTest) { |
+ UIFont* font = [UIFont systemFontOfSize:20.0]; |
+ CGFloat font_line_height = font.ascender - font.descender; |
+ CGFloat line_height_multiple = 2.0; |
+ base::scoped_nsobject<NSMutableParagraphStyle> style( |
+ [[NSMutableParagraphStyle alloc] init]); |
+ [style setLineHeightMultiple:line_height_multiple]; |
+ base::scoped_nsobject<NSMutableAttributedString> str( |
+ [[NSMutableAttributedString alloc] |
+ initWithString:@"test" |
+ attributes:@{ |
+ NSParagraphStyleAttributeName : style, |
+ NSFontAttributeName : font |
+ }]); |
+ ASSERT_EQ(font_line_height * line_height_multiple, |
+ core_text_util::GetLineHeight(str, NSMakeRange(0, [str length]))); |
+} |
+ |
+} // namespace |