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 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" |
17 #include "chrome/browser/bookmarks/bookmark_utils.h" | 17 #include "chrome/browser/bookmarks/bookmark_utils.h" |
18 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" | 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" |
23 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" | 23 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" |
24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
25 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 25 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
26 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 26 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 } | 1230 } |
1231 | 1231 |
1232 // Verify that the folder menu presentation properly tracks mouse movements | 1232 // Verify that the folder menu presentation properly tracks mouse movements |
1233 // over the bar. Until there is a click no folder menus should show. After a | 1233 // over the bar. Until there is a click no folder menus should show. After a |
1234 // click on a folder folder menus should show until another click on a folder | 1234 // click on a folder folder menus should show until another click on a folder |
1235 // button, and a click outside the bar and its folder menus. | 1235 // button, and a click outside the bar and its folder menus. |
1236 TEST_F(BookmarkBarControllerTest, TestFolderButtons) { | 1236 TEST_F(BookmarkBarControllerTest, TestFolderButtons) { |
1237 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1237 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1238 const BookmarkNode* root = model->bookmark_bar_node(); | 1238 const BookmarkNode* root = model->bookmark_bar_node(); |
1239 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b 4f:[ 4f1b 4f2b ] "); | 1239 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b 4f:[ 4f1b 4f2b ] "); |
1240 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1240 test::AddNodesFromModelString(model, root, model_string); |
1241 | 1241 |
1242 // Validate initial model and that we do not have a folder controller. | 1242 // Validate initial model and that we do not have a folder controller. |
1243 std::string actualModelString = | 1243 std::string actualModelString = test::ModelStringFromNode(root); |
1244 BookmarkModelTestUtils::ModelStringFromNode(root); | |
1245 EXPECT_EQ(model_string, actualModelString); | 1244 EXPECT_EQ(model_string, actualModelString); |
1246 EXPECT_FALSE([bar_ folderController]); | 1245 EXPECT_FALSE([bar_ folderController]); |
1247 | 1246 |
1248 // Add a real bookmark so we can click on it. | 1247 // Add a real bookmark so we can click on it. |
1249 const BookmarkNode* folder = root->GetChild(3); | 1248 const BookmarkNode* folder = root->GetChild(3); |
1250 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("CLICK ME"), | 1249 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("CLICK ME"), |
1251 GURL("http://www.google.com/")); | 1250 GURL("http://www.google.com/")); |
1252 | 1251 |
1253 // Click on a folder button. | 1252 // Click on a folder button. |
1254 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"4f"]; | 1253 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"4f"]; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 | 1444 |
1446 // Now that we've closed the bookmark bar (with animation) the folder menu | 1445 // Now that we've closed the bookmark bar (with animation) the folder menu |
1447 // should have been closed thus releasing the folderController. | 1446 // should have been closed thus releasing the folderController. |
1448 EXPECT_FALSE([bar_ folderController]); | 1447 EXPECT_FALSE([bar_ folderController]); |
1449 } | 1448 } |
1450 | 1449 |
1451 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) { | 1450 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) { |
1452 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1451 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1453 const BookmarkNode* root = model->bookmark_bar_node(); | 1452 const BookmarkNode* root = model->bookmark_bar_node(); |
1454 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1453 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1455 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1454 test::AddNodesFromModelString(model, root, model_string); |
1456 | 1455 |
1457 // Validate initial model. | 1456 // Validate initial model. |
1458 std::string actualModelString = | 1457 std::string actualModelString = test::ModelStringFromNode(root); |
1459 BookmarkModelTestUtils::ModelStringFromNode(root); | |
1460 EXPECT_EQ(model_string, actualModelString); | 1458 EXPECT_EQ(model_string, actualModelString); |
1461 | 1459 |
1462 // Remember how many buttons are showing. | 1460 // Remember how many buttons are showing. |
1463 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1461 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
1464 NSArray* buttons = [bar_ buttons]; | 1462 NSArray* buttons = [bar_ buttons]; |
1465 | 1463 |
1466 // Move a button around a bit. | 1464 // Move a button around a bit. |
1467 [bar_ moveButtonFromIndex:0 toIndex:2]; | 1465 [bar_ moveButtonFromIndex:0 toIndex:2]; |
1468 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:0] title]); | 1466 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:0] title]); |
1469 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:1] title]); | 1467 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:1] title]); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 EXPECT_EQ(31.0, NSWidth([view frame])); | 1517 EXPECT_EQ(31.0, NSWidth([view frame])); |
1520 EXPECT_FALSE([view isHidden]); | 1518 EXPECT_FALSE([view isHidden]); |
1521 [bar_ shrinkOrHideView:view forMaxX:29.0]; | 1519 [bar_ shrinkOrHideView:view forMaxX:29.0]; |
1522 EXPECT_TRUE([view isHidden]); | 1520 EXPECT_TRUE([view isHidden]); |
1523 } | 1521 } |
1524 | 1522 |
1525 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { | 1523 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { |
1526 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1524 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1527 const BookmarkNode* root = model->bookmark_bar_node(); | 1525 const BookmarkNode* root = model->bookmark_bar_node(); |
1528 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1526 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1529 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1527 test::AddNodesFromModelString(model, root, model_string); |
1530 [bar_ frameDidChange]; | 1528 [bar_ frameDidChange]; |
1531 | 1529 |
1532 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, | 1530 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, |
1533 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, | 1531 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, |
1534 123.0 }; | 1532 123.0 }; |
1535 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, | 1533 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, |
1536 YES, YES, YES, NO, NO, NO, NO}; | 1534 YES, YES, YES, NO, NO, NO, NO}; |
1537 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, | 1535 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, |
1538 2, 1 }; | 1536 2, 1 }; |
1539 | 1537 |
(...skipping 15 matching lines...) Expand all Loading... |
1555 CommandLine::ForCurrentProcess()->AppendSwitch( | 1553 CommandLine::ForCurrentProcess()->AppendSwitch( |
1556 switches::kEnableInstantExtendedAPI); | 1554 switches::kEnableInstantExtendedAPI); |
1557 } | 1555 } |
1558 }; | 1556 }; |
1559 | 1557 |
1560 TEST_F(BookmarkBarControllerWithInstantExtendedTest, | 1558 TEST_F(BookmarkBarControllerWithInstantExtendedTest, |
1561 BookmarksWithAppsPageShortcut) { | 1559 BookmarksWithAppsPageShortcut) { |
1562 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1560 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1563 const BookmarkNode* root = model->bookmark_bar_node(); | 1561 const BookmarkNode* root = model->bookmark_bar_node(); |
1564 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1562 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1565 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1563 test::AddNodesFromModelString(model, root, model_string); |
1566 [bar_ frameDidChange]; | 1564 [bar_ frameDidChange]; |
1567 | 1565 |
1568 // Apps page shortcut button should be visible. | 1566 // Apps page shortcut button should be visible. |
1569 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1567 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
1570 | 1568 |
1571 // Bookmarks should be to the right of the Apps page shortcut button. | 1569 // Bookmarks should be to the right of the Apps page shortcut button. |
1572 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1570 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
1573 CGFloat right = apps_button_right; | 1571 CGFloat right = apps_button_right; |
1574 NSArray* buttons = [bar_ buttons]; | 1572 NSArray* buttons = [bar_ buttons]; |
1575 for (size_t i = 0; i < [buttons count]; ++i) { | 1573 for (size_t i = 0; i < [buttons count]; ++i) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 | 1757 |
1760 TEST_F(BookmarkBarControllerDragDropTest, DragMoveBarBookmarkToOffTheSide) { | 1758 TEST_F(BookmarkBarControllerDragDropTest, DragMoveBarBookmarkToOffTheSide) { |
1761 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1759 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1762 const BookmarkNode* root = model->bookmark_bar_node(); | 1760 const BookmarkNode* root = model->bookmark_bar_node(); |
1763 const std::string model_string("1bWithLongName 2fWithLongName:[ " | 1761 const std::string model_string("1bWithLongName 2fWithLongName:[ " |
1764 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName " | 1762 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName " |
1765 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " | 1763 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " |
1766 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1764 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1767 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1765 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1768 "11bWithLongName 12bWithLongName 13b "); | 1766 "11bWithLongName 12bWithLongName 13b "); |
1769 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1767 test::AddNodesFromModelString(model, root, model_string); |
1770 | 1768 |
1771 // Validate initial model. | 1769 // Validate initial model. |
1772 std::string actualModelString = | 1770 std::string actualModelString = test::ModelStringFromNode(root); |
1773 BookmarkModelTestUtils::ModelStringFromNode(root); | |
1774 EXPECT_EQ(model_string, actualModelString); | 1771 EXPECT_EQ(model_string, actualModelString); |
1775 | 1772 |
1776 // Insure that the off-the-side is not showing. | 1773 // Insure that the off-the-side is not showing. |
1777 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); | 1774 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); |
1778 | 1775 |
1779 // Remember how many buttons are showing and are available. | 1776 // Remember how many buttons are showing and are available. |
1780 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1777 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
1781 int oldChildCount = root->child_count(); | 1778 int oldChildCount = root->child_count(); |
1782 | 1779 |
1783 // Pop up the off-the-side menu. | 1780 // Pop up the off-the-side menu. |
(...skipping 28 matching lines...) Expand all Loading... |
1812 | 1809 |
1813 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { | 1810 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { |
1814 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1811 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1815 const BookmarkNode* root = model->bookmark_bar_node(); | 1812 const BookmarkNode* root = model->bookmark_bar_node(); |
1816 const std::string model_string("1bWithLongName 2bWithLongName " | 1813 const std::string model_string("1bWithLongName 2bWithLongName " |
1817 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1814 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1818 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1815 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1819 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " | 1816 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " |
1820 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " | 1817 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " |
1821 "19bWithLongName 20bWithLongName "); | 1818 "19bWithLongName 20bWithLongName "); |
1822 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1819 test::AddNodesFromModelString(model, root, model_string); |
1823 | 1820 |
1824 const BookmarkNode* other = model->other_node(); | 1821 const BookmarkNode* other = model->other_node(); |
1825 const std::string other_string("1other 2other 3other "); | 1822 const std::string other_string("1other 2other 3other "); |
1826 BookmarkModelTestUtils::AddNodesFromModelString(model, other, other_string); | 1823 test::AddNodesFromModelString(model, other, other_string); |
1827 | 1824 |
1828 // Validate initial model. | 1825 // Validate initial model. |
1829 std::string actualModelString = | 1826 std::string actualModelString = test::ModelStringFromNode(root); |
1830 BookmarkModelTestUtils::ModelStringFromNode(root); | |
1831 EXPECT_EQ(model_string, actualModelString); | 1827 EXPECT_EQ(model_string, actualModelString); |
1832 std::string actualOtherString = | 1828 std::string actualOtherString = test::ModelStringFromNode(other); |
1833 BookmarkModelTestUtils::ModelStringFromNode(other); | |
1834 EXPECT_EQ(other_string, actualOtherString); | 1829 EXPECT_EQ(other_string, actualOtherString); |
1835 | 1830 |
1836 // Insure that the off-the-side is showing. | 1831 // Insure that the off-the-side is showing. |
1837 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); | 1832 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); |
1838 | 1833 |
1839 // Remember how many buttons are showing and are available. | 1834 // Remember how many buttons are showing and are available. |
1840 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1835 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
1841 int oldRootCount = root->child_count(); | 1836 int oldRootCount = root->child_count(); |
1842 int oldOtherCount = other->child_count(); | 1837 int oldOtherCount = other->child_count(); |
1843 | 1838 |
(...skipping 23 matching lines...) Expand all Loading... |
1867 EXPECT_EQ(oldRootCount - 1, newRootCount); | 1862 EXPECT_EQ(oldRootCount - 1, newRootCount); |
1868 EXPECT_EQ(oldOTSCount - 1, newOTSCount); | 1863 EXPECT_EQ(oldOTSCount - 1, newOTSCount); |
1869 EXPECT_EQ(oldOtherCount + 1, newOtherCount); | 1864 EXPECT_EQ(oldOtherCount + 1, newOtherCount); |
1870 } | 1865 } |
1871 | 1866 |
1872 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { | 1867 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { |
1873 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1868 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1874 const BookmarkNode* root = model->bookmark_bar_node(); | 1869 const BookmarkNode* root = model->bookmark_bar_node(); |
1875 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1870 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1876 "2f3b ] 3b 4b "); | 1871 "2f3b ] 3b 4b "); |
1877 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1872 test::AddNodesFromModelString(model, root, model_string); |
1878 const BookmarkNode* other = model->other_node(); | 1873 const BookmarkNode* other = model->other_node(); |
1879 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] " | 1874 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] " |
1880 "O4f:[ O4f1b O4f2f ] 05b "); | 1875 "O4f:[ O4f1b O4f2f ] 05b "); |
1881 BookmarkModelTestUtils::AddNodesFromModelString(model, other, other_string); | 1876 test::AddNodesFromModelString(model, other, other_string); |
1882 | 1877 |
1883 // Validate initial model. | 1878 // Validate initial model. |
1884 std::string actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 1879 std::string actual = test::ModelStringFromNode(root); |
1885 EXPECT_EQ(model_string, actual); | 1880 EXPECT_EQ(model_string, actual); |
1886 actual = BookmarkModelTestUtils::ModelStringFromNode(other); | 1881 actual = test::ModelStringFromNode(other); |
1887 EXPECT_EQ(other_string, actual); | 1882 EXPECT_EQ(other_string, actual); |
1888 | 1883 |
1889 // Remember the little ones. | 1884 // Remember the little ones. |
1890 int oldChildCount = root->child_count(); | 1885 int oldChildCount = root->child_count(); |
1891 | 1886 |
1892 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; | 1887 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; |
1893 ASSERT_TRUE(targetButton); | 1888 ASSERT_TRUE(targetButton); |
1894 | 1889 |
1895 // Gen up some dragging data. | 1890 // Gen up some dragging data. |
1896 const BookmarkNode* newNode = other->GetChild(2); | 1891 const BookmarkNode* newNode = other->GetChild(2); |
1897 [bar_ setDragDataNode:newNode]; | 1892 [bar_ setDragDataNode:newNode]; |
1898 base::scoped_nsobject<FakeDragInfo> dragInfo([[FakeDragInfo alloc] init]); | 1893 base::scoped_nsobject<FakeDragInfo> dragInfo([[FakeDragInfo alloc] init]); |
1899 [dragInfo setDropLocation:[targetButton center]]; | 1894 [dragInfo setDropLocation:[targetButton center]]; |
1900 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; | 1895 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; |
1901 | 1896 |
1902 // There should one more button in the bar. | 1897 // There should one more button in the bar. |
1903 int newChildCount = root->child_count(); | 1898 int newChildCount = root->child_count(); |
1904 EXPECT_EQ(oldChildCount + 1, newChildCount); | 1899 EXPECT_EQ(oldChildCount + 1, newChildCount); |
1905 // Verify the model. | 1900 // Verify the model. |
1906 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1901 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1907 "2f3b ] O3f:[ O3f1b O3f2f ] 3b 4b "); | 1902 "2f3b ] O3f:[ O3f1b O3f2f ] 3b 4b "); |
1908 actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 1903 actual = test::ModelStringFromNode(root); |
1909 EXPECT_EQ(expected, actual); | 1904 EXPECT_EQ(expected, actual); |
1910 oldChildCount = newChildCount; | 1905 oldChildCount = newChildCount; |
1911 | 1906 |
1912 // Now do it over a folder button. | 1907 // Now do it over a folder button. |
1913 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; | 1908 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; |
1914 ASSERT_TRUE(targetButton); | 1909 ASSERT_TRUE(targetButton); |
1915 NSPoint targetPoint = [targetButton center]; | 1910 NSPoint targetPoint = [targetButton center]; |
1916 newNode = other->GetChild(2); // Should be O4f. | 1911 newNode = other->GetChild(2); // Should be O4f. |
1917 EXPECT_EQ(newNode->GetTitle(), ASCIIToUTF16("O4f")); | 1912 EXPECT_EQ(newNode->GetTitle(), ASCIIToUTF16("O4f")); |
1918 [bar_ setDragDataNode:newNode]; | 1913 [bar_ setDragDataNode:newNode]; |
1919 [dragInfo setDropLocation:targetPoint]; | 1914 [dragInfo setDropLocation:targetPoint]; |
1920 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; | 1915 [bar_ dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; |
1921 | 1916 |
1922 newChildCount = root->child_count(); | 1917 newChildCount = root->child_count(); |
1923 EXPECT_EQ(oldChildCount, newChildCount); | 1918 EXPECT_EQ(oldChildCount, newChildCount); |
1924 // Verify the model. | 1919 // Verify the model. |
1925 const std::string expected1("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1920 const std::string expected1("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1926 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " | 1921 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " |
1927 "3b 4b "); | 1922 "3b 4b "); |
1928 actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 1923 actual = test::ModelStringFromNode(root); |
1929 EXPECT_EQ(expected1, actual); | 1924 EXPECT_EQ(expected1, actual); |
1930 } | 1925 } |
1931 | 1926 |
1932 TEST_F(BookmarkBarControllerDragDropTest, AddURLs) { | 1927 TEST_F(BookmarkBarControllerDragDropTest, AddURLs) { |
1933 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1928 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1934 const BookmarkNode* root = model->bookmark_bar_node(); | 1929 const BookmarkNode* root = model->bookmark_bar_node(); |
1935 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1930 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1936 "2f3b ] 3b 4b "); | 1931 "2f3b ] 3b 4b "); |
1937 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1932 test::AddNodesFromModelString(model, root, model_string); |
1938 | 1933 |
1939 // Validate initial model. | 1934 // Validate initial model. |
1940 std::string actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 1935 std::string actual = test::ModelStringFromNode(root); |
1941 EXPECT_EQ(model_string, actual); | 1936 EXPECT_EQ(model_string, actual); |
1942 | 1937 |
1943 // Remember the children. | 1938 // Remember the children. |
1944 int oldChildCount = root->child_count(); | 1939 int oldChildCount = root->child_count(); |
1945 | 1940 |
1946 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; | 1941 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; |
1947 ASSERT_TRUE(targetButton); | 1942 ASSERT_TRUE(targetButton); |
1948 | 1943 |
1949 NSArray* urls = [NSArray arrayWithObjects: @"http://www.a.com/", | 1944 NSArray* urls = [NSArray arrayWithObjects: @"http://www.a.com/", |
1950 @"http://www.b.com/", nil]; | 1945 @"http://www.b.com/", nil]; |
1951 NSArray* titles = [NSArray arrayWithObjects: @"SiteA", @"SiteB", nil]; | 1946 NSArray* titles = [NSArray arrayWithObjects: @"SiteA", @"SiteB", nil]; |
1952 [bar_ addURLs:urls withTitles:titles at:[targetButton center]]; | 1947 [bar_ addURLs:urls withTitles:titles at:[targetButton center]]; |
1953 | 1948 |
1954 // There should two more nodes in the bar. | 1949 // There should two more nodes in the bar. |
1955 int newChildCount = root->child_count(); | 1950 int newChildCount = root->child_count(); |
1956 EXPECT_EQ(oldChildCount + 2, newChildCount); | 1951 EXPECT_EQ(oldChildCount + 2, newChildCount); |
1957 // Verify the model. | 1952 // Verify the model. |
1958 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1953 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1959 "2f3b ] SiteA SiteB 3b 4b "); | 1954 "2f3b ] SiteA SiteB 3b 4b "); |
1960 actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 1955 actual = test::ModelStringFromNode(root); |
1961 EXPECT_EQ(expected, actual); | 1956 EXPECT_EQ(expected, actual); |
1962 } | 1957 } |
1963 | 1958 |
1964 TEST_F(BookmarkBarControllerDragDropTest, ControllerForNode) { | 1959 TEST_F(BookmarkBarControllerDragDropTest, ControllerForNode) { |
1965 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1960 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1966 const BookmarkNode* root = model->bookmark_bar_node(); | 1961 const BookmarkNode* root = model->bookmark_bar_node(); |
1967 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1962 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1968 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1963 test::AddNodesFromModelString(model, root, model_string); |
1969 | 1964 |
1970 // Validate initial model. | 1965 // Validate initial model. |
1971 std::string actualModelString = | 1966 std::string actualModelString = test::ModelStringFromNode(root); |
1972 BookmarkModelTestUtils::ModelStringFromNode(root); | |
1973 EXPECT_EQ(model_string, actualModelString); | 1967 EXPECT_EQ(model_string, actualModelString); |
1974 | 1968 |
1975 // Find the main bar controller. | 1969 // Find the main bar controller. |
1976 const void* expectedController = bar_; | 1970 const void* expectedController = bar_; |
1977 const void* actualController = [bar_ controllerForNode:root]; | 1971 const void* actualController = [bar_ controllerForNode:root]; |
1978 EXPECT_EQ(expectedController, actualController); | 1972 EXPECT_EQ(expectedController, actualController); |
1979 } | 1973 } |
1980 | 1974 |
1981 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 1975 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
1982 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1976 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
1983 const BookmarkNode* root = model->bookmark_bar_node(); | 1977 const BookmarkNode* root = model->bookmark_bar_node(); |
1984 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 1978 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
1985 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 1979 test::AddNodesFromModelString(model, root, model_string); |
1986 | 1980 |
1987 // Validate initial model. | 1981 // Validate initial model. |
1988 std::string actualModel = BookmarkModelTestUtils::ModelStringFromNode(root); | 1982 std::string actualModel = test::ModelStringFromNode(root); |
1989 EXPECT_EQ(model_string, actualModel); | 1983 EXPECT_EQ(model_string, actualModel); |
1990 | 1984 |
1991 // Test a series of points starting at the right edge of the bar. | 1985 // Test a series of points starting at the right edge of the bar. |
1992 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 1986 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
1993 ASSERT_TRUE(targetButton); | 1987 ASSERT_TRUE(targetButton); |
1994 NSPoint targetPoint = [targetButton left]; | 1988 NSPoint targetPoint = [targetButton left]; |
1995 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * | 1989 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * |
1996 bookmarks::kBookmarkHorizontalPadding; | 1990 bookmarks::kBookmarkHorizontalPadding; |
1997 const CGFloat baseOffset = targetPoint.x; | 1991 const CGFloat baseOffset = targetPoint.x; |
1998 CGFloat expected = leftMarginIndicatorPosition; | 1992 CGFloat expected = leftMarginIndicatorPosition; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 object:nil | 2039 object:nil |
2046 userInfo:dict]; | 2040 userInfo:dict]; |
2047 EXPECT_FALSE([button isContinuousPulsing]); | 2041 EXPECT_FALSE([button isContinuousPulsing]); |
2048 } | 2042 } |
2049 | 2043 |
2050 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkDataToTrash) { | 2044 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkDataToTrash) { |
2051 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2045 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
2052 const BookmarkNode* root = model->bookmark_bar_node(); | 2046 const BookmarkNode* root = model->bookmark_bar_node(); |
2053 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2047 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2054 "2f3b ] 3b 4b "); | 2048 "2f3b ] 3b 4b "); |
2055 BookmarkModelTestUtils::AddNodesFromModelString(model, root, model_string); | 2049 test::AddNodesFromModelString(model, root, model_string); |
2056 | 2050 |
2057 // Validate initial model. | 2051 // Validate initial model. |
2058 std::string actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 2052 std::string actual = test::ModelStringFromNode(root); |
2059 EXPECT_EQ(model_string, actual); | 2053 EXPECT_EQ(model_string, actual); |
2060 | 2054 |
2061 int oldChildCount = root->child_count(); | 2055 int oldChildCount = root->child_count(); |
2062 | 2056 |
2063 // Drag a button to the trash. | 2057 // Drag a button to the trash. |
2064 BookmarkButton* buttonToDelete = [bar_ buttonWithTitleEqualTo:@"3b"]; | 2058 BookmarkButton* buttonToDelete = [bar_ buttonWithTitleEqualTo:@"3b"]; |
2065 ASSERT_TRUE(buttonToDelete); | 2059 ASSERT_TRUE(buttonToDelete); |
2066 EXPECT_TRUE([bar_ canDragBookmarkButtonToTrash:buttonToDelete]); | 2060 EXPECT_TRUE([bar_ canDragBookmarkButtonToTrash:buttonToDelete]); |
2067 [bar_ didDragBookmarkToTrash:buttonToDelete]; | 2061 [bar_ didDragBookmarkToTrash:buttonToDelete]; |
2068 | 2062 |
2069 // There should be one less button in the bar. | 2063 // There should be one less button in the bar. |
2070 int newChildCount = root->child_count(); | 2064 int newChildCount = root->child_count(); |
2071 EXPECT_EQ(oldChildCount - 1, newChildCount); | 2065 EXPECT_EQ(oldChildCount - 1, newChildCount); |
2072 // Verify the model. | 2066 // Verify the model. |
2073 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2067 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2074 "2f3b ] 4b "); | 2068 "2f3b ] 4b "); |
2075 actual = BookmarkModelTestUtils::ModelStringFromNode(root); | 2069 actual = test::ModelStringFromNode(root); |
2076 EXPECT_EQ(expected, actual); | 2070 EXPECT_EQ(expected, actual); |
2077 | 2071 |
2078 // Verify that the other bookmark folder can't be deleted. | 2072 // Verify that the other bookmark folder can't be deleted. |
2079 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2073 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
2080 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2074 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
2081 } | 2075 } |
2082 | 2076 |
2083 } // namespace | 2077 } // namespace |
OLD | NEW |