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

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

Issue 2793363002: [Mac] Remove no-op method in bookmark bar controller (Closed)
Patch Set: Make test clearer Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bookmarks/bookmark_model_factory.h" 5 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
6 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" 6 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h"
7 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 7 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
8 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" 8 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 13 matching lines...) Expand all
24 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; 24 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo;
25 25
26 } // The namespace must end here -- I need to use OpenInfo in 26 } // The namespace must end here -- I need to use OpenInfo in
27 // FakeBookmarkBarController but can't place 27 // FakeBookmarkBarController but can't place
28 // FakeBookmarkBarController itself in the namespace ("error: 28 // FakeBookmarkBarController itself in the namespace ("error:
29 // Objective-C declarations may only appear in global scope") 29 // Objective-C declarations may only appear in global scope")
30 30
31 // Oddly, we are our own delegate. 31 // Oddly, we are our own delegate.
32 @interface FakeBookmarkBarController : BookmarkBarController { 32 @interface FakeBookmarkBarController : BookmarkBarController {
33 @public 33 @public
34 base::scoped_nsobject<NSMutableArray> callbacks_; 34 std::vector<SEL> called_selectors_;
35 std::vector<OpenInfo> opens_; 35 std::vector<OpenInfo> opens_;
36 } 36 }
37 @end 37 @end
38 38
39 @implementation FakeBookmarkBarController 39 @implementation FakeBookmarkBarController
40 40
41 - (id)initWithBrowser:(Browser*)browser {
42 if ((self = [super initWithBrowser:browser
43 initialWidth:100 // arbitrary
44 delegate:nil])) {
45 callbacks_.reset([[NSMutableArray alloc] init]);
46 }
47 return self;
48 }
49
50 - (void)loaded:(BookmarkModel*)model { 41 - (void)loaded:(BookmarkModel*)model {
51 [callbacks_ addObject:[NSNumber numberWithInt:0]]; 42 called_selectors_.push_back(_cmd);
52 }
53
54 - (void)beingDeleted:(BookmarkModel*)model {
55 [callbacks_ addObject:[NSNumber numberWithInt:1]];
56 } 43 }
57 44
58 - (void)nodeMoved:(BookmarkModel*)model 45 - (void)nodeMoved:(BookmarkModel*)model
59 oldParent:(const BookmarkNode*)oldParent oldIndex:(int)oldIndex 46 oldParent:(const BookmarkNode*)oldParent oldIndex:(int)oldIndex
60 newParent:(const BookmarkNode*)newParent newIndex:(int)newIndex { 47 newParent:(const BookmarkNode*)newParent newIndex:(int)newIndex {
61 [callbacks_ addObject:[NSNumber numberWithInt:2]]; 48 called_selectors_.push_back(_cmd);
62 } 49 }
63 50
64 - (void)nodeAdded:(BookmarkModel*)model 51 - (void)nodeAdded:(BookmarkModel*)model
65 parent:(const BookmarkNode*)oldParent index:(int)index { 52 parent:(const BookmarkNode*)oldParent index:(int)index {
66 [callbacks_ addObject:[NSNumber numberWithInt:3]]; 53 called_selectors_.push_back(_cmd);
67 } 54 }
68 55
69 - (void)nodeChanged:(BookmarkModel*)model 56 - (void)nodeChanged:(BookmarkModel*)model
70 node:(const BookmarkNode*)node { 57 node:(const BookmarkNode*)node {
71 [callbacks_ addObject:[NSNumber numberWithInt:4]]; 58 called_selectors_.push_back(_cmd);
72 } 59 }
73 60
74 - (void)nodeFaviconLoaded:(BookmarkModel*)model 61 - (void)nodeFaviconLoaded:(BookmarkModel*)model
75 node:(const BookmarkNode*)node { 62 node:(const BookmarkNode*)node {
76 [callbacks_ addObject:[NSNumber numberWithInt:5]]; 63 called_selectors_.push_back(_cmd);
77 } 64 }
78 65
79 - (void)nodeChildrenReordered:(BookmarkModel*)model 66 - (void)nodeChildrenReordered:(BookmarkModel*)model
80 node:(const BookmarkNode*)node { 67 node:(const BookmarkNode*)node {
81 [callbacks_ addObject:[NSNumber numberWithInt:6]]; 68 called_selectors_.push_back(_cmd);
82 } 69 }
83 70
84 - (void)nodeRemoved:(BookmarkModel*)model 71 - (void)nodeRemoved:(BookmarkModel*)model
85 parent:(const BookmarkNode*)oldParent index:(int)index { 72 parent:(const BookmarkNode*)oldParent index:(int)index {
86 [callbacks_ addObject:[NSNumber numberWithInt:7]]; 73 called_selectors_.push_back(_cmd);
87 } 74 }
88 75
89 // Save the request. 76 // Save the request.
90 - (void)openBookmarkURL:(const GURL&)url 77 - (void)openBookmarkURL:(const GURL&)url
91 disposition:(WindowOpenDisposition)disposition { 78 disposition:(WindowOpenDisposition)disposition {
92 opens_.push_back(OpenInfo(url, disposition)); 79 opens_.push_back(OpenInfo(url, disposition));
93 } 80 }
94 81
95 @end 82 @end
96 83
97 84
98 class BookmarkBarBridgeTest : public CocoaProfileTest { 85 class BookmarkBarBridgeTest : public CocoaProfileTest {
99 }; 86 };
100 87
101 // Call all the callbacks; make sure they are all redirected to the objc object. 88 // Call all the callbacks; make sure they are all redirected to the objc object.
102 TEST_F(BookmarkBarBridgeTest, TestRedirect) { 89 TEST_F(BookmarkBarBridgeTest, TestRedirect) {
103 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 90 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
104 91
105 base::scoped_nsobject<NSView> parentView( 92 base::scoped_nsobject<NSView> parentView(
106 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 93 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
107 base::scoped_nsobject<NSView> webView( 94 base::scoped_nsobject<NSView> webView(
108 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 95 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
109 base::scoped_nsobject<NSView> infoBarsView( 96 base::scoped_nsobject<NSView> infoBarsView(
110 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 97 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
111 98
112 base::scoped_nsobject<FakeBookmarkBarController> controller( 99 base::scoped_nsobject<FakeBookmarkBarController> controller(
113 [[FakeBookmarkBarController alloc] initWithBrowser:browser()]); 100 [[FakeBookmarkBarController alloc] initWithBrowser:browser()
101 initialWidth:100 // arbitrary
102 delegate:nil]);
114 EXPECT_TRUE(controller.get()); 103 EXPECT_TRUE(controller.get());
115 std::unique_ptr<BookmarkBarBridge> bridge( 104 std::unique_ptr<BookmarkBarBridge> bridge(
116 new BookmarkBarBridge(profile(), controller.get(), model)); 105 new BookmarkBarBridge(profile(), controller.get(), model));
117 EXPECT_TRUE(bridge.get()); 106 EXPECT_TRUE(bridge.get());
118 107
119 bridge->BookmarkModelLoaded(NULL, false); 108 bridge->BookmarkModelLoaded(NULL, false);
120 bridge->BookmarkModelBeingDeleted(NULL); 109 // |BookmarkModelBeingDeleted| is a no-op.
121 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0); 110 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0);
122 bridge->BookmarkNodeAdded(NULL, NULL, 0); 111 bridge->BookmarkNodeAdded(NULL, NULL, 0);
123 bridge->BookmarkNodeChanged(NULL, NULL); 112 bridge->BookmarkNodeChanged(NULL, NULL);
124 bridge->BookmarkNodeFaviconChanged(NULL, NULL); 113 bridge->BookmarkNodeFaviconChanged(NULL, NULL);
125 bridge->BookmarkNodeChildrenReordered(NULL, NULL); 114 bridge->BookmarkNodeChildrenReordered(NULL, NULL);
126 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL, std::set<GURL>()); 115 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL, std::set<GURL>());
127 116 // 7 calls above plus an initial Loaded() in init routine makes 8.
128 // 8 calls above plus an initial Loaded() in init routine makes 9 117 EXPECT_EQ(controller.get()->called_selectors_.size(), 8U);
129 EXPECT_TRUE([controller.get()->callbacks_ count] == 9); 118 std::vector<SEL> expected_selectors = {
130 119 @selector(loaded:), // initial from init
131 for (int x = 1; x < 9; x++) { 120 @selector(loaded:),
132 NSNumber* num = [NSNumber numberWithInt:x-1]; 121 @selector(nodeMoved:oldParent:oldIndex:newParent:newIndex:),
133 EXPECT_NSEQ(num, [controller.get()->callbacks_ objectAtIndex:x]); 122 @selector(nodeAdded:parent:index:),
134 } 123 @selector(nodeChanged:node:),
124 @selector(nodeFaviconLoaded:node:),
125 @selector(nodeChildrenReordered:node:),
126 @selector(nodeRemoved:parent:index:)
127 };
128 EXPECT_EQ(controller.get()->called_selectors_, expected_selectors);
135 } 129 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.mm ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698