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

Side by Side Diff: content/common/font_descriptor_mac_unittest.mm

Issue 6289009: [Mac] Implement the system dictionary popup by implementing NSTextInput methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Clang Created 9 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « content/common/font_descriptor_mac.mm ('k') | content/common/view_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « content/common/font_descriptor_mac.mm ('k') | content/common/view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698