summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:43:01 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:43:01 +0000
commitf940976145eb807c85eef2d14c38ace469773a60 (patch)
treeaa0e0b35e67c375a2d8e1c124c8225d3ae3b6b56 /chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
parent70ac49883a4e9b48a875110ff342feb1a8724813 (diff)
downloadchromium_src-f940976145eb807c85eef2d14c38ace469773a60.zip
chromium_src-f940976145eb807c85eef2d14c38ace469773a60.tar.gz
chromium_src-f940976145eb807c85eef2d14c38ace469773a60.tar.bz2
Bookmark bar, now with buttons.
Much of this CL is refactoring; it's not as large as it looks. (Do I always claim that? It's really true this time.) Review URL: http://codereview.chromium.org/115150 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm129
1 files changed, 129 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm b/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
new file mode 100644
index 0000000..c5ac97b
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm
@@ -0,0 +1,129 @@
+// 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.
+
+#include "chrome/browser/cocoa/bookmark_bar_bridge.h"
+#include "chrome/browser/cocoa/bookmark_bar_controller.h"
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#include "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TODO(jrg): add OCMock to Chromium to save some typing.
+
+namespace {
+
+// Information needed to open a URL, as passed to the
+// BookmarkBarController's delegate.
+typedef std::pair<GURL,WindowOpenDisposition> OpenInfo;
+
+} // The namespace must end here -- I need to use OpenInfo in
+ // FakeBookmarkBarController but can't place
+ // FakeBookmarkBarController itself in the namespace ("error:
+ // Objective-C declarations may only appear in global scope")
+
+// Oddly, we are our own delegate.
+@interface FakeBookmarkBarController :
+ BookmarkBarController<BookmarkURLOpener> {
+ @public
+ scoped_nsobject<NSMutableArray> callbacks_;
+
+ std::vector<OpenInfo> opens_;
+}
+@end
+
+@implementation FakeBookmarkBarController
+
+- (id)initWithProfile:(Profile*)profile
+ contentArea:(NSView*)content {
+ if ((self = [super initWithProfile:profile
+ contentView:content
+ delegate:self])) {
+ callbacks_.reset([[NSMutableArray alloc] init]);
+ }
+ return self;
+}
+
+- (void)loaded:(BookmarkModel*)model {
+ [callbacks_ addObject:[NSNumber numberWithInt:0]];
+}
+
+- (void)beingDeleted:(BookmarkModel*)model {
+ [callbacks_ addObject:[NSNumber numberWithInt:1]];
+}
+
+- (void)nodeMoved:(BookmarkModel*)model
+ oldParent:(BookmarkNode*)oldParent oldIndex:(int)oldIndex
+ newParent:(BookmarkNode*)newParent newIndex:(int)newIndex {
+ [callbacks_ addObject:[NSNumber numberWithInt:2]];
+}
+
+- (void)nodeAdded:(BookmarkModel*)model
+ parent:(BookmarkNode*)oldParent index:(int)index {
+ [callbacks_ addObject:[NSNumber numberWithInt:3]];
+}
+
+- (void)nodeChanged:(BookmarkModel*)model
+ node:(BookmarkNode*)node {
+ [callbacks_ addObject:[NSNumber numberWithInt:4]];
+}
+
+- (void)nodeFavIconLoaded:(BookmarkModel*)model
+ node:(BookmarkNode*)node {
+ [callbacks_ addObject:[NSNumber numberWithInt:5]];
+}
+
+- (void)nodeChildrenReordered:(BookmarkModel*)model
+ node:(BookmarkNode*)node {
+ [callbacks_ addObject:[NSNumber numberWithInt:6]];
+}
+
+// Save the request.
+- (void)openBookmarkURL:(const GURL&)url
+ disposition:(WindowOpenDisposition)disposition {
+ opens_.push_back(OpenInfo(url, disposition));
+}
+
+@end
+
+
+class BookmarkBarBridgeTest : public testing::Test {
+ public:
+ BookmarkBarBridgeTest() {
+ NSRect content_frame = NSMakeRect(0, 0, 100, 100);
+ view_.reset([[NSView alloc] initWithFrame:content_frame]);
+ }
+
+ CocoaTestHelper cocoa_helper_;
+ BrowserTestHelper browser_test_helper_;
+ scoped_nsobject<NSView> view_;
+};
+
+// Call all the callbacks; make sure they are all redirected to the objc object.
+TEST_F(BookmarkBarBridgeTest, TestRedirect) {
+ Profile *profile = browser_test_helper_.profile();
+ BookmarkModel *model = profile->GetBookmarkModel();
+
+ scoped_nsobject<FakeBookmarkBarController>
+ controller([[FakeBookmarkBarController alloc] initWithProfile:profile
+ contentArea:view_]);
+ EXPECT_TRUE(controller.get());
+ scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(controller.get(),
+ model));
+ EXPECT_TRUE(bridge.get());
+
+ bridge->Loaded(NULL);
+ bridge->BookmarkModelBeingDeleted(NULL);
+ bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0);
+ bridge->BookmarkNodeAdded(NULL, NULL, 0);
+ bridge->BookmarkNodeChanged(NULL, NULL);
+ bridge->BookmarkNodeFavIconLoaded(NULL, NULL);
+ bridge->BookmarkNodeChildrenReordered(NULL, NULL);
+
+ // 7 calls above plus an initial Loaded() in init routine makes 8
+ EXPECT_TRUE([controller.get()->callbacks_ count] == 8);
+
+ for (int x = 1; x < 8; x++) {
+ NSNumber *num = [NSNumber numberWithInt:x-1];
+ EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]);
+ }
+}