diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:06:06 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:06:06 +0000 |
commit | c422c9199cfaff70b58abdb12d8d0e5b6bcd8101 (patch) | |
tree | 2be9a86945b18e9a00f3b225dbc352e0b8a5aad6 /chrome/browser/cocoa/bookmark_folder_target_unittest.mm | |
parent | 594f4ff352685bb83b71d1402264bc2cf2116e67 (diff) | |
download | chromium_src-c422c9199cfaff70b58abdb12d8d0e5b6bcd8101.zip chromium_src-c422c9199cfaff70b58abdb12d8d0e5b6bcd8101.tar.gz chromium_src-c422c9199cfaff70b58abdb12d8d0e5b6bcd8101.tar.bz2 |
Cmd-click in bookmark subfolders will open all.
Refactor code for better sharing.
BUG=http://crbug.com/26380 (cmd-click in subfolders now opens all)
BUG=http://crbug.com/35966 (code dup reduced)
TEST=\
Cmd-click a folder in the bar --> open all
Cmd-click a folder in a SUBfolder of the bar --> open all
Review URL: http://codereview.chromium.org/1134008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42546 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_folder_target_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_folder_target_unittest.mm | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_folder_target_unittest.mm b/chrome/browser/cocoa/bookmark_folder_target_unittest.mm new file mode 100644 index 0000000..179892e --- /dev/null +++ b/chrome/browser/cocoa/bookmark_folder_target_unittest.mm @@ -0,0 +1,92 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/bookmark_bar_controller.h" +#import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" +#import "chrome/browser/cocoa/bookmark_folder_target.h" +#include "chrome/browser/cocoa/bookmark_button.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#include "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" +#import "third_party/ocmock/OCMock/OCMock.h" + + +class BookmarkFolderTargetTest : public CocoaTest { + public: + virtual void SetUp() { + CocoaTest::SetUp(); + BookmarkModel* model = helper_.profile()->GetBookmarkModel(); + bmbNode_ = model->GetBookmarkBarNode(); + } + + BrowserTestHelper helper_; + const BookmarkNode* bmbNode_; +}; + +TEST_F(BookmarkFolderTargetTest, StartWithNothing) { + // Need a fake "button" which has a bookmark node. + id sender = [OCMockObject mockForClass:[BookmarkButton class]]; + [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; + + // Fake controller + id controller = [OCMockObject mockForClass:[BookmarkBarFolderController + class]]; + // No current folder + [[[controller stub] andReturn:nil] folderController]; + + // Make sure we get an addNew + [[controller expect] addNewFolderControllerWithParentButton:sender]; + + scoped_nsobject<BookmarkFolderTarget> target( + [[BookmarkFolderTarget alloc] initWithController:controller]); + + [target openBookmarkFolderFromButton:sender]; + [controller verify]; +} + +TEST_F(BookmarkFolderTargetTest, ReopenSame) { + // Need a fake "button" which has a bookmark node. + id sender = [OCMockObject mockForClass:[BookmarkButton class]]; + [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; + + // Fake controller + id controller = [OCMockObject mockForClass:[BookmarkBarFolderController + class]]; + // YES a current folder. Self-mock that as well, so "same" will be true. + [[[controller stub] andReturn:controller] folderController]; + [[[controller stub] andReturn:sender] parentButton]; + + // Make sure we close all and do NOT create a new one. + [[controller expect] closeAllBookmarkFolders]; + + scoped_nsobject<BookmarkFolderTarget> target( + [[BookmarkFolderTarget alloc] initWithController:controller]); + + [target openBookmarkFolderFromButton:sender]; + [controller verify]; +} + +TEST_F(BookmarkFolderTargetTest, ReopenNotSame) { + // Need a fake "button" which has a bookmark node. + id sender = [OCMockObject mockForClass:[BookmarkButton class]]; + [[[sender stub] andReturnValue:OCMOCK_VALUE(bmbNode_)] bookmarkNode]; + + // Fake controller + id controller = [OCMockObject mockForClass:[BookmarkBarFolderController + class]]; + // YES a current folder but NOT same. + [[[controller stub] andReturn:controller] folderController]; + [[[controller stub] andReturn:nil] parentButton]; + + // Make sure we close all AND create a new one. + [[controller expect] closeAllBookmarkFolders]; + [[controller expect] addNewFolderControllerWithParentButton:sender]; + + scoped_nsobject<BookmarkFolderTarget> target( + [[BookmarkFolderTarget alloc] initWithController:controller]); + + [target openBookmarkFolderFromButton:sender]; + [controller verify]; +} |