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

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_bridge_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 #include "chrome/browser/cocoa/bookmark_bar_bridge.h" 5 #include "chrome/browser/cocoa/bookmark_bar_bridge.h"
6 #include "chrome/browser/cocoa/bookmark_bar_controller.h" 6 #include "chrome/browser/cocoa/bookmark_bar_controller.h"
7 #include "chrome/browser/cocoa/browser_test_helper.h" 7 #include "chrome/browser/cocoa/browser_test_helper.h"
8 #include "chrome/browser/cocoa/cocoa_test_helper.h" 8 #include "chrome/browser/cocoa/cocoa_test_helper.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 // TODO(jrg): add OCMock to Chromium to save some typing. 11 // TODO(jrg): add OCMock to Chromium to save some typing.
12 12
13 namespace { 13 namespace {
14 14
15 // Information needed to open a URL, as passed to the 15 // Information needed to open a URL, as passed to the
16 // BookmarkBarController's delegate. 16 // BookmarkBarController's delegate.
17 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; 17 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo;
18 18
19 } // The namespace must end here -- I need to use OpenInfo in 19 } // The namespace must end here -- I need to use OpenInfo in
20 // FakeBookmarkBarController but can't place 20 // FakeBookmarkBarController but can't place
21 // FakeBookmarkBarController itself in the namespace ("error: 21 // FakeBookmarkBarController itself in the namespace ("error:
22 // Objective-C declarations may only appear in global scope") 22 // Objective-C declarations may only appear in global scope")
23 23
24 // Oddly, we are our own delegate. 24 // Oddly, we are our own delegate.
25 @interface FakeBookmarkBarController : 25 @interface FakeBookmarkBarController :
26 BookmarkBarController<BookmarkURLOpener> { 26 BookmarkBarController<BookmarkURLOpener> {
27 @public 27 @public
28 scoped_nsobject<NSMutableArray> callbacks_; 28 scoped_nsobject<NSMutableArray> callbacks_;
29
30 std::vector<OpenInfo> opens_; 29 std::vector<OpenInfo> opens_;
31 } 30 }
32 @end 31 @end
33 32
34 @implementation FakeBookmarkBarController 33 @implementation FakeBookmarkBarController
35 34
36 - (id)initWithProfile:(Profile*)profile 35 - (id)initWithProfile:(Profile*)profile view:(NSView*)view {
37 contentArea:(NSView*)content {
38 if ((self = [super initWithProfile:profile 36 if ((self = [super initWithProfile:profile
39 contentView:content 37 view:(BookmarkBarView*)view
38 webContentView:nil
40 delegate:self])) { 39 delegate:self])) {
41 callbacks_.reset([[NSMutableArray alloc] init]); 40 callbacks_.reset([[NSMutableArray alloc] init]);
42 } 41 }
43 return self; 42 return self;
44 } 43 }
45 44
46 - (void)loaded:(BookmarkModel*)model { 45 - (void)loaded:(BookmarkModel*)model {
47 [callbacks_ addObject:[NSNumber numberWithInt:0]]; 46 [callbacks_ addObject:[NSNumber numberWithInt:0]];
48 } 47 }
49 48
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 CocoaTestHelper cocoa_helper_; 95 CocoaTestHelper cocoa_helper_;
97 BrowserTestHelper browser_test_helper_; 96 BrowserTestHelper browser_test_helper_;
98 scoped_nsobject<NSView> view_; 97 scoped_nsobject<NSView> view_;
99 }; 98 };
100 99
101 // Call all the callbacks; make sure they are all redirected to the objc object. 100 // Call all the callbacks; make sure they are all redirected to the objc object.
102 TEST_F(BookmarkBarBridgeTest, TestRedirect) { 101 TEST_F(BookmarkBarBridgeTest, TestRedirect) {
103 Profile *profile = browser_test_helper_.profile(); 102 Profile *profile = browser_test_helper_.profile();
104 BookmarkModel *model = profile->GetBookmarkModel(); 103 BookmarkModel *model = profile->GetBookmarkModel();
105 104
105 scoped_nsobject<NSView> view([[NSView alloc]
106 initWithFrame:NSMakeRect(0,0,10,10)]);
107 [view.get() setHidden:YES];
106 scoped_nsobject<FakeBookmarkBarController> 108 scoped_nsobject<FakeBookmarkBarController>
107 controller([[FakeBookmarkBarController alloc] initWithProfile:profile 109 controller([[FakeBookmarkBarController alloc] initWithProfile:profile
108 contentArea:view_]); 110 view:view.get()]);
109 EXPECT_TRUE(controller.get()); 111 EXPECT_TRUE(controller.get());
110 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(controller.get(), 112 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(controller.get(),
111 model)); 113 model));
112 EXPECT_TRUE(bridge.get()); 114 EXPECT_TRUE(bridge.get());
113 115
114 bridge->Loaded(NULL); 116 bridge->Loaded(NULL);
115 bridge->BookmarkModelBeingDeleted(NULL); 117 bridge->BookmarkModelBeingDeleted(NULL);
116 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0); 118 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0);
117 bridge->BookmarkNodeAdded(NULL, NULL, 0); 119 bridge->BookmarkNodeAdded(NULL, NULL, 0);
118 bridge->BookmarkNodeChanged(NULL, NULL); 120 bridge->BookmarkNodeChanged(NULL, NULL);
119 bridge->BookmarkNodeFavIconLoaded(NULL, NULL); 121 bridge->BookmarkNodeFavIconLoaded(NULL, NULL);
120 bridge->BookmarkNodeChildrenReordered(NULL, NULL); 122 bridge->BookmarkNodeChildrenReordered(NULL, NULL);
121 123
122 // 7 calls above plus an initial Loaded() in init routine makes 8 124 // 7 calls above plus an initial Loaded() in init routine makes 8
123 EXPECT_TRUE([controller.get()->callbacks_ count] == 8); 125 EXPECT_TRUE([controller.get()->callbacks_ count] == 8);
124 126
125 for (int x = 1; x < 8; x++) { 127 for (int x = 1; x < 8; x++) {
126 NSNumber *num = [NSNumber numberWithInt:x-1]; 128 NSNumber *num = [NSNumber numberWithInt:x-1];
127 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]); 129 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]);
128 } 130 }
129 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698