OLD | NEW |
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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 disposition:(WindowOpenDisposition)disposition { | 23 disposition:(WindowOpenDisposition)disposition { |
24 url_ = url; | 24 url_ = url; |
25 disposition_ = disposition; | 25 disposition_ = disposition; |
26 } | 26 } |
27 @end | 27 @end |
28 | 28 |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 static const int kContentAreaHeight = 500; | 32 static const int kContentAreaHeight = 500; |
| 33 static const int kInfoBarViewHeight = 30; |
33 | 34 |
34 class BookmarkBarControllerTest : public testing::Test { | 35 class BookmarkBarControllerTest : public testing::Test { |
35 public: | 36 public: |
36 BookmarkBarControllerTest() { | 37 BookmarkBarControllerTest() { |
37 NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight); | 38 NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight); |
| 39 // |infobar_frame| is set to be directly above |content_frame|. |
| 40 NSRect infobar_frame = NSMakeRect(0, kContentAreaHeight, |
| 41 800, kInfoBarViewHeight); |
38 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 42 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
39 content_area_.reset([[NSView alloc] initWithFrame:content_frame]); | 43 content_area_.reset([[NSView alloc] initWithFrame:content_frame]); |
| 44 infobar_view_.reset([[NSView alloc] initWithFrame:infobar_frame]); |
40 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); | 45 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); |
41 [parent_view_ setHidden:YES]; | 46 [parent_view_ setHidden:YES]; |
42 bar_.reset( | 47 bar_.reset( |
43 [[BookmarkBarController alloc] initWithProfile:helper_.profile() | 48 [[BookmarkBarController alloc] initWithProfile:helper_.profile() |
44 parentView:parent_view_.get() | 49 parentView:parent_view_.get() |
45 webContentView:content_area_.get() | 50 webContentView:content_area_.get() |
| 51 infoBarsView:infobar_view_.get() |
46 delegate:nil]); | 52 delegate:nil]); |
47 [bar_ view]; // force loading of the nib | 53 [bar_ view]; // force loading of the nib |
48 } | 54 } |
49 | 55 |
50 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 56 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
51 scoped_nsobject<NSView> content_area_; | 57 scoped_nsobject<NSView> content_area_; |
| 58 scoped_nsobject<NSView> infobar_view_; |
52 scoped_nsobject<NSView> parent_view_; | 59 scoped_nsobject<NSView> parent_view_; |
53 BrowserTestHelper helper_; | 60 BrowserTestHelper helper_; |
54 scoped_nsobject<BookmarkBarController> bar_; | 61 scoped_nsobject<BookmarkBarController> bar_; |
55 }; | 62 }; |
56 | 63 |
57 TEST_F(BookmarkBarControllerTest, ShowHide) { | 64 TEST_F(BookmarkBarControllerTest, ShowHide) { |
58 // Assume hidden by default in a new profile. | 65 // Assume hidden by default in a new profile. |
59 EXPECT_FALSE([bar_ isBookmarkBarVisible]); | 66 EXPECT_FALSE([bar_ isBookmarkBarVisible]); |
60 EXPECT_TRUE([[bar_ view] isHidden]); | 67 EXPECT_TRUE([[bar_ view] isHidden]); |
61 | 68 |
62 // Awkwardness to look like we've been installed. | 69 // Awkwardness to look like we've been installed. |
63 [parent_view_ addSubview:[bar_ view]]; | 70 [parent_view_ addSubview:[bar_ view]]; |
64 NSRect frame = [[[bar_ view] superview] frame]; | 71 NSRect frame = [[[bar_ view] superview] frame]; |
65 frame.origin.y = 100; | 72 frame.origin.y = 100; |
66 [[[bar_ view] superview] setFrame:frame]; | 73 [[[bar_ view] superview] setFrame:frame]; |
67 | 74 |
68 // Show and hide it by toggling. | 75 // Show and hide it by toggling. |
69 [bar_ toggleBookmarkBar]; | 76 [bar_ toggleBookmarkBar]; |
70 EXPECT_TRUE([bar_ isBookmarkBarVisible]); | 77 EXPECT_TRUE([bar_ isBookmarkBarVisible]); |
71 EXPECT_FALSE([[bar_ view] isHidden]); | 78 EXPECT_FALSE([[bar_ view] isHidden]); |
72 NSRect content_frame = [content_area_ frame]; | 79 NSRect content_frame = [content_area_ frame]; |
| 80 NSRect infobar_frame = [infobar_view_ frame]; |
73 EXPECT_NE(content_frame.size.height, kContentAreaHeight); | 81 EXPECT_NE(content_frame.size.height, kContentAreaHeight); |
| 82 EXPECT_EQ(NSMaxY(content_frame), NSMinY(infobar_frame)); |
| 83 EXPECT_EQ(kInfoBarViewHeight, infobar_frame.size.height); |
74 EXPECT_GT([[bar_ view] frame].size.height, 0); | 84 EXPECT_GT([[bar_ view] frame].size.height, 0); |
75 | 85 |
76 [bar_ toggleBookmarkBar]; | 86 [bar_ toggleBookmarkBar]; |
77 EXPECT_FALSE([bar_ isBookmarkBarVisible]); | 87 EXPECT_FALSE([bar_ isBookmarkBarVisible]); |
78 EXPECT_TRUE([[bar_ view] isHidden]); | 88 EXPECT_TRUE([[bar_ view] isHidden]); |
79 content_frame = [content_area_ frame]; | 89 content_frame = [content_area_ frame]; |
| 90 infobar_frame = [infobar_view_ frame]; |
80 EXPECT_EQ(content_frame.size.height, kContentAreaHeight); | 91 EXPECT_EQ(content_frame.size.height, kContentAreaHeight); |
| 92 EXPECT_EQ(NSMaxY(content_frame), NSMinY(infobar_frame)); |
| 93 EXPECT_EQ(kInfoBarViewHeight, infobar_frame.size.height); |
81 EXPECT_EQ([[bar_ view] frame].size.height, 0); | 94 EXPECT_EQ([[bar_ view] frame].size.height, 0); |
82 } | 95 } |
83 | 96 |
84 // Confirm openBookmark: forwards the request to the controller's delegate | 97 // Confirm openBookmark: forwards the request to the controller's delegate |
85 TEST_F(BookmarkBarControllerTest, OpenBookmark) { | 98 TEST_F(BookmarkBarControllerTest, OpenBookmark) { |
86 GURL gurl("http://walla.walla.ding.dong.com"); | 99 GURL gurl("http://walla.walla.ding.dong.com"); |
87 scoped_ptr<BookmarkNode> node(new BookmarkNode(gurl)); | 100 scoped_ptr<BookmarkNode> node(new BookmarkNode(gurl)); |
88 scoped_nsobject<BookmarkURLOpenerPong> pong([[BookmarkURLOpenerPong alloc] | 101 scoped_nsobject<BookmarkURLOpenerPong> pong([[BookmarkURLOpenerPong alloc] |
89 init]); | 102 init]); |
90 [bar_ setDelegate:pong.get()]; | 103 [bar_ setDelegate:pong.get()]; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write | 182 // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write |
170 // appropriate tests. | 183 // appropriate tests. |
171 } | 184 } |
172 | 185 |
173 // Test drawing, mostly to ensure nothing leaks or crashes. | 186 // Test drawing, mostly to ensure nothing leaks or crashes. |
174 TEST_F(BookmarkBarControllerTest, Display) { | 187 TEST_F(BookmarkBarControllerTest, Display) { |
175 [[bar_ view] display]; | 188 [[bar_ view] display]; |
176 } | 189 } |
177 | 190 |
178 } // namespace | 191 } // namespace |
OLD | NEW |