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

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

Issue 155358: More 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
(...skipping 14 matching lines...) Expand all
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 std::vector<OpenInfo> opens_; 29 std::vector<OpenInfo> opens_;
30 } 30 }
31 @end 31 @end
32 32
33 @implementation FakeBookmarkBarController 33 @implementation FakeBookmarkBarController
34 34
35 - (id)initWithProfile:(Profile*)profile view:(NSView*)view { 35 - (id)initWithProfile:(Profile*)profile
36 parentView:(NSView*)parentView
37 webContentView:(NSView*)webContentView {
36 if ((self = [super initWithProfile:profile 38 if ((self = [super initWithProfile:profile
37 view:(BookmarkBarView*)view 39 parentView:parentView
38 webContentView:nil 40 webContentView:webContentView
39 delegate:self])) { 41 delegate:self])) {
40 callbacks_.reset([[NSMutableArray alloc] init]); 42 callbacks_.reset([[NSMutableArray alloc] init]);
41 } 43 }
42 return self; 44 return self;
43 } 45 }
44 46
45 - (void)loaded:(BookmarkModel*)model { 47 - (void)loaded:(BookmarkModel*)model {
46 [callbacks_ addObject:[NSNumber numberWithInt:0]]; 48 [callbacks_ addObject:[NSNumber numberWithInt:0]];
47 } 49 }
48 50
(...skipping 20 matching lines...) Expand all
69 - (void)nodeFavIconLoaded:(BookmarkModel*)model 71 - (void)nodeFavIconLoaded:(BookmarkModel*)model
70 node:(const BookmarkNode*)node { 72 node:(const BookmarkNode*)node {
71 [callbacks_ addObject:[NSNumber numberWithInt:5]]; 73 [callbacks_ addObject:[NSNumber numberWithInt:5]];
72 } 74 }
73 75
74 - (void)nodeChildrenReordered:(BookmarkModel*)model 76 - (void)nodeChildrenReordered:(BookmarkModel*)model
75 node:(const BookmarkNode*)node { 77 node:(const BookmarkNode*)node {
76 [callbacks_ addObject:[NSNumber numberWithInt:6]]; 78 [callbacks_ addObject:[NSNumber numberWithInt:6]];
77 } 79 }
78 80
81 - (void)nodeRemoved:(BookmarkModel*)model
82 parent:(const BookmarkNode*)oldParent index:(int)index {
83 [callbacks_ addObject:[NSNumber numberWithInt:7]];
84 }
85
79 // Save the request. 86 // Save the request.
80 - (void)openBookmarkURL:(const GURL&)url 87 - (void)openBookmarkURL:(const GURL&)url
81 disposition:(WindowOpenDisposition)disposition { 88 disposition:(WindowOpenDisposition)disposition {
82 opens_.push_back(OpenInfo(url, disposition)); 89 opens_.push_back(OpenInfo(url, disposition));
83 } 90 }
84 91
85 @end 92 @end
86 93
87 94
88 class BookmarkBarBridgeTest : public testing::Test { 95 class BookmarkBarBridgeTest : public testing::Test {
89 public: 96 public:
90 BookmarkBarBridgeTest() { 97 BookmarkBarBridgeTest() {
91 NSRect content_frame = NSMakeRect(0, 0, 100, 100); 98 NSRect content_frame = NSMakeRect(0, 0, 100, 100);
92 view_.reset([[NSView alloc] initWithFrame:content_frame]); 99 view_.reset([[NSView alloc] initWithFrame:content_frame]);
93 } 100 }
94 101
95 CocoaTestHelper cocoa_helper_; 102 CocoaTestHelper cocoa_helper_;
96 BrowserTestHelper browser_test_helper_; 103 BrowserTestHelper browser_test_helper_;
97 scoped_nsobject<NSView> view_; 104 scoped_nsobject<NSView> view_;
98 }; 105 };
99 106
100 // Call all the callbacks; make sure they are all redirected to the objc object. 107 // Call all the callbacks; make sure they are all redirected to the objc object.
101 TEST_F(BookmarkBarBridgeTest, TestRedirect) { 108 TEST_F(BookmarkBarBridgeTest, TestRedirect) {
102 Profile *profile = browser_test_helper_.profile(); 109 Profile *profile = browser_test_helper_.profile();
103 BookmarkModel *model = profile->GetBookmarkModel(); 110 BookmarkModel *model = profile->GetBookmarkModel();
104 111
105 scoped_nsobject<NSView> view([[NSView alloc] 112 scoped_nsobject<NSView> parentView([[NSView alloc]
106 initWithFrame:NSMakeRect(0,0,10,10)]); 113 initWithFrame:NSMakeRect(0,0,100,100)]);
107 [view.get() setHidden:YES]; 114 scoped_nsobject<NSView> webView([[NSView alloc]
115 initWithFrame:NSMakeRect(0,0,100,100)]);
116
108 scoped_nsobject<FakeBookmarkBarController> 117 scoped_nsobject<FakeBookmarkBarController>
109 controller([[FakeBookmarkBarController alloc] initWithProfile:profile 118 controller([[FakeBookmarkBarController alloc]
110 view:view.get()]); 119 initWithProfile:profile
120 parentView:parentView.get()
121 webContentView:webView.get()]);
111 EXPECT_TRUE(controller.get()); 122 EXPECT_TRUE(controller.get());
112 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(controller.get(), 123 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(controller.get(),
113 model)); 124 model));
114 EXPECT_TRUE(bridge.get()); 125 EXPECT_TRUE(bridge.get());
115 126
116 bridge->Loaded(NULL); 127 bridge->Loaded(NULL);
117 bridge->BookmarkModelBeingDeleted(NULL); 128 bridge->BookmarkModelBeingDeleted(NULL);
118 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0); 129 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0);
119 bridge->BookmarkNodeAdded(NULL, NULL, 0); 130 bridge->BookmarkNodeAdded(NULL, NULL, 0);
120 bridge->BookmarkNodeChanged(NULL, NULL); 131 bridge->BookmarkNodeChanged(NULL, NULL);
121 bridge->BookmarkNodeFavIconLoaded(NULL, NULL); 132 bridge->BookmarkNodeFavIconLoaded(NULL, NULL);
122 bridge->BookmarkNodeChildrenReordered(NULL, NULL); 133 bridge->BookmarkNodeChildrenReordered(NULL, NULL);
134 bridge->BookmarkNodeRemoved(NULL, NULL, 0);
123 135
124 // 7 calls above plus an initial Loaded() in init routine makes 8 136 // 8 calls above plus an initial Loaded() in init routine makes 9
125 EXPECT_TRUE([controller.get()->callbacks_ count] == 8); 137 EXPECT_TRUE([controller.get()->callbacks_ count] == 9);
126 138
127 for (int x = 1; x < 8; x++) { 139 for (int x = 1; x < 9; x++) {
128 NSNumber *num = [NSNumber numberWithInt:x-1]; 140 NSNumber *num = [NSNumber numberWithInt:x-1];
129 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]); 141 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]);
130 } 142 }
131 } 143 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_bridge.mm ('k') | chrome/browser/cocoa/bookmark_bar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698