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

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

Issue 23622022: Revert 221930 "[OSX] Turn on canvas_skia for OSX" (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | « trunk/src/ui/gfx/canvas_mac.mm ('k') | trunk/src/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 2013 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/base/range/range.h"
13 #include "ui/gfx/font.h"
14 #include "ui/gfx/font_list.h"
15
16 namespace gfx {
17
18 namespace {
19
20 // Mac-specific code for string size computations. This is a verbatim copy
21 // of the old implementation that used to be in canvas_mac.mm.
22 void CanvasMac_SizeStringInt(const base::string16& text,
23 const gfx::FontList& font_list,
24 int* width,
25 int* height,
26 int line_height,
27 int flags) {
28 DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
29 DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
30
31 NSFont* native_font = font_list.GetPrimaryFont().GetNativeFont();
32 NSString* ns_string = base::SysUTF16ToNSString(text);
33 NSDictionary* attributes =
34 [NSDictionary dictionaryWithObject:native_font
35 forKey:NSFontAttributeName];
36 NSSize string_size = [ns_string sizeWithAttributes:attributes];
37 *width = string_size.width;
38 *height = font_list.GetHeight();
39 }
40
41 } // namespace
42
43 class CanvasTestMac : public testing::Test {
44 protected:
45 // Compare the size returned by Canvas::SizeStringInt to the size generated
46 // by the platform-specific version in CanvasMac_SizeStringInt. Will generate
47 // expectation failure on any mismatch. Only works for single-line text
48 // without specified line height, since that is all the platform
49 // implementation supports.
50 void CompareSizes(const char* text) {
51 gfx::FontList font_list(font_);
52 base::string16 text16 = base::UTF8ToUTF16(text);
53
54 int mac_width = -1;
55 int mac_height = -1;
56 CanvasMac_SizeStringInt(text16, font_list, &mac_width, &mac_height, 0, 0);
57
58 int canvas_width = -1;
59 int canvas_height = -1;
60 Canvas::SizeStringInt(
61 text16, font_list, &canvas_width, &canvas_height, 0, 0);
62
63 EXPECT_EQ(mac_width, canvas_width) << " width for " << text;
64 EXPECT_EQ(mac_height, canvas_height) << " height for " << text;
65 }
66
67 private:
68 gfx::Font font_;
69 };
70
71 // Tests that Canvas' SizeStringInt yields result consistent with a native
72 // implementation.
73 TEST_F(CanvasTestMac, StringSizeIdenticalForSkia) {
74 CompareSizes("");
75 CompareSizes("Foo");
76 CompareSizes("Longword");
77 CompareSizes("This is a complete sentence.");
78 }
79
80 } // namespace gfx
OLDNEW
« no previous file with comments | « trunk/src/ui/gfx/canvas_mac.mm ('k') | trunk/src/ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698