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

Side by Side Diff: ui/gfx/canvas_unittest_mac.mm

Issue 23604055: [OSX] Turn on canvas_skia for OSX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « ui/gfx/canvas_mac.mm ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/canvas.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/font.h"
13 #include "ui/gfx/font_list.h"
14
15 namespace gfx {
16
17 namespace {
18
19 // Mac-specific code for string size computations. This is a verbatim copy
20 // of the old implementation that used to be in canvas_mac.mm.
21 void CanvasMac_SizeStringInt(const base::string16& text,
22 const FontList& font_list,
23 int* width,
24 int* height,
25 int line_height,
26 int flags) {
27 DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
28 DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
29
30 NSFont* native_font = font_list.GetPrimaryFont().GetNativeFont();
31 NSString* ns_string = base::SysUTF16ToNSString(text);
32 NSDictionary* attributes =
33 [NSDictionary dictionaryWithObject:native_font
34 forKey:NSFontAttributeName];
35 NSSize string_size = [ns_string sizeWithAttributes:attributes];
36 *width = string_size.width;
37 *height = font_list.GetHeight();
38 }
39
40 } // namespace
41
42 class CanvasTestMac : public testing::Test {
43 protected:
44 // Compare the size returned by Canvas::SizeStringInt to the size generated
45 // by the platform-specific version in CanvasMac_SizeStringInt. Will generate
46 // expectation failure on any mismatch. Only works for single-line text
47 // without specified line height, since that is all the platform
48 // implementation supports.
49 void CompareSizes(const char* text) {
50 const int kReallyLargeNumber = 12345678;
51 FontList font_list(font_);
52 base::string16 text16 = base::UTF8ToUTF16(text);
53
54 int mac_width = kReallyLargeNumber;
Alexei Svitkine (slow) 2013/09/13 02:06:37 Just pass in 0 instead.
groby-ooo-7-16 2013/09/13 18:09:07 I do this deliberately to catch cases where it acc
55 int mac_height = kReallyLargeNumber;
56 CanvasMac_SizeStringInt(text16, font_list, &mac_width, &mac_height, 0, 0);
57
58 int canvas_width = kReallyLargeNumber;
59 int canvas_height = kReallyLargeNumber;
60 Canvas::SizeStringInt(
61 text16, font_list, &canvas_width, &canvas_height, 0, 0);
62
63 EXPECT_NE(kReallyLargeNumber, mac_width) << "no width for " << text;
64 EXPECT_NE(kReallyLargeNumber, mac_height) << "no height for " << text;
65 EXPECT_EQ(mac_width, canvas_width) << " width for " << text;
66 EXPECT_EQ(mac_height, canvas_height) << " height for " << text;
67 }
68
69 private:
70 Font font_;
71 };
72
73 // Tests that Canvas' SizeStringInt yields result consistent with a native
74 // implementation.
75 TEST_F(CanvasTestMac, StringSizeIdenticalForSkia) {
76 CompareSizes("");
77 CompareSizes("Foo");
78 CompareSizes("Longword");
79 CompareSizes("This is a complete sentence.");
80 }
81
82 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_mac.mm ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698