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

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_controller_unittest.mm

Issue 149308: a bunch of bookmark bar changes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 8 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #import "chrome/browser/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/cocoa/cocoa_test_helper.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 // Pretend BookmarkURLOpener delegate to keep track of requests
14 @interface BookmarkURLOpenerPong : NSObject<BookmarkURLOpener> {
15 @public
16 GURL url_;
17 }
18 @end
19
20 @implementation BookmarkURLOpenerPong
21 - (void)openBookmarkURL:(const GURL&)url
22 disposition:(WindowOpenDisposition)disposition {
23 url_ = url;
24 }
25 @end
26
27
13 namespace { 28 namespace {
14 29
15 static const int kContentAreaHeight = 500; 30 static const int kContentAreaHeight = 500;
16 31
17 class BookmarkBarControllerTest : public testing::Test { 32 class BookmarkBarControllerTest : public testing::Test {
18 public: 33 public:
19 BookmarkBarControllerTest() { 34 BookmarkBarControllerTest() {
20 NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight); 35 NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight);
36 NSRect bar_frame = NSMakeRect(0, 0, 800, 0);
21 content_area_.reset([[NSView alloc] initWithFrame:content_frame]); 37 content_area_.reset([[NSView alloc] initWithFrame:content_frame]);
38 bar_view_.reset([[NSView alloc] initWithFrame:bar_frame]);
39 [bar_view_ setHidden:YES];
40 BookmarkBarView *bbv = (BookmarkBarView*)bar_view_.get();
22 bar_.reset( 41 bar_.reset(
23 [[BookmarkBarController alloc] initWithProfile:helper_.profile() 42 [[BookmarkBarController alloc] initWithProfile:helper_.profile()
24 contentView:content_area_.get() 43 view:bbv
44 webContentView:content_area_.get()
25 delegate:nil]); 45 delegate:nil]);
26 NSView* parent = cocoa_helper_.contentView(); 46 NSView* parent = cocoa_helper_.contentView();
27 [parent addSubview:content_area_.get()]; 47 [parent addSubview:content_area_.get()];
28 [parent addSubview:[bar_ view]]; 48 [parent addSubview:[bar_ view]];
29 } 49 }
30 50
31 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... 51 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
32 scoped_nsobject<NSView> content_area_; 52 scoped_nsobject<NSView> content_area_;
53 scoped_nsobject<NSView> bar_view_;
33 BrowserTestHelper helper_; 54 BrowserTestHelper helper_;
34 scoped_nsobject<BookmarkBarController> bar_; 55 scoped_nsobject<BookmarkBarController> bar_;
35 }; 56 };
36 57
37 TEST_F(BookmarkBarControllerTest, ShowHide) { 58 TEST_F(BookmarkBarControllerTest, ShowHide) {
38 // Assume hidden by default in a new profile. 59 // Assume hidden by default in a new profile.
39 EXPECT_FALSE([bar_ isBookmarkBarVisible]); 60 EXPECT_FALSE([bar_ isBookmarkBarVisible]);
40 EXPECT_TRUE([[bar_ view] isHidden]); 61 EXPECT_TRUE([[bar_ view] isHidden]);
62 EXPECT_EQ([bar_view_ frame].size.height, 0);
41 63
42 // Show and hide it by toggling. 64 // Show and hide it by toggling.
43 [bar_ toggleBookmarkBar]; 65 [bar_ toggleBookmarkBar];
44 EXPECT_TRUE([bar_ isBookmarkBarVisible]); 66 EXPECT_TRUE([bar_ isBookmarkBarVisible]);
45 EXPECT_FALSE([[bar_ view] isHidden]); 67 EXPECT_FALSE([[bar_ view] isHidden]);
46 NSRect content_frame = [content_area_ frame]; 68 NSRect content_frame = [content_area_ frame];
47 EXPECT_NE(content_frame.size.height, kContentAreaHeight); 69 EXPECT_NE(content_frame.size.height, kContentAreaHeight);
70 EXPECT_GT([bar_view_ frame].size.height, 0);
48 [bar_ toggleBookmarkBar]; 71 [bar_ toggleBookmarkBar];
49 EXPECT_FALSE([bar_ isBookmarkBarVisible]); 72 EXPECT_FALSE([bar_ isBookmarkBarVisible]);
50 EXPECT_TRUE([[bar_ view] isHidden]); 73 EXPECT_TRUE([[bar_ view] isHidden]);
51 content_frame = [content_area_ frame]; 74 content_frame = [content_area_ frame];
52 EXPECT_EQ(content_frame.size.height, kContentAreaHeight); 75 EXPECT_EQ(content_frame.size.height, kContentAreaHeight);
76 EXPECT_EQ([bar_view_ frame].size.height, 0);
53 } 77 }
54 78
55 // TODO(jrg): replace getTabContents 79 // Confirm openBookmark: forwards the request to the controller's delegate
56 TEST_F(BookmarkBarControllerTest, OpenBookmark) { 80 TEST_F(BookmarkBarControllerTest, OpenBookmark) {
81 GURL gurl("http://walla.walla.ding.dong.com");
82 scoped_ptr<BookmarkNode> node(new BookmarkNode(gurl));
83 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.
84 init]);
85 [bar_ setDelegate:pong.get()];
86
87 scoped_nsobject<NSButtonCell> cell([[NSButtonCell alloc] init]);
88 scoped_nsobject<NSButton> button([[NSButton alloc] init]);
89 [button setCell:cell.get()];
90 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]];
91 [bar_ openBookmark:button];
92
93 EXPECT_EQ(pong.get()->url_, node->GetURL());
57 } 94 }
58 95
59 // TODO(jrg): Make sure showing the bookmark bar calls loaded: (to process bookm arks) 96 // TODO(jrg): Make sure showing the bookmark bar calls loaded: (to
97 // process bookmarks)
60 TEST_F(BookmarkBarControllerTest, ShowAndLoad) { 98 TEST_F(BookmarkBarControllerTest, ShowAndLoad) {
61 } 99 }
62 100
63 // TODO(jrg): Make sure a cleared bar has no subviews 101 // TODO(jrg): Make sure a cleared bar has no subviews
64 TEST_F(BookmarkBarControllerTest, Clear) { 102 TEST_F(BookmarkBarControllerTest, Clear) {
65 } 103 }
66 104
67 // TODO(jrg): Make sure loaded: does something useful 105 // TODO(jrg): Make sure loaded: does something useful
68 TEST_F(BookmarkBarControllerTest, Loaded) { 106 TEST_F(BookmarkBarControllerTest, Loaded) {
69 // Clear; make sure no views 107 // Clear; make sure no views
(...skipping 13 matching lines...) Expand all
83 // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write 121 // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write
84 // appropriate tests. 122 // appropriate tests.
85 } 123 }
86 124
87 // Test drawing, mostly to ensure nothing leaks or crashes. 125 // Test drawing, mostly to ensure nothing leaks or crashes.
88 TEST_F(BookmarkBarControllerTest, Display) { 126 TEST_F(BookmarkBarControllerTest, Display) {
89 [[bar_ view] display]; 127 [[bar_ view] display];
90 } 128 }
91 129
92 } // namespace 130 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.mm ('k') | chrome/browser/cocoa/bookmark_button_cell.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698