- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_folder_button_cell_unittest.mm
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.
4
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 "grit/ui_resources.h"
9 #include "ui/base/resource/resource_bundle.h"
10
11 namespace {
12
13 class BookmarkBarFolderButtonCellTest : public CocoaTest {
14 };
15
16 // Basic creation.
17 TEST_F(BookmarkBarFolderButtonCellTest, Create) {
18   base::scoped_nsobject<BookmarkBarFolderButtonCell> cell;
19   cell.reset([[BookmarkBarFolderButtonCell buttonCellForNode:nil
20                                                         text:nil
21                                                        image:nil
22                                               menuController:nil] retain]);
23   EXPECT_TRUE(cell);
24 }
25
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]);
31
32   ASSERT_TRUE(view.get());
33   ASSERT_TRUE(folder_view.get());
34
35   ResourceBundle& rb = ResourceBundle::GetSharedInstance();
36   base::scoped_nsobject<NSImage> image(
37       rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
38   ASSERT_TRUE(image.get());
39
40   base::scoped_nsobject<BookmarkButtonCell> cell(
41       [[BookmarkButtonCell alloc] initTextCell:@"Testing"]);
42   base::scoped_nsobject<BookmarkBarFolderButtonCell> folder_cell(
43       [[BookmarkBarFolderButtonCell buttonCellForNode:nil
44                                                  text:@"Testing"
45                                                 image:image
46                                        menuController:nil] retain]);
47
48   ASSERT_TRUE(cell.get());
49   ASSERT_TRUE(folder_cell.get());
50
51   [view setCell:cell.get()];
52   [folder_view setCell:folder_cell.get()];
53
54   [[test_window() contentView] addSubview:view];
55   [[test_window() contentView] addSubview:folder_view];
56
57   NSRect rect = NSMakeRect(20, 20, 20, 20);
58
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;
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 cellSize]).width;
66
67   EXPECT_LT(cell_x_without_title, cell_x_with_title);
68   EXPECT_LT(cell_width_without_title, cell_width_with_title);
69
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;
73
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;
77
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);
80 }
81
82 } // namespace