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

Side by Side Diff: ui/base/cocoa/three_part_image_unittest.mm

Issue 918533005: Mac: Optimize TabView drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split ThreePartImage Created 5 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "base/memory/scoped_ptr.h"
6 #include "ui/base/cocoa/three_part_image.h"
Robert Sesek 2015/02/12 21:56:37 This should be the first #include and then separat
Andre 2015/02/12 22:10:37 Done.
7 #include "testing/gtest_mac.h"
8 #import "ui/gfx/test/ui_cocoa_test_helper.h"
9 #include "ui/resources/grit/ui_resources.h"
10
11 #define EXPECT_EQ_RECT(a, b) \
Robert Sesek 2015/02/12 21:56:37 There's EXPECT_NSRECT_EQ.
Andre 2015/02/12 22:10:38 Done.
12 EXPECT_NSEQ(NSStringFromRect(a), NSStringFromRect(b))
13
14 namespace ui {
15 namespace test {
16
17 TEST(ThreePartImageTest, GetRects) {
18 ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
19 IDR_BROWSER_ACTION_BADGE_CENTER,
20 IDR_BROWSER_ACTION_BADGE_RIGHT);
21 NSRect bounds = NSMakeRect(0, 0, 20, 11);
22 EXPECT_EQ_RECT(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
23 EXPECT_EQ_RECT(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
24 EXPECT_EQ_RECT(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
25 }
26
27 TEST(ThreePartImageTest, GetRectsWithoutMiddle) {
28 ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
29 0,
30 IDR_BROWSER_ACTION_BADGE_RIGHT);
31 NSRect bounds = NSMakeRect(0, 0, 20, 11);
32 EXPECT_EQ_RECT(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
33 EXPECT_EQ_RECT(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
34 EXPECT_EQ_RECT(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
35 }
36
37 TEST(ThreePartImageTest, HitTest) {
38 ThreePartImage image(IDR_BACK_ARROW, 0, IDR_FORWARD_ARROW);
39 NSRect bounds = NSMakeRect(0, 0, 512, 128);
40
41 // The middle of the arrows are hits.
42 EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds));
43 EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds));
44
45 // No middle image means the middle rect is a hit.
46 EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds));
47
48 // The corners are transparent.
49 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 0), bounds));
50 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 127), bounds));
51 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 0), bounds));
52 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 127), bounds));
53 }
54
55 } // namespace test
56 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698