diff options
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_controller_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index c75262f..671e9f1 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -10,6 +10,21 @@ #import "chrome/browser/cocoa/cocoa_test_helper.h" #include "testing/gtest/include/gtest/gtest.h" +// Pretend BookmarkURLOpener delegate to keep track of requests +@interface BookmarkURLOpenerPong : NSObject<BookmarkURLOpener> { + @public + GURL url_; +} +@end + +@implementation BookmarkURLOpenerPong +- (void)openBookmarkURL:(const GURL&)url + disposition:(WindowOpenDisposition)disposition { + url_ = url; +} +@end + + namespace { static const int kContentAreaHeight = 500; @@ -18,10 +33,15 @@ class BookmarkBarControllerTest : public testing::Test { public: BookmarkBarControllerTest() { NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight); + NSRect bar_frame = NSMakeRect(0, 0, 800, 0); content_area_.reset([[NSView alloc] initWithFrame:content_frame]); + bar_view_.reset([[NSView alloc] initWithFrame:bar_frame]); + [bar_view_ setHidden:YES]; + BookmarkBarView *bbv = (BookmarkBarView*)bar_view_.get(); bar_.reset( [[BookmarkBarController alloc] initWithProfile:helper_.profile() - contentView:content_area_.get() + view:bbv + webContentView:content_area_.get() delegate:nil]); NSView* parent = cocoa_helper_.contentView(); [parent addSubview:content_area_.get()]; @@ -30,6 +50,7 @@ class BookmarkBarControllerTest : public testing::Test { CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... scoped_nsobject<NSView> content_area_; + scoped_nsobject<NSView> bar_view_; BrowserTestHelper helper_; scoped_nsobject<BookmarkBarController> bar_; }; @@ -38,6 +59,7 @@ TEST_F(BookmarkBarControllerTest, ShowHide) { // Assume hidden by default in a new profile. EXPECT_FALSE([bar_ isBookmarkBarVisible]); EXPECT_TRUE([[bar_ view] isHidden]); + EXPECT_EQ([bar_view_ frame].size.height, 0); // Show and hide it by toggling. [bar_ toggleBookmarkBar]; @@ -45,18 +67,34 @@ TEST_F(BookmarkBarControllerTest, ShowHide) { EXPECT_FALSE([[bar_ view] isHidden]); NSRect content_frame = [content_area_ frame]; EXPECT_NE(content_frame.size.height, kContentAreaHeight); + EXPECT_GT([bar_view_ frame].size.height, 0); [bar_ toggleBookmarkBar]; EXPECT_FALSE([bar_ isBookmarkBarVisible]); EXPECT_TRUE([[bar_ view] isHidden]); content_frame = [content_area_ frame]; EXPECT_EQ(content_frame.size.height, kContentAreaHeight); + EXPECT_EQ([bar_view_ frame].size.height, 0); } -// TODO(jrg): replace getTabContents +// Confirm openBookmark: forwards the request to the controller's delegate TEST_F(BookmarkBarControllerTest, OpenBookmark) { + GURL gurl("http://walla.walla.ding.dong.com"); + scoped_ptr<BookmarkNode> node(new BookmarkNode(gurl)); + scoped_nsobject<BookmarkURLOpenerPong> pong([[BookmarkURLOpenerPong alloc] + init]); + [bar_ setDelegate:pong.get()]; + + scoped_nsobject<NSButtonCell> cell([[NSButtonCell alloc] init]); + scoped_nsobject<NSButton> button([[NSButton alloc] init]); + [button setCell:cell.get()]; + [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; + [bar_ openBookmark:button]; + + EXPECT_EQ(pong.get()->url_, node->GetURL()); } -// TODO(jrg): Make sure showing the bookmark bar calls loaded: (to process bookmarks) +// TODO(jrg): Make sure showing the bookmark bar calls loaded: (to +// process bookmarks) TEST_F(BookmarkBarControllerTest, ShowAndLoad) { } |