Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell_unittest.mm

Issue 8792001: A BookmarkBarFolderButtonCell should have the favicon aligned left when no title is provided (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: ASSERTS on pointers Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ASSERT_TRUE(view.get());
32 ASSERT_TRUE(folder_view.get());
33
34 scoped_nsobject<NSImage> image(
35 [gfx::GetCachedImageWithName(@"nav.pdf") retain]);
36 ASSERT_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 ASSERT_TRUE(cell.get());
47 ASSERT_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(20, 20, 20, 20);
56
57 [cell setBookmarkCellText:@"" image:image];
58 float cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x;
59 float cell_width_without_title = ([cell cellSize]).width;
60
61 [cell setBookmarkCellText:@"test" image:image];
62 float cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x;
63 float cell_width_with_title = ([cell cellSize]).width;
64
65 EXPECT_LT(cell_x_without_title, cell_x_with_title);
66 EXPECT_LT(cell_width_without_title, cell_width_with_title);
67
68 [folder_cell setBookmarkCellText:@"" image:image];
69 float folder_cell_x_without_title = ([cell imageRectForBounds:rect]).origin.x;
70 float folder_cell_width_without_title = ([cell cellSize]).width;
71
72 [folder_cell setBookmarkCellText:@"test" image:image];
73 float folder_cell_x_with_title = ([cell imageRectForBounds:rect]).origin.x;
74 float folder_cell_width_with_title = ([cell cellSize]).width;
75
76 EXPECT_EQ(folder_cell_x_without_title, folder_cell_x_with_title);
77 EXPECT_EQ(folder_cell_width_without_title, folder_cell_width_with_title);
78 }
79
24 } // namespace 80 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698