OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_nsobject.h" | 5 #include "base/memory/scoped_nsobject.h" |
6 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 6 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
8 #include "ui/gfx/mac/nsimage_cache.h" | |
8 | 9 |
9 namespace { | 10 namespace { |
10 | 11 |
11 class BookmarkBarFolderButtonCellTest : public CocoaTest { | 12 class BookmarkBarFolderButtonCellTest : public CocoaTest { |
12 }; | 13 }; |
13 | 14 |
14 // Basic creation. | 15 // Basic creation. |
15 TEST_F(BookmarkBarFolderButtonCellTest, Create) { | 16 TEST_F(BookmarkBarFolderButtonCellTest, Create) { |
16 scoped_nsobject<BookmarkBarFolderButtonCell> cell; | 17 scoped_nsobject<BookmarkBarFolderButtonCell> cell; |
17 cell.reset([[BookmarkBarFolderButtonCell buttonCellForNode:nil | 18 cell.reset([[BookmarkBarFolderButtonCell buttonCellForNode:nil |
18 contextMenu:nil | 19 contextMenu:nil |
19 cellText:nil | 20 cellText:nil |
20 cellImage:nil] retain]); | 21 cellImage:nil] retain]); |
21 EXPECT_TRUE(cell); | 22 EXPECT_TRUE(cell); |
22 } | 23 } |
23 | 24 |
25 TEST_F(BookmarkBarFolderButtonCellTest, FaviconPositioning) { | |
26 NSRect frame = NSMakeRect(0, 0, 50, 30); | |
27 scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]); | |
28 scoped_nsobject<NSButton> folder_view( | |
29 [[NSButton alloc] initWithFrame:frame]); | |
30 | |
31 EXPECT_TRUE(view.get()); | |
32 EXPECT_TRUE(folder_view.get()); | |
33 | |
34 scoped_nsobject<NSImage> image( | |
35 [gfx::GetCachedImageWithName(@"nav.pdf") retain]); | |
36 EXPECT_TRUE(image.get()); | |
37 | |
38 scoped_nsobject<BookmarkButtonCell> cell( | |
39 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); | |
40 scoped_nsobject<BookmarkBarFolderButtonCell> folder_cell( | |
41 [[BookmarkBarFolderButtonCell buttonCellForNode:nil | |
42 contextMenu:nil | |
43 cellText:@"Testing" | |
44 cellImage:image] retain]); | |
45 | |
46 EXPECT_TRUE(cell.get()); | |
47 EXPECT_TRUE(folder_cell.get()); | |
48 | |
49 [view setCell:cell.get()]; | |
50 [folder_view setCell:folder_cell.get()]; | |
51 | |
52 [[test_window() contentView] addSubview:view]; | |
53 [[test_window() contentView] addSubview:folder_view]; | |
54 | |
55 NSRect rect = NSMakeRect(50, 50, 50, 50); | |
56 | |
57 [cell setBookmarkCellText:@"" image:image]; | |
58 float cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x; | |
59 float cell_width_without_title = | |
60 ([cell imageRectForBounds:rect]).size.width; | |
61 EXPECT_EQ(NSImageOnly, [cell imagePosition]); | |
Ilya Sherman
2011/12/14 21:38:07
nit: Please remove these statements, as they are n
| |
62 | |
63 [cell setBookmarkCellText:@"test" image:image]; | |
64 float cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x; | |
65 float cell_width_with_title = ([cell imageRectForBounds:rect]).size.width; | |
66 EXPECT_EQ(NSImageLeft, [cell imagePosition]); | |
67 | |
68 EXPECT_NE(cell_x_without_title, cell_x_with_title); | |
Ilya Sherman
2011/12/14 21:38:07
nit: EXPECT_LT rather than EXPECT_NE
| |
69 EXPECT_EQ(cell_width_without_title, cell_width_with_title); | |
Ilya Sherman
2011/12/14 21:38:07
This currently tests that the bookmark icons withi
KushalP
2011/12/14 22:10:05
I've just looked through the NSCell and NSButton A
| |
70 | |
71 [folder_cell setBookmarkCellText:@"" image:image]; | |
72 float folder_cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x; | |
73 float folder_cell_width_without_title = | |
74 ([cell imageRectForBounds:rect]).size.width; | |
75 EXPECT_EQ(NSImageLeft, [cell imagePosition]); | |
76 | |
77 [folder_cell setBookmarkCellText:@"test" image:image]; | |
78 float folder_cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x; | |
79 float folder_cell_width_with_title = | |
80 ([cell imageRectForBounds:rect]).size.width; | |
81 EXPECT_EQ(NSImageLeft, [cell imagePosition]); | |
82 | |
83 EXPECT_EQ(folder_cell_x_without_title, folder_cell_x_with_title); | |
84 EXPECT_EQ(folder_cell_width_without_title, folder_cell_width_with_title); | |
85 } | |
86 | |
24 } // namespace | 87 } // namespace |
OLD | NEW |