Chromium Code Reviews| 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()); | |
|
Ryan Sleevi
2011/12/15 00:45:54
Drive by: Should these be ASSERT_TRUEs instead?
KushalP
2011/12/15 01:29:26
Yes they should. Updating now.
| |
| 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(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 |
| OLD | NEW |