OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" | 5 #import "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
13 #import "ui/base/test/ui_cocoa_test_helper.h" | 13 #import "ui/base/test/ui_cocoa_test_helper.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class DownArrowPopupMenuCellTest : public ui::CocoaTest { | 17 class DownArrowPopupMenuCellTest : public ui::CocoaTest { |
18 public: | 18 public: |
19 DownArrowPopupMenuCellTest() { | 19 DownArrowPopupMenuCellTest() { |
20 NSRect frame = NSMakeRect(0, 0, 50, 30); | 20 NSRect frame = NSMakeRect(0, 0, 50, 30); |
21 view_.reset([[NSButton alloc] initWithFrame:frame]); | 21 view_.reset([[NSButton alloc] initWithFrame:frame]); |
22 scoped_nsobject<DownArrowPopupMenuCell> cell( | 22 base::scoped_nsobject<DownArrowPopupMenuCell> cell( |
23 [[DownArrowPopupMenuCell alloc] initTextCell:@"Testing"]); | 23 [[DownArrowPopupMenuCell alloc] initTextCell:@"Testing"]); |
24 [view_ setCell:cell.get()]; | 24 [view_ setCell:cell.get()]; |
25 [[test_window() contentView] addSubview:view_]; } | 25 [[test_window() contentView] addSubview:view_]; } |
26 | 26 |
27 protected: | 27 protected: |
28 scoped_nsobject<NSButton> view_; | 28 base::scoped_nsobject<NSButton> view_; |
29 | 29 |
30 private: | 30 private: |
31 DISALLOW_COPY_AND_ASSIGN(DownArrowPopupMenuCellTest); | 31 DISALLOW_COPY_AND_ASSIGN(DownArrowPopupMenuCellTest); |
32 }; | 32 }; |
33 | 33 |
34 TEST_VIEW(DownArrowPopupMenuCellTest, view_) | 34 TEST_VIEW(DownArrowPopupMenuCellTest, view_) |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 // Make internal messages visible for testing | 38 // Make internal messages visible for testing |
39 @interface DownArrowPopupMenuCell (Testing) | 39 @interface DownArrowPopupMenuCell (Testing) |
40 | 40 |
41 - (NSSize)cellSize; | 41 - (NSSize)cellSize; |
42 - (NSSize)imageSize; | 42 - (NSSize)imageSize; |
43 | 43 |
44 @end | 44 @end |
45 | 45 |
46 // Test size computations, make sure they deliver correct results. | 46 // Test size computations, make sure they deliver correct results. |
47 TEST_F(DownArrowPopupMenuCellTest, Defaults) { | 47 TEST_F(DownArrowPopupMenuCellTest, Defaults) { |
48 DownArrowPopupMenuCell* cell = | 48 DownArrowPopupMenuCell* cell = |
49 static_cast<DownArrowPopupMenuCell*>([view_ cell]); | 49 static_cast<DownArrowPopupMenuCell*>([view_ cell]); |
50 ASSERT_TRUE([cell isKindOfClass:[DownArrowPopupMenuCell class]]); | 50 ASSERT_TRUE([cell isKindOfClass:[DownArrowPopupMenuCell class]]); |
51 | 51 |
52 NSRect rect = NSMakeRect(0, 0, 11, 17); | 52 NSRect rect = NSMakeRect(0, 0, 11, 17); |
53 scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:rect.size]); | 53 base::scoped_nsobject<NSImage> image( |
| 54 [[NSImage alloc] initWithSize:rect.size]); |
54 [cell setImage:image forButtonState:image_button_cell::kDefaultState]; | 55 [cell setImage:image forButtonState:image_button_cell::kDefaultState]; |
55 [view_ setTitle:@"Testing"]; | 56 [view_ setTitle:@"Testing"]; |
56 | 57 |
57 EXPECT_EQ(NSWidth(rect), [cell imageSize].width); | 58 EXPECT_EQ(NSWidth(rect), [cell imageSize].width); |
58 EXPECT_EQ(NSHeight(rect), [cell imageSize].height); | 59 EXPECT_EQ(NSHeight(rect), [cell imageSize].height); |
59 | 60 |
60 NSAttributedString* title = [cell attributedTitle]; | 61 NSAttributedString* title = [cell attributedTitle]; |
61 NSSize titleSize = [title size]; | 62 NSSize titleSize = [title size]; |
62 EXPECT_EQ(titleSize.width + [image size].width + kButtonGap, | 63 EXPECT_EQ(titleSize.width + [image size].width + kButtonGap, |
63 [cell cellSize].width); | 64 [cell cellSize].width); |
64 EXPECT_EQ(std::max(titleSize.height, [image size].height), | 65 EXPECT_EQ(std::max(titleSize.height, [image size].height), |
65 [cell cellSize].height); | 66 [cell cellSize].height); |
66 } | 67 } |
OLD | NEW |