OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/font_descriptor_mac.h" | 5 #include "content/common/font_descriptor_mac.h" |
6 | 6 |
7 #include <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 // Create an NSFont via a FontDescriptor object. | 70 // Create an NSFont via a FontDescriptor object. |
71 NSFont* MakeNSFont(const std::string& font_name, float font_point_size) { | 71 NSFont* MakeNSFont(const std::string& font_name, float font_point_size) { |
72 FontDescriptor desc; | 72 FontDescriptor desc; |
73 desc.font_name = UTF8ToUTF16(font_name); | 73 desc.font_name = UTF8ToUTF16(font_name); |
74 desc.font_point_size = font_point_size; | 74 desc.font_point_size = font_point_size; |
75 return desc.nsFont(); | 75 return desc.ToNSFont(); |
76 } | 76 } |
77 | 77 |
78 // Verify that serialization and deserialization of fonts with various styles | 78 // Verify that serialization and deserialization of fonts with various styles |
79 // is performed correctly by FontDescriptor. | 79 // is performed correctly by FontDescriptor. |
80 TEST_F(FontSerializationTest, StyledFonts) { | 80 TEST_F(FontSerializationTest, StyledFonts) { |
81 NSFont* plain_font = [NSFont systemFontOfSize:12.0]; | 81 NSFont* plain_font = [NSFont systemFontOfSize:12.0]; |
82 ASSERT_TRUE(plain_font != nil); | 82 ASSERT_TRUE(plain_font != nil); |
83 FontDescriptor desc_plain(plain_font); | 83 FontDescriptor desc_plain(plain_font); |
84 EXPECT_TRUE(CompareFonts(plain_font, desc_plain.nsFont())); | 84 EXPECT_TRUE(CompareFonts(plain_font, desc_plain.ToNSFont())); |
85 | 85 |
86 NSFont* bold_font = [NSFont boldSystemFontOfSize:30.0]; | 86 NSFont* bold_font = [NSFont boldSystemFontOfSize:30.0]; |
87 ASSERT_TRUE(bold_font != nil); | 87 ASSERT_TRUE(bold_font != nil); |
88 FontDescriptor desc_bold(bold_font); | 88 FontDescriptor desc_bold(bold_font); |
89 EXPECT_TRUE(CompareFonts(bold_font, desc_bold.nsFont())); | 89 EXPECT_TRUE(CompareFonts(bold_font, desc_bold.ToNSFont())); |
90 | 90 |
91 NSFont* italic_bold_font = | 91 NSFont* italic_bold_font = |
92 [[NSFontManager sharedFontManager] | 92 [[NSFontManager sharedFontManager] |
93 fontWithFamily:base::SysUTF8ToNSString(kCourierFontName) | 93 fontWithFamily:base::SysUTF8ToNSString(kCourierFontName) |
94 traits:(NSBoldFontMask | NSItalicFontMask) | 94 traits:(NSBoldFontMask | NSItalicFontMask) |
95 weight:5 | 95 weight:5 |
96 size:18.0]; | 96 size:18.0]; |
97 ASSERT_TRUE(italic_bold_font != nil); | 97 ASSERT_TRUE(italic_bold_font != nil); |
98 FontDescriptor desc_italic_bold(italic_bold_font); | 98 FontDescriptor desc_italic_bold(italic_bold_font); |
99 EXPECT_TRUE(CompareFonts(italic_bold_font, desc_italic_bold.nsFont())); | 99 EXPECT_TRUE(CompareFonts(italic_bold_font, desc_italic_bold.ToNSFont())); |
100 } | 100 } |
101 | 101 |
102 // Test that FontDescriptor doesn't crash when used with bad parameters. | 102 // Test that FontDescriptor doesn't crash when used with bad parameters. |
103 // This is important since FontDescriptors are constructed with parameters | 103 // This is important since FontDescriptors are constructed with parameters |
104 // sent over IPC and bad values must not trigger unexpected behavior. | 104 // sent over IPC and bad values must not trigger unexpected behavior. |
105 TEST_F(FontSerializationTest, BadParameters) { | 105 TEST_F(FontSerializationTest, BadParameters) { |
106 EXPECT_NSNE(MakeNSFont(kCourierFontName, 12), nil); | 106 EXPECT_NSNE(MakeNSFont(kCourierFontName, 12), nil); |
107 EXPECT_NSNE(MakeNSFont(kCourierFontName, std::numeric_limits<float>::min()), | 107 EXPECT_NSNE(MakeNSFont(kCourierFontName, std::numeric_limits<float>::min()), |
108 nil); | 108 nil); |
109 EXPECT_NSNE(MakeNSFont(kCourierFontName, 0), nil); | 109 EXPECT_NSNE(MakeNSFont(kCourierFontName, 0), nil); |
110 EXPECT_NSNE(MakeNSFont(kCourierFontName, std::numeric_limits<float>::max()), | 110 EXPECT_NSNE(MakeNSFont(kCourierFontName, std::numeric_limits<float>::max()), |
111 nil); | 111 nil); |
112 } | 112 } |
113 | 113 |
114 } // namespace | 114 } // namespace |
OLD | NEW |