OLD | NEW |
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 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
11 | 11 |
12 // TODO(jrg): add OCMock to Chromium to save some typing. | 12 // TODO(jrg): add OCMock to Chromium to save some typing. |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Information needed to open a URL, as passed to the | 16 // Information needed to open a URL, as passed to the |
17 // BookmarkBarController's delegate. | 17 // BookmarkBarController's delegate. |
18 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; | 18 typedef std::pair<GURL,WindowOpenDisposition> OpenInfo; |
19 | 19 |
20 } // The namespace must end here -- I need to use OpenInfo in | 20 } // The namespace must end here -- I need to use OpenInfo in |
21 // FakeBookmarkBarController but can't place | 21 // FakeBookmarkBarController but can't place |
22 // FakeBookmarkBarController itself in the namespace ("error: | 22 // FakeBookmarkBarController itself in the namespace ("error: |
23 // Objective-C declarations may only appear in global scope") | 23 // Objective-C declarations may only appear in global scope") |
24 | 24 |
25 // Oddly, we are our own delegate. | 25 // Oddly, we are our own delegate. |
26 @interface FakeBookmarkBarController : | 26 @interface FakeBookmarkBarController : BookmarkBarController { |
27 BookmarkBarController<BookmarkURLOpener> { | |
28 @public | 27 @public |
29 scoped_nsobject<NSMutableArray> callbacks_; | 28 scoped_nsobject<NSMutableArray> callbacks_; |
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)initWithBrowser:(Browser*)browser { | 35 - (id)initWithBrowser:(Browser*)browser { |
37 if ((self = [super initWithBrowser:browser | 36 if ((self = [super initWithBrowser:browser |
38 initialWidth:100 // arbitrary | 37 initialWidth:100 // arbitrary |
39 compressDelegate:nil | 38 compressDelegate:nil |
40 resizeDelegate:nil | 39 resizeDelegate:nil])) { |
41 urlDelegate:self])) { | |
42 callbacks_.reset([[NSMutableArray alloc] init]); | 40 callbacks_.reset([[NSMutableArray alloc] init]); |
43 } | 41 } |
44 return self; | 42 return self; |
45 } | 43 } |
46 | 44 |
47 - (void)loaded:(BookmarkModel*)model { | 45 - (void)loaded:(BookmarkModel*)model { |
48 [callbacks_ addObject:[NSNumber numberWithInt:0]]; | 46 [callbacks_ addObject:[NSNumber numberWithInt:0]]; |
49 } | 47 } |
50 | 48 |
51 - (void)beingDeleted:(BookmarkModel*)model { | 49 - (void)beingDeleted:(BookmarkModel*)model { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL); | 126 bridge->BookmarkNodeRemoved(NULL, NULL, 0, NULL); |
129 | 127 |
130 // 8 calls above plus an initial Loaded() in init routine makes 9 | 128 // 8 calls above plus an initial Loaded() in init routine makes 9 |
131 EXPECT_TRUE([controller.get()->callbacks_ count] == 9); | 129 EXPECT_TRUE([controller.get()->callbacks_ count] == 9); |
132 | 130 |
133 for (int x = 1; x < 9; x++) { | 131 for (int x = 1; x < 9; x++) { |
134 NSNumber *num = [NSNumber numberWithInt:x-1]; | 132 NSNumber *num = [NSNumber numberWithInt:x-1]; |
135 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]); | 133 EXPECT_TRUE([[controller.get()->callbacks_ objectAtIndex:x] isEqual:num]); |
136 } | 134 } |
137 } | 135 } |
OLD | NEW |