Chromium Code Reviews| Index: chrome/browser/cocoa/bookmark_bar_controller_unittest.mm |
| =================================================================== |
| --- chrome/browser/cocoa/bookmark_bar_controller_unittest.mm (revision 20198) |
| +++ chrome/browser/cocoa/bookmark_bar_controller_unittest.mm (working copy) |
| @@ -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 @@ |
| 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 @@ |
| 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 @@ |
| // 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 @@ |
| 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] |
|
pink (ping after 24hrs)
2009/07/09 14:19:42
the problem with converting this to a scoped objec
John Grabowski
2009/07/09 22:07:26
It's a good idea; I will follow-up in a future CL.
|
| + 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) { |
| } |