1 // Copyright (c) 2012 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 "base/mac/scoped_nsobject.h"
6 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/resources/grit/ui_resources.h"
13 class BookmarkBarFolderButtonCellTest : public CocoaTest {
17 TEST_F(BookmarkBarFolderButtonCellTest, Create) {
18 base::scoped_nsobject<BookmarkBarFolderButtonCell> cell;
19 cell.reset([[BookmarkBarFolderButtonCell buttonCellForNode:nil
22 menuController:nil] retain]);
26 TEST_F(BookmarkBarFolderButtonCellTest, FaviconPositioning) {
27 NSRect frame = NSMakeRect(0, 0, 50, 30);
28 base::scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]);
29 base::scoped_nsobject<NSButton> folder_view(
30 [[NSButton alloc] initWithFrame:frame]);
32 ASSERT_TRUE(view.get());
33 ASSERT_TRUE(folder_view.get());
35 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
36 base::scoped_nsobject<NSImage> image(
37 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
38 ASSERT_TRUE(image.get());
40 base::scoped_nsobject<BookmarkButtonCell> cell(
41 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]);
42 base::scoped_nsobject<BookmarkBarFolderButtonCell> folder_cell(
43 [[BookmarkBarFolderButtonCell buttonCellForNode:nil
46 menuController:nil] retain]);
48 ASSERT_TRUE(cell.get());
49 ASSERT_TRUE(folder_cell.get());
51 [view setCell:cell.get()];
52 [folder_view setCell:folder_cell.get()];
54 [[test_window() contentView] addSubview:view];
55 [[test_window() contentView] addSubview:folder_view];
57 NSRect rect = NSMakeRect(20, 20, 20, 20);
59 [cell setBookmarkCellText:@"" image:image];
60 float cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x;
61 float cell_width_without_title = ([cell cellSize]).width;
63 [cell setBookmarkCellText:@"test" image:image];
64 float cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x;
65 float cell_width_with_title = ([cell cellSize]).width;
67 EXPECT_LT(cell_x_without_title, cell_x_with_title);
68 EXPECT_LT(cell_width_without_title, cell_width_with_title);
70 [folder_cell setBookmarkCellText:@"" image:image];
71 float folder_cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x;
72 float folder_cell_width_without_title = ([cell cellSize]).width;
74 [folder_cell setBookmarkCellText:@"test" image:image];
75 float folder_cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x;
76 float folder_cell_width_with_title = ([cell cellSize]).width;
78 EXPECT_EQ(folder_cell_x_without_title, folder_cell_x_with_title);
79 EXPECT_EQ(folder_cell_width_without_title, folder_cell_width_with_title);