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

Unified Diff: ios/chrome/browser/ui/util/core_text_util_unittest.mm

Issue 2588733002: Upstream Chrome on iOS source code [9/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/util/core_text_util.mm ('k') | ios/chrome/browser/ui/util/label_link_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ios/chrome/browser/ui/util/core_text_util.mm ('k') | ios/chrome/browser/ui/util/label_link_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698