Chromium Code Reviews| Index: ui/gfx/canvas_mac_unittest.mm |
| diff --git a/ui/gfx/canvas_mac_unittest.mm b/ui/gfx/canvas_mac_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dda59dc063be575980a123ddb06947a239d7ada7 |
| --- /dev/null |
| +++ b/ui/gfx/canvas_mac_unittest.mm |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/canvas.h" |
| + |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/range/range.h" |
| +#include "ui/gfx/font.h" |
| +#include "ui/gfx/font_list.h" |
| + |
| +namespace { |
| + |
| +// 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.
|
| +void CanvasMac_SizeStringInt(const base::string16& text, |
| + const gfx::FontList& font_list, |
| + int* width, |
| + int* height, |
| + int line_height, |
| + int flags) { |
| + DLOG_IF(WARNING, line_height != 0) << "Line heights not implemented."; |
| + DLOG_IF(WARNING, flags & Canvas::MULTI_LINE) << "Multi-line not implemented."; |
| + |
| + NSFont* native_font = font_list.GetPrimaryFont().GetNativeFont(); |
| + NSString* ns_string = base::SysUTF16ToNSString(text); |
| + NSDictionary* attributes = |
| + [NSDictionary dictionaryWithObject:native_font |
| + forKey:NSFontAttributeName]; |
| + NSSize string_size = [ns_string sizeWithAttributes:attributes]; |
| + *width = string_size.width; |
| + *height = font_list.GetHeight(); |
| +} |
| + |
| +} // namespace |
| + |
| +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/
|
| + |
| +class CanvasMacTest : public testing::Test { |
| + protected: |
| + 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.
|
| + gfx::FontList font_list(font_); |
| + base::string16 text16 = base::UTF8ToUTF16(text); |
| + |
| + int mac_width = -1; |
| + int mac_height = -1; |
| + CanvasMac_SizeStringInt(text16, font_list, &mac_width, &mac_height, 0, 0); |
| + |
| + int canvas_width = -1; |
| + int canvas_height = -1; |
| + Canvas::SizeStringInt( |
| + text16, font_list, &canvas_width, &canvas_height, 0, 0); |
| + |
| + EXPECT_EQ(mac_width, canvas_width) << " width for " << text; |
| + EXPECT_EQ(mac_height, canvas_height) << " height for " << text; |
| + } |
| + |
| + private: |
| + gfx::Font font_; |
| +}; |
| + |
| + // Tests that Canvas' SizeStringInt yields result consistent with a native |
| + // implementation. |
| + TEST_F(CanvasMacTest, StringSizeIdenticalForSkia) { |
| + CompareSizes(""); |
| + CompareSizes("Foo"); |
| + CompareSizes("Longword"); |
| + CompareSizes("This is a complete sentence."); |
| +} |
| + |
| +} // gfx |