summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-15 13:58:17 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-15 13:58:17 +0000
commit8fdac81e046a1ae0cb085a5f549aa6379a5a069f (patch)
tree567e4e559c70db5c2941c0c62f42f40bf13598ac /chrome/browser
parent1e76d8ad90eae14be11f5151c8670a89b3e19aec (diff)
downloadchromium_src-8fdac81e046a1ae0cb085a5f549aa6379a5a069f.zip
chromium_src-8fdac81e046a1ae0cb085a5f549aa6379a5a069f.tar.gz
chromium_src-8fdac81e046a1ae0cb085a5f549aa6379a5a069f.tar.bz2
Add unit test for bookmark bar controller.
Review URL: http://codereview.chromium.org/73051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.h11
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm9
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller_unittest.mm68
3 files changed, 82 insertions, 6 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h
index 6c8e4c0..eec8a60 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.h
+++ b/chrome/browser/cocoa/bookmark_bar_controller.h
@@ -35,15 +35,18 @@ class Profile;
- (id)initWithProfile:(Profile*)profile
contentArea:(NSView*)content;
-// Change the visibility state of the bookmark bar to |enable|.
-- (void)showBookmarkBar:(BOOL)enable;
+// Returns whether or not the bookmark bar is visible.
+- (BOOL)isBookmarkBarVisible;
// Toggle the state of the bookmark bar.
- (void)toggleBookmarkBar;
-// Returns whether or not the bookmark bar is visible.
-- (BOOL)isBookmarkBarVisible;
+@end
+// These APIs should only be used by unit tests, in place of "friend" classes.
+@interface BookmarkBarController(TestingAPI)
+// Access to the bookmark bar's view represented by this controller.
+- (NSView*)view;
@end
#endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index 74cc215..55ff71d 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -11,6 +11,7 @@
@interface BookmarkBarController(Private)
- (void)applyContentAreaOffset:(BOOL)apply;
- (void)positionBar;
+- (void)showBookmarkBar:(BOOL)enable;
@end
@implementation BookmarkBarController
@@ -55,11 +56,11 @@
[bookmarkView_ setFrame:barFrame];
}
-// Show or hide the bar based on the value of enable. Handles animating the
+// Show or hide the bar based on the value of |enable|. Handles animating the
// resize of the content view.
- (void)showBookmarkBar:(BOOL)enable {
contentAreaHasOffset_ = enable;
- [[bookmarkView_ animator] setHidden:enable ? NO : YES];
+ [bookmarkView_ setHidden:enable ? NO : YES];
[self applyContentAreaOffset:enable];
if (enable) {
@@ -108,4 +109,8 @@
[self showBookmarkBar:visible ? YES : NO];
}
+- (NSView*)view {
+ return bookmarkView_;
+}
+
@end
diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm
new file mode 100644
index 0000000..6d6e2daa
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm
@@ -0,0 +1,68 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_nsobject.h"
+#import "chrome/browser/cocoa/bookmark_bar_controller.h"
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+static const int kContentAreaHeight = 500;
+
+class BookmarkBarControllerTest : public testing::Test {
+ public:
+ BookmarkBarControllerTest() {
+ // Bootstrap Cocoa. It's very unhappy without this.
+ [NSApplication sharedApplication];
+
+ // Create a window and put a content view in it that's slightly smaller in
+ // height.
+ NSRect frame = NSMakeRect(0, 0, 800, 600);
+ window_.reset([[NSWindow alloc] initWithContentRect:frame
+ styleMask:0
+ backing:NSBackingStoreBuffered
+ defer:NO]);
+ [window_ orderFront:nil];
+ NSRect content_frame = NSMakeRect(0, 0, 800, kContentAreaHeight);
+ content_area_.reset([[NSView alloc] initWithFrame:content_frame]);
+ bar_.reset(
+ [[BookmarkBarController alloc] initWithProfile:helper_.GetProfile()
+ contentArea:content_area_.get()]);
+ }
+
+ scoped_nsobject<NSWindow> window_;
+ scoped_nsobject<NSView> content_area_;
+ BrowserTestHelper helper_;
+ scoped_nsobject<BookmarkBarController> bar_;
+};
+
+TEST_F(BookmarkBarControllerTest, ShowHide) {
+ // Assume hidden by default in a new profile.
+ EXPECT_FALSE([bar_ isBookmarkBarVisible]);
+ EXPECT_TRUE([[bar_ view] isHidden]);
+
+ // Show and hide it by toggling.
+ // TODO(pinkerton): When visible, ensure the content area has been resized.
+ // When hidden again, ensure the content area is back to what it at the start.
+ // However, this can't currently be unit-tested due to CoreAnimation.
+ [bar_ toggleBookmarkBar];
+ EXPECT_TRUE([bar_ isBookmarkBarVisible]);
+ EXPECT_FALSE([[bar_ view] isHidden]);
+ NSRect content_frame = [content_area_ frame];
+ // EXPECT_NE(content_frame.size.height, kContentAreaHeight);
+ [bar_ toggleBookmarkBar];
+ EXPECT_FALSE([bar_ isBookmarkBarVisible]);
+ EXPECT_TRUE([[bar_ view] isHidden]);
+ content_frame = [content_area_ frame];
+ EXPECT_EQ(content_frame.size.height, kContentAreaHeight);
+}
+
+TEST_F(BookmarkBarControllerTest, Contents) {
+ // TODO(jrg): When there are items on the bar, flesh this out.
+}
+
+} // namespace