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

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

Issue 2577913004: Update a unit test so it doesn't rely on obsolete resources. (Closed)
Patch Set: compile Created 4 years 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 | « no previous file | ui/resources/default_100_percent/common/browser_action_badge_center.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/base/cocoa/three_part_image.h" 5 #include "ui/base/cocoa/three_part_image.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "testing/gtest_mac.h" 9 #include "testing/gtest_mac.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #import "ui/gfx/test/ui_cocoa_test_helper.h" 11 #import "ui/gfx/test/ui_cocoa_test_helper.h"
12 #include "ui/gfx/image/image_unittest_util.h"
12 #include "ui/resources/grit/ui_resources.h" 13 #include "ui/resources/grit/ui_resources.h"
13 14
14 namespace ui { 15 namespace ui {
15 namespace test { 16 namespace test {
16 17
17 TEST(ThreePartImageTest, GetRects) { 18 TEST(ThreePartImageTest, GetRects) {
18 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 19 const int kHeight = 11;
20 const int kLeftWidth = 3;
21 const int kMiddleWidth = 5;
22 const int kRightWidth = 7;
19 base::scoped_nsobject<NSImage> leftImage( 23 base::scoped_nsobject<NSImage> leftImage(
20 rb.GetNativeImageNamed(IDR_BROWSER_ACTION_BADGE_LEFT).CopyNSImage()); 24 gfx::test::CreateImage(kLeftWidth, kHeight).CopyNSImage());
21 base::scoped_nsobject<NSImage> middleImage( 25 base::scoped_nsobject<NSImage> middleImage(
22 rb.GetNativeImageNamed(IDR_BROWSER_ACTION_BADGE_CENTER).CopyNSImage()); 26 gfx::test::CreateImage(kMiddleWidth, kHeight).CopyNSImage());
23 base::scoped_nsobject<NSImage> rightImage( 27 base::scoped_nsobject<NSImage> rightImage(
24 rb.GetNativeImageNamed(IDR_BROWSER_ACTION_BADGE_RIGHT).CopyNSImage()); 28 gfx::test::CreateImage(kRightWidth, kHeight).CopyNSImage());
25 ThreePartImage image(leftImage, middleImage, rightImage); 29 ThreePartImage image(leftImage, middleImage, rightImage);
26 NSRect bounds = NSMakeRect(0, 0, 20, 11); 30 NSRect bounds =
27 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds)); 31 NSMakeRect(0, 0, kLeftWidth + kMiddleWidth + kRightWidth, kHeight);
28 EXPECT_NSRECT_EQ(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds)); 32 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, kLeftWidth, kHeight),
29 EXPECT_NSRECT_EQ(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds)); 33 image.GetLeftRect(bounds));
30 } 34 EXPECT_NSRECT_EQ(NSMakeRect(kLeftWidth, 0, kMiddleWidth, kHeight),
35 image.GetMiddleRect(bounds));
36 EXPECT_NSRECT_EQ(
37 NSMakeRect(kLeftWidth + kMiddleWidth, 0, kRightWidth, kHeight),
38 image.GetRightRect(bounds));
31 39
32 TEST(ThreePartImageTest, GetRectsWithoutMiddle) { 40 ThreePartImage image2(leftImage, nullptr, rightImage);
33 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 41 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, kLeftWidth, kHeight),
34 base::scoped_nsobject<NSImage> leftImage( 42 image.GetLeftRect(bounds));
35 rb.GetNativeImageNamed(IDR_BROWSER_ACTION_BADGE_LEFT).CopyNSImage()); 43 EXPECT_NSRECT_EQ(NSMakeRect(kLeftWidth, 0, kMiddleWidth, kHeight),
36 base::scoped_nsobject<NSImage> rightImage( 44 image.GetMiddleRect(bounds));
37 rb.GetNativeImageNamed(IDR_BROWSER_ACTION_BADGE_RIGHT).CopyNSImage()); 45 EXPECT_NSRECT_EQ(
38 ThreePartImage image(leftImage, nullptr, rightImage); 46 NSMakeRect(kLeftWidth + kMiddleWidth, 0, kRightWidth, kHeight),
39 NSRect bounds = NSMakeRect(0, 0, 20, 11); 47 image.GetRightRect(bounds));
40 EXPECT_NSRECT_EQ(NSMakeRect(0, 0, 4, 11), image.GetLeftRect(bounds));
41 EXPECT_NSRECT_EQ(NSMakeRect(4, 0, 12, 11), image.GetMiddleRect(bounds));
42 EXPECT_NSRECT_EQ(NSMakeRect(16, 0, 4, 11), image.GetRightRect(bounds));
43 } 48 }
44 49
45 TEST(ThreePartImageTest, HitTest) { 50 TEST(ThreePartImageTest, HitTest) {
46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 51 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
47 base::scoped_nsobject<NSImage> leftImage( 52 base::scoped_nsobject<NSImage> leftImage(
48 rb.GetNativeImageNamed(IDR_BACK_ARROW).CopyNSImage()); 53 rb.GetNativeImageNamed(IDR_BACK_ARROW).CopyNSImage());
49 base::scoped_nsobject<NSImage> rightImage( 54 base::scoped_nsobject<NSImage> rightImage(
50 rb.GetNativeImageNamed(IDR_FORWARD_ARROW).CopyNSImage()); 55 rb.GetNativeImageNamed(IDR_FORWARD_ARROW).CopyNSImage());
51 ThreePartImage image(leftImage, nullptr, rightImage); 56 ThreePartImage image(leftImage, nullptr, rightImage);
52 NSRect bounds = NSMakeRect(0, 0, 512, 128); 57 NSRect bounds = NSMakeRect(0, 0, 512, 128);
53 58
54 // The middle of the arrows are hits. 59 // The middle of the arrows are hits.
55 EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds)); 60 EXPECT_TRUE(image.HitTest(NSMakePoint(64, 64), bounds));
56 EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds)); 61 EXPECT_TRUE(image.HitTest(NSMakePoint(448, 64), bounds));
57 62
58 // No middle image means the middle rect is a hit. 63 // No middle image means the middle rect is a hit.
59 EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds)); 64 EXPECT_TRUE(image.HitTest(NSMakePoint(256, 64), bounds));
60 65
61 // The corners are transparent. 66 // The corners are transparent.
62 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 0), bounds)); 67 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 0), bounds));
63 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 127), bounds)); 68 EXPECT_FALSE(image.HitTest(NSMakePoint(0, 127), bounds));
64 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 0), bounds)); 69 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 0), bounds));
65 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 127), bounds)); 70 EXPECT_FALSE(image.HitTest(NSMakePoint(511, 127), bounds));
66 } 71 }
67 72
68 } // namespace test 73 } // namespace test
69 } // namespace ui 74 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/resources/default_100_percent/common/browser_action_badge_center.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698