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.
5 #include "ui/base/cocoa/three_part_image.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest_mac.h"
9 #import "ui/gfx/test/ui_cocoa_test_helper.h"
10 #include "ui/resources/grit/ui_resources.h"
15 TEST(ThreePartImageTest, GetRects) {
16 ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
17 IDR_BROWSER_ACTION_BADGE_CENTER,
18 IDR_BROWSER_ACTION_BADGE_RIGHT);
19 NSRect bounds = NSMakeRect(0, 0, 20, 11);
20 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
21 EXPECT_NSRECT_EQ(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
22 EXPECT_NSRECT_EQ(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
25 TEST(ThreePartImageTest, GetRectsWithoutMiddle) {
26 ThreePartImage image(IDR_BROWSER_ACTION_BADGE_LEFT,
28 IDR_BROWSER_ACTION_BADGE_RIGHT);
29 NSRect bounds = NSMakeRect(0, 0, 20, 11);
30 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
31 EXPECT_NSRECT_EQ(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
32 EXPECT_NSRECT_EQ(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
35 TEST(ThreePartImageTest, HitTest) {
36 ThreePartImage image(IDR_BACK_ARROW, 0, IDR_FORWARD_ARROW);
37 NSRect bounds = NSMakeRect(0, 0, 512, 128);
39 // The middle of the arrows are hits.
40 EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds));
41 EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds));
43 // No middle image means the middle rect is a hit.
44 EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds));
46 // The corners are transparent.
47 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 0), bounds));
48 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 127), bounds));
49 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 0), bounds));
50 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 127), bounds));