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 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 BookmarkButton* button = [buttons objectAtIndex:3]; | 618 BookmarkButton* button = [buttons objectAtIndex:3]; |
619 DeleteBookmark(button, profile()); | 619 DeleteBookmark(button, profile()); |
620 CGFloat newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 620 CGFloat newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
621 EXPECT_CGFLOAT_EQ(oldTop, newTop); | 621 EXPECT_CGFLOAT_EQ(oldTop, newTop); |
622 | 622 |
623 // Scroll so that both the top and bottom scroll arrows show, make sure | 623 // Scroll so that both the top and bottom scroll arrows show, make sure |
624 // the top of the window has moved up, then delete a visible button and | 624 // the top of the window has moved up, then delete a visible button and |
625 // make sure the top has not moved. | 625 // make sure the top has not moved. |
626 oldTop = newTop; | 626 oldTop = newTop; |
627 const CGFloat scrollOneBookmark = bookmarks::kBookmarkFolderButtonHeight + | 627 const CGFloat scrollOneBookmark = bookmarks::kBookmarkFolderButtonHeight + |
628 bookmarks::BookmarkVerticalPadding(); | 628 bookmarks::kBookmarkVerticalPadding; |
629 NSUInteger buttonCounter = 0; | 629 NSUInteger buttonCounter = 0; |
630 NSUInteger extraButtonLimit = 3; | 630 NSUInteger extraButtonLimit = 3; |
631 while (![bbfc canScrollDown] || extraButtonLimit > 0) { | 631 while (![bbfc canScrollDown] || extraButtonLimit > 0) { |
632 [bbfc performOneScroll:scrollOneBookmark updateMouseSelection:NO]; | 632 [bbfc performOneScroll:scrollOneBookmark updateMouseSelection:NO]; |
633 ++buttonCounter; | 633 ++buttonCounter; |
634 if ([bbfc canScrollDown]) | 634 if ([bbfc canScrollDown]) |
635 --extraButtonLimit; | 635 --extraButtonLimit; |
636 } | 636 } |
637 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 637 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
638 EXPECT_NE(oldTop, newTop); | 638 EXPECT_NE(oldTop, newTop); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 BookmarkBarFolderController* folderController = [bar_ folderController]; | 770 BookmarkBarFolderController* folderController = [bar_ folderController]; |
771 EXPECT_TRUE(folderController); | 771 EXPECT_TRUE(folderController); |
772 NSWindow* toWindow = [folderController window]; | 772 NSWindow* toWindow = [folderController window]; |
773 EXPECT_TRUE(toWindow); | 773 EXPECT_TRUE(toWindow); |
774 NSRect oldToWindowFrame = [toWindow frame]; | 774 NSRect oldToWindowFrame = [toWindow frame]; |
775 // Drag a bar button onto a bookmark (i.e. not a folder) in a folder | 775 // Drag a bar button onto a bookmark (i.e. not a folder) in a folder |
776 // so it should end up below the target bookmark. | 776 // so it should end up below the target bookmark. |
777 BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 777 BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
778 ASSERT_TRUE(draggedButton); | 778 ASSERT_TRUE(draggedButton); |
779 CGFloat horizontalShift = | 779 CGFloat horizontalShift = |
780 NSWidth([draggedButton frame]) + bookmarks::BookmarkHorizontalPadding(); | 780 NSWidth([draggedButton frame]) + bookmarks::kBookmarkHorizontalPadding; |
781 BookmarkButton* targetButton = | 781 BookmarkButton* targetButton = |
782 [folderController buttonWithTitleEqualTo:@"2f1b"]; | 782 [folderController buttonWithTitleEqualTo:@"2f1b"]; |
783 ASSERT_TRUE(targetButton); | 783 ASSERT_TRUE(targetButton); |
784 [folderController dragButton:draggedButton | 784 [folderController dragButton:draggedButton |
785 to:[targetButton center] | 785 to:[targetButton center] |
786 copy:NO]; | 786 copy:NO]; |
787 // The button should have landed just after "2f1b". | 787 // The button should have landed just after "2f1b". |
788 const std::string expected_string("2f:[ 2f1b 1b 2f2f:[ 2f2f1b " | 788 const std::string expected_string("2f:[ 2f1b 1b 2f2f:[ 2f2f1b " |
789 "2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ " | 789 "2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ " |
790 "4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); | 790 "4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 // Pop open the new folder window and verify it has one (empty) item. | 1283 // Pop open the new folder window and verify it has one (empty) item. |
1284 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; | 1284 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; |
1285 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) | 1285 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) |
1286 withObject:button]; | 1286 withObject:button]; |
1287 BookmarkBarFolderController* folderController = [bar_ folderController]; | 1287 BookmarkBarFolderController* folderController = [bar_ folderController]; |
1288 EXPECT_TRUE(folderController); | 1288 EXPECT_TRUE(folderController); |
1289 NSWindow* folderWindow = [folderController window]; | 1289 NSWindow* folderWindow = [folderController window]; |
1290 EXPECT_TRUE(folderWindow); | 1290 EXPECT_TRUE(folderWindow); |
1291 CGFloat expectedHeight = | 1291 CGFloat expectedHeight = |
1292 (CGFloat)bookmarks::kBookmarkFolderButtonHeight + | 1292 (CGFloat)bookmarks::kBookmarkFolderButtonHeight + |
1293 bookmarks::BookmarkTopVerticalPadding() + | 1293 bookmarks::kBookmarkTopVerticalPadding + |
1294 bookmarks::BookmarkBottomVerticalPadding(); | 1294 bookmarks::kBookmarkBottomVerticalPadding; |
1295 NSRect windowFrame = [folderWindow frame]; | 1295 NSRect windowFrame = [folderWindow frame]; |
1296 CGFloat windowHeight = NSHeight(windowFrame); | 1296 CGFloat windowHeight = NSHeight(windowFrame); |
1297 EXPECT_CGFLOAT_EQ(expectedHeight, windowHeight); | 1297 EXPECT_CGFLOAT_EQ(expectedHeight, windowHeight); |
1298 EXPECT_FALSE([folderController canScrollUp]); | 1298 EXPECT_FALSE([folderController canScrollUp]); |
1299 EXPECT_FALSE([folderController canScrollDown]); | 1299 EXPECT_FALSE([folderController canScrollDown]); |
1300 | 1300 |
1301 // Now add a real bookmark and reopen. | 1301 // Now add a real bookmark and reopen. |
1302 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("a"), | 1302 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("a"), |
1303 GURL("http://a.com/")); | 1303 GURL("http://a.com/")); |
1304 folderController = [bar_ folderController]; | 1304 folderController = [bar_ folderController]; |
(...skipping 10 matching lines...) Expand all Loading... |
1315 CGFloat widthDelta = NSWidth(visibleFrame) - NSWidth(scrollFrame); | 1315 CGFloat widthDelta = NSWidth(visibleFrame) - NSWidth(scrollFrame); |
1316 | 1316 |
1317 CGFloat menuHeight = NSHeight(menuFrame); | 1317 CGFloat menuHeight = NSHeight(menuFrame); |
1318 EXPECT_CGFLOAT_EQ(expectedHeight, menuHeight); | 1318 EXPECT_CGFLOAT_EQ(expectedHeight, menuHeight); |
1319 CGFloat scrollerWidth = NSWidth(scrollFrame); | 1319 CGFloat scrollerWidth = NSWidth(scrollFrame); |
1320 button = [folderController buttonWithTitleEqualTo:@"a"]; | 1320 button = [folderController buttonWithTitleEqualTo:@"a"]; |
1321 CGFloat buttonWidth = NSWidth([button frame]); | 1321 CGFloat buttonWidth = NSWidth([button frame]); |
1322 EXPECT_CGFLOAT_EQ(scrollerWidth, buttonWidth); | 1322 EXPECT_CGFLOAT_EQ(scrollerWidth, buttonWidth); |
1323 CGFloat visibleWidth = NSWidth(visibleFrame); | 1323 CGFloat visibleWidth = NSWidth(visibleFrame); |
1324 EXPECT_CGFLOAT_EQ(visibleWidth - widthDelta, buttonWidth); | 1324 EXPECT_CGFLOAT_EQ(visibleWidth - widthDelta, buttonWidth); |
1325 if (ui::MaterialDesignController::IsModeMaterial()) { | 1325 EXPECT_CGFLOAT_EQ(scrollerWidth, NSWidth([folderView frame])); |
1326 EXPECT_CGFLOAT_EQ(scrollerWidth, NSWidth([folderView frame])); | |
1327 } else { | |
1328 EXPECT_LT(scrollerWidth, NSWidth([folderView frame])); | |
1329 } | |
1330 | 1326 |
1331 // Add a wider bookmark and make sure the button widths match. | 1327 // Add a wider bookmark and make sure the button widths match. |
1332 int reallyWideButtonNumber = folder->child_count(); | 1328 int reallyWideButtonNumber = folder->child_count(); |
1333 model->AddURL(folder, reallyWideButtonNumber, | 1329 model->AddURL(folder, reallyWideButtonNumber, |
1334 ASCIIToUTF16("A really, really, really, really, really, " | 1330 ASCIIToUTF16("A really, really, really, really, really, " |
1335 "really long name"), | 1331 "really long name"), |
1336 GURL("http://www.google.com/a")); | 1332 GURL("http://www.google.com/a")); |
1337 BookmarkButton* bigButton = | 1333 BookmarkButton* bigButton = |
1338 [folderController buttonWithTitleEqualTo: | 1334 [folderController buttonWithTitleEqualTo: |
1339 @"A really, really, really, really, really, really long name"]; | 1335 @"A really, really, really, really, really, really long name"]; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 EXPECT_EQ(model_string, actual); | 1592 EXPECT_EQ(model_string, actual); |
1597 | 1593 |
1598 // Pop open the folder. | 1594 // Pop open the folder. |
1599 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; | 1595 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; |
1600 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) | 1596 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) |
1601 withObject:button]; | 1597 withObject:button]; |
1602 BookmarkBarFolderController* folder = [bar_ folderController]; | 1598 BookmarkBarFolderController* folder = [bar_ folderController]; |
1603 EXPECT_TRUE(folder); | 1599 EXPECT_TRUE(folder); |
1604 | 1600 |
1605 // Test a series of points starting at the top of the folder. | 1601 // Test a series of points starting at the top of the folder. |
1606 const CGFloat yTopOffset = 0.5 * bookmarks::BookmarkTopVerticalPadding(); | 1602 const CGFloat yTopOffset = 0.5 * bookmarks::kBookmarkTopVerticalPadding; |
1607 const CGFloat yBottomOffset = | 1603 const CGFloat yBottomOffset = |
1608 0.5 * bookmarks::BookmarkBottomVerticalPadding(); | 1604 0.5 * bookmarks::kBookmarkBottomVerticalPadding; |
1609 BookmarkButton* targetButton = [folder buttonWithTitleEqualTo:@"2f1b"]; | 1605 BookmarkButton* targetButton = [folder buttonWithTitleEqualTo:@"2f1b"]; |
1610 ASSERT_TRUE(targetButton); | 1606 ASSERT_TRUE(targetButton); |
1611 NSPoint targetPoint = [targetButton top]; | 1607 NSPoint targetPoint = [targetButton top]; |
1612 CGFloat pos = [folder indicatorPosForDragToPoint:targetPoint]; | 1608 CGFloat pos = [folder indicatorPosForDragToPoint:targetPoint]; |
1613 EXPECT_CGFLOAT_EQ(targetPoint.y + yTopOffset, pos); | 1609 EXPECT_CGFLOAT_EQ(targetPoint.y + yTopOffset, pos); |
1614 pos = [folder indicatorPosForDragToPoint:[targetButton bottom]]; | 1610 pos = [folder indicatorPosForDragToPoint:[targetButton bottom]]; |
1615 targetButton = [folder buttonWithTitleEqualTo:@"2f2f"]; | 1611 targetButton = [folder buttonWithTitleEqualTo:@"2f2f"]; |
1616 EXPECT_CGFLOAT_EQ([targetButton top].y + yTopOffset, pos); | 1612 EXPECT_CGFLOAT_EQ([targetButton top].y + yTopOffset, pos); |
1617 pos = [folder indicatorPosForDragToPoint:NSMakePoint(10,0)]; | 1613 pos = [folder indicatorPosForDragToPoint:NSMakePoint(10,0)]; |
1618 targetButton = [folder buttonWithTitleEqualTo:@"2f3b"]; | 1614 targetButton = [folder buttonWithTitleEqualTo:@"2f3b"]; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 DeleteBookmark([folder parentButton], profile()); | 1670 DeleteBookmark([folder parentButton], profile()); |
1675 EXPECT_FALSE([folder folderController]); | 1671 EXPECT_FALSE([folder folderController]); |
1676 } | 1672 } |
1677 | 1673 |
1678 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so | 1674 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so |
1679 // they are hard to test. Factor out "fire timers" into routines | 1675 // they are hard to test. Factor out "fire timers" into routines |
1680 // which can be overridden to fire immediately to make behavior | 1676 // which can be overridden to fire immediately to make behavior |
1681 // confirmable. | 1677 // confirmable. |
1682 // There is a similar problem with mouseEnteredButton: and | 1678 // There is a similar problem with mouseEnteredButton: and |
1683 // mouseExitedButton:. | 1679 // mouseExitedButton:. |
OLD | NEW |