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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | 10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" |
11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 #include "third_party/ocmock/gtest_support.h" | 14 #include "third_party/ocmock/gtest_support.h" |
15 #import "third_party/ocmock/OCMock/OCMock.h" | 15 #import "third_party/ocmock/OCMock/OCMock.h" |
| 16 #include "third_party/ocmock/ocmock_extensions.h" |
16 | 17 |
17 @interface OCMockObject(PreventRetainCycle) | 18 @interface OCMockObject(PreventRetainCycle) |
18 - (void)clearRecordersAndExpectations; | 19 - (void)clearRecordersAndExpectations; |
19 @end | 20 @end |
20 | 21 |
21 @implementation OCMockObject(PreventRetainCycle) | 22 @implementation OCMockObject(PreventRetainCycle) |
22 | 23 |
23 // We need a mechanism to clear the invocation handlers to break a | 24 // We need a mechanism to clear the invocation handlers to break a |
24 // retain cycle (see below; search for "retain cycle"). | 25 // retain cycle (see below; search for "retain cycle"). |
25 - (void)clearRecordersAndExpectations { | 26 - (void)clearRecordersAndExpectations { |
(...skipping 17 matching lines...) Expand all Loading... |
43 } | 44 } |
44 | 45 |
45 BrowserTestHelper helper_; | 46 BrowserTestHelper helper_; |
46 const BookmarkNode* bmbNode_; | 47 const BookmarkNode* bmbNode_; |
47 base::mac::ScopedNSAutoreleasePool pool_; | 48 base::mac::ScopedNSAutoreleasePool pool_; |
48 }; | 49 }; |
49 | 50 |
50 TEST_F(BookmarkFolderTargetTest, StartWithNothing) { | 51 TEST_F(BookmarkFolderTargetTest, StartWithNothing) { |
51 // Need a fake "button" which has a bookmark node. | 52 // Need a fake "button" which has a bookmark node. |
52 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 53 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
53 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 54 [[[sender stub] andReturnPointer:bmbNode_] bookmarkNode]; |
54 | 55 |
55 // Fake controller | 56 // Fake controller |
56 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 57 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
57 class]]; | 58 class]]; |
58 // No current folder | 59 // No current folder |
59 [[[controller stub] andReturn:nil] folderController]; | 60 [[[controller stub] andReturn:nil] folderController]; |
60 | 61 |
61 // Make sure we get an addNew | 62 // Make sure we get an addNew |
62 [[controller expect] addNewFolderControllerWithParentButton:sender]; | 63 [[controller expect] addNewFolderControllerWithParentButton:sender]; |
63 | 64 |
64 scoped_nsobject<BookmarkFolderTarget> target( | 65 scoped_nsobject<BookmarkFolderTarget> target( |
65 [[BookmarkFolderTarget alloc] initWithController:controller]); | 66 [[BookmarkFolderTarget alloc] initWithController:controller]); |
66 | 67 |
67 [target openBookmarkFolderFromButton:sender]; | 68 [target openBookmarkFolderFromButton:sender]; |
68 EXPECT_OCMOCK_VERIFY(controller); | 69 EXPECT_OCMOCK_VERIFY(controller); |
69 } | 70 } |
70 | 71 |
71 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { | 72 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { |
72 // Need a fake "button" which has a bookmark node. | 73 // Need a fake "button" which has a bookmark node. |
73 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 74 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
74 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 75 [[[sender stub] andReturnPointer:bmbNode_] bookmarkNode]; |
75 | 76 |
76 // Fake controller | 77 // Fake controller |
77 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 78 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
78 class]]; | 79 class]]; |
79 // YES a current folder. Self-mock that as well, so "same" will be | 80 // YES a current folder. Self-mock that as well, so "same" will be |
80 // true. Note this creates a retain cycle in OCMockObject; we | 81 // true. Note this creates a retain cycle in OCMockObject; we |
81 // accomodate at the end of this function. | 82 // accomodate at the end of this function. |
82 [[[controller stub] andReturn:controller] folderController]; | 83 [[[controller stub] andReturn:controller] folderController]; |
83 [[[controller stub] andReturn:sender] parentButton]; | 84 [[[controller stub] andReturn:sender] parentButton]; |
84 | 85 |
(...skipping 10 matching lines...) Expand all Loading... |
95 // Our use of OCMockObject means an object can return itself. This | 96 // Our use of OCMockObject means an object can return itself. This |
96 // creates a retain cycle, since OCMock retains all objects used in | 97 // creates a retain cycle, since OCMock retains all objects used in |
97 // mock creation. Clear out the invocation handlers of all | 98 // mock creation. Clear out the invocation handlers of all |
98 // OCMockRecorders we used to break the cycles. | 99 // OCMockRecorders we used to break the cycles. |
99 [controller clearRecordersAndExpectations]; | 100 [controller clearRecordersAndExpectations]; |
100 } | 101 } |
101 | 102 |
102 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { | 103 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { |
103 // Need a fake "button" which has a bookmark node. | 104 // Need a fake "button" which has a bookmark node. |
104 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 105 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
105 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 106 [[[sender stub] andReturnPointer:bmbNode_] bookmarkNode]; |
106 | 107 |
107 // Fake controller | 108 // Fake controller |
108 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 109 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
109 class]]; | 110 class]]; |
110 // YES a current folder but NOT same. | 111 // YES a current folder but NOT same. |
111 [[[controller stub] andReturn:controller] folderController]; | 112 [[[controller stub] andReturn:controller] folderController]; |
112 [[[controller stub] andReturn:nil] parentButton]; | 113 [[[controller stub] andReturn:nil] parentButton]; |
113 | 114 |
114 // Insure the controller gets a chance to decide which folders to | 115 // Insure the controller gets a chance to decide which folders to |
115 // close and open. | 116 // close and open. |
116 [[controller expect] addNewFolderControllerWithParentButton:sender]; | 117 [[controller expect] addNewFolderControllerWithParentButton:sender]; |
117 | 118 |
118 scoped_nsobject<BookmarkFolderTarget> target( | 119 scoped_nsobject<BookmarkFolderTarget> target( |
119 [[BookmarkFolderTarget alloc] initWithController:controller]); | 120 [[BookmarkFolderTarget alloc] initWithController:controller]); |
120 | 121 |
121 [target openBookmarkFolderFromButton:sender]; | 122 [target openBookmarkFolderFromButton:sender]; |
122 EXPECT_OCMOCK_VERIFY(controller); | 123 EXPECT_OCMOCK_VERIFY(controller); |
123 | 124 |
124 // Break retain cycles. | 125 // Break retain cycles. |
125 [controller clearRecordersAndExpectations]; | 126 [controller clearRecordersAndExpectations]; |
126 } | 127 } |
OLD | NEW |