Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 BookmarkBarView* view = [bar_ buttonView]; 522 BookmarkBarView* view = [bar_ buttonView];
523 DCHECK(view); 523 DCHECK(view);
524 NSView* noItemContainer = [view noItemContainer]; 524 NSView* noItemContainer = [view noItemContainer];
525 DCHECK(noItemContainer); 525 DCHECK(noItemContainer);
526 526
527 EXPECT_FALSE([noItemContainer isHidden]); 527 EXPECT_FALSE([noItemContainer isHidden]);
528 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), 528 const BookmarkNode* node = model->AddURL(bar, bar->child_count(),
529 ASCIIToUTF16("title"), 529 ASCIIToUTF16("title"),
530 GURL("http://www.google.com")); 530 GURL("http://www.google.com"));
531 EXPECT_TRUE([noItemContainer isHidden]); 531 EXPECT_TRUE([noItemContainer isHidden]);
532 model->Remove(bar, bar->GetIndexOf(node)); 532 model->Remove(node);
533 EXPECT_FALSE([noItemContainer isHidden]); 533 EXPECT_FALSE([noItemContainer isHidden]);
534 534
535 // Now try it using a bookmark from the Other Bookmarks. 535 // Now try it using a bookmark from the Other Bookmarks.
536 const BookmarkNode* otherBookmarks = model->other_node(); 536 const BookmarkNode* otherBookmarks = model->other_node();
537 node = model->AddURL(otherBookmarks, otherBookmarks->child_count(), 537 node = model->AddURL(otherBookmarks, otherBookmarks->child_count(),
538 ASCIIToUTF16("TheOther"), 538 ASCIIToUTF16("TheOther"),
539 GURL("http://www.other.com")); 539 GURL("http://www.other.com"));
540 EXPECT_FALSE([noItemContainer isHidden]); 540 EXPECT_FALSE([noItemContainer isHidden]);
541 // Move it from Other Bookmarks to the bar. 541 // Move it from Other Bookmarks to the bar.
542 model->Move(node, bar, 0); 542 model->Move(node, bar, 0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // Open "off the side" menu. 575 // Open "off the side" menu.
576 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; 576 [bar_ openOffTheSideFolderFromButton:offTheSideButton];
577 BookmarkBarFolderController* bbfc = [bar_ folderController]; 577 BookmarkBarFolderController* bbfc = [bar_ folderController];
578 EXPECT_TRUE(bbfc); 578 EXPECT_TRUE(bbfc);
579 [bbfc setIgnoreAnimations:YES]; 579 [bbfc setIgnoreAnimations:YES];
580 while (!parent->empty()) { 580 while (!parent->empty()) {
581 // We've completed the job so we're done. 581 // We've completed the job so we're done.
582 if ([bar_ offTheSideButtonIsHidden]) 582 if ([bar_ offTheSideButtonIsHidden])
583 break; 583 break;
584 // Delete the last button. 584 // Delete the last button.
585 model->Remove(parent, parent->child_count() - 1); 585 model->Remove(parent->GetChild(parent->child_count() - 1));
586 // If last one make sure the menu is closed and the button is hidden. 586 // If last one make sure the menu is closed and the button is hidden.
587 // Else make sure menu stays open. 587 // Else make sure menu stays open.
588 if ([bar_ offTheSideButtonIsHidden]) { 588 if ([bar_ offTheSideButtonIsHidden]) {
589 EXPECT_FALSE([bar_ folderController]); 589 EXPECT_FALSE([bar_ folderController]);
590 } else { 590 } else {
591 EXPECT_TRUE([bar_ folderController]); 591 EXPECT_TRUE([bar_ folderController]);
592 } 592 }
593 } 593 }
594 } 594 }
595 595
(...skipping 30 matching lines...) Expand all
626 // First we mouse-enter the button to make things harder. 626 // First we mouse-enter the button to make things harder.
627 NSArray* buttons = [bbfc buttons]; 627 NSArray* buttons = [bbfc buttons];
628 for (BookmarkButton* button in buttons) { 628 for (BookmarkButton* button in buttons) {
629 if ([button bookmarkNode] == parent->GetChild(indices[i])) { 629 if ([button bookmarkNode] == parent->GetChild(indices[i])) {
630 [bbfc mouseEnteredButton:button event:nil]; 630 [bbfc mouseEnteredButton:button event:nil];
631 break; 631 break;
632 } 632 }
633 } 633 }
634 // Then we remove the node. This triggers the button to get 634 // Then we remove the node. This triggers the button to get
635 // deleted. 635 // deleted.
636 model->Remove(parent, indices[i]); 636 model->Remove(parent->GetChild(indices[i]));
637 // Force visual update which is otherwise delayed. 637 // Force visual update which is otherwise delayed.
638 [[bbfc window] displayIfNeeded]; 638 [[bbfc window] displayIfNeeded];
639 } 639 }
640 } 640 }
641 } 641 }
642 } 642 }
643 643
644 // Test whether |-dragShouldLockBarVisibility| returns NO iff the bar is 644 // Test whether |-dragShouldLockBarVisibility| returns NO iff the bar is
645 // detached. 645 // detached.
646 TEST_F(BookmarkBarControllerTest, TestDragShouldLockBarVisibility) { 646 TEST_F(BookmarkBarControllerTest, TestDragShouldLockBarVisibility) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 796 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
797 EXPECT_EQ(0U, [[bar_ buttons] count]); 797 EXPECT_EQ(0U, [[bar_ buttons] count]);
798 // Add one; make sure we see it. 798 // Add one; make sure we see it.
799 const BookmarkNode* parent = model->bookmark_bar_node(); 799 const BookmarkNode* parent = model->bookmark_bar_node();
800 model->AddURL(parent, parent->child_count(), 800 model->AddURL(parent, parent->child_count(),
801 ASCIIToUTF16("title"), GURL("http://www.google.com")); 801 ASCIIToUTF16("title"), GURL("http://www.google.com"));
802 EXPECT_EQ(1U, [[bar_ buttons] count]); 802 EXPECT_EQ(1U, [[bar_ buttons] count]);
803 803
804 // Add 30 which we expect to be 'too many'. Make sure we don't see 804 // Add 30 which we expect to be 'too many'. Make sure we don't see
805 // 30 buttons. 805 // 30 buttons.
806 model->Remove(parent, 0); 806 model->Remove(parent->GetChild(0));
807 EXPECT_EQ(0U, [[bar_ buttons] count]); 807 EXPECT_EQ(0U, [[bar_ buttons] count]);
808 for (int i=0; i<30; i++) { 808 for (int i=0; i<30; i++) {
809 model->AddURL(parent, parent->child_count(), 809 model->AddURL(parent, parent->child_count(),
810 ASCIIToUTF16("title"), GURL("http://www.google.com")); 810 ASCIIToUTF16("title"), GURL("http://www.google.com"));
811 } 811 }
812 int count = [[bar_ buttons] count]; 812 int count = [[bar_ buttons] count];
813 EXPECT_LT(count, 30L); 813 EXPECT_LT(count, 30L);
814 814
815 // Add 10 more (to the front of the list so the on-screen buttons 815 // Add 10 more (to the front of the list so the on-screen buttons
816 // would change) and make sure the count stays the same. 816 // would change) and make sure the count stays the same.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 const char* urls[] = { "https://secret.url.com", 885 const char* urls[] = { "https://secret.url.com",
886 "http://super.duper.web.site.for.doodz.gov", 886 "http://super.duper.web.site.for.doodz.gov",
887 "http://www.foo-bar-baz.com/" }; 887 "http://www.foo-bar-baz.com/" };
888 const BookmarkNode* parent = model->bookmark_bar_node(); 888 const BookmarkNode* parent = model->bookmark_bar_node();
889 for (unsigned int i = 0; i < arraysize(urls); i++) { 889 for (unsigned int i = 0; i < arraysize(urls); i++) {
890 model->AddURL(parent, parent->child_count(), 890 model->AddURL(parent, parent->child_count(),
891 ASCIIToUTF16("title"), GURL(urls[i])); 891 ASCIIToUTF16("title"), GURL(urls[i]));
892 } 892 }
893 EXPECT_EQ(3, parent->child_count()); 893 EXPECT_EQ(3, parent->child_count());
894 const BookmarkNode* middle_node = parent->GetChild(1); 894 const BookmarkNode* middle_node = parent->GetChild(1);
895 model->Remove(middle_node->parent(), 895 model->Remove(middle_node);
896 middle_node->parent()->GetIndexOf(middle_node));
897 896
898 EXPECT_EQ(2, parent->child_count()); 897 EXPECT_EQ(2, parent->child_count());
899 EXPECT_EQ(parent->GetChild(0)->url(), GURL(urls[0])); 898 EXPECT_EQ(parent->GetChild(0)->url(), GURL(urls[0]));
900 // node 2 moved into spot 1 899 // node 2 moved into spot 1
901 EXPECT_EQ(parent->GetChild(1)->url(), GURL(urls[2])); 900 EXPECT_EQ(parent->GetChild(1)->url(), GURL(urls[2]));
902 } 901 }
903 902
904 // TODO(jrg): write a test to confirm that nodeFaviconLoaded calls 903 // TODO(jrg): write a test to confirm that nodeFaviconLoaded calls
905 // checkForBookmarkButtonGrowth:. 904 // checkForBookmarkButtonGrowth:.
906 905
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 for (BookmarkButton* barButton in barButtons) { 1364 for (BookmarkButton* barButton in barButtons) {
1366 if ([barButton superview]) { 1365 if ([barButton superview]) {
1367 EXPECT_NE([folderButton bookmarkNode], [barButton bookmarkNode]); 1366 EXPECT_NE([folderButton bookmarkNode], [barButton bookmarkNode]);
1368 } 1367 }
1369 } 1368 }
1370 } 1369 }
1371 1370
1372 // Delete a bookmark in the off-the-side and verify it's gone. 1371 // Delete a bookmark in the off-the-side and verify it's gone.
1373 BookmarkButton* button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"]; 1372 BookmarkButton* button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"];
1374 EXPECT_TRUE(button); 1373 EXPECT_TRUE(button);
1375 model->Remove(parent, parent->child_count() - 2); 1374 model->Remove(parent->GetChild(parent->child_count() - 2));
1376 button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"]; 1375 button = [bbfc buttonWithTitleEqualTo:@"DELETE_ME"];
1377 EXPECT_FALSE(button); 1376 EXPECT_FALSE(button);
1378 } 1377 }
1379 1378
1380 TEST_F(BookmarkBarControllerTest, EventToExitCheck) { 1379 TEST_F(BookmarkBarControllerTest, EventToExitCheck) {
1381 NSEvent* event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); 1380 NSEvent* event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0);
1382 EXPECT_FALSE([bar_ isEventAnExitEvent:event]); 1381 EXPECT_FALSE([bar_ isEventAnExitEvent:event]);
1383 1382
1384 BookmarkBarFolderWindow* folderWindow = [[[BookmarkBarFolderWindow alloc] 1383 BookmarkBarFolderWindow* folderWindow = [[[BookmarkBarFolderWindow alloc]
1385 init] autorelease]; 1384 init] autorelease];
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 "2f3b ] 4b "); 2129 "2f3b ] 4b ");
2131 actual = bookmarks::test::ModelStringFromNode(root); 2130 actual = bookmarks::test::ModelStringFromNode(root);
2132 EXPECT_EQ(expected, actual); 2131 EXPECT_EQ(expected, actual);
2133 2132
2134 // Verify that the other bookmark folder can't be deleted. 2133 // Verify that the other bookmark folder can't be deleted.
2135 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; 2134 BookmarkButton *otherButton = [bar_ otherBookmarksButton];
2136 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); 2135 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]);
2137 } 2136 }
2138 2137
2139 } // namespace 2138 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698