OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_nsobject.h" | 8 #include "base/scoped_nsobject.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... |
37 - (void)validateMenuSpacing { | 37 - (void)validateMenuSpacing { |
38 BOOL firstButton = YES; | 38 BOOL firstButton = YES; |
39 CGFloat lastVerticalOffset = 0.0; | 39 CGFloat lastVerticalOffset = 0.0; |
40 for (BookmarkButton* button in [self buttons]) { | 40 for (BookmarkButton* button in [self buttons]) { |
41 if (firstButton) { | 41 if (firstButton) { |
42 firstButton = NO; | 42 firstButton = NO; |
43 lastVerticalOffset = [button frame].origin.y; | 43 lastVerticalOffset = [button frame].origin.y; |
44 } else { | 44 } else { |
45 CGFloat nextVerticalOffset = [button frame].origin.y; | 45 CGFloat nextVerticalOffset = [button frame].origin.y; |
46 EXPECT_CGFLOAT_EQ(lastVerticalOffset - | 46 EXPECT_CGFLOAT_EQ(lastVerticalOffset - |
47 bookmarks::kBookmarkButtonVerticalSpan, | 47 bookmarks::kBookmarkFolderButtonHeight, |
48 nextVerticalOffset); | 48 nextVerticalOffset); |
49 lastVerticalOffset = nextVerticalOffset; | 49 lastVerticalOffset = nextVerticalOffset; |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
53 @end | 53 @end |
54 | 54 |
55 // Don't use a high window level when running unit tests -- it'll | 55 // Don't use a high window level when running unit tests -- it'll |
56 // interfere with anything else you are working on. | 56 // interfere with anything else you are working on. |
57 // For testing. | 57 // For testing. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 // us its center for hit testing. | 476 // us its center for hit testing. |
477 BookmarkButton* targetButton = nil; | 477 BookmarkButton* targetButton = nil; |
478 NSPoint scrollPoint = [scrollView documentVisibleRect].origin; | 478 NSPoint scrollPoint = [scrollView documentVisibleRect].origin; |
479 for (BookmarkButton* button in [bbfc buttons]) { | 479 for (BookmarkButton* button in [bbfc buttons]) { |
480 NSRect buttonFrame = [button frame]; | 480 NSRect buttonFrame = [button frame]; |
481 buttonFrame.origin.y -= scrollPoint.y; | 481 buttonFrame.origin.y -= scrollPoint.y; |
482 if (buttonFrame.origin.y < 0.0) | 482 if (buttonFrame.origin.y < 0.0) |
483 break; | 483 break; |
484 targetButton = button; | 484 targetButton = button; |
485 } | 485 } |
| 486 EXPECT_TRUE(targetButton != nil); |
486 NSPoint hitPoint = [targetButton frame].origin; | 487 NSPoint hitPoint = [targetButton frame].origin; |
487 hitPoint.x += 50.0; | 488 hitPoint.x += 50.0; |
488 hitPoint.y += (bookmarks::kBookmarkButtonHeight / 2.0) - scrollPoint.y; | 489 hitPoint.y += (bookmarks::kBookmarkFolderButtonHeight / 2.0) - scrollPoint.y; |
| 490 hitPoint = [targetButton convertPoint:hitPoint toView:scrollView]; |
489 | 491 |
490 for (int i = 0; i < 3; i++) { | 492 for (int i = 0; i < 3; i++) { |
491 CGFloat height = NSHeight([window frame]); | 493 CGFloat height = NSHeight([window frame]); |
492 [bbfc performOneScroll:60]; | 494 [bbfc performOneScroll:60]; |
493 EXPECT_GT(NSHeight([window frame]), height); | 495 EXPECT_GT(NSHeight([window frame]), height); |
494 NSView* hit = [scrollView hitTest:hitPoint]; | 496 NSView* hit = [scrollView hitTest:hitPoint]; |
495 // We should hit a bookmark button. | 497 // We should hit a bookmark button. |
496 EXPECT_TRUE([[hit className] isEqualToString:@"BookmarkButton"]); | 498 EXPECT_TRUE([[hit className] isEqualToString:@"BookmarkButton"]); |
497 EXPECT_NE(hit, savedHit); | 499 EXPECT_NE(hit, savedHit); |
498 savedHit = hit; | 500 savedHit = hit; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 CGFloat oldTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 552 CGFloat oldTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
551 BookmarkButton* button = [buttons objectAtIndex:3]; | 553 BookmarkButton* button = [buttons objectAtIndex:3]; |
552 [folder deleteBookmark:button]; | 554 [folder deleteBookmark:button]; |
553 CGFloat newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 555 CGFloat newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
554 EXPECT_CGFLOAT_EQ(oldTop, newTop); | 556 EXPECT_CGFLOAT_EQ(oldTop, newTop); |
555 | 557 |
556 // Scroll so that both the top and bottom scroll arrows show, make sure | 558 // Scroll so that both the top and bottom scroll arrows show, make sure |
557 // the top of the window has moved up, then delete a visible button and | 559 // the top of the window has moved up, then delete a visible button and |
558 // make sure the top has not moved. | 560 // make sure the top has not moved. |
559 oldTop = newTop; | 561 oldTop = newTop; |
560 const CGFloat scrollOneBookmark = bookmarks::kBookmarkButtonHeight + | 562 const CGFloat scrollOneBookmark = bookmarks::kBookmarkFolderButtonHeight + |
561 bookmarks::kBookmarkVerticalPadding; | 563 bookmarks::kBookmarkVerticalPadding; |
562 NSUInteger buttonCounter = 0; | 564 NSUInteger buttonCounter = 0; |
563 NSUInteger extraButtonLimit = 3; | 565 NSUInteger extraButtonLimit = 3; |
564 while (![bbfc canScrollDown] || extraButtonLimit > 0) { | 566 while (![bbfc canScrollDown] || extraButtonLimit > 0) { |
565 [bbfc performOneScroll:scrollOneBookmark]; | 567 [bbfc performOneScroll:scrollOneBookmark]; |
566 ++buttonCounter; | 568 ++buttonCounter; |
567 if ([bbfc canScrollDown]) | 569 if ([bbfc canScrollDown]) |
568 --extraButtonLimit; | 570 --extraButtonLimit; |
569 } | 571 } |
570 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); | 572 newTop = [menuWindow frame].origin.y + NSHeight([menuWindow frame]); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 NSRect newToFolderFrame = [toFolder frame]; | 724 NSRect newToFolderFrame = [toFolder frame]; |
723 NSRect newToWindowFrame = [toWindow frame]; | 725 NSRect newToWindowFrame = [toWindow frame]; |
724 // The toFolder should have shifted left horizontally but not vertically. | 726 // The toFolder should have shifted left horizontally but not vertically. |
725 NSRect expectedToFolderFrame = | 727 NSRect expectedToFolderFrame = |
726 NSOffsetRect(oldToFolderFrame, -horizontalShift, 0); | 728 NSOffsetRect(oldToFolderFrame, -horizontalShift, 0); |
727 EXPECT_NSRECT_EQ(expectedToFolderFrame, newToFolderFrame); | 729 EXPECT_NSRECT_EQ(expectedToFolderFrame, newToFolderFrame); |
728 // The toWindow should have shifted left horizontally, down vertically, | 730 // The toWindow should have shifted left horizontally, down vertically, |
729 // and grown vertically. | 731 // and grown vertically. |
730 NSRect expectedToWindowFrame = oldToWindowFrame; | 732 NSRect expectedToWindowFrame = oldToWindowFrame; |
731 expectedToWindowFrame.origin.x -= horizontalShift; | 733 expectedToWindowFrame.origin.x -= horizontalShift; |
732 CGFloat diff = (bookmarks::kBookmarkBarHeight + | 734 expectedToWindowFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
733 2*bookmarks::kBookmarkVerticalPadding); | 735 expectedToWindowFrame.size.height += bookmarks::kBookmarkFolderButtonHeight; |
734 expectedToWindowFrame.origin.y -= diff; | |
735 expectedToWindowFrame.size.height += diff; | |
736 EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame); | 736 EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame); |
737 | 737 |
738 // Check button spacing. | 738 // Check button spacing. |
739 [folderController validateMenuSpacing]; | 739 [folderController validateMenuSpacing]; |
740 | 740 |
741 // Move the button back to the bar at the beginning. | 741 // Move the button back to the bar at the beginning. |
742 draggedButton = [folderController buttonWithTitleEqualTo:@"1b"]; | 742 draggedButton = [folderController buttonWithTitleEqualTo:@"1b"]; |
743 ASSERT_TRUE(draggedButton); | 743 ASSERT_TRUE(draggedButton); |
744 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; | 744 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; |
745 ASSERT_TRUE(targetButton); | 745 ASSERT_TRUE(targetButton); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 "4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); | 789 "4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); |
790 EXPECT_EQ(expected_1, model_test_utils::ModelStringFromNode(root)); | 790 EXPECT_EQ(expected_1, model_test_utils::ModelStringFromNode(root)); |
791 | 791 |
792 // Gather the new frames. | 792 // Gather the new frames. |
793 NSRect newToFolderFrame = [toFolder frame]; | 793 NSRect newToFolderFrame = [toFolder frame]; |
794 NSRect newToWindowFrame = [toWindow frame]; | 794 NSRect newToWindowFrame = [toWindow frame]; |
795 // The toFolder should have shifted. | 795 // The toFolder should have shifted. |
796 EXPECT_NSRECT_EQ(oldToFolderFrame, newToFolderFrame); | 796 EXPECT_NSRECT_EQ(oldToFolderFrame, newToFolderFrame); |
797 // The toWindow should have shifted down vertically and grown vertically. | 797 // The toWindow should have shifted down vertically and grown vertically. |
798 NSRect expectedToWindowFrame = oldToWindowFrame; | 798 NSRect expectedToWindowFrame = oldToWindowFrame; |
799 CGFloat diff = (bookmarks::kBookmarkBarHeight + | 799 expectedToWindowFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
800 2*bookmarks::kBookmarkVerticalPadding); | 800 expectedToWindowFrame.size.height += bookmarks::kBookmarkFolderButtonHeight; |
801 expectedToWindowFrame.origin.y -= diff; | |
802 expectedToWindowFrame.size.height += diff; | |
803 EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame); | 801 EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame); |
804 | 802 |
805 // Copy the button back to the bar after "3b". | 803 // Copy the button back to the bar after "3b". |
806 draggedButton = [folderController buttonWithTitleEqualTo:@"1b"]; | 804 draggedButton = [folderController buttonWithTitleEqualTo:@"1b"]; |
807 ASSERT_TRUE(draggedButton); | 805 ASSERT_TRUE(draggedButton); |
808 targetButton = [bar_ buttonWithTitleEqualTo:@"4f"]; | 806 targetButton = [bar_ buttonWithTitleEqualTo:@"4f"]; |
809 ASSERT_TRUE(targetButton); | 807 ASSERT_TRUE(targetButton); |
810 [bar_ dragButton:draggedButton | 808 [bar_ dragButton:draggedButton |
811 to:[targetButton left] | 809 to:[targetButton left] |
812 copy:YES]; | 810 copy:YES]; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // Check button spacing. | 866 // Check button spacing. |
869 [folderController validateMenuSpacing]; | 867 [folderController validateMenuSpacing]; |
870 [subfolderController validateMenuSpacing]; | 868 [subfolderController validateMenuSpacing]; |
871 | 869 |
872 // Check the window layouts. The folder window should not have changed, | 870 // Check the window layouts. The folder window should not have changed, |
873 // but the subfolder window should have shifted vertically and grown. | 871 // but the subfolder window should have shifted vertically and grown. |
874 NSRect newToWindowFrame = [toWindow frame]; | 872 NSRect newToWindowFrame = [toWindow frame]; |
875 EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame); | 873 EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame); |
876 NSRect newToSubwindowFrame = [toSubwindow frame]; | 874 NSRect newToSubwindowFrame = [toSubwindow frame]; |
877 NSRect expectedToSubwindowFrame = oldToSubwindowFrame; | 875 NSRect expectedToSubwindowFrame = oldToSubwindowFrame; |
878 expectedToSubwindowFrame.origin.y -= | 876 expectedToSubwindowFrame.origin.y -= bookmarks::kBookmarkFolderButtonHeight; |
879 (bookmarks::kBookmarkButtonHeight + bookmarks::kVisualHeightOffset); | |
880 expectedToSubwindowFrame.size.height += | 877 expectedToSubwindowFrame.size.height += |
881 (bookmarks::kBookmarkButtonHeight + bookmarks::kVisualHeightOffset); | 878 bookmarks::kBookmarkFolderButtonHeight; |
882 EXPECT_NSRECT_EQ(expectedToSubwindowFrame, newToSubwindowFrame); | 879 EXPECT_NSRECT_EQ(expectedToSubwindowFrame, newToSubwindowFrame); |
883 } | 880 } |
884 | 881 |
885 TEST_F(BookmarkBarFolderControllerMenuTest, DragMoveWithinFolder) { | 882 TEST_F(BookmarkBarFolderControllerMenuTest, DragMoveWithinFolder) { |
886 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); | 883 BookmarkModel& model(*helper_.profile()->GetBookmarkModel()); |
887 const BookmarkNode* root = model.GetBookmarkBarNode(); | 884 const BookmarkNode* root = model.GetBookmarkBarNode(); |
888 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b " | 885 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b " |
889 "2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b " | 886 "2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b " |
890 "4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); | 887 "4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b "); |
891 model_test_utils::AddNodesFromModelString(model, root, model_string); | 888 model_test_utils::AddNodesFromModelString(model, root, model_string); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 ASCIIToUTF16("BIG")); | 1171 ASCIIToUTF16("BIG")); |
1175 | 1172 |
1176 // Pop open the new folder window and verify it has one (empty) item. | 1173 // Pop open the new folder window and verify it has one (empty) item. |
1177 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; | 1174 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"BIG"]; |
1178 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) | 1175 [[button target] performSelector:@selector(openBookmarkFolderFromButton:) |
1179 withObject:button]; | 1176 withObject:button]; |
1180 BookmarkBarFolderController* folderController = [bar_ folderController]; | 1177 BookmarkBarFolderController* folderController = [bar_ folderController]; |
1181 EXPECT_TRUE(folderController); | 1178 EXPECT_TRUE(folderController); |
1182 NSWindow* folderWindow = [folderController window]; | 1179 NSWindow* folderWindow = [folderController window]; |
1183 EXPECT_TRUE(folderWindow); | 1180 EXPECT_TRUE(folderWindow); |
1184 CGFloat expectedHeight = (CGFloat)bookmarks::kBookmarkButtonHeight + | 1181 CGFloat expectedHeight = (CGFloat)bookmarks::kBookmarkFolderButtonHeight + |
1185 (2*bookmarks::kBookmarkVerticalPadding); | 1182 (2*bookmarks::kBookmarkVerticalPadding); |
1186 NSRect windowFrame = [folderWindow frame]; | 1183 NSRect windowFrame = [folderWindow frame]; |
1187 CGFloat windowHeight = NSHeight(windowFrame); | 1184 CGFloat windowHeight = NSHeight(windowFrame); |
1188 EXPECT_CGFLOAT_EQ(expectedHeight, windowHeight); | 1185 EXPECT_CGFLOAT_EQ(expectedHeight, windowHeight); |
1189 EXPECT_FALSE([folderController canScrollUp]); | 1186 EXPECT_FALSE([folderController canScrollUp]); |
1190 EXPECT_FALSE([folderController canScrollDown]); | 1187 EXPECT_FALSE([folderController canScrollDown]); |
1191 | 1188 |
1192 // Now add a real bookmark and reopen. | 1189 // Now add a real bookmark and reopen. |
1193 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("a"), | 1190 model.AddURL(folder, folder->GetChildCount(), ASCIIToUTF16("a"), |
1194 GURL("http://a.com/")); | 1191 GURL("http://a.com/")); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 [folder deleteBookmark:folder]; | 1550 [folder deleteBookmark:folder]; |
1554 EXPECT_FALSE([folder folderController]); | 1551 EXPECT_FALSE([folder folderController]); |
1555 } | 1552 } |
1556 | 1553 |
1557 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so | 1554 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so |
1558 // they are hard to test. Factor out "fire timers" into routines | 1555 // they are hard to test. Factor out "fire timers" into routines |
1559 // which can be overridden to fire immediately to make behavior | 1556 // which can be overridden to fire immediately to make behavior |
1560 // confirmable. | 1557 // confirmable. |
1561 // There is a similar problem with mouseEnteredButton: and | 1558 // There is a similar problem with mouseEnteredButton: and |
1562 // mouseExitedButton:. | 1559 // mouseExitedButton:. |
OLD | NEW |