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

Side by Side Diff: ui/gfx/canvas_unittest.cc

Issue 557953004: Makes GetClipBounds() return the enclosing rect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « ui/gfx/canvas.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/font_list.h" 11 #include "ui/gfx/font_list.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/rect_f.h"
14 #include "ui/gfx/skia_util.h"
12 15
13 namespace gfx { 16 namespace gfx {
14 17
15 class CanvasTest : public testing::Test { 18 class CanvasTest : public testing::Test {
16 protected: 19 protected:
17 int GetStringWidth(const char *text) { 20 int GetStringWidth(const char *text) {
18 return Canvas::GetStringWidth(base::UTF8ToUTF16(text), font_list_); 21 return Canvas::GetStringWidth(base::UTF8ToUTF16(text), font_list_);
19 } 22 }
20 23
21 gfx::Size SizeStringInt(const char *text, int width, int line_height) { 24 gfx::Size SizeStringInt(const char *text, int width, int line_height) {
(...skipping 17 matching lines...) Expand all
39 TEST_F(CanvasTest, StringWidthEmptyString) { 42 TEST_F(CanvasTest, StringWidthEmptyString) {
40 EXPECT_EQ(0, GetStringWidth("")); 43 EXPECT_EQ(0, GetStringWidth(""));
41 } 44 }
42 45
43 TEST_F(CanvasTest, StringSizeEmptyString) { 46 TEST_F(CanvasTest, StringSizeEmptyString) {
44 gfx::Size size = SizeStringInt("", 0, 0); 47 gfx::Size size = SizeStringInt("", 0, 0);
45 EXPECT_EQ(0, size.width()); 48 EXPECT_EQ(0, size.width());
46 EXPECT_GT(size.height(), 0); 49 EXPECT_GT(size.height(), 0);
47 } 50 }
48 51
52 // Verifies GetClipBounds() returns the correct value.
53 TEST_F(CanvasTest, ClipRectWithScaling) {
54 Canvas canvas(gfx::Size(200, 100), 2.25, true);
55 canvas.sk_canvas()->clipRect(RectFToSkRect(gfx::RectF(100, 0, 20, 1.7f)));
danakj 2014/09/10 18:27:16 nit: 1.2 to show it's not just rounding?
sky 2014/09/10 18:29:51 Actually, the 1.2 isn't the interesting part here.
danakj 2014/09/10 18:32:13 Ooh didn't see the scaling, ok cool :)
56 gfx::Rect clip_rect;
57 ASSERT_TRUE(canvas.GetClipBounds(&clip_rect));
58 // Use Contains() rather than Equals() as skia may extend the rect in certain
59 // directions. None-the-less the clip must contain the region we damaged.
60 EXPECT_TRUE(clip_rect.Contains(gfx::Rect(100, 0, 20, 2)));
61 }
62
49 // Line height is only supported on Skia. 63 // Line height is only supported on Skia.
50 #if defined(OS_MACOSX) || defined(OS_ANDROID) 64 #if defined(OS_MACOSX) || defined(OS_ANDROID)
51 #define MAYBE_StringSizeWithLineHeight DISABLED_StringSizeWithLineHeight 65 #define MAYBE_StringSizeWithLineHeight DISABLED_StringSizeWithLineHeight
52 #else 66 #else
53 #define MAYBE_StringSizeWithLineHeight StringSizeWithLineHeight 67 #define MAYBE_StringSizeWithLineHeight StringSizeWithLineHeight
54 #endif 68 #endif
55 69
56 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) { 70 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) {
57 gfx::Size one_line_size = SizeStringInt("Q", 0, 0); 71 gfx::Size one_line_size = SizeStringInt("Q", 0, 0);
58 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000); 72 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000);
59 EXPECT_EQ(one_line_size.width(), four_line_size.width()); 73 EXPECT_EQ(one_line_size.width(), four_line_size.width());
60 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height()); 74 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height());
61 } 75 }
62 76
63 } // namespace gfx 77 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698