diff options
author | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-05 23:09:30 +0000 |
---|---|---|
committer | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-05 23:09:30 +0000 |
commit | 080bf942acf0599e0d1811f07f5cef304cf355c4 (patch) | |
tree | 1e9104f67bd1c1ecf75b53f4c0003b02493979cf /chrome/browser/cocoa/bookmark_tree_controller_unittest.mm | |
parent | 0f28580a84220d218288bfdec6bb689b2e1b8d29 (diff) | |
download | chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.zip chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.tar.gz chromium_src-080bf942acf0599e0d1811f07f5cef304cf355c4.tar.bz2 |
Add additional pasteboard tests to BookmarkTreeControllerTest.
Split up one method in BookmarkTreeController to improve testability.
BUG=13149
TEST=BookmarkTreeControllerTest.MoveNodes
Review URL: http://codereview.chromium.org/523069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_tree_controller_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_tree_controller_unittest.mm | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/bookmark_tree_controller_unittest.mm b/chrome/browser/cocoa/bookmark_tree_controller_unittest.mm index dc22f19..0720a1c 100644 --- a/chrome/browser/cocoa/bookmark_tree_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_tree_controller_unittest.mm @@ -50,6 +50,14 @@ class BookmarkTreeControllerTest : public CocoaTest { return [manager_ itemFromNode:node]; } + id AddFolderToBar(const std::wstring& title) { + BookmarkModel* model = [manager_ bookmarkModel]; + const BookmarkNode* bar = model->GetBookmarkBarNode(); + const BookmarkNode* node; + node = model->AddGroup(bar, bar->GetChildCount(), title); + return [manager_ itemFromNode:node]; + } + BrowserTestHelper browser_test_helper_; BookmarkManagerController* manager_; BookmarkTreeController* treeController_; @@ -60,11 +68,16 @@ TEST_F(BookmarkTreeControllerTest, Model) { // Select nothing in the group list and check tree is empty: BookmarkGroupsController* groupsController = [manager_ groupsController]; [groupsController setSelectedGroup:nil]; - ASSERT_EQ(nil, [treeController_ group]); + EXPECT_EQ(nil, [treeController_ group]); // Select the bookmarks bar and check that it's shown in the tree: id barItem = SelectBar(); - ASSERT_EQ(barItem, [treeController_ group]); + EXPECT_EQ(barItem, [treeController_ group]); + + // Check the outline-item mapping methods: + const BookmarkNode* barNode = [manager_ nodeFromItem:barItem]; + EXPECT_EQ(nil, [treeController_ itemFromNode:barNode]); + EXPECT_EQ(barNode, [treeController_ nodeFromItem:nil]); } TEST_F(BookmarkTreeControllerTest, Selection) { @@ -88,6 +101,68 @@ TEST_F(BookmarkTreeControllerTest, Selection) { EXPECT_TRUE([sel isEqual:[treeController_ selectedItems]]); } +TEST_F(BookmarkTreeControllerTest, MoveNodes) { + // Add three bookmarks and a folder. + NSOutlineView* outline = [treeController_ outline]; + SelectBar(); + id test1 = AddToBar(L"Test 1", "http://example.com/test1"); + id test2 = AddToBar(L"Test 2", "http://example.com/test2"); + id folder = AddFolderToBar(L"Folder"); + id test3 = AddToBar(L"Test 3", "http://example.com/test3"); + [outline expandItem:folder]; + + const BookmarkNode* groupNode = [treeController_ nodeFromItem:nil]; + const BookmarkNode* node1 = [manager_ nodeFromItem:test1]; + const BookmarkNode* node2 = [manager_ nodeFromItem:test2]; + const BookmarkNode* folderNode = [manager_ nodeFromItem:folder]; + const BookmarkNode* node3 = [manager_ nodeFromItem:test3]; + + // Check where dropped URLs would go: + NSInteger dropIndex = NSOutlineViewDropOnItemIndex; + const BookmarkNode* target = [treeController_ nodeForDropOnItem:test1 + proposedIndex:&dropIndex]; + EXPECT_EQ(NULL, target); + dropIndex = 0; + target = [treeController_ nodeForDropOnItem:test1 + proposedIndex:&dropIndex]; + EXPECT_EQ(groupNode, target); + EXPECT_EQ(1, dropIndex); + dropIndex = 0; + target = [treeController_ nodeForDropOnItem:folder + proposedIndex:&dropIndex]; + EXPECT_EQ(folderNode, target); + EXPECT_EQ(0, dropIndex); + dropIndex = NSOutlineViewDropOnItemIndex; + target = [treeController_ nodeForDropOnItem:folder + proposedIndex:&dropIndex]; + EXPECT_EQ(folderNode, target); + EXPECT_EQ(0, dropIndex); + + // Move the first and third item into the folder. + std::vector<const BookmarkNode*> nodes; + nodes.push_back(node1); + nodes.push_back(node3); + [treeController_ moveNodes:nodes toFolder:folderNode atIndex:0]; + + // Verify bookmark model hierarchy. + EXPECT_EQ(folderNode, node1->GetParent()); + EXPECT_EQ(folderNode, node3->GetParent()); + EXPECT_EQ(groupNode, folderNode->GetParent()); + EXPECT_EQ(groupNode, node2->GetParent()); + + // Verify NSOutlineView hierarchy. + EXPECT_EQ(folder, [outline parentForItem:test1]); + EXPECT_EQ(folder, [outline parentForItem:test3]); + EXPECT_EQ(nil, [outline parentForItem:test2]); + EXPECT_EQ(nil, [outline parentForItem:folder]); + + // Verify the moved nodes are selected. + EXPECT_TRUE([[outline selectedRowIndexes] + isEqual:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 2)]]); + NSArray* sel = [treeController_ selectedItems]; + EXPECT_TRUE([sel isEqual:([NSArray arrayWithObjects:test1, test3, nil])]); +} + TEST_F(BookmarkTreeControllerTest, CopyURLs) { SelectBar(); AddToBar(L"Test 1", "http://example.com/test1"); |