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 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 [[NSNotificationCenter defaultCenter] | 516 [[NSNotificationCenter defaultCenter] |
517 postNotificationName:NSViewFrameDidChangeNotification | 517 postNotificationName:NSViewFrameDidChangeNotification |
518 object:[bar view]]; | 518 object:[bar view]]; |
519 | 519 |
520 EXPECT_GT([bar toggles], 0); | 520 EXPECT_GT([bar toggles], 0); |
521 } | 521 } |
522 | 522 |
523 // Confirm our "no items" container goes away when we add the 1st | 523 // Confirm our "no items" container goes away when we add the 1st |
524 // bookmark, and comes back when we delete the bookmark. | 524 // bookmark, and comes back when we delete the bookmark. |
525 TEST_F(BookmarkBarControllerTest, NoItemContainerGoesAway) { | 525 TEST_F(BookmarkBarControllerTest, NoItemContainerGoesAway) { |
526 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 526 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
527 const BookmarkNode* bar = model->bookmark_bar_node(); | 527 const BookmarkNode* bar = model->bookmark_bar_node(); |
528 | 528 |
529 [bar_ loaded:model]; | 529 [bar_ loaded:model]; |
530 BookmarkBarView* view = [bar_ buttonView]; | 530 BookmarkBarView* view = [bar_ buttonView]; |
531 DCHECK(view); | 531 DCHECK(view); |
532 NSView* noItemContainer = [view noItemContainer]; | 532 NSView* noItemContainer = [view noItemContainer]; |
533 DCHECK(noItemContainer); | 533 DCHECK(noItemContainer); |
534 | 534 |
535 EXPECT_FALSE([noItemContainer isHidden]); | 535 EXPECT_FALSE([noItemContainer isHidden]); |
536 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), | 536 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), |
(...skipping 12 matching lines...) Expand all Loading... |
549 // Move it from Other Bookmarks to the bar. | 549 // Move it from Other Bookmarks to the bar. |
550 model->Move(node, bar, 0); | 550 model->Move(node, bar, 0); |
551 EXPECT_TRUE([noItemContainer isHidden]); | 551 EXPECT_TRUE([noItemContainer isHidden]); |
552 // Move it back to Other Bookmarks from the bar. | 552 // Move it back to Other Bookmarks from the bar. |
553 model->Move(node, otherBookmarks, 0); | 553 model->Move(node, otherBookmarks, 0); |
554 EXPECT_FALSE([noItemContainer isHidden]); | 554 EXPECT_FALSE([noItemContainer isHidden]); |
555 } | 555 } |
556 | 556 |
557 // Confirm off the side button only enabled when reasonable. | 557 // Confirm off the side button only enabled when reasonable. |
558 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { | 558 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { |
559 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 559 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
560 | 560 |
561 [bar_ loaded:model]; | 561 [bar_ loaded:model]; |
562 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 562 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
563 | 563 |
564 for (int i = 0; i < 2; i++) { | 564 for (int i = 0; i < 2; i++) { |
565 bookmarks::AddIfNotBookmarked( | 565 bookmarks::AddIfNotBookmarked( |
566 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); | 566 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); |
567 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 567 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
568 } | 568 } |
569 | 569 |
(...skipping 28 matching lines...) Expand all Loading... |
598 } else { | 598 } else { |
599 EXPECT_TRUE([bar_ folderController]); | 599 EXPECT_TRUE([bar_ folderController]); |
600 } | 600 } |
601 } | 601 } |
602 } | 602 } |
603 | 603 |
604 // http://crbug.com/46175 is a crash when deleting bookmarks from the | 604 // http://crbug.com/46175 is a crash when deleting bookmarks from the |
605 // off-the-side menu while it is open. This test tries to bang hard | 605 // off-the-side menu while it is open. This test tries to bang hard |
606 // in this area to reproduce the crash. | 606 // in this area to reproduce the crash. |
607 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { | 607 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { |
608 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 608 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
609 [bar_ loaded:model]; | 609 [bar_ loaded:model]; |
610 | 610 |
611 // Add a lot of bookmarks (per the bug). | 611 // Add a lot of bookmarks (per the bug). |
612 const BookmarkNode* parent = model->bookmark_bar_node(); | 612 const BookmarkNode* parent = model->bookmark_bar_node(); |
613 for (int i = 0; i < 100; i++) { | 613 for (int i = 0; i < 100; i++) { |
614 std::ostringstream title; | 614 std::ostringstream title; |
615 title << "super duper wide title " << i; | 615 title << "super duper wide title " << i; |
616 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), | 616 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), |
617 GURL("http://superfriends.hall-of-justice.edu")); | 617 GURL("http://superfriends.hall-of-justice.edu")); |
618 } | 618 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 680 } |
681 | 681 |
682 // Confirm uniqueness. | 682 // Confirm uniqueness. |
683 std::sort(tags.begin(), tags.end()); | 683 std::sort(tags.begin(), tags.end()); |
684 for (unsigned int i=0; i<(tags.size()-1); i++) { | 684 for (unsigned int i=0; i<(tags.size()-1); i++) { |
685 EXPECT_NE(tags[i], tags[i+1]); | 685 EXPECT_NE(tags[i], tags[i+1]); |
686 } | 686 } |
687 } | 687 } |
688 | 688 |
689 TEST_F(BookmarkBarControllerTest, MenuForFolderNode) { | 689 TEST_F(BookmarkBarControllerTest, MenuForFolderNode) { |
690 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 690 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
691 | 691 |
692 // First make sure something (e.g. "(empty)" string) is always present. | 692 // First make sure something (e.g. "(empty)" string) is always present. |
693 NSMenu* menu = [bar_ menuForFolderNode:model->bookmark_bar_node()]; | 693 NSMenu* menu = [bar_ menuForFolderNode:model->bookmark_bar_node()]; |
694 EXPECT_GT([menu numberOfItems], 0); | 694 EXPECT_GT([menu numberOfItems], 0); |
695 | 695 |
696 // Test two bookmarks. | 696 // Test two bookmarks. |
697 GURL gurl("http://www.foo.com"); | 697 GURL gurl("http://www.foo.com"); |
698 bookmarks::AddIfNotBookmarked(model, gurl, ASCIIToUTF16("small")); | 698 bookmarks::AddIfNotBookmarked(model, gurl, ASCIIToUTF16("small")); |
699 bookmarks::AddIfNotBookmarked( | 699 bookmarks::AddIfNotBookmarked( |
700 model, GURL("http://www.cnn.com"), ASCIIToUTF16("bigger title")); | 700 model, GURL("http://www.cnn.com"), ASCIIToUTF16("bigger title")); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 base::scoped_nsobject<BookmarkButton> button([[BookmarkButton alloc] init]); | 744 base::scoped_nsobject<BookmarkButton> button([[BookmarkButton alloc] init]); |
745 [button setCell:cell.get()]; | 745 [button setCell:cell.get()]; |
746 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; | 746 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; |
747 | 747 |
748 [bar_ openBookmark:button]; | 748 [bar_ openBookmark:button]; |
749 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); | 749 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); |
750 EXPECT_EQ(noOpenBar()->dispositions_[0], CURRENT_TAB); | 750 EXPECT_EQ(noOpenBar()->dispositions_[0], CURRENT_TAB); |
751 } | 751 } |
752 | 752 |
753 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { | 753 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { |
754 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 754 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
755 NSView* buttonView = [bar_ buttonView]; | 755 NSView* buttonView = [bar_ buttonView]; |
756 EXPECT_EQ(0U, [[bar_ buttons] count]); | 756 EXPECT_EQ(0U, [[bar_ buttons] count]); |
757 unsigned int initial_subview_count = [[buttonView subviews] count]; | 757 unsigned int initial_subview_count = [[buttonView subviews] count]; |
758 | 758 |
759 // Make sure a redundant call doesn't choke | 759 // Make sure a redundant call doesn't choke |
760 [bar_ clearBookmarkBar]; | 760 [bar_ clearBookmarkBar]; |
761 EXPECT_EQ(0U, [[bar_ buttons] count]); | 761 EXPECT_EQ(0U, [[bar_ buttons] count]); |
762 EXPECT_EQ(initial_subview_count, [[buttonView subviews] count]); | 762 EXPECT_EQ(initial_subview_count, [[buttonView subviews] count]); |
763 | 763 |
764 GURL gurl1("http://superfriends.hall-of-justice.edu"); | 764 GURL gurl1("http://superfriends.hall-of-justice.edu"); |
(...skipping 29 matching lines...) Expand all Loading... |
794 | 794 |
795 // Explicit test of loaded: since this is a convenient spot | 795 // Explicit test of loaded: since this is a convenient spot |
796 [bar_ loaded:model]; | 796 [bar_ loaded:model]; |
797 EXPECT_EQ(2U, [[bar_ buttons] count]); | 797 EXPECT_EQ(2U, [[bar_ buttons] count]); |
798 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); | 798 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); |
799 } | 799 } |
800 | 800 |
801 // Make sure we don't create too many buttons; we only really need | 801 // Make sure we don't create too many buttons; we only really need |
802 // ones that will be visible. | 802 // ones that will be visible. |
803 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { | 803 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { |
804 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 804 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
805 EXPECT_EQ(0U, [[bar_ buttons] count]); | 805 EXPECT_EQ(0U, [[bar_ buttons] count]); |
806 // Add one; make sure we see it. | 806 // Add one; make sure we see it. |
807 const BookmarkNode* parent = model->bookmark_bar_node(); | 807 const BookmarkNode* parent = model->bookmark_bar_node(); |
808 model->AddURL(parent, parent->child_count(), | 808 model->AddURL(parent, parent->child_count(), |
809 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 809 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
810 EXPECT_EQ(1U, [[bar_ buttons] count]); | 810 EXPECT_EQ(1U, [[bar_ buttons] count]); |
811 | 811 |
812 // Add 30 which we expect to be 'too many'. Make sure we don't see | 812 // Add 30 which we expect to be 'too many'. Make sure we don't see |
813 // 30 buttons. | 813 // 30 buttons. |
814 model->Remove(parent->GetChild(0)); | 814 model->Remove(parent->GetChild(0)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 for (unsigned int i = 0; i < arraysize(widths); i++) { | 854 for (unsigned int i = 0; i < arraysize(widths); i++) { |
855 NSRect r = [bar_ frameForBookmarkButtonFromCell:[cells objectAtIndex:i] | 855 NSRect r = [bar_ frameForBookmarkButtonFromCell:[cells objectAtIndex:i] |
856 xOffset:&x_offset]; | 856 xOffset:&x_offset]; |
857 EXPECT_GE(r.origin.x, x_end); | 857 EXPECT_GE(r.origin.x, x_end); |
858 x_end = NSMaxX(r); | 858 x_end = NSMaxX(r); |
859 } | 859 } |
860 } | 860 } |
861 | 861 |
862 TEST_F(BookmarkBarControllerTest, CheckForGrowth) { | 862 TEST_F(BookmarkBarControllerTest, CheckForGrowth) { |
863 WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope. | 863 WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope. |
864 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 864 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
865 GURL gurl1("http://www.google.com"); | 865 GURL gurl1("http://www.google.com"); |
866 base::string16 title1(ASCIIToUTF16("x")); | 866 base::string16 title1(ASCIIToUTF16("x")); |
867 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 867 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
868 | 868 |
869 GURL gurl2("http://www.google.com/blah"); | 869 GURL gurl2("http://www.google.com/blah"); |
870 base::string16 title2(ASCIIToUTF16("y")); | 870 base::string16 title2(ASCIIToUTF16("y")); |
871 bookmarks::AddIfNotBookmarked(model, gurl2, title2); | 871 bookmarks::AddIfNotBookmarked(model, gurl2, title2); |
872 | 872 |
873 EXPECT_EQ(2U, [[bar_ buttons] count]); | 873 EXPECT_EQ(2U, [[bar_ buttons] count]); |
874 CGFloat width_1 = [[[bar_ buttons] objectAtIndex:0] frame].size.width; | 874 CGFloat width_1 = [[[bar_ buttons] objectAtIndex:0] frame].size.width; |
875 CGFloat x_2 = [[[bar_ buttons] objectAtIndex:1] frame].origin.x; | 875 CGFloat x_2 = [[[bar_ buttons] objectAtIndex:1] frame].origin.x; |
876 | 876 |
877 NSButton* first = [[bar_ buttons] objectAtIndex:0]; | 877 NSButton* first = [[bar_ buttons] objectAtIndex:0]; |
878 [[first cell] setTitle:@"This is a really big title; watch out mom!"]; | 878 [[first cell] setTitle:@"This is a really big title; watch out mom!"]; |
879 [bar_ checkForBookmarkButtonGrowth:first]; | 879 [bar_ checkForBookmarkButtonGrowth:first]; |
880 | 880 |
881 // Make sure the 1st button is now wider, the 2nd one is moved over, | 881 // Make sure the 1st button is now wider, the 2nd one is moved over, |
882 // and they don't overlap. | 882 // and they don't overlap. |
883 NSRect frame_1 = [[[bar_ buttons] objectAtIndex:0] frame]; | 883 NSRect frame_1 = [[[bar_ buttons] objectAtIndex:0] frame]; |
884 NSRect frame_2 = [[[bar_ buttons] objectAtIndex:1] frame]; | 884 NSRect frame_2 = [[[bar_ buttons] objectAtIndex:1] frame]; |
885 EXPECT_GT(frame_1.size.width, width_1); | 885 EXPECT_GT(frame_1.size.width, width_1); |
886 EXPECT_GT(frame_2.origin.x, x_2); | 886 EXPECT_GT(frame_2.origin.x, x_2); |
887 EXPECT_GE(frame_2.origin.x, frame_1.origin.x + frame_1.size.width); | 887 EXPECT_GE(frame_2.origin.x, frame_1.origin.x + frame_1.size.width); |
888 } | 888 } |
889 | 889 |
890 TEST_F(BookmarkBarControllerTest, DeleteBookmark) { | 890 TEST_F(BookmarkBarControllerTest, DeleteBookmark) { |
891 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 891 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
892 | 892 |
893 const char* urls[] = { "https://secret.url.com", | 893 const char* urls[] = { "https://secret.url.com", |
894 "http://super.duper.web.site.for.doodz.gov", | 894 "http://super.duper.web.site.for.doodz.gov", |
895 "http://www.foo-bar-baz.com/" }; | 895 "http://www.foo-bar-baz.com/" }; |
896 const BookmarkNode* parent = model->bookmark_bar_node(); | 896 const BookmarkNode* parent = model->bookmark_bar_node(); |
897 for (unsigned int i = 0; i < arraysize(urls); i++) { | 897 for (unsigned int i = 0; i < arraysize(urls); i++) { |
898 model->AddURL(parent, parent->child_count(), | 898 model->AddURL(parent, parent->child_count(), |
899 ASCIIToUTF16("title"), GURL(urls[i])); | 899 ASCIIToUTF16("title"), GURL(urls[i])); |
900 } | 900 } |
901 EXPECT_EQ(3, parent->child_count()); | 901 EXPECT_EQ(3, parent->child_count()); |
902 const BookmarkNode* middle_node = parent->GetChild(1); | 902 const BookmarkNode* middle_node = parent->GetChild(1); |
903 model->Remove(middle_node); | 903 model->Remove(middle_node); |
904 | 904 |
905 EXPECT_EQ(2, parent->child_count()); | 905 EXPECT_EQ(2, parent->child_count()); |
906 EXPECT_EQ(parent->GetChild(0)->url(), GURL(urls[0])); | 906 EXPECT_EQ(parent->GetChild(0)->url(), GURL(urls[0])); |
907 // node 2 moved into spot 1 | 907 // node 2 moved into spot 1 |
908 EXPECT_EQ(parent->GetChild(1)->url(), GURL(urls[2])); | 908 EXPECT_EQ(parent->GetChild(1)->url(), GURL(urls[2])); |
909 } | 909 } |
910 | 910 |
911 // TODO(jrg): write a test to confirm that nodeFaviconLoaded calls | 911 // TODO(jrg): write a test to confirm that nodeFaviconLoaded calls |
912 // checkForBookmarkButtonGrowth:. | 912 // checkForBookmarkButtonGrowth:. |
913 | 913 |
914 TEST_F(BookmarkBarControllerTest, Cell) { | 914 TEST_F(BookmarkBarControllerTest, Cell) { |
915 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 915 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
916 [bar_ loaded:model]; | 916 [bar_ loaded:model]; |
917 | 917 |
918 const BookmarkNode* parent = model->bookmark_bar_node(); | 918 const BookmarkNode* parent = model->bookmark_bar_node(); |
919 model->AddURL(parent, parent->child_count(), | 919 model->AddURL(parent, parent->child_count(), |
920 ASCIIToUTF16("supertitle"), | 920 ASCIIToUTF16("supertitle"), |
921 GURL("http://superfriends.hall-of-justice.edu")); | 921 GURL("http://superfriends.hall-of-justice.edu")); |
922 const BookmarkNode* node = parent->GetChild(0); | 922 const BookmarkNode* node = parent->GetChild(0); |
923 | 923 |
924 NSCell* cell = [bar_ cellForBookmarkNode:node]; | 924 NSCell* cell = [bar_ cellForBookmarkNode:node]; |
925 EXPECT_TRUE(cell); | 925 EXPECT_TRUE(cell); |
(...skipping 11 matching lines...) Expand all Loading... |
937 } | 937 } |
938 | 938 |
939 // Test drawing, mostly to ensure nothing leaks or crashes. | 939 // Test drawing, mostly to ensure nothing leaks or crashes. |
940 TEST_F(BookmarkBarControllerTest, Display) { | 940 TEST_F(BookmarkBarControllerTest, Display) { |
941 [[bar_ view] display]; | 941 [[bar_ view] display]; |
942 } | 942 } |
943 | 943 |
944 // Test that middle clicking on a bookmark button results in an open action, | 944 // Test that middle clicking on a bookmark button results in an open action, |
945 // except for offTheSideButton, as it just opens its folder menu. | 945 // except for offTheSideButton, as it just opens its folder menu. |
946 TEST_F(BookmarkBarControllerTest, MiddleClick) { | 946 TEST_F(BookmarkBarControllerTest, MiddleClick) { |
947 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 947 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
948 GURL gurl1("http://www.google.com/"); | 948 GURL gurl1("http://www.google.com/"); |
949 base::string16 title1(ASCIIToUTF16("x")); | 949 base::string16 title1(ASCIIToUTF16("x")); |
950 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 950 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
951 | 951 |
952 EXPECT_EQ(1U, [[bar_ buttons] count]); | 952 EXPECT_EQ(1U, [[bar_ buttons] count]); |
953 NSButton* first = [[bar_ buttons] objectAtIndex:0]; | 953 NSButton* first = [[bar_ buttons] objectAtIndex:0]; |
954 EXPECT_TRUE(first); | 954 EXPECT_TRUE(first); |
955 | 955 |
956 [first otherMouseUp: | 956 [first otherMouseUp: |
957 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 957 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
(...skipping 25 matching lines...) Expand all Loading... |
983 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); | 983 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); |
984 | 984 |
985 // Middle clicking again on it should close the folder. | 985 // Middle clicking again on it should close the folder. |
986 [offTheSideButton otherMouseUp: | 986 [offTheSideButton otherMouseUp: |
987 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 987 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
988 bbfc = [bar_ folderController]; | 988 bbfc = [bar_ folderController]; |
989 EXPECT_FALSE(bbfc); | 989 EXPECT_FALSE(bbfc); |
990 } | 990 } |
991 | 991 |
992 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { | 992 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { |
993 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 993 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
994 [bar_ loaded:model]; | 994 [bar_ loaded:model]; |
995 EXPECT_FALSE([[[bar_ buttonView] noItemContainer] isHidden]); | 995 EXPECT_FALSE([[[bar_ buttonView] noItemContainer] isHidden]); |
996 } | 996 } |
997 | 997 |
998 TEST_F(BookmarkBarControllerTest, HidesHelpMessageWithBookmark) { | 998 TEST_F(BookmarkBarControllerTest, HidesHelpMessageWithBookmark) { |
999 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 999 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1000 | 1000 |
1001 const BookmarkNode* parent = model->bookmark_bar_node(); | 1001 const BookmarkNode* parent = model->bookmark_bar_node(); |
1002 model->AddURL(parent, parent->child_count(), | 1002 model->AddURL(parent, parent->child_count(), |
1003 ASCIIToUTF16("title"), GURL("http://one.com")); | 1003 ASCIIToUTF16("title"), GURL("http://one.com")); |
1004 | 1004 |
1005 [bar_ loaded:model]; | 1005 [bar_ loaded:model]; |
1006 EXPECT_TRUE([[[bar_ buttonView] noItemContainer] isHidden]); | 1006 EXPECT_TRUE([[[bar_ buttonView] noItemContainer] isHidden]); |
1007 } | 1007 } |
1008 | 1008 |
1009 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { | 1009 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { |
1010 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1010 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1011 | 1011 |
1012 const BookmarkNode* parent = model->bookmark_bar_node(); | 1012 const BookmarkNode* parent = model->bookmark_bar_node(); |
1013 model->AddURL(parent, parent->child_count(), | 1013 model->AddURL(parent, parent->child_count(), |
1014 ASCIIToUTF16("title"), GURL("http://one.com")); | 1014 ASCIIToUTF16("title"), GURL("http://one.com")); |
1015 | 1015 |
1016 [bar_ loaded:model]; | 1016 [bar_ loaded:model]; |
1017 | 1017 |
1018 // Make sure the internal bookmark button also is the correct height. | 1018 // Make sure the internal bookmark button also is the correct height. |
1019 NSArray* buttons = [bar_ buttons]; | 1019 NSArray* buttons = [bar_ buttons]; |
1020 EXPECT_GT([buttons count], 0u); | 1020 EXPECT_GT([buttons count], 0u); |
(...skipping 30 matching lines...) Expand all Loading... |
1051 }; | 1051 }; |
1052 EXPECT_EQ(arraysize(urls), arraysize(titles)); | 1052 EXPECT_EQ(arraysize(urls), arraysize(titles)); |
1053 | 1053 |
1054 NSMutableArray* nsurls = [NSMutableArray array]; | 1054 NSMutableArray* nsurls = [NSMutableArray array]; |
1055 NSMutableArray* nstitles = [NSMutableArray array]; | 1055 NSMutableArray* nstitles = [NSMutableArray array]; |
1056 for (size_t i = 0; i < arraysize(urls); ++i) { | 1056 for (size_t i = 0; i < arraysize(urls); ++i) { |
1057 [nsurls addObject:base::SysUTF8ToNSString(urls[i])]; | 1057 [nsurls addObject:base::SysUTF8ToNSString(urls[i])]; |
1058 [nstitles addObject:base::SysUTF8ToNSString(titles[i])]; | 1058 [nstitles addObject:base::SysUTF8ToNSString(titles[i])]; |
1059 } | 1059 } |
1060 | 1060 |
1061 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1061 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1062 const BookmarkNode* parent = model->bookmark_bar_node(); | 1062 const BookmarkNode* parent = model->bookmark_bar_node(); |
1063 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; | 1063 [bar_ addURLs:nsurls withTitles:nstitles at:NSZeroPoint]; |
1064 EXPECT_EQ(4, parent->child_count()); | 1064 EXPECT_EQ(4, parent->child_count()); |
1065 for (int i = 0; i < parent->child_count(); ++i) { | 1065 for (int i = 0; i < parent->child_count(); ++i) { |
1066 GURL gurl = parent->GetChild(i)->url(); | 1066 GURL gurl = parent->GetChild(i)->url(); |
1067 if (gurl.scheme() == "http" || | 1067 if (gurl.scheme() == "http" || |
1068 gurl.scheme() == "javascript") { | 1068 gurl.scheme() == "javascript") { |
1069 EXPECT_EQ(parent->GetChild(i)->url(), GURL(urls[i])); | 1069 EXPECT_EQ(parent->GetChild(i)->url(), GURL(urls[i])); |
1070 } else { | 1070 } else { |
1071 // Be flexible if the scheme needed to be added. | 1071 // Be flexible if the scheme needed to be added. |
1072 std::string gurl_string = gurl.spec(); | 1072 std::string gurl_string = gurl.spec(); |
1073 std::string my_string = parent->GetChild(i)->url().spec(); | 1073 std::string my_string = parent->GetChild(i)->url().spec(); |
1074 EXPECT_NE(gurl_string.find(my_string), std::string::npos); | 1074 EXPECT_NE(gurl_string.find(my_string), std::string::npos); |
1075 } | 1075 } |
1076 EXPECT_EQ(parent->GetChild(i)->GetTitle(), ASCIIToUTF16(titles[i])); | 1076 EXPECT_EQ(parent->GetChild(i)->GetTitle(), ASCIIToUTF16(titles[i])); |
1077 } | 1077 } |
1078 } | 1078 } |
1079 | 1079 |
1080 TEST_F(BookmarkBarControllerTest, TestDragButton) { | 1080 TEST_F(BookmarkBarControllerTest, TestDragButton) { |
1081 WithNoAnimation at_all; | 1081 WithNoAnimation at_all; |
1082 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1082 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1083 | 1083 |
1084 GURL gurls[] = { GURL("http://www.google.com/a"), | 1084 GURL gurls[] = { GURL("http://www.google.com/a"), |
1085 GURL("http://www.google.com/b"), | 1085 GURL("http://www.google.com/b"), |
1086 GURL("http://www.google.com/c") }; | 1086 GURL("http://www.google.com/c") }; |
1087 base::string16 titles[] = { ASCIIToUTF16("a"), | 1087 base::string16 titles[] = { ASCIIToUTF16("a"), |
1088 ASCIIToUTF16("b"), | 1088 ASCIIToUTF16("b"), |
1089 ASCIIToUTF16("c") }; | 1089 ASCIIToUTF16("c") }; |
1090 for (unsigned i = 0; i < arraysize(titles); i++) | 1090 for (unsigned i = 0; i < arraysize(titles); i++) |
1091 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); | 1091 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); |
1092 | 1092 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 copy:NO]; | 1144 copy:NO]; |
1145 // Gone from the bar | 1145 // Gone from the bar |
1146 EXPECT_EQ(arraysize(titles), [[bar_ buttons] count]); | 1146 EXPECT_EQ(arraysize(titles), [[bar_ buttons] count]); |
1147 // In the folder | 1147 // In the folder |
1148 EXPECT_EQ(2, folder->child_count()); | 1148 EXPECT_EQ(2, folder->child_count()); |
1149 // At the end | 1149 // At the end |
1150 EXPECT_EQ(title, folder->GetChild(1)->GetTitle()); | 1150 EXPECT_EQ(title, folder->GetChild(1)->GetTitle()); |
1151 } | 1151 } |
1152 | 1152 |
1153 TEST_F(BookmarkBarControllerTest, TestCopyButton) { | 1153 TEST_F(BookmarkBarControllerTest, TestCopyButton) { |
1154 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1154 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1155 | 1155 |
1156 GURL gurls[] = { GURL("http://www.google.com/a"), | 1156 GURL gurls[] = { GURL("http://www.google.com/a"), |
1157 GURL("http://www.google.com/b"), | 1157 GURL("http://www.google.com/b"), |
1158 GURL("http://www.google.com/c") }; | 1158 GURL("http://www.google.com/c") }; |
1159 base::string16 titles[] = { ASCIIToUTF16("a"), | 1159 base::string16 titles[] = { ASCIIToUTF16("a"), |
1160 ASCIIToUTF16("b"), | 1160 ASCIIToUTF16("b"), |
1161 ASCIIToUTF16("c") }; | 1161 ASCIIToUTF16("c") }; |
1162 for (unsigned i = 0; i < arraysize(titles); i++) | 1162 for (unsigned i = 0; i < arraysize(titles); i++) |
1163 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); | 1163 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); |
1164 | 1164 |
1165 EXPECT_EQ([[bar_ buttons] count], arraysize(titles)); | 1165 EXPECT_EQ([[bar_ buttons] count], arraysize(titles)); |
1166 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:0] title]); | 1166 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:0] title]); |
1167 | 1167 |
1168 // Drag 'a' between 'b' and 'c'. | 1168 // Drag 'a' between 'b' and 'c'. |
1169 CGFloat x = NSMinX([[[bar_ buttons] objectAtIndex:2] frame]); | 1169 CGFloat x = NSMinX([[[bar_ buttons] objectAtIndex:2] frame]); |
1170 x += [[bar_ view] frame].origin.x; | 1170 x += [[bar_ view] frame].origin.x; |
1171 [bar_ dragButton:[[bar_ buttons] objectAtIndex:0] | 1171 [bar_ dragButton:[[bar_ buttons] objectAtIndex:0] |
1172 to:NSMakePoint(x, 0) | 1172 to:NSMakePoint(x, 0) |
1173 copy:YES]; | 1173 copy:YES]; |
1174 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:0] title]); | 1174 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:0] title]); |
1175 EXPECT_NSEQ(@"b", [[[bar_ buttons] objectAtIndex:1] title]); | 1175 EXPECT_NSEQ(@"b", [[[bar_ buttons] objectAtIndex:1] title]); |
1176 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:2] title]); | 1176 EXPECT_NSEQ(@"a", [[[bar_ buttons] objectAtIndex:2] title]); |
1177 EXPECT_NSEQ(@"c", [[[bar_ buttons] objectAtIndex:3] title]); | 1177 EXPECT_NSEQ(@"c", [[[bar_ buttons] objectAtIndex:3] title]); |
1178 EXPECT_EQ([[bar_ buttons] count], 4U); | 1178 EXPECT_EQ([[bar_ buttons] count], 4U); |
1179 } | 1179 } |
1180 | 1180 |
1181 // Fake a theme with colored text. Apply it and make sure bookmark | 1181 // Fake a theme with colored text. Apply it and make sure bookmark |
1182 // buttons have the same colored text. Repeat more than once. | 1182 // buttons have the same colored text. Repeat more than once. |
1183 TEST_F(BookmarkBarControllerTest, TestThemedButton) { | 1183 TEST_F(BookmarkBarControllerTest, TestThemedButton) { |
1184 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1184 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1185 bookmarks::AddIfNotBookmarked( | 1185 bookmarks::AddIfNotBookmarked( |
1186 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); | 1186 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); |
1187 BookmarkButton* button = [[bar_ buttons] objectAtIndex:0]; | 1187 BookmarkButton* button = [[bar_ buttons] objectAtIndex:0]; |
1188 EXPECT_TRUE(button); | 1188 EXPECT_TRUE(button); |
1189 | 1189 |
1190 NSArray* colors = [NSArray arrayWithObjects:[NSColor redColor], | 1190 NSArray* colors = [NSArray arrayWithObjects:[NSColor redColor], |
1191 [NSColor blueColor], | 1191 [NSColor blueColor], |
1192 nil]; | 1192 nil]; |
1193 for (NSColor* color in colors) { | 1193 for (NSColor* color in colors) { |
1194 FakeTheme theme(color); | 1194 FakeTheme theme(color); |
1195 [bar_ updateTheme:&theme]; | 1195 [bar_ updateTheme:&theme]; |
1196 NSAttributedString* astr = [button attributedTitle]; | 1196 NSAttributedString* astr = [button attributedTitle]; |
1197 EXPECT_TRUE(astr); | 1197 EXPECT_TRUE(astr); |
1198 EXPECT_NSEQ(@"small", [astr string]); | 1198 EXPECT_NSEQ(@"small", [astr string]); |
1199 // Pick a char in the middle to test (index 3) | 1199 // Pick a char in the middle to test (index 3) |
1200 NSDictionary* attributes = [astr attributesAtIndex:3 effectiveRange:NULL]; | 1200 NSDictionary* attributes = [astr attributesAtIndex:3 effectiveRange:NULL]; |
1201 NSColor* newColor = | 1201 NSColor* newColor = |
1202 [attributes objectForKey:NSForegroundColorAttributeName]; | 1202 [attributes objectForKey:NSForegroundColorAttributeName]; |
1203 EXPECT_NSEQ(newColor, color); | 1203 EXPECT_NSEQ(newColor, color); |
1204 } | 1204 } |
1205 } | 1205 } |
1206 | 1206 |
1207 // Test that delegates and targets of buttons are cleared on dealloc. | 1207 // Test that delegates and targets of buttons are cleared on dealloc. |
1208 TEST_F(BookmarkBarControllerTest, TestClearOnDealloc) { | 1208 TEST_F(BookmarkBarControllerTest, TestClearOnDealloc) { |
1209 // Make some bookmark buttons. | 1209 // Make some bookmark buttons. |
1210 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1210 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1211 GURL gurls[] = { GURL("http://www.foo.com/"), | 1211 GURL gurls[] = { GURL("http://www.foo.com/"), |
1212 GURL("http://www.bar.com/"), | 1212 GURL("http://www.bar.com/"), |
1213 GURL("http://www.baz.com/") }; | 1213 GURL("http://www.baz.com/") }; |
1214 base::string16 titles[] = { ASCIIToUTF16("a"), | 1214 base::string16 titles[] = { ASCIIToUTF16("a"), |
1215 ASCIIToUTF16("b"), | 1215 ASCIIToUTF16("b"), |
1216 ASCIIToUTF16("c") }; | 1216 ASCIIToUTF16("c") }; |
1217 for (size_t i = 0; i < arraysize(titles); i++) | 1217 for (size_t i = 0; i < arraysize(titles); i++) |
1218 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); | 1218 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); |
1219 | 1219 |
1220 // Get and retain the buttons so we can examine them after dealloc. | 1220 // Get and retain the buttons so we can examine them after dealloc. |
(...skipping 14 matching lines...) Expand all Loading... |
1235 | 1235 |
1236 // Make sure that everything is cleared. | 1236 // Make sure that everything is cleared. |
1237 for (BookmarkButton* button in buttons.get()) { | 1237 for (BookmarkButton* button in buttons.get()) { |
1238 EXPECT_FALSE([button delegate]); | 1238 EXPECT_FALSE([button delegate]); |
1239 EXPECT_FALSE([button target]); | 1239 EXPECT_FALSE([button target]); |
1240 EXPECT_FALSE([button action]); | 1240 EXPECT_FALSE([button action]); |
1241 } | 1241 } |
1242 } | 1242 } |
1243 | 1243 |
1244 TEST_F(BookmarkBarControllerTest, TestFolders) { | 1244 TEST_F(BookmarkBarControllerTest, TestFolders) { |
1245 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1245 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1246 | 1246 |
1247 // Create some folder buttons. | 1247 // Create some folder buttons. |
1248 const BookmarkNode* parent = model->bookmark_bar_node(); | 1248 const BookmarkNode* parent = model->bookmark_bar_node(); |
1249 const BookmarkNode* folder = model->AddFolder(parent, | 1249 const BookmarkNode* folder = model->AddFolder(parent, |
1250 parent->child_count(), | 1250 parent->child_count(), |
1251 ASCIIToUTF16("folder")); | 1251 ASCIIToUTF16("folder")); |
1252 model->AddURL(folder, folder->child_count(), | 1252 model->AddURL(folder, folder->child_count(), |
1253 ASCIIToUTF16("f1"), GURL("http://framma-lamma.com")); | 1253 ASCIIToUTF16("f1"), GURL("http://framma-lamma.com")); |
1254 folder = model->AddFolder(parent, parent->child_count(), | 1254 folder = model->AddFolder(parent, parent->child_count(), |
1255 ASCIIToUTF16("empty")); | 1255 ASCIIToUTF16("empty")); |
(...skipping 23 matching lines...) Expand all Loading... |
1279 | 1279 |
1280 // Clean up. | 1280 // Clean up. |
1281 [bar_ closeBookmarkFolder:nil]; | 1281 [bar_ closeBookmarkFolder:nil]; |
1282 } | 1282 } |
1283 | 1283 |
1284 // Verify that the folder menu presentation properly tracks mouse movements | 1284 // Verify that the folder menu presentation properly tracks mouse movements |
1285 // over the bar. Until there is a click no folder menus should show. After a | 1285 // over the bar. Until there is a click no folder menus should show. After a |
1286 // click on a folder folder menus should show until another click on a folder | 1286 // click on a folder folder menus should show until another click on a folder |
1287 // button, and a click outside the bar and its folder menus. | 1287 // button, and a click outside the bar and its folder menus. |
1288 TEST_F(BookmarkBarControllerTest, TestFolderButtons) { | 1288 TEST_F(BookmarkBarControllerTest, TestFolderButtons) { |
1289 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1289 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1290 const BookmarkNode* root = model->bookmark_bar_node(); | 1290 const BookmarkNode* root = model->bookmark_bar_node(); |
1291 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b 4f:[ 4f1b 4f2b ] "); | 1291 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b 4f:[ 4f1b 4f2b ] "); |
1292 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1292 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1293 | 1293 |
1294 // Validate initial model and that we do not have a folder controller. | 1294 // Validate initial model and that we do not have a folder controller. |
1295 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1295 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
1296 EXPECT_EQ(model_string, actualModelString); | 1296 EXPECT_EQ(model_string, actualModelString); |
1297 EXPECT_FALSE([bar_ folderController]); | 1297 EXPECT_FALSE([bar_ folderController]); |
1298 | 1298 |
1299 // Add a real bookmark so we can click on it. | 1299 // Add a real bookmark so we can click on it. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 } | 1343 } |
1344 | 1344 |
1345 // Make sure the "off the side" folder looks like a bookmark folder | 1345 // Make sure the "off the side" folder looks like a bookmark folder |
1346 // but only contains "off the side" items. | 1346 // but only contains "off the side" items. |
1347 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { | 1347 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { |
1348 | 1348 |
1349 // It starts hidden. | 1349 // It starts hidden. |
1350 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 1350 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
1351 | 1351 |
1352 // Create some buttons. | 1352 // Create some buttons. |
1353 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1353 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1354 const BookmarkNode* parent = model->bookmark_bar_node(); | 1354 const BookmarkNode* parent = model->bookmark_bar_node(); |
1355 for (int x = 0; x < 30; x++) { | 1355 for (int x = 0; x < 30; x++) { |
1356 model->AddURL(parent, parent->child_count(), | 1356 model->AddURL(parent, parent->child_count(), |
1357 ASCIIToUTF16("medium-size-title"), | 1357 ASCIIToUTF16("medium-size-title"), |
1358 GURL("http://framma-lamma.com")); | 1358 GURL("http://framma-lamma.com")); |
1359 } | 1359 } |
1360 // Add a couple more so we can delete one and make sure its button goes away. | 1360 // Add a couple more so we can delete one and make sure its button goes away. |
1361 model->AddURL(parent, parent->child_count(), | 1361 model->AddURL(parent, parent->child_count(), |
1362 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); | 1362 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); |
1363 model->AddURL(parent, parent->child_count(), | 1363 model->AddURL(parent, parent->child_count(), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 charactersIgnoringModifiers:@"x" | 1422 charactersIgnoringModifiers:@"x" |
1423 isARepeat:NO | 1423 isARepeat:NO |
1424 keyCode:87]; | 1424 keyCode:87]; |
1425 EXPECT_FALSE([bar_ isEventAnExitEvent:event]); | 1425 EXPECT_FALSE([bar_ isEventAnExitEvent:event]); |
1426 | 1426 |
1427 [[[bar_ view] window] removeChildWindow:folderWindow]; | 1427 [[[bar_ view] window] removeChildWindow:folderWindow]; |
1428 } | 1428 } |
1429 | 1429 |
1430 TEST_F(BookmarkBarControllerTest, DropDestination) { | 1430 TEST_F(BookmarkBarControllerTest, DropDestination) { |
1431 // Make some buttons. | 1431 // Make some buttons. |
1432 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1432 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1433 const BookmarkNode* parent = model->bookmark_bar_node(); | 1433 const BookmarkNode* parent = model->bookmark_bar_node(); |
1434 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 1")); | 1434 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 1")); |
1435 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 2")); | 1435 model->AddFolder(parent, parent->child_count(), ASCIIToUTF16("folder 2")); |
1436 EXPECT_EQ([[bar_ buttons] count], 2U); | 1436 EXPECT_EQ([[bar_ buttons] count], 2U); |
1437 | 1437 |
1438 // Confirm "off to left" and "off to right" match nothing. | 1438 // Confirm "off to left" and "off to right" match nothing. |
1439 NSPoint p = NSMakePoint(-1, 2); | 1439 NSPoint p = NSMakePoint(-1, 2); |
1440 EXPECT_FALSE([bar_ buttonForDroppingOnAtPoint:p]); | 1440 EXPECT_FALSE([bar_ buttonForDroppingOnAtPoint:p]); |
1441 EXPECT_TRUE([bar_ shouldShowIndicatorShownForPoint:p]); | 1441 EXPECT_TRUE([bar_ shouldShowIndicatorShownForPoint:p]); |
1442 p = NSMakePoint(50000, 10); | 1442 p = NSMakePoint(50000, 10); |
(...skipping 17 matching lines...) Expand all Loading... |
1460 x = NSMinX([button frame]) + viewFrameXOffset; | 1460 x = NSMinX([button frame]) + viewFrameXOffset; |
1461 EXPECT_NE(button, | 1461 EXPECT_NE(button, |
1462 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 9)]); | 1462 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 9)]); |
1463 x = NSMaxX([button frame]) + viewFrameXOffset; | 1463 x = NSMaxX([button frame]) + viewFrameXOffset; |
1464 EXPECT_NE(button, | 1464 EXPECT_NE(button, |
1465 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 11)]); | 1465 [bar_ buttonForDroppingOnAtPoint:NSMakePoint(x, 11)]); |
1466 } | 1466 } |
1467 } | 1467 } |
1468 | 1468 |
1469 TEST_F(BookmarkBarControllerTest, CloseFolderOnAnimate) { | 1469 TEST_F(BookmarkBarControllerTest, CloseFolderOnAnimate) { |
1470 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1470 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1471 [bar_ setStateAnimationsEnabled:YES]; | 1471 [bar_ setStateAnimationsEnabled:YES]; |
1472 const BookmarkNode* parent = model->bookmark_bar_node(); | 1472 const BookmarkNode* parent = model->bookmark_bar_node(); |
1473 const BookmarkNode* folder = model->AddFolder(parent, | 1473 const BookmarkNode* folder = model->AddFolder(parent, |
1474 parent->child_count(), | 1474 parent->child_count(), |
1475 ASCIIToUTF16("folder")); | 1475 ASCIIToUTF16("folder")); |
1476 model->AddFolder(parent, parent->child_count(), | 1476 model->AddFolder(parent, parent->child_count(), |
1477 ASCIIToUTF16("sibbling folder")); | 1477 ASCIIToUTF16("sibbling folder")); |
1478 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("title a"), | 1478 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("title a"), |
1479 GURL("http://www.google.com/a")); | 1479 GURL("http://www.google.com/a")); |
1480 model->AddURL(folder, folder->child_count(), | 1480 model->AddURL(folder, folder->child_count(), |
(...skipping 17 matching lines...) Expand all Loading... |
1498 // should have been closed thus releasing the folderController. | 1498 // should have been closed thus releasing the folderController. |
1499 EXPECT_FALSE([bar_ folderController]); | 1499 EXPECT_FALSE([bar_ folderController]); |
1500 | 1500 |
1501 // Stop the pending animation to tear down cleanly. | 1501 // Stop the pending animation to tear down cleanly. |
1502 [bar_ updateState:BookmarkBar::DETACHED | 1502 [bar_ updateState:BookmarkBar::DETACHED |
1503 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 1503 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
1504 EXPECT_FALSE([bar_ isAnimationRunning]); | 1504 EXPECT_FALSE([bar_ isAnimationRunning]); |
1505 } | 1505 } |
1506 | 1506 |
1507 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) { | 1507 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) { |
1508 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1508 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1509 const BookmarkNode* root = model->bookmark_bar_node(); | 1509 const BookmarkNode* root = model->bookmark_bar_node(); |
1510 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1510 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1511 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1511 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1512 | 1512 |
1513 // Validate initial model. | 1513 // Validate initial model. |
1514 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1514 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
1515 EXPECT_EQ(model_string, actualModelString); | 1515 EXPECT_EQ(model_string, actualModelString); |
1516 | 1516 |
1517 // Remember how many buttons are showing. | 1517 // Remember how many buttons are showing. |
1518 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1518 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 // Simiulate browser window width change and ensure that the bookmark buttons | 1580 // Simiulate browser window width change and ensure that the bookmark buttons |
1581 // that should be visible are visible. | 1581 // that should be visible are visible. |
1582 // Appears to fail on Mac 10.11 bot on the waterfall; http://crbug.com/612640. | 1582 // Appears to fail on Mac 10.11 bot on the waterfall; http://crbug.com/612640. |
1583 TEST_F(BookmarkBarControllerTest, DISABLED_LastBookmarkResizeBehavior) { | 1583 TEST_F(BookmarkBarControllerTest, DISABLED_LastBookmarkResizeBehavior) { |
1584 // Hide the apps shortcut. | 1584 // Hide the apps shortcut. |
1585 profile()->GetPrefs()->SetBoolean( | 1585 profile()->GetPrefs()->SetBoolean( |
1586 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | 1586 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
1587 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1587 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
1588 | 1588 |
1589 // Add three buttons to the bookmark bar. | 1589 // Add three buttons to the bookmark bar. |
1590 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1590 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1591 const BookmarkNode* root = model->bookmark_bar_node(); | 1591 const BookmarkNode* root = model->bookmark_bar_node(); |
1592 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1592 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1593 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1593 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1594 [bar_ frameDidChange]; | 1594 [bar_ frameDidChange]; |
1595 | 1595 |
1596 // Step through simulated window resizings. In resizing from the first width | 1596 // Step through simulated window resizings. In resizing from the first width |
1597 // to the second, the bookmark bar should transition from displaying one | 1597 // to the second, the bookmark bar should transition from displaying one |
1598 // button to two. Of the next 5 widths, the third transitions the bar from | 1598 // button to two. Of the next 5 widths, the third transitions the bar from |
1599 // displaying two buttons to three. The next width (200.0) resizes the bar to | 1599 // displaying two buttons to three. The next width (200.0) resizes the bar to |
1600 // a large width that does not change the number of visible buttons, and the | 1600 // a large width that does not change the number of visible buttons, and the |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 NSRect frame = [[bar_ view] frame]; | 1659 NSRect frame = [[bar_ view] frame]; |
1660 frame.size.width = view_widths[i] + bookmarks::BookmarkRightMargin(); | 1660 frame.size.width = view_widths[i] + bookmarks::BookmarkRightMargin(); |
1661 [[bar_ view] setFrame:frame]; | 1661 [[bar_ view] setFrame:frame]; |
1662 EXPECT_EQ(off_the_side_button_is_hidden_results[i], | 1662 EXPECT_EQ(off_the_side_button_is_hidden_results[i], |
1663 [bar_ offTheSideButtonIsHidden]); | 1663 [bar_ offTheSideButtonIsHidden]); |
1664 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]); | 1664 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]); |
1665 } | 1665 } |
1666 } | 1666 } |
1667 | 1667 |
1668 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { | 1668 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { |
1669 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1669 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1670 const BookmarkNode* root = model->bookmark_bar_node(); | 1670 const BookmarkNode* root = model->bookmark_bar_node(); |
1671 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 1671 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
1672 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1672 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1673 [bar_ frameDidChange]; | 1673 [bar_ frameDidChange]; |
1674 | 1674 |
1675 // Apps page shortcut button should be visible. | 1675 // Apps page shortcut button should be visible. |
1676 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); | 1676 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
1677 | 1677 |
1678 // Bookmarks should be to the right of the Apps page shortcut button. | 1678 // Bookmarks should be to the right of the Apps page shortcut button. |
1679 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); | 1679 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 initialWidth:NSWidth(parent_frame) | 1746 initialWidth:NSWidth(parent_frame) |
1747 delegate:nil]); | 1747 delegate:nil]); |
1748 // Forces loading of the nib. | 1748 // Forces loading of the nib. |
1749 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; | 1749 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; |
1750 // Awkwardness to look like we've been installed. | 1750 // Awkwardness to look like we've been installed. |
1751 [parent_view_ addSubview:[bar_ view]]; | 1751 [parent_view_ addSubview:[bar_ view]]; |
1752 NSRect frame = [[[bar_ view] superview] frame]; | 1752 NSRect frame = [[[bar_ view] superview] frame]; |
1753 frame.origin.y = 100; | 1753 frame.origin.y = 100; |
1754 [[[bar_ view] superview] setFrame:frame]; | 1754 [[[bar_ view] superview] setFrame:frame]; |
1755 | 1755 |
1756 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1756 BookmarkModel* model = |
| 1757 BookmarkModelFactory::GetForBrowserContext(profile()); |
1757 parent_ = model->bookmark_bar_node(); | 1758 parent_ = model->bookmark_bar_node(); |
1758 // { one, { two-one, two-two }, three } | 1759 // { one, { two-one, two-two }, three } |
1759 model->AddURL(parent_, parent_->child_count(), ASCIIToUTF16("title"), | 1760 model->AddURL(parent_, parent_->child_count(), ASCIIToUTF16("title"), |
1760 GURL("http://one.com")); | 1761 GURL("http://one.com")); |
1761 folder_ = model->AddFolder(parent_, parent_->child_count(), | 1762 folder_ = model->AddFolder(parent_, parent_->child_count(), |
1762 ASCIIToUTF16("folder")); | 1763 ASCIIToUTF16("folder")); |
1763 model->AddURL(folder_, folder_->child_count(), | 1764 model->AddURL(folder_, folder_->child_count(), |
1764 ASCIIToUTF16("title"), GURL("http://two-one.com")); | 1765 ASCIIToUTF16("title"), GURL("http://two-one.com")); |
1765 model->AddURL(folder_, folder_->child_count(), | 1766 model->AddURL(folder_, folder_->child_count(), |
1766 ASCIIToUTF16("title"), GURL("http://two-two.com")); | 1767 ASCIIToUTF16("title"), GURL("http://two-two.com")); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 | 1872 |
1872 bar_.reset([[BookmarkBarControllerDragData alloc] | 1873 bar_.reset([[BookmarkBarControllerDragData alloc] |
1873 initWithBrowser:browser() | 1874 initWithBrowser:browser() |
1874 initialWidth:NSWidth([parent_view_ frame]) | 1875 initialWidth:NSWidth([parent_view_ frame]) |
1875 delegate:nil]); | 1876 delegate:nil]); |
1876 InstallAndToggleBar(bar_.get()); | 1877 InstallAndToggleBar(bar_.get()); |
1877 } | 1878 } |
1878 }; | 1879 }; |
1879 | 1880 |
1880 TEST_F(BookmarkBarControllerDragDropTest, DragMoveBarBookmarkToOffTheSide) { | 1881 TEST_F(BookmarkBarControllerDragDropTest, DragMoveBarBookmarkToOffTheSide) { |
1881 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1882 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1882 const BookmarkNode* root = model->bookmark_bar_node(); | 1883 const BookmarkNode* root = model->bookmark_bar_node(); |
1883 const std::string model_string("1bWithLongName 2fWithLongName:[ " | 1884 const std::string model_string("1bWithLongName 2fWithLongName:[ " |
1884 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName " | 1885 "2f1bWithLongName 2f2fWithLongName:[ 2f2f1bWithLongName " |
1885 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " | 1886 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " |
1886 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1887 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1887 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1888 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1888 "11bWithLongName 12bWithLongName 13b "); | 1889 "11bWithLongName 12bWithLongName 13b "); |
1889 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1890 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1890 | 1891 |
1891 // Validate initial model. | 1892 // Validate initial model. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 int newDisplayedButtons = [bar_ displayedButtonCount]; | 1924 int newDisplayedButtons = [bar_ displayedButtonCount]; |
1924 int newChildCount = root->child_count(); | 1925 int newChildCount = root->child_count(); |
1925 int newOTSCount = (int)[[otsController buttons] count]; | 1926 int newOTSCount = (int)[[otsController buttons] count]; |
1926 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); | 1927 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); |
1927 EXPECT_EQ(oldChildCount + 1, newChildCount); | 1928 EXPECT_EQ(oldChildCount + 1, newChildCount); |
1928 EXPECT_EQ(oldOTSCount + 1, newOTSCount); | 1929 EXPECT_EQ(oldOTSCount + 1, newOTSCount); |
1929 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); | 1930 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); |
1930 } | 1931 } |
1931 | 1932 |
1932 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { | 1933 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { |
1933 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1934 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1934 const BookmarkNode* root = model->bookmark_bar_node(); | 1935 const BookmarkNode* root = model->bookmark_bar_node(); |
1935 const std::string model_string("1bWithLongName 2bWithLongName " | 1936 const std::string model_string("1bWithLongName 2bWithLongName " |
1936 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1937 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1937 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1938 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1938 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " | 1939 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " |
1939 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " | 1940 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " |
1940 "19bWithLongName 20bWithLongName "); | 1941 "19bWithLongName 20bWithLongName "); |
1941 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1942 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1942 | 1943 |
1943 const BookmarkNode* other = model->other_node(); | 1944 const BookmarkNode* other = model->other_node(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1980 // and one more in other bookmarks. | 1981 // and one more in other bookmarks. |
1981 int newRootCount = root->child_count(); | 1982 int newRootCount = root->child_count(); |
1982 int newOTSCount = (int)[[otsController buttons] count]; | 1983 int newOTSCount = (int)[[otsController buttons] count]; |
1983 int newOtherCount = other->child_count(); | 1984 int newOtherCount = other->child_count(); |
1984 EXPECT_EQ(oldRootCount - 1, newRootCount); | 1985 EXPECT_EQ(oldRootCount - 1, newRootCount); |
1985 EXPECT_EQ(oldOTSCount - 1, newOTSCount); | 1986 EXPECT_EQ(oldOTSCount - 1, newOTSCount); |
1986 EXPECT_EQ(oldOtherCount + 1, newOtherCount); | 1987 EXPECT_EQ(oldOtherCount + 1, newOtherCount); |
1987 } | 1988 } |
1988 | 1989 |
1989 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { | 1990 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkData) { |
1990 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1991 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1991 const BookmarkNode* root = model->bookmark_bar_node(); | 1992 const BookmarkNode* root = model->bookmark_bar_node(); |
1992 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 1993 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
1993 "2f3b ] 3b 4b "); | 1994 "2f3b ] 3b 4b "); |
1994 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1995 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1995 const BookmarkNode* other = model->other_node(); | 1996 const BookmarkNode* other = model->other_node(); |
1996 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] " | 1997 const std::string other_string("O1b O2b O3f:[ O3f1b O3f2f ] " |
1997 "O4f:[ O4f1b O4f2f ] 05b "); | 1998 "O4f:[ O4f1b O4f2f ] 05b "); |
1998 bookmarks::test::AddNodesFromModelString(model, other, other_string); | 1999 bookmarks::test::AddNodesFromModelString(model, other, other_string); |
1999 | 2000 |
2000 // Validate initial model. | 2001 // Validate initial model. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 EXPECT_EQ(oldChildCount, newChildCount); | 2041 EXPECT_EQ(oldChildCount, newChildCount); |
2041 // Verify the model. | 2042 // Verify the model. |
2042 const std::string expected1("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2043 const std::string expected1("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2043 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " | 2044 "2f3b O4f:[ O4f1b O4f2f ] ] O3f:[ O3f1b O3f2f ] " |
2044 "3b 4b "); | 2045 "3b 4b "); |
2045 actual = bookmarks::test::ModelStringFromNode(root); | 2046 actual = bookmarks::test::ModelStringFromNode(root); |
2046 EXPECT_EQ(expected1, actual); | 2047 EXPECT_EQ(expected1, actual); |
2047 } | 2048 } |
2048 | 2049 |
2049 TEST_F(BookmarkBarControllerDragDropTest, AddURLs) { | 2050 TEST_F(BookmarkBarControllerDragDropTest, AddURLs) { |
2050 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2051 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2051 const BookmarkNode* root = model->bookmark_bar_node(); | 2052 const BookmarkNode* root = model->bookmark_bar_node(); |
2052 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2053 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2053 "2f3b ] 3b 4b "); | 2054 "2f3b ] 3b 4b "); |
2054 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2055 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
2055 | 2056 |
2056 // Validate initial model. | 2057 // Validate initial model. |
2057 std::string actual = bookmarks::test::ModelStringFromNode(root); | 2058 std::string actual = bookmarks::test::ModelStringFromNode(root); |
2058 EXPECT_EQ(model_string, actual); | 2059 EXPECT_EQ(model_string, actual); |
2059 | 2060 |
2060 // Remember the children. | 2061 // Remember the children. |
(...skipping 11 matching lines...) Expand all Loading... |
2072 int newChildCount = root->child_count(); | 2073 int newChildCount = root->child_count(); |
2073 EXPECT_EQ(oldChildCount + 2, newChildCount); | 2074 EXPECT_EQ(oldChildCount + 2, newChildCount); |
2074 // Verify the model. | 2075 // Verify the model. |
2075 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2076 const std::string expected("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2076 "2f3b ] SiteA SiteB 3b 4b "); | 2077 "2f3b ] SiteA SiteB 3b 4b "); |
2077 actual = bookmarks::test::ModelStringFromNode(root); | 2078 actual = bookmarks::test::ModelStringFromNode(root); |
2078 EXPECT_EQ(expected, actual); | 2079 EXPECT_EQ(expected, actual); |
2079 } | 2080 } |
2080 | 2081 |
2081 TEST_F(BookmarkBarControllerDragDropTest, ControllerForNode) { | 2082 TEST_F(BookmarkBarControllerDragDropTest, ControllerForNode) { |
2082 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2083 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2083 const BookmarkNode* root = model->bookmark_bar_node(); | 2084 const BookmarkNode* root = model->bookmark_bar_node(); |
2084 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); | 2085 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); |
2085 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2086 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
2086 | 2087 |
2087 // Validate initial model. | 2088 // Validate initial model. |
2088 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 2089 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
2089 EXPECT_EQ(model_string, actualModelString); | 2090 EXPECT_EQ(model_string, actualModelString); |
2090 | 2091 |
2091 // Find the main bar controller. | 2092 // Find the main bar controller. |
2092 const void* expectedController = bar_; | 2093 const void* expectedController = bar_; |
2093 const void* actualController = [bar_ controllerForNode:root]; | 2094 const void* actualController = [bar_ controllerForNode:root]; |
2094 EXPECT_EQ(expectedController, actualController); | 2095 EXPECT_EQ(expectedController, actualController); |
2095 } | 2096 } |
2096 | 2097 |
2097 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 2098 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
2098 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2099 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2099 const BookmarkNode* root = model->bookmark_bar_node(); | 2100 const BookmarkNode* root = model->bookmark_bar_node(); |
2100 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 2101 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
2101 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2102 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
2102 | 2103 |
2103 // Hide the apps shortcut. | 2104 // Hide the apps shortcut. |
2104 profile()->GetPrefs()->SetBoolean( | 2105 profile()->GetPrefs()->SetBoolean( |
2105 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | 2106 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
2106 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 2107 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
2107 | 2108 |
2108 // Validate initial model. | 2109 // Validate initial model. |
(...skipping 18 matching lines...) Expand all Loading... |
2127 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; | 2128 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; |
2128 targetPoint = [targetButton right]; | 2129 targetPoint = [targetButton right]; |
2129 targetPoint.x += 100; // Somewhere off to the right. | 2130 targetPoint.x += 100; // Somewhere off to the right. |
2130 CGFloat xDelta = 0.5 * bookmarks::BookmarkHorizontalPadding(); | 2131 CGFloat xDelta = 0.5 * bookmarks::BookmarkHorizontalPadding(); |
2131 expected = NSMaxX([targetButton frame]) + xDelta; | 2132 expected = NSMaxX([targetButton frame]) + xDelta; |
2132 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2133 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
2133 EXPECT_CGFLOAT_EQ(expected, actual); | 2134 EXPECT_CGFLOAT_EQ(expected, actual); |
2134 } | 2135 } |
2135 | 2136 |
2136 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { | 2137 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { |
2137 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2138 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2138 const BookmarkNode* root = model->bookmark_bar_node(); | 2139 const BookmarkNode* root = model->bookmark_bar_node(); |
2139 GURL gurl("http://www.google.com"); | 2140 GURL gurl("http://www.google.com"); |
2140 const BookmarkNode* node = model->AddURL(root, root->child_count(), | 2141 const BookmarkNode* node = model->AddURL(root, root->child_count(), |
2141 ASCIIToUTF16("title"), gurl); | 2142 ASCIIToUTF16("title"), gurl); |
2142 | 2143 |
2143 BookmarkButton* button = [[bar_ buttons] objectAtIndex:0]; | 2144 BookmarkButton* button = [[bar_ buttons] objectAtIndex:0]; |
2144 EXPECT_FALSE([button isContinuousPulsing]); | 2145 EXPECT_FALSE([button isContinuousPulsing]); |
2145 [bar_ startPulsingBookmarkNode:node]; | 2146 [bar_ startPulsingBookmarkNode:node]; |
2146 EXPECT_TRUE([button isContinuousPulsing]); | 2147 EXPECT_TRUE([button isContinuousPulsing]); |
2147 [bar_ stopPulsingBookmarkNode]; | 2148 [bar_ stopPulsingBookmarkNode]; |
(...skipping 23 matching lines...) Expand all Loading... |
2171 // Removing a pulsing folder is allowed. | 2172 // Removing a pulsing folder is allowed. |
2172 [bar_ startPulsingBookmarkNode:inner]; | 2173 [bar_ startPulsingBookmarkNode:inner]; |
2173 BookmarkButton* folder2_button = [[bar_ buttons] objectAtIndex:2]; | 2174 BookmarkButton* folder2_button = [[bar_ buttons] objectAtIndex:2]; |
2174 EXPECT_TRUE([folder2_button isContinuousPulsing]); | 2175 EXPECT_TRUE([folder2_button isContinuousPulsing]); |
2175 model->Remove(folder2); | 2176 model->Remove(folder2); |
2176 EXPECT_FALSE([folder2_button isContinuousPulsing]); | 2177 EXPECT_FALSE([folder2_button isContinuousPulsing]); |
2177 [bar_ stopPulsingBookmarkNode]; // Should not crash. | 2178 [bar_ stopPulsingBookmarkNode]; // Should not crash. |
2178 } | 2179 } |
2179 | 2180 |
2180 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkDataToTrash) { | 2181 TEST_F(BookmarkBarControllerDragDropTest, DragBookmarkDataToTrash) { |
2181 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2182 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2182 const BookmarkNode* root = model->bookmark_bar_node(); | 2183 const BookmarkNode* root = model->bookmark_bar_node(); |
2183 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " | 2184 const std::string model_string("1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b 2f2f3b ] " |
2184 "2f3b ] 3b 4b "); | 2185 "2f3b ] 3b 4b "); |
2185 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2186 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
2186 | 2187 |
2187 // Validate initial model. | 2188 // Validate initial model. |
2188 std::string actual = bookmarks::test::ModelStringFromNode(root); | 2189 std::string actual = bookmarks::test::ModelStringFromNode(root); |
2189 EXPECT_EQ(model_string, actual); | 2190 EXPECT_EQ(model_string, actual); |
2190 | 2191 |
2191 int oldChildCount = root->child_count(); | 2192 int oldChildCount = root->child_count(); |
(...skipping 12 matching lines...) Expand all Loading... |
2204 "2f3b ] 4b "); | 2205 "2f3b ] 4b "); |
2205 actual = bookmarks::test::ModelStringFromNode(root); | 2206 actual = bookmarks::test::ModelStringFromNode(root); |
2206 EXPECT_EQ(expected, actual); | 2207 EXPECT_EQ(expected, actual); |
2207 | 2208 |
2208 // Verify that the other bookmark folder can't be deleted. | 2209 // Verify that the other bookmark folder can't be deleted. |
2209 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2210 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
2210 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2211 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
2211 } | 2212 } |
2212 | 2213 |
2213 } // namespace | 2214 } // namespace |
OLD | NEW |