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

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

Issue 23456020: Turn on canvas_skia for OSX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit test/ 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
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/base/range/range.h"
13 #include "ui/gfx/font.h"
14 #include "ui/gfx/font_list.h"
15
16 namespace {
17
18 // Mac-specific code for string size computations. Verbatim from canvas_mac.mm.
Alexei Svitkine (slow) 2013/09/06 17:01:06 Since canvas_mac.mm is going away, change the comm
groby-ooo-7-16 2013/09/06 17:51:25 Done.
19 void CanvasMac_SizeStringInt(const base::string16& text,
20 const gfx::FontList& font_list,
21 int* width,
22 int* height,
23 int line_height,
24 int flags) {
25 DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented.";
26 DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented.";
27
28 NSFont* native_font = font_list.GetPrimaryFont().GetNativeFont();
29 NSString* ns_string = base::SysUTF16ToNSString(text);
30 NSDictionary* attributes =
31 [NSDictionary dictionaryWithObject:native_font
32 forKey:NSFontAttributeName];
33 NSSize string_size = [ns_string sizeWithAttributes:attributes];
34 *width = string_size.width;
35 *height = font_list.GetHeight();
36 }
37
38 } // namespace
39
40 namespace gfx {
Alexei Svitkine (slow) 2013/09/06 17:01:06 Make this surround the anon namespace (currently y
groby-ooo-7-16 2013/09/06 17:51:25 Sigh. Bitten by debug code, again. Done. On 2013/
41
42 class CanvasMacTest : public testing::Test {
43 protected:
44 void CompareSizes(const char* text) {
Alexei Svitkine (slow) 2013/09/06 17:01:06 Add a comment.
groby-ooo-7-16 2013/09/06 17:51:25 Done.
45 gfx::FontList font_list(font_);
46 base::string16 text16 = base::UTF8ToUTF16(text);
47
48 int mac_width = -1;
49 int mac_height = -1;
50 CanvasMac_SizeStringInt(text16, font_list, &mac_width, &mac_height, 0, 0);
51
52 int canvas_width = -1;
53 int canvas_height = -1;
54 Canvas::SizeStringInt(
55 text16, font_list, &canvas_width, &canvas_height, 0, 0);
56
57 EXPECT_EQ(mac_width, canvas_width) << " width for " << text;
58 EXPECT_EQ(mac_height, canvas_height) << " height for " << text;
59 }
60
61 private:
62 gfx::Font font_;
63 };
64
65 // Tests that Canvas' SizeStringInt yields result consistent with a native
66 // implementation.
67 TEST_F(CanvasMacTest, StringSizeIdenticalForSkia) {
68 CompareSizes("");
69 CompareSizes("Foo");
70 CompareSizes("Longword");
71 CompareSizes("This is a complete sentence.");
72 }
73
74 } // gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_mac.mm ('k') | ui/ui.gyp » ('j') | ui/ui_unittests.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698