OLD | NEW |
---|---|
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" |
Mark Mentovai
2013/06/24 21:29:48
#include what you use.
| |
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/cocoa_profile_test.h" | 8 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #import "testing/gtest_mac.h" | 10 #import "testing/gtest_mac.h" |
11 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
12 | 12 |
13 // TODO(jrg): use OCMock. | 13 // TODO(jrg): use OCMock. |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Information needed to open a URL, as passed to the | 17 // Information needed to open a URL, as passed to the |
18 // BookmarkBarController's delegate. | 18 // BookmarkBarController's delegate. |
19 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; | 19 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; |
20 | 20 |
21 } // The namespace must end here -- I need to use OpenInfo in | 21 } // The namespace must end here -- I need to use OpenInfo in |
22 // FakeBookmarkBarController but can't place | 22 // FakeBookmarkBarController but can't place |
23 // FakeBookmarkBarController itself in the namespace ("error: | 23 // FakeBookmarkBarController itself in the namespace ("error: |
24 // Objective-C declarations may only appear in global scope") | 24 // Objective-C declarations may only appear in global scope") |
25 | 25 |
26 // Oddly, we are our own delegate. | 26 // Oddly, we are our own delegate. |
27 @interface FakeBookmarkBarController : BookmarkBarController { | 27 @interface FakeBookmarkBarController : BookmarkBarController { |
28 @public | 28 @public |
29 scoped_nsobject<NSMutableArray> callbacks_; | 29 base::scoped_nsobject<NSMutableArray> callbacks_; |
30 std::vector<OpenInfo> opens_; | 30 std::vector<OpenInfo> opens_; |
31 } | 31 } |
32 @end | 32 @end |
33 | 33 |
34 @implementation FakeBookmarkBarController | 34 @implementation FakeBookmarkBarController |
35 | 35 |
36 - (id)initWithBrowser:(Browser*)browser { | 36 - (id)initWithBrowser:(Browser*)browser { |
37 if ((self = [super initWithBrowser:browser | 37 if ((self = [super initWithBrowser:browser |
38 initialWidth:100 // arbitrary | 38 initialWidth:100 // arbitrary |
39 delegate:nil | 39 delegate:nil |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 @end | 91 @end |
92 | 92 |
93 | 93 |
94 class BookmarkBarBridgeTest : public CocoaProfileTest { | 94 class BookmarkBarBridgeTest : public CocoaProfileTest { |
95 }; | 95 }; |
96 | 96 |
97 // Call all the callbacks; make sure they are all redirected to the objc object. | 97 // Call all the callbacks; make sure they are all redirected to the objc object. |
98 TEST_F(BookmarkBarBridgeTest, TestRedirect) { | 98 TEST_F(BookmarkBarBridgeTest, TestRedirect) { |
99 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 99 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
100 | 100 |
101 scoped_nsobject<NSView> parentView([[NSView alloc] | 101 base::scoped_nsobject<NSView> parentView( |
102 initWithFrame:NSMakeRect(0,0,100,100)]); | 102 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); |
103 scoped_nsobject<NSView> webView([[NSView alloc] | 103 base::scoped_nsobject<NSView> webView( |
104 initWithFrame:NSMakeRect(0,0,100,100)]); | 104 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); |
105 scoped_nsobject<NSView> infoBarsView( | 105 base::scoped_nsobject<NSView> infoBarsView( |
106 [[NSView alloc] initWithFrame:NSMakeRect(0,0,100,100)]); | 106 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); |
107 | 107 |
108 scoped_nsobject<FakeBookmarkBarController> | 108 base::scoped_nsobject<FakeBookmarkBarController> controller( |
109 controller([[FakeBookmarkBarController alloc] initWithBrowser:browser()]); | 109 [[FakeBookmarkBarController alloc] initWithBrowser:browser()]); |
110 EXPECT_TRUE(controller.get()); | 110 EXPECT_TRUE(controller.get()); |
111 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(profile(), | 111 scoped_ptr<BookmarkBarBridge> bridge(new BookmarkBarBridge(profile(), |
112 controller.get(), | 112 controller.get(), |
113 model)); | 113 model)); |
114 EXPECT_TRUE(bridge.get()); | 114 EXPECT_TRUE(bridge.get()); |
115 | 115 |
116 bridge->Loaded(NULL, false); | 116 bridge->Loaded(NULL, false); |
117 bridge->BookmarkModelBeingDeleted(NULL); | 117 bridge->BookmarkModelBeingDeleted(NULL); |
118 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0); | 118 bridge->BookmarkNodeMoved(NULL, NULL, 0, NULL, 0); |
119 bridge->BookmarkNodeAdded(NULL, NULL, 0); | 119 bridge->BookmarkNodeAdded(NULL, NULL, 0); |
120 bridge->BookmarkNodeChanged(NULL, NULL); | 120 bridge->BookmarkNodeChanged(NULL, NULL); |
121 bridge->BookmarkNodeFaviconChanged(NULL, NULL); | 121 bridge->BookmarkNodeFaviconChanged(NULL, NULL); |
122 bridge->BookmarkNodeChildrenReordered(NULL, NULL); | 122 bridge->BookmarkNodeChildrenReordered(NULL, NULL); |
123 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL); | 123 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL); |
124 | 124 |
125 // 8 calls above plus an initial Loaded() in init routine makes 9 | 125 // 8 calls above plus an initial Loaded() in init routine makes 9 |
126 EXPECT_TRUE([controller.get()->callbacks_ count] == 9); | 126 EXPECT_TRUE([controller.get()->callbacks_ count] == 9); |
127 | 127 |
128 for (int x = 1; x < 9; x++) { | 128 for (int x = 1; x < 9; x++) { |
129 NSNumber* num = [NSNumber numberWithInt:x-1]; | 129 NSNumber* num = [NSNumber numberWithInt:x-1]; |
130 EXPECT_NSEQ(num, [controller.get()->callbacks_ objectAtIndex:x]); | 130 EXPECT_NSEQ(num, [controller.get()->callbacks_ objectAtIndex:x]); |
131 } | 131 } |
132 } | 132 } |
OLD | NEW |