OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 6 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
8 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 8 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 - (void)clearRecordersAndExpectations { | 25 - (void)clearRecordersAndExpectations { |
26 [recorders removeAllObjects]; | 26 [recorders removeAllObjects]; |
27 [expectations removeAllObjects]; | 27 [expectations removeAllObjects]; |
28 } | 28 } |
29 | 29 |
30 @end | 30 @end |
31 | 31 |
32 | 32 |
33 class BookmarkFolderTargetTest : public CocoaTest { | 33 class BookmarkFolderTargetTest : public CocoaTest { |
34 public: | 34 public: |
35 virtual void SetUp() { | 35 BookmarkFolderTargetTest() { |
36 CocoaTest::SetUp(); | |
37 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); | 36 BookmarkModel* model = helper_.profile()->GetBookmarkModel(); |
38 bmbNode_ = model->bookmark_bar_node(); | 37 bmbNode_ = model->bookmark_bar_node(); |
39 } | 38 } |
40 virtual void TearDown() { | |
41 pool_.Recycle(); | |
42 CocoaTest::TearDown(); | |
43 } | |
44 | 39 |
45 BrowserTestHelper helper_; | 40 BrowserTestHelper helper_; |
46 const BookmarkNode* bmbNode_; | 41 const BookmarkNode* bmbNode_; |
47 base::mac::ScopedNSAutoreleasePool pool_; | |
48 }; | 42 }; |
49 | 43 |
50 TEST_F(BookmarkFolderTargetTest, StartWithNothing) { | |
51 // Need a fake "button" which has a bookmark node. | |
52 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | |
53 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | |
54 | |
55 // Fake controller | |
56 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | |
57 class]]; | |
58 // No current folder | |
59 [[[controller stub] andReturn:nil] folderController]; | |
60 | |
61 // Make sure we get an addNew | |
62 [[controller expect] addNewFolderControllerWithParentButton:sender]; | |
63 | |
64 scoped_nsobject<BookmarkFolderTarget> target( | |
65 [[BookmarkFolderTarget alloc] initWithController:controller]); | |
66 | |
67 [target openBookmarkFolderFromButton:sender]; | |
68 EXPECT_OCMOCK_VERIFY(controller); | |
69 } | |
70 | |
71 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { | 44 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { |
72 // Need a fake "button" which has a bookmark node. | 45 // Need a fake "button" which has a bookmark node. |
73 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 46 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
74 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 47 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; |
75 | 48 |
76 // Fake controller | 49 // Fake controller |
77 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 50 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
78 class]]; | 51 class]]; |
79 // YES a current folder. Self-mock that as well, so "same" will be | 52 // YES a current folder. Self-mock that as well, so "same" will be |
80 // true. Note this creates a retain cycle in OCMockObject; we | 53 // true. Note this creates a retain cycle in OCMockObject; we |
81 // accomodate at the end of this function. | 54 // accomodate at the end of this function. |
82 [[[controller stub] andReturn:controller] folderController]; | |
83 [[[controller stub] andReturn:sender] parentButton]; | 55 [[[controller stub] andReturn:sender] parentButton]; |
84 | 56 |
| 57 // Fake bookmark bar. |
| 58 id barController = [OCMockObject mockForClass:[BookmarkBarController class]]; |
| 59 [[[barController stub] andReturn:controller] folderController]; |
| 60 |
85 // The folder is open, so a click should close just that folder (and | 61 // The folder is open, so a click should close just that folder (and |
86 // any subfolders). | 62 // any subfolders). |
87 [[controller expect] closeBookmarkFolder:controller]; | 63 [[barController expect] closeBookmarkFolder:barController]; |
88 | 64 |
89 scoped_nsobject<BookmarkFolderTarget> target( | 65 scoped_nsobject<BookmarkFolderTarget> target( |
90 [[BookmarkFolderTarget alloc] initWithController:controller]); | 66 [[BookmarkFolderTarget alloc] initWithController:barController]); |
91 | 67 |
92 [target openBookmarkFolderFromButton:sender]; | 68 [target openBookmarkFolderFromButton:sender]; |
93 EXPECT_OCMOCK_VERIFY(controller); | 69 EXPECT_OCMOCK_VERIFY(controller); |
| 70 EXPECT_OCMOCK_VERIFY(barController); |
94 | 71 |
95 // Our use of OCMockObject means an object can return itself. This | 72 // Our use of OCMockObject means an object can return itself. This |
96 // creates a retain cycle, since OCMock retains all objects used in | 73 // creates a retain cycle, since OCMock retains all objects used in |
97 // mock creation. Clear out the invocation handlers of all | 74 // mock creation. Clear out the invocation handlers of all |
98 // OCMockRecorders we used to break the cycles. | 75 // OCMockRecorders we used to break the cycles. |
99 [controller clearRecordersAndExpectations]; | 76 [controller clearRecordersAndExpectations]; |
100 } | 77 } |
101 | 78 |
102 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { | 79 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { |
103 // Need a fake "button" which has a bookmark node. | 80 // Need a fake "button" which has a bookmark node. |
104 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 81 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
105 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 82 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; |
106 | 83 |
107 // Fake controller | 84 // Fake controller |
108 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 85 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
109 class]]; | 86 class]]; |
110 // YES a current folder but NOT same. | 87 // YES a current folder but NOT same. |
111 [[[controller stub] andReturn:controller] folderController]; | |
112 [[[controller stub] andReturn:nil] parentButton]; | 88 [[[controller stub] andReturn:nil] parentButton]; |
113 | 89 |
| 90 // Fake bookmark bar. |
| 91 id barController = [OCMockObject mockForClass:[BookmarkBarController class]]; |
| 92 [[[barController stub] andReturn:controller] folderController]; |
| 93 |
114 // Insure the controller gets a chance to decide which folders to | 94 // Insure the controller gets a chance to decide which folders to |
115 // close and open. | 95 // close and open. |
116 [[controller expect] addNewFolderControllerWithParentButton:sender]; | 96 [[barController expect] addNewFolderControllerWithParentButton:sender]; |
117 | 97 |
118 scoped_nsobject<BookmarkFolderTarget> target( | 98 scoped_nsobject<BookmarkFolderTarget> target( |
119 [[BookmarkFolderTarget alloc] initWithController:controller]); | 99 [[BookmarkFolderTarget alloc] initWithController:barController]); |
120 | 100 |
121 [target openBookmarkFolderFromButton:sender]; | 101 [target openBookmarkFolderFromButton:sender]; |
122 EXPECT_OCMOCK_VERIFY(controller); | 102 EXPECT_OCMOCK_VERIFY(controller); |
| 103 EXPECT_OCMOCK_VERIFY(barController); |
123 | 104 |
124 // Break retain cycles. | 105 // Break retain cycles. |
125 [controller clearRecordersAndExpectations]; | 106 [controller clearRecordersAndExpectations]; |
126 } | 107 } |
OLD | NEW |