| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 EXPECT_EQ(ids[i], [bar_ nodeIdFromMenuTag:tags[i]]); | 679 EXPECT_EQ(ids[i], [bar_ nodeIdFromMenuTag:tags[i]]); |
| 680 } | 680 } |
| 681 | 681 |
| 682 // Confirm uniqueness. | 682 // Confirm uniqueness. |
| 683 std::sort(tags.begin(), tags.end()); | 683 std::sort(tags.begin(), tags.end()); |
| 684 for (unsigned int i=0; i<(tags.size()-1); i++) { | 684 for (unsigned int i=0; i<(tags.size()-1); i++) { |
| 685 EXPECT_NE(tags[i], tags[i+1]); | 685 EXPECT_NE(tags[i], tags[i+1]); |
| 686 } | 686 } |
| 687 } | 687 } |
| 688 | 688 |
| 689 TEST_F(BookmarkBarControllerTest, MenuForFolderNode) { | |
| 690 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
| 691 | |
| 692 // First make sure something (e.g. "(empty)" string) is always present. | |
| 693 NSMenu* menu = [bar_ menuForFolderNode:model->bookmark_bar_node()]; | |
| 694 EXPECT_GT([menu numberOfItems], 0); | |
| 695 | |
| 696 // Test two bookmarks. | |
| 697 GURL gurl("http://www.foo.com"); | |
| 698 bookmarks::AddIfNotBookmarked(model, gurl, ASCIIToUTF16("small")); | |
| 699 bookmarks::AddIfNotBookmarked( | |
| 700 model, GURL("http://www.cnn.com"), ASCIIToUTF16("bigger title")); | |
| 701 menu = [bar_ menuForFolderNode:model->bookmark_bar_node()]; | |
| 702 EXPECT_EQ([menu numberOfItems], 2); | |
| 703 NSMenuItem *item = [menu itemWithTitle:@"bigger title"]; | |
| 704 EXPECT_TRUE(item); | |
| 705 item = [menu itemWithTitle:@"small"]; | |
| 706 EXPECT_TRUE(item); | |
| 707 if (item) { | |
| 708 int64_t tag = [bar_ nodeIdFromMenuTag:[item tag]]; | |
| 709 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, tag); | |
| 710 EXPECT_TRUE(node); | |
| 711 EXPECT_EQ(gurl, node->url()); | |
| 712 } | |
| 713 | |
| 714 // Test with an actual folder as well | |
| 715 const BookmarkNode* parent = model->bookmark_bar_node(); | |
| 716 const BookmarkNode* folder = model->AddFolder(parent, | |
| 717 parent->child_count(), | |
| 718 ASCIIToUTF16("folder")); | |
| 719 model->AddURL(folder, folder->child_count(), | |
| 720 ASCIIToUTF16("f1"), GURL("http://framma-lamma.com")); | |
| 721 model->AddURL(folder, folder->child_count(), | |
| 722 ASCIIToUTF16("f2"), GURL("http://framma-lamma-ding-dong.com")); | |
| 723 menu = [bar_ menuForFolderNode:model->bookmark_bar_node()]; | |
| 724 EXPECT_EQ([menu numberOfItems], 3); | |
| 725 | |
| 726 item = [menu itemWithTitle:@"folder"]; | |
| 727 EXPECT_TRUE(item); | |
| 728 EXPECT_TRUE([item hasSubmenu]); | |
| 729 NSMenu *submenu = [item submenu]; | |
| 730 EXPECT_TRUE(submenu); | |
| 731 EXPECT_EQ(2, [submenu numberOfItems]); | |
| 732 EXPECT_TRUE([submenu itemWithTitle:@"f1"]); | |
| 733 EXPECT_TRUE([submenu itemWithTitle:@"f2"]); | |
| 734 } | |
| 735 | |
| 736 // Confirm openBookmark: forwards the request to the controller's delegate | 689 // Confirm openBookmark: forwards the request to the controller's delegate |
| 737 TEST_F(BookmarkBarControllerTest, OpenBookmark) { | 690 TEST_F(BookmarkBarControllerTest, OpenBookmark) { |
| 738 GURL gurl("http://walla.walla.ding.dong.com"); | 691 GURL gurl("http://walla.walla.ding.dong.com"); |
| 739 std::unique_ptr<BookmarkNode> node(new BookmarkNode(gurl)); | 692 std::unique_ptr<BookmarkNode> node(new BookmarkNode(gurl)); |
| 740 | 693 |
| 741 base::scoped_nsobject<BookmarkButtonCell> cell( | 694 base::scoped_nsobject<BookmarkButtonCell> cell( |
| 742 [[BookmarkButtonCell alloc] init]); | 695 [[BookmarkButtonCell alloc] init]); |
| 743 [cell setBookmarkNode:node.get()]; | 696 [cell setBookmarkNode:node.get()]; |
| 744 base::scoped_nsobject<BookmarkButton> button([[BookmarkButton alloc] init]); | 697 base::scoped_nsobject<BookmarkButton> button([[BookmarkButton alloc] init]); |
| 745 [button setCell:cell.get()]; | 698 [button setCell:cell.get()]; |
| (...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 "2f3b ] 4b "); | 2173 "2f3b ] 4b "); |
| 2221 actual = bookmarks::test::ModelStringFromNode(root); | 2174 actual = bookmarks::test::ModelStringFromNode(root); |
| 2222 EXPECT_EQ(expected, actual); | 2175 EXPECT_EQ(expected, actual); |
| 2223 | 2176 |
| 2224 // Verify that the other bookmark folder can't be deleted. | 2177 // Verify that the other bookmark folder can't be deleted. |
| 2225 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2178 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
| 2226 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2179 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
| 2227 } | 2180 } |
| 2228 | 2181 |
| 2229 } // namespace | 2182 } // namespace |
| OLD | NEW |