| 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" |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 EXPECT_FALSE([view isHidden]); | 1527 EXPECT_FALSE([view isHidden]); |
| 1528 [bar_ shrinkOrHideView:view forMaxX:31.0]; | 1528 [bar_ shrinkOrHideView:view forMaxX:31.0]; |
| 1529 EXPECT_EQ(31.0, NSWidth([view frame])); | 1529 EXPECT_EQ(31.0, NSWidth([view frame])); |
| 1530 EXPECT_FALSE([view isHidden]); | 1530 EXPECT_FALSE([view isHidden]); |
| 1531 [bar_ shrinkOrHideView:view forMaxX:29.0]; | 1531 [bar_ shrinkOrHideView:view forMaxX:29.0]; |
| 1532 EXPECT_TRUE([view isHidden]); | 1532 EXPECT_TRUE([view isHidden]); |
| 1533 } | 1533 } |
| 1534 | 1534 |
| 1535 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { | 1535 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { |
| 1536 // Hide the apps shortcut. | 1536 // Hide the apps shortcut. |
| 1537 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1537 profile()->GetPrefs()->SetBoolean( |
| 1538 false); | 1538 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
| 1539 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1539 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1540 | 1540 |
| 1541 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1541 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 1542 const BookmarkNode* root = model->bookmark_bar_node(); | 1542 const BookmarkNode* root = model->bookmark_bar_node(); |
| 1543 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1543 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
| 1544 test::AddNodesFromModelString(model, root, model_string); | 1544 test::AddNodesFromModelString(model, root, model_string); |
| 1545 [bar_ frameDidChange]; | 1545 [bar_ frameDidChange]; |
| 1546 | 1546 |
| 1547 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, | 1547 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, |
| 1548 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, | 1548 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1576 // Bookmarks should be to the right of the Apps page shortcut button. | 1576 // Bookmarks should be to the right of the Apps page shortcut button. |
| 1577 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1577 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
| 1578 CGFloat right = apps_button_right; | 1578 CGFloat right = apps_button_right; |
| 1579 NSArray* buttons = [bar_ buttons]; | 1579 NSArray* buttons = [bar_ buttons]; |
| 1580 for (size_t i = 0; i < [buttons count]; ++i) { | 1580 for (size_t i = 0; i < [buttons count]; ++i) { |
| 1581 EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame])); | 1581 EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame])); |
| 1582 right = NSMaxX([[buttons objectAtIndex:i] frame]); | 1582 right = NSMaxX([[buttons objectAtIndex:i] frame]); |
| 1583 } | 1583 } |
| 1584 | 1584 |
| 1585 // Removing the Apps button should move every bookmark to the left. | 1585 // Removing the Apps button should move every bookmark to the left. |
| 1586 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1586 profile()->GetPrefs()->SetBoolean( |
| 1587 false); | 1587 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
| 1588 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1588 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1589 EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame])); | 1589 EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame])); |
| 1590 for (size_t i = 1; i < [buttons count]; ++i) { | 1590 for (size_t i = 1; i < [buttons count]; ++i) { |
| 1591 EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]), | 1591 EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]), |
| 1592 NSMinX([[buttons objectAtIndex:i] frame])); | 1592 NSMinX([[buttons objectAtIndex:i] frame])); |
| 1593 } | 1593 } |
| 1594 } | 1594 } |
| 1595 | 1595 |
| 1596 TEST_F(BookmarkBarControllerTest, BookmarksWithoutAppsPageShortcut) { | 1596 TEST_F(BookmarkBarControllerTest, BookmarksWithoutAppsPageShortcut) { |
| 1597 // The no item containers should be to the right of the Apps button. | 1597 // The no item containers should be to the right of the Apps button. |
| 1598 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1598 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1599 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1599 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
| 1600 EXPECT_LE(apps_button_right, | 1600 EXPECT_LE(apps_button_right, |
| 1601 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); | 1601 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); |
| 1602 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), | 1602 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), |
| 1603 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); | 1603 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); |
| 1604 | 1604 |
| 1605 // Removing the Apps button should move the no item containers to the left. | 1605 // Removing the Apps button should move the no item containers to the left. |
| 1606 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1606 profile()->GetPrefs()->SetBoolean( |
| 1607 false); | 1607 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
| 1608 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1608 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1609 EXPECT_GT(apps_button_right, | 1609 EXPECT_GT(apps_button_right, |
| 1610 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); | 1610 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); |
| 1611 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), | 1611 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), |
| 1612 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); | 1612 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); |
| 1613 } | 1613 } |
| 1614 | 1614 |
| 1615 TEST_F(BookmarkBarControllerTest, ManagedShowAppsShortcutInBookmarksBar) { | 1615 TEST_F(BookmarkBarControllerTest, ManagedShowAppsShortcutInBookmarksBar) { |
| 1616 // By default the pref is not managed and the apps shortcut is shown. | 1616 // By default the pref is not managed and the apps shortcut is shown. |
| 1617 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); | 1617 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); |
| 1618 EXPECT_FALSE( | 1618 EXPECT_FALSE(prefs->IsManagedPreference( |
| 1619 prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar)); | 1619 bookmarks::prefs::kShowAppsShortcutInBookmarkBar)); |
| 1620 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1620 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1621 | 1621 |
| 1622 // Hide the apps shortcut by policy, via the managed pref. | 1622 // Hide the apps shortcut by policy, via the managed pref. |
| 1623 prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar, | 1623 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 1624 new base::FundamentalValue(false)); | 1624 new base::FundamentalValue(false)); |
| 1625 EXPECT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1625 EXPECT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1626 | 1626 |
| 1627 // And try showing it via policy too. | 1627 // And try showing it via policy too. |
| 1628 prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar, | 1628 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 1629 new base::FundamentalValue(true)); | 1629 new base::FundamentalValue(true)); |
| 1630 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1630 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1631 } | 1631 } |
| 1632 | 1632 |
| 1633 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { | 1633 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { |
| 1634 public: | 1634 public: |
| 1635 virtual void SetUp() { | 1635 virtual void SetUp() { |
| 1636 BookmarkBarControllerTest::SetUp(); | 1636 BookmarkBarControllerTest::SetUp(); |
| 1637 ASSERT_TRUE(profile()); | 1637 ASSERT_TRUE(profile()); |
| 1638 | 1638 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 EXPECT_EQ(expectedController, actualController); | 1996 EXPECT_EQ(expectedController, actualController); |
| 1997 } | 1997 } |
| 1998 | 1998 |
| 1999 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 1999 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
| 2000 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2000 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 2001 const BookmarkNode* root = model->bookmark_bar_node(); | 2001 const BookmarkNode* root = model->bookmark_bar_node(); |
| 2002 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 2002 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
| 2003 test::AddNodesFromModelString(model, root, model_string); | 2003 test::AddNodesFromModelString(model, root, model_string); |
| 2004 | 2004 |
| 2005 // Hide the apps shortcut. | 2005 // Hide the apps shortcut. |
| 2006 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 2006 profile()->GetPrefs()->SetBoolean( |
| 2007 false); | 2007 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
| 2008 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 2008 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 2009 | 2009 |
| 2010 // Validate initial model. | 2010 // Validate initial model. |
| 2011 std::string actualModel = test::ModelStringFromNode(root); | 2011 std::string actualModel = test::ModelStringFromNode(root); |
| 2012 EXPECT_EQ(model_string, actualModel); | 2012 EXPECT_EQ(model_string, actualModel); |
| 2013 | 2013 |
| 2014 // Test a series of points starting at the right edge of the bar. | 2014 // Test a series of points starting at the right edge of the bar. |
| 2015 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 2015 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
| 2016 ASSERT_TRUE(targetButton); | 2016 ASSERT_TRUE(targetButton); |
| 2017 NSPoint targetPoint = [targetButton left]; | 2017 NSPoint targetPoint = [targetButton left]; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 "2f3b ] 4b "); | 2097 "2f3b ] 4b "); |
| 2098 actual = test::ModelStringFromNode(root); | 2098 actual = test::ModelStringFromNode(root); |
| 2099 EXPECT_EQ(expected, actual); | 2099 EXPECT_EQ(expected, actual); |
| 2100 | 2100 |
| 2101 // Verify that the other bookmark folder can't be deleted. | 2101 // Verify that the other bookmark folder can't be deleted. |
| 2102 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2102 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
| 2103 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2103 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
| 2104 } | 2104 } |
| 2105 | 2105 |
| 2106 } // namespace | 2106 } // namespace |
| OLD | NEW |