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