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.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 6 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 7 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // Fake controller | 51 // Fake controller |
52 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 52 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
53 class]]; | 53 class]]; |
54 // No current folder | 54 // No current folder |
55 [[[controller stub] andReturn:nil] folderController]; | 55 [[[controller stub] andReturn:nil] folderController]; |
56 | 56 |
57 // Make sure we get an addNew | 57 // Make sure we get an addNew |
58 [[controller expect] addNewFolderControllerWithParentButton:sender]; | 58 [[controller expect] addNewFolderControllerWithParentButton:sender]; |
59 | 59 |
60 scoped_nsobject<BookmarkFolderTarget> target( | 60 base::scoped_nsobject<BookmarkFolderTarget> target( |
61 [[BookmarkFolderTarget alloc] initWithController:controller]); | 61 [[BookmarkFolderTarget alloc] initWithController:controller]); |
62 | 62 |
63 [target openBookmarkFolderFromButton:sender]; | 63 [target openBookmarkFolderFromButton:sender]; |
64 EXPECT_OCMOCK_VERIFY(controller); | 64 EXPECT_OCMOCK_VERIFY(controller); |
65 } | 65 } |
66 | 66 |
67 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { | 67 TEST_F(BookmarkFolderTargetTest, ReopenSameFolder) { |
68 // Need a fake "button" which has a bookmark node. | 68 // Need a fake "button" which has a bookmark node. |
69 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 69 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
70 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 70 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; |
71 | 71 |
72 // Fake controller | 72 // Fake controller |
73 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 73 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
74 class]]; | 74 class]]; |
75 // YES a current folder. Self-mock that as well, so "same" will be | 75 // YES a current folder. Self-mock that as well, so "same" will be |
76 // true. Note this creates a retain cycle in OCMockObject; we | 76 // true. Note this creates a retain cycle in OCMockObject; we |
77 // accomodate at the end of this function. | 77 // accomodate at the end of this function. |
78 [[[controller stub] andReturn:controller] folderController]; | 78 [[[controller stub] andReturn:controller] folderController]; |
79 [[[controller stub] andReturn:sender] parentButton]; | 79 [[[controller stub] andReturn:sender] parentButton]; |
80 | 80 |
81 // The folder is open, so a click should close just that folder (and | 81 // The folder is open, so a click should close just that folder (and |
82 // any subfolders). | 82 // any subfolders). |
83 [[controller expect] closeBookmarkFolder:controller]; | 83 [[controller expect] closeBookmarkFolder:controller]; |
84 | 84 |
85 scoped_nsobject<BookmarkFolderTarget> target( | 85 base::scoped_nsobject<BookmarkFolderTarget> target( |
86 [[BookmarkFolderTarget alloc] initWithController:controller]); | 86 [[BookmarkFolderTarget alloc] initWithController:controller]); |
87 | 87 |
88 [target openBookmarkFolderFromButton:sender]; | 88 [target openBookmarkFolderFromButton:sender]; |
89 EXPECT_OCMOCK_VERIFY(controller); | 89 EXPECT_OCMOCK_VERIFY(controller); |
90 | 90 |
91 // Our use of OCMockObject means an object can return itself. This | 91 // Our use of OCMockObject means an object can return itself. This |
92 // creates a retain cycle, since OCMock retains all objects used in | 92 // creates a retain cycle, since OCMock retains all objects used in |
93 // mock creation. Clear out the invocation handlers of all | 93 // mock creation. Clear out the invocation handlers of all |
94 // OCMockRecorders we used to break the cycles. | 94 // OCMockRecorders we used to break the cycles. |
95 [controller clearRecordersAndExpectations]; | 95 [controller clearRecordersAndExpectations]; |
96 } | 96 } |
97 | 97 |
98 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { | 98 TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { |
99 // Need a fake "button" which has a bookmark node. | 99 // Need a fake "button" which has a bookmark node. |
100 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; | 100 id sender = [OCMockObject mockForClass:[BookmarkButton class]]; |
101 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; | 101 [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; |
102 | 102 |
103 // Fake controller | 103 // Fake controller |
104 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController | 104 id controller = [OCMockObject mockForClass:[BookmarkBarFolderController |
105 class]]; | 105 class]]; |
106 // YES a current folder but NOT same. | 106 // YES a current folder but NOT same. |
107 [[[controller stub] andReturn:controller] folderController]; | 107 [[[controller stub] andReturn:controller] folderController]; |
108 [[[controller stub] andReturn:nil] parentButton]; | 108 [[[controller stub] andReturn:nil] parentButton]; |
109 | 109 |
110 // Insure the controller gets a chance to decide which folders to | 110 // Insure the controller gets a chance to decide which folders to |
111 // close and open. | 111 // close and open. |
112 [[controller expect] addNewFolderControllerWithParentButton:sender]; | 112 [[controller expect] addNewFolderControllerWithParentButton:sender]; |
113 | 113 |
114 scoped_nsobject<BookmarkFolderTarget> target( | 114 base::scoped_nsobject<BookmarkFolderTarget> target( |
115 [[BookmarkFolderTarget alloc] initWithController:controller]); | 115 [[BookmarkFolderTarget alloc] initWithController:controller]); |
116 | 116 |
117 [target openBookmarkFolderFromButton:sender]; | 117 [target openBookmarkFolderFromButton:sender]; |
118 EXPECT_OCMOCK_VERIFY(controller); | 118 EXPECT_OCMOCK_VERIFY(controller); |
119 | 119 |
120 // Break retain cycles. | 120 // Break retain cycles. |
121 [controller clearRecordersAndExpectations]; | 121 [controller clearRecordersAndExpectations]; |
122 } | 122 } |
OLD | NEW |