| 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 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 EXPECT_EQ(40.0, NSWidth([view frame])); | 1515 EXPECT_EQ(40.0, NSWidth([view frame])); |
| 1516 EXPECT_FALSE([view isHidden]); | 1516 EXPECT_FALSE([view isHidden]); |
| 1517 [bar_ shrinkOrHideView:view forMaxX:31.0]; | 1517 [bar_ shrinkOrHideView:view forMaxX:31.0]; |
| 1518 EXPECT_EQ(31.0, NSWidth([view frame])); | 1518 EXPECT_EQ(31.0, NSWidth([view frame])); |
| 1519 EXPECT_FALSE([view isHidden]); | 1519 EXPECT_FALSE([view isHidden]); |
| 1520 [bar_ shrinkOrHideView:view forMaxX:29.0]; | 1520 [bar_ shrinkOrHideView:view forMaxX:29.0]; |
| 1521 EXPECT_TRUE([view isHidden]); | 1521 EXPECT_TRUE([view isHidden]); |
| 1522 } | 1522 } |
| 1523 | 1523 |
| 1524 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { | 1524 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { |
| 1525 // Hide the apps shortcut. |
| 1526 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, |
| 1527 false); |
| 1528 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1529 |
| 1525 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1530 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 1526 const BookmarkNode* root = model->bookmark_bar_node(); | 1531 const BookmarkNode* root = model->bookmark_bar_node(); |
| 1527 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1532 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
| 1528 test::AddNodesFromModelString(model, root, model_string); | 1533 test::AddNodesFromModelString(model, root, model_string); |
| 1529 [bar_ frameDidChange]; | 1534 [bar_ frameDidChange]; |
| 1530 | 1535 |
| 1531 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, | 1536 CGFloat viewWidths[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, 155.0, |
| 1532 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, | 1537 200.0, 155.0, 154.0, 153.0, 152.0, 151.0, 124.0, |
| 1533 123.0 }; | 1538 123.0 }; |
| 1534 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, | 1539 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, |
| 1535 YES, YES, YES, NO, NO, NO, NO}; | 1540 YES, YES, YES, NO, NO, NO, NO}; |
| 1536 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, | 1541 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, |
| 1537 2, 1 }; | 1542 2, 1 }; |
| 1538 | 1543 |
| 1539 for (unsigned int i = 0; i < sizeof(viewWidths) / sizeof(viewWidths[0]); | 1544 for (unsigned int i = 0; i < sizeof(viewWidths) / sizeof(viewWidths[0]); |
| 1540 ++i) { | 1545 ++i) { |
| 1541 NSRect frame = [[bar_ view] frame]; | 1546 NSRect frame = [[bar_ view] frame]; |
| 1542 frame.size.width = viewWidths[i] + bookmarks::kBookmarkRightMargin; | 1547 frame.size.width = viewWidths[i] + bookmarks::kBookmarkRightMargin; |
| 1543 [[bar_ view] setFrame:frame]; | 1548 [[bar_ view] setFrame:frame]; |
| 1544 EXPECT_EQ(offTheSideButtonIsHiddenResults[i], | 1549 EXPECT_EQ(offTheSideButtonIsHiddenResults[i], |
| 1545 [bar_ offTheSideButtonIsHidden]); | 1550 [bar_ offTheSideButtonIsHidden]); |
| 1546 EXPECT_EQ(displayedButtonCountResults[i], [bar_ displayedButtonCount]); | 1551 EXPECT_EQ(displayedButtonCountResults[i], [bar_ displayedButtonCount]); |
| 1547 } | 1552 } |
| 1548 } | 1553 } |
| 1549 | 1554 |
| 1550 class BookmarkBarControllerWithInstantExtendedTest : | 1555 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { |
| 1551 public BookmarkBarControllerTest { | |
| 1552 public: | |
| 1553 virtual void AddCommandLineSwitches() OVERRIDE { | |
| 1554 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1555 switches::kEnableInstantExtendedAPI); | |
| 1556 } | |
| 1557 }; | |
| 1558 | |
| 1559 TEST_F(BookmarkBarControllerWithInstantExtendedTest, | |
| 1560 BookmarksWithAppsPageShortcut) { | |
| 1561 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1556 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 1562 const BookmarkNode* root = model->bookmark_bar_node(); | 1557 const BookmarkNode* root = model->bookmark_bar_node(); |
| 1563 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1558 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
| 1564 test::AddNodesFromModelString(model, root, model_string); | 1559 test::AddNodesFromModelString(model, root, model_string); |
| 1565 [bar_ frameDidChange]; | 1560 [bar_ frameDidChange]; |
| 1566 | 1561 |
| 1567 // Apps page shortcut button should be visible. | 1562 // Apps page shortcut button should be visible. |
| 1568 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1563 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1569 | 1564 |
| 1570 // Bookmarks should be to the right of the Apps page shortcut button. | 1565 // Bookmarks should be to the right of the Apps page shortcut button. |
| 1571 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1566 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
| 1572 CGFloat right = apps_button_right; | 1567 CGFloat right = apps_button_right; |
| 1573 NSArray* buttons = [bar_ buttons]; | 1568 NSArray* buttons = [bar_ buttons]; |
| 1574 for (size_t i = 0; i < [buttons count]; ++i) { | 1569 for (size_t i = 0; i < [buttons count]; ++i) { |
| 1575 EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame])); | 1570 EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame])); |
| 1576 right = NSMaxX([[buttons objectAtIndex:i] frame]); | 1571 right = NSMaxX([[buttons objectAtIndex:i] frame]); |
| 1577 } | 1572 } |
| 1578 | 1573 |
| 1579 // Removing the Apps button should move every bookmark to the left. | 1574 // Removing the Apps button should move every bookmark to the left. |
| 1580 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1575 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, |
| 1581 false); | 1576 false); |
| 1582 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1577 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1583 EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame])); | 1578 EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame])); |
| 1584 for (size_t i = 1; i < [buttons count]; ++i) { | 1579 for (size_t i = 1; i < [buttons count]; ++i) { |
| 1585 EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]), | 1580 EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]), |
| 1586 NSMinX([[buttons objectAtIndex:i] frame])); | 1581 NSMinX([[buttons objectAtIndex:i] frame])); |
| 1587 } | 1582 } |
| 1588 } | 1583 } |
| 1589 | 1584 |
| 1590 TEST_F(BookmarkBarControllerWithInstantExtendedTest, | 1585 TEST_F(BookmarkBarControllerTest, BookmarksWithoutAppsPageShortcut) { |
| 1591 BookmarksWithoutAppsPageShortcut) { | |
| 1592 // The no item containers should be to the right of the Apps button. | 1586 // The no item containers should be to the right of the Apps button. |
| 1593 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1587 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1594 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1588 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
| 1595 EXPECT_LE(apps_button_right, | 1589 EXPECT_LE(apps_button_right, |
| 1596 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); | 1590 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); |
| 1597 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), | 1591 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), |
| 1598 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); | 1592 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); |
| 1599 | 1593 |
| 1600 // Removing the Apps button should move the no item containers to the left. | 1594 // Removing the Apps button should move the no item containers to the left. |
| 1601 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1595 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 const void* actualController = [bar_ controllerForNode:root]; | 1966 const void* actualController = [bar_ controllerForNode:root]; |
| 1973 EXPECT_EQ(expectedController, actualController); | 1967 EXPECT_EQ(expectedController, actualController); |
| 1974 } | 1968 } |
| 1975 | 1969 |
| 1976 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 1970 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
| 1977 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1971 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 1978 const BookmarkNode* root = model->bookmark_bar_node(); | 1972 const BookmarkNode* root = model->bookmark_bar_node(); |
| 1979 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 1973 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
| 1980 test::AddNodesFromModelString(model, root, model_string); | 1974 test::AddNodesFromModelString(model, root, model_string); |
| 1981 | 1975 |
| 1976 // Hide the apps shortcut. |
| 1977 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, |
| 1978 false); |
| 1979 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1980 |
| 1982 // Validate initial model. | 1981 // Validate initial model. |
| 1983 std::string actualModel = test::ModelStringFromNode(root); | 1982 std::string actualModel = test::ModelStringFromNode(root); |
| 1984 EXPECT_EQ(model_string, actualModel); | 1983 EXPECT_EQ(model_string, actualModel); |
| 1985 | 1984 |
| 1986 // 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. |
| 1987 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 1986 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
| 1988 ASSERT_TRUE(targetButton); | 1987 ASSERT_TRUE(targetButton); |
| 1989 NSPoint targetPoint = [targetButton left]; | 1988 NSPoint targetPoint = [targetButton left]; |
| 1990 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * | 1989 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * |
| 1991 bookmarks::kBookmarkHorizontalPadding; | 1990 bookmarks::kBookmarkHorizontalPadding; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2069 "2f3b ] 4b "); | 2068 "2f3b ] 4b "); |
| 2070 actual = test::ModelStringFromNode(root); | 2069 actual = test::ModelStringFromNode(root); |
| 2071 EXPECT_EQ(expected, actual); | 2070 EXPECT_EQ(expected, actual); |
| 2072 | 2071 |
| 2073 // Verify that the other bookmark folder can't be deleted. | 2072 // Verify that the other bookmark folder can't be deleted. |
| 2074 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2073 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
| 2075 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2074 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
| 2076 } | 2075 } |
| 2077 | 2076 |
| 2078 } // namespace | 2077 } // namespace |
| OLD | NEW |