OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h" |
8 | 8 |
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class ImageDecorationTest : public CocoaTest { | 14 class ImageDecorationTest : public CocoaTest { |
15 public: | 15 public: |
16 ImageDecoration decoration_; | 16 ImageDecoration decoration_; |
17 }; | 17 }; |
18 | 18 |
19 TEST_F(ImageDecorationTest, SetGetImage) { | 19 TEST_F(ImageDecorationTest, SetGetImage) { |
20 EXPECT_FALSE(decoration_.GetImage()); | 20 EXPECT_FALSE(decoration_.GetImage()); |
21 | 21 |
22 const NSSize kImageSize = NSMakeSize(20.0, 20.0); | 22 const NSSize kImageSize = NSMakeSize(20.0, 20.0); |
23 scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:kImageSize]); | 23 base::scoped_nsobject<NSImage> image( |
| 24 [[NSImage alloc] initWithSize:kImageSize]); |
24 | 25 |
25 decoration_.SetImage(image); | 26 decoration_.SetImage(image); |
26 EXPECT_EQ(decoration_.GetImage(), image); | 27 EXPECT_EQ(decoration_.GetImage(), image); |
27 | 28 |
28 decoration_.SetImage(nil); | 29 decoration_.SetImage(nil); |
29 EXPECT_FALSE(decoration_.GetImage()); | 30 EXPECT_FALSE(decoration_.GetImage()); |
30 } | 31 } |
31 | 32 |
32 TEST_F(ImageDecorationTest, GetWidthForSpace) { | 33 TEST_F(ImageDecorationTest, GetWidthForSpace) { |
33 const CGFloat kWide = 100.0; | 34 const CGFloat kWide = 100.0; |
34 const CGFloat kNarrow = 10.0; | 35 const CGFloat kNarrow = 10.0; |
35 | 36 |
36 // Decoration with no image is omitted. | 37 // Decoration with no image is omitted. |
37 EXPECT_EQ(decoration_.GetWidthForSpace(kWide), | 38 EXPECT_EQ(decoration_.GetWidthForSpace(kWide), |
38 LocationBarDecoration::kOmittedWidth); | 39 LocationBarDecoration::kOmittedWidth); |
39 | 40 |
40 const NSSize kImageSize = NSMakeSize(20.0, 20.0); | 41 const NSSize kImageSize = NSMakeSize(20.0, 20.0); |
41 scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:kImageSize]); | 42 base::scoped_nsobject<NSImage> image( |
| 43 [[NSImage alloc] initWithSize:kImageSize]); |
42 | 44 |
43 // Decoration takes up the space of the image. | 45 // Decoration takes up the space of the image. |
44 decoration_.SetImage(image); | 46 decoration_.SetImage(image); |
45 EXPECT_EQ(decoration_.GetWidthForSpace(kWide), kImageSize.width); | 47 EXPECT_EQ(decoration_.GetWidthForSpace(kWide), kImageSize.width); |
46 | 48 |
47 // If the image doesn't fit, decoration is omitted. | 49 // If the image doesn't fit, decoration is omitted. |
48 EXPECT_EQ(decoration_.GetWidthForSpace(kNarrow), | 50 EXPECT_EQ(decoration_.GetWidthForSpace(kNarrow), |
49 LocationBarDecoration::kOmittedWidth); | 51 LocationBarDecoration::kOmittedWidth); |
50 } | 52 } |
51 | 53 |
52 // TODO(shess): It would be nice to test mouse clicks and dragging, | 54 // TODO(shess): It would be nice to test mouse clicks and dragging, |
53 // but those are hard because they require a real |owner|. | 55 // but those are hard because they require a real |owner|. |
54 | 56 |
55 } // namespace | 57 } // namespace |
OLD | NEW |