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

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

Issue 2751573002: [Mac] Refactor bookmark bar controller (Closed)
Patch Set: Factor layout tests to helper, address CL comments Created 3 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 #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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 extensions::ExtensionSystem::Get(profile())) 306 extensions::ExtensionSystem::Get(profile()))
307 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), 307 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(),
308 extension_dir, false); 308 extension_dir, false);
309 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 309 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
310 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); 310 NSRect parent_frame = NSMakeRect(0, 0, 800, 50);
311 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); 311 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]);
312 [parent_view_ setHidden:YES]; 312 [parent_view_ setHidden:YES];
313 } 313 }
314 314
315 void InstallAndToggleBar(BookmarkBarController* bar) { 315 void InstallAndToggleBar(BookmarkBarController* bar) {
316 // In OSX 10.10, the owner of a nib file is retain/autoreleased during the 316 // Loads the view.
317 // initialization of the nib. Wrapping the nib loading in an 317 [[bar controlledView] setResizeDelegate:resizeDelegate_];
318 // autoreleasepool ensures that tests can control the destruction timing of
319 // the controller.
320 @autoreleasepool {
321 // Forces loading of the nib.
322 [[bar controlledView] setResizeDelegate:resizeDelegate_];
323 }
324 // Awkwardness to look like we've been installed. 318 // Awkwardness to look like we've been installed.
325 for (NSView* subView in [parent_view_ subviews]) 319 for (NSView* subView in [parent_view_ subviews])
326 [subView removeFromSuperview]; 320 [subView removeFromSuperview];
327 [parent_view_ addSubview:[bar view]]; 321 [parent_view_ addSubview:[bar view]];
328 NSRect frame = [[[bar view] superview] frame]; 322 NSRect frame = [[[bar view] superview] frame];
329 frame.origin.y = 100; 323 frame.origin.y = 100;
330 [[[bar view] superview] setFrame:frame]; 324 [[[bar view] superview] setFrame:frame];
331 325
332 // Make sure it's on in a window so viewDidMoveToWindow is called 326 // Make sure it's on in a window so viewDidMoveToWindow is called
333 NSView* contentView = [test_window() contentView]; 327 NSView* contentView = [test_window() contentView];
(...skipping 27 matching lines...) Expand all
361 // are no outstanding references to bar_, and that calling bar_.reset() will 355 // are no outstanding references to bar_, and that calling bar_.reset() will
362 // synchronously destroy bar_. 356 // synchronously destroy bar_.
363 base::RunLoop().RunUntilIdle(); 357 base::RunLoop().RunUntilIdle();
364 } 358 }
365 359
366 virtual void AddCommandLineSwitches() {} 360 virtual void AddCommandLineSwitches() {}
367 361
368 BookmarkBarControllerNoOpen* noOpenBar() { 362 BookmarkBarControllerNoOpen* noOpenBar() {
369 return (BookmarkBarControllerNoOpen*)bar_.get(); 363 return (BookmarkBarControllerNoOpen*)bar_.get();
370 } 364 }
365
366 // Verifies that the i-th button has the title of the i-th child node of
367 // |node|.
368 void VerifyButtonTitles(const BookmarkNode* node) {
369 ASSERT_LE((int)[[bar_ buttons] count], node->child_count());
370 int numButtons = [[bar_ buttons] count];
371 for (int i = 0; i < numButtons; i++) {
372 EXPECT_NSEQ([[[bar_ buttons] objectAtIndex:i] title],
373 base::SysUTF16ToNSString(node->GetChild(i)->GetTitle()));
374 }
375 }
376
377 // Verifies that |view|
378 // * With a blank layout applied:
379 // - Is hidden
380 //
381 // * With |layout| applied:
382 // - Is visible
383 // - Has x origin |expected_x_origin|
384 // If |check_exact_width| is true:
385 // - has width |expected_width|
386 // Otherwise:
387 // - has width > 0 (|expected_width| is ignored in this case)
388 void VerifyViewLayout(NSView* view,
389 bookmarks::BookmarkBarLayout& layout,
390 CGFloat expected_x_origin,
391 CGFloat expected_width,
392 bool check_exact_width) {
393 ASSERT_TRUE(view);
394
395 bookmarks::BookmarkBarLayout empty_layout = {};
396 [bar_ applyLayout:empty_layout animated:NO];
397 EXPECT_TRUE([view isHidden]);
398
399 [bar_ applyLayout:layout animated:NO];
400 EXPECT_CGFLOAT_EQ(NSMinX([view frame]), expected_x_origin);
401 CGFloat actual_width = NSWidth([view frame]);
402 if (check_exact_width) {
403 EXPECT_CGFLOAT_EQ(actual_width, expected_width);
404 } else {
405 EXPECT_GT(actual_width, 0);
406 }
407 }
371 }; 408 };
372 409
373 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) { 410 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) {
374 [bar_ updateState:BookmarkBar::SHOW 411 [bar_ updateState:BookmarkBar::SHOW
375 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; 412 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE];
376 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]); 413 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]);
377 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]); 414 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]);
378 EXPECT_TRUE([bar_ isVisible]); 415 EXPECT_TRUE([bar_ isVisible]);
379 EXPECT_FALSE([bar_ isAnimationRunning]); 416 EXPECT_FALSE([bar_ isAnimationRunning]);
380 EXPECT_FALSE([[bar_ view] isHidden]); 417 EXPECT_FALSE([[bar_ view] isHidden]);
(...skipping 29 matching lines...) Expand all
410 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { 447 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) {
411 [bar_ updateState:BookmarkBar::DETACHED 448 [bar_ updateState:BookmarkBar::DETACHED
412 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; 449 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE];
413 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]); 450 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]);
414 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]); 451 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]);
415 EXPECT_TRUE([bar_ isVisible]); 452 EXPECT_TRUE([bar_ isVisible]);
416 EXPECT_FALSE([bar_ isAnimationRunning]); 453 EXPECT_FALSE([bar_ isAnimationRunning]);
417 EXPECT_FALSE([[bar_ view] isHidden]); 454 EXPECT_FALSE([[bar_ view] isHidden]);
418 EXPECT_GT([resizeDelegate_ height], 0); 455 EXPECT_GT([resizeDelegate_ height], 0);
419 EXPECT_GT([[bar_ view] frame].size.height, 0); 456 EXPECT_GT([[bar_ view] frame].size.height, 0);
420
421 // Make sure no buttons fall off the bar, either now or when resized
422 // bigger or smaller.
423 CGFloat sizes[] = { 300.0, -100.0, 200.0, -420.0 };
424 CGFloat previousX = 0.0;
425 for (unsigned x = 0; x < arraysize(sizes); x++) {
426 // Confirm the buttons moved from the last check (which may be
427 // init but that's fine).
428 CGFloat newX = [[bar_ offTheSideButton] frame].origin.x;
429 EXPECT_NE(previousX, newX);
430 previousX = newX;
431
432 // Confirm the buttons have a reasonable bounds. Recall that |-frame|
433 // returns rectangles in the superview's coordinates.
434 NSRect buttonViewFrame =
435 [[bar_ buttonView] convertRect:[[bar_ buttonView] frame]
436 fromView:[[bar_ buttonView] superview]];
437 EXPECT_EQ([bar_ buttonView], [[bar_ offTheSideButton] superview]);
438 EXPECT_TRUE(NSContainsRect(buttonViewFrame,
439 [[bar_ offTheSideButton] frame]));
440 EXPECT_EQ([bar_ buttonView], [[bar_ otherBookmarksButton] superview]);
441 EXPECT_TRUE(NSContainsRect(buttonViewFrame,
442 [[bar_ otherBookmarksButton] frame]));
443
444 // Now move them implicitly.
445 // We confirm FrameChangeNotification works in the next unit test;
446 // we simply assume it works here to resize or reposition the
447 // buttons above.
448 NSRect frame = [[bar_ view] frame];
449 frame.size.width += sizes[x];
450 [[bar_ view] setFrame:frame];
451 }
452 } 457 }
453 458
454 // Test whether |-updateState:...| sets currentState as expected. Make 459 // Test whether |-updateState:...| sets currentState as expected. Make
455 // sure things don't crash. 460 // sure things don't crash.
456 TEST_F(BookmarkBarControllerTest, StateChanges) { 461 TEST_F(BookmarkBarControllerTest, StateChanges) {
457 // First, go in one-at-a-time cycle. 462 // First, go in one-at-a-time cycle.
458 [bar_ updateState:BookmarkBar::HIDDEN 463 [bar_ updateState:BookmarkBar::HIDDEN
459 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; 464 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE];
460 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]); 465 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]);
461 EXPECT_FALSE([bar_ isVisible]); 466 EXPECT_FALSE([bar_ isVisible]);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 InstallAndToggleBar(bar.get()); 519 InstallAndToggleBar(bar.get());
515 520
516 // Send a frame did change notification for the pong's view. 521 // Send a frame did change notification for the pong's view.
517 [[NSNotificationCenter defaultCenter] 522 [[NSNotificationCenter defaultCenter]
518 postNotificationName:NSViewFrameDidChangeNotification 523 postNotificationName:NSViewFrameDidChangeNotification
519 object:[bar view]]; 524 object:[bar view]];
520 525
521 EXPECT_GT([bar toggles], 0); 526 EXPECT_GT([bar toggles], 0);
522 } 527 }
523 528
524 // Confirm our "no items" container goes away when we add the 1st 529 TEST_F(BookmarkBarControllerTest, ApplyLayoutNoItemTextField) {
525 // bookmark, and comes back when we delete the bookmark. 530 NSTextField* text_field = [[bar_ buttonView] noItemTextField];
526 TEST_F(BookmarkBarControllerTest, NoItemContainerGoesAway) { 531
527 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 532 bookmarks::BookmarkBarLayout layout = {};
528 const BookmarkNode* bar = model->bookmark_bar_node(); 533 layout.visible_elements |= bookmarks::kVisibleElementsMaskNoItemTextField;
529 534 layout.no_item_textfield_offset = 10;
530 [bar_ loaded:model]; 535 layout.no_item_textfield_width = 20;
531 BookmarkBarView* view = [bar_ buttonView]; 536
532 DCHECK(view); 537 VerifyViewLayout(text_field, layout, 10, 20, true);
533 NSView* noItemContainer = [view noItemContainer]; 538 }
534 DCHECK(noItemContainer); 539
535 540 TEST_F(BookmarkBarControllerTest, ApplyLayoutImportBookmarksButton) {
536 EXPECT_FALSE([noItemContainer isHidden]); 541 NSButton* button = [[bar_ buttonView] importBookmarksButton];
537 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), 542
538 ASCIIToUTF16("title"), 543 bookmarks::BookmarkBarLayout layout = {};
539 GURL("http://www.google.com")); 544 // This button never appears without the no item text field appearing, so
540 EXPECT_TRUE([noItemContainer isHidden]); 545 // show that too.
546 layout.visible_elements |= bookmarks::kVisibleElementsMaskNoItemTextField;
547 layout.no_item_textfield_offset = 10;
548 layout.no_item_textfield_width = 20;
549 layout.visible_elements |=
550 bookmarks::kVisibleElementsMaskImportBookmarksButton;
551 layout.import_bookmarks_button_offset = 30;
552 layout.import_bookmarks_button_width = 40;
553
554 VerifyViewLayout(button, layout, 30, 40, true);
555 }
556
557 TEST_F(BookmarkBarControllerTest, ApplyLayoutSupervisedButton) {
558 NSButton* button = [bar_ supervisedBookmarksButton];
559
560 bookmarks::BookmarkBarLayout layout = {};
561 layout.visible_elements |=
562 bookmarks::kVisibleElementsMaskSupervisedBookmarksButton;
563 layout.supervised_bookmarks_button_offset = 40;
564
565 VerifyViewLayout(button, layout, 40, CGFLOAT_MAX, false);
566 }
567 TEST_F(BookmarkBarControllerTest, ApplyLayoutManagedButton) {
568 NSButton* button = [bar_ managedBookmarksButton];
569
570 bookmarks::BookmarkBarLayout layout = {};
571 layout.visible_elements |=
572 bookmarks::kVisibleElementsMaskManagedBookmarksButton;
573 layout.managed_bookmarks_button_offset = 50;
574
575 VerifyViewLayout(button, layout, 50, CGFLOAT_MAX, false);
576 }
577
578 TEST_F(BookmarkBarControllerTest, ApplyLayoutOffTheSideButton) {
579 NSButton* button = [bar_ offTheSideButton];
580
581 bookmarks::BookmarkBarLayout layout = {};
582 layout.visible_elements |= bookmarks::kVisibleElementsMaskOffTheSideButton;
583 layout.off_the_side_button_offset = 100;
584
585 VerifyViewLayout(button, layout, 100, CGFLOAT_MAX, false);
586 }
587
588 TEST_F(BookmarkBarControllerTest, ApplyLayoutOtherBookmarksButton) {
589 NSButton* button = [bar_ otherBookmarksButton];
590
591 bookmarks::BookmarkBarLayout layout = {};
592 layout.visible_elements |=
593 bookmarks::kVisibleElementsMaskOtherBookmarksButton;
594 layout.other_bookmarks_button_offset = 110;
595
596 VerifyViewLayout(button, layout, 110, CGFLOAT_MAX, false);
597 }
598
599 TEST_F(BookmarkBarControllerTest, ApplyLayoutAppsButton) {
600 NSButton* button = [bar_ appsPageShortcutButton];
601
602 bookmarks::BookmarkBarLayout layout = {};
603 layout.visible_elements |= bookmarks::kVisibleElementsMaskAppsButton;
604 layout.apps_button_offset = 5;
605
606 VerifyViewLayout(button, layout, 5, CGFLOAT_MAX, false);
607 }
608
609 TEST_F(BookmarkBarControllerTest, ApplyLayoutBookmarkButtons) {
610 // Add some bookmarks
611 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
612 GURL gurls[] = {
613 GURL("http://www.google.com/a"), GURL("http://www.google.com/b"),
614 GURL("http://www.google.com/c"), GURL("http://www.google.com/d")};
615
616 base::string16 titles[] = {ASCIIToUTF16("a"), ASCIIToUTF16("b"),
617 ASCIIToUTF16("c"), ASCIIToUTF16("d")};
618 for (size_t i = 0; i < arraysize(titles); i++)
619 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]);
620
621 // Apply an empty layout. This should clear the buttons.
622 bookmarks::BookmarkBarLayout layout = {};
623 [bar_ applyLayout:layout animated:NO];
624 EXPECT_EQ([[bar_ buttons] count], 0U);
625
626 const BookmarkNode* parentNode = model->bookmark_bar_node();
627 EXPECT_EQ(parentNode->child_count(), 4);
628 // Ask the layout to show the first 2 nodes
629 for (int i = 0; i < 3; i++) {
630 const BookmarkNode* node = parentNode->GetChild(i);
631 layout.button_offsets[node->id()] =
632 bookmarks::kDefaultBookmarkWidth * (i + 1);
633 }
634 [bar_ applyLayout:layout animated:NO];
635 EXPECT_EQ([[bar_ buttons] count], 3U);
636 CGFloat lastMax = 0;
637 for (int i = 0; i < 3; i++) {
638 const BookmarkNode* node = parentNode->GetChild(i);
639 BookmarkButton* button = [[bar_ buttons] objectAtIndex:i];
640 EXPECT_EQ([button bookmarkNode], node);
641 EXPECT_CGFLOAT_EQ(NSMinX([button frame]),
642 bookmarks::kDefaultBookmarkWidth * (i + 1));
643 EXPECT_GT(NSWidth([button frame]), 0);
644 EXPECT_EQ([button superview], [bar_ buttonView]);
645 // Ensure buttons don't overlap.
646 EXPECT_GT(NSMinX([button frame]), lastMax);
647 lastMax = NSMaxX([button frame]);
648 }
649 VerifyButtonTitles(parentNode);
650 }
651 // TODO(lgrey): Add tests for RTL in a follow-up.
652 // crbug.com/648554
653
654 TEST_F(BookmarkBarControllerTest, LayoutNoBookmarks) {
655 // With no apps button, or managed/supervised buttons:
656 profile()->GetPrefs()->SetBoolean(
657 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
658 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
659 // Only the no item text field and import bookmarks button are showing.
660 EXPECT_EQ(
661 layout.visible_elements,
662 (unsigned int)(bookmarks::kVisibleElementsMaskImportBookmarksButton |
663 bookmarks::kVisibleElementsMaskNoItemTextField));
664
665 EXPECT_EQ(layout.VisibleButtonCount(), 0U);
666
667 // The import bookmarks button is after the no item text field and they don't
668 // overlap
669 EXPECT_GT(layout.import_bookmarks_button_offset,
670 layout.no_item_textfield_offset + layout.no_item_textfield_width);
671 // And they both have a width
672 EXPECT_GT(layout.no_item_textfield_width, 0);
673 EXPECT_GT(layout.import_bookmarks_button_width, 0);
674 // And start at the correct offset
675 EXPECT_EQ(layout.no_item_textfield_offset,
676 bookmarks::kBookmarkLeftMargin +
677 bookmarks::kInitialNoItemTextFieldXOrigin);
678 // With apps button:
679 profile()->GetPrefs()->SetBoolean(
680 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, true);
681 layout = [bar_ layoutFromCurrentState];
682
683 // Only the apps button, no item text field and import bookmarks button are
684 // showing.
685 EXPECT_EQ(
686 layout.visible_elements,
687 (unsigned int)(bookmarks::kVisibleElementsMaskImportBookmarksButton |
688 bookmarks::kVisibleElementsMaskNoItemTextField |
689 bookmarks::kVisibleElementsMaskAppsButton));
690 EXPECT_EQ(layout.VisibleButtonCount(), 0U);
691 // The no item text field is after the apps button
692 EXPECT_GT(layout.no_item_textfield_offset, layout.apps_button_offset);
693
694 // And the apps button is at the correct offset
695 EXPECT_EQ(layout.apps_button_offset, bookmarks::kBookmarkLeftMargin);
696
697 // TODO(lgrey): It seems prohibitively difficult/maybe impossible
698 // to test the managed/supervised buttons at this time.
699 }
700
701 TEST_F(BookmarkBarControllerTest, LayoutManagedAppsButton) {
702 // By default the pref is not managed and the apps shortcut is shown.
703 sync_preferences::TestingPrefServiceSyncable* prefs =
704 profile()->GetTestingPrefService();
705 EXPECT_FALSE(prefs->IsManagedPreference(
706 bookmarks::prefs::kShowAppsShortcutInBookmarkBar));
707 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
708 EXPECT_TRUE(layout.IsAppsButtonVisible());
709
710 // Hide the apps shortcut by policy, via the managed pref.
711 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
712 base::MakeUnique<base::Value>(false));
713 layout = [bar_ layoutFromCurrentState];
714 EXPECT_FALSE(layout.IsAppsButtonVisible());
715
716 // And try showing it via policy too.
717 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
718 base::MakeUnique<base::Value>(true));
719 layout = [bar_ layoutFromCurrentState];
720 EXPECT_TRUE(layout.IsAppsButtonVisible());
721 }
722
723 TEST_F(BookmarkBarControllerTest, NoItemsResizing) {
724 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
725 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() &&
726 layout.IsImportBookmarksButtonVisible());
727 CGFloat oldOffset = layout.import_bookmarks_button_offset;
728 CGFloat oldWidth = layout.import_bookmarks_button_width;
729 CGRect viewFrame = [[bar_ view] frame];
730 CGFloat originalViewWidth = NSWidth(viewFrame);
731 // Assert that the import bookmarks button fits.
732 EXPECT_GT(originalViewWidth, oldOffset + oldWidth);
733 // Resize the view to cut the import bookmarks button in half.
734 viewFrame.size.width = oldOffset + oldWidth * 0.5;
735 [[bar_ view] setFrame:viewFrame];
736 layout = [bar_ layoutFromCurrentState];
737 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() &&
738 layout.IsImportBookmarksButtonVisible());
739 EXPECT_CGFLOAT_EQ(layout.import_bookmarks_button_offset, oldOffset);
740 EXPECT_LT(layout.import_bookmarks_button_width, oldWidth);
741 // Resize the view to cut off the import bookmarks button entirely.
742 viewFrame.size.width = layout.import_bookmarks_button_offset - 1;
743 [[bar_ view] setFrame:viewFrame];
744 layout = [bar_ layoutFromCurrentState];
745 EXPECT_FALSE(layout.IsImportBookmarksButtonVisible());
746 EXPECT_TRUE(layout.IsNoItemTextFieldVisible());
747 // Now, cut the text field in half
748 oldOffset = layout.no_item_textfield_offset;
749 oldWidth = layout.no_item_textfield_width;
750 viewFrame.size.width = oldOffset + oldWidth * 0.5;
751 [[bar_ view] setFrame:viewFrame];
752 layout = [bar_ layoutFromCurrentState];
753 EXPECT_TRUE(layout.IsNoItemTextFieldVisible());
754 EXPECT_CGFLOAT_EQ(layout.no_item_textfield_offset, oldOffset);
755 EXPECT_LT(layout.no_item_textfield_width, oldWidth);
756 // Make the view too small to fit either.
757 viewFrame.size.width = bookmarks::kBookmarkLeftMargin;
758 [[bar_ view] setFrame:viewFrame];
759 layout = [bar_ layoutFromCurrentState];
760 EXPECT_FALSE(layout.IsNoItemTextFieldVisible() ||
761 layout.IsImportBookmarksButtonVisible());
762 // Sanity check
763 viewFrame.size.width = originalViewWidth;
764 [[bar_ view] setFrame:viewFrame];
765 layout = [bar_ layoutFromCurrentState];
766 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() &&
767 layout.IsImportBookmarksButtonVisible());
768 }
769
770 TEST_F(BookmarkBarControllerTest, LayoutOtherBookmarks) {
771 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
772 const BookmarkNode* otherBookmarks = model->other_node();
773 model->AddURL(otherBookmarks, otherBookmarks->child_count(),
774 ASCIIToUTF16("TheOther"), GURL("http://www.other.com"));
775 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
776 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible());
777 EXPECT_EQ(layout.VisibleButtonCount(), 0U);
778 EXPECT_GT(layout.other_bookmarks_button_offset, 0);
779 CGFloat offsetFromMaxX =
780 NSWidth([[bar_ view] frame]) - layout.other_bookmarks_button_offset;
781 // Resize the view and ensure the button stays pinned to the right edge.
782 CGRect viewFrame = [[bar_ view] frame];
783 // Half of the original size
784 viewFrame.size.width = std::ceil(NSWidth(viewFrame) * 0.5);
785 [[bar_ view] setFrame:viewFrame];
786 layout = [bar_ layoutFromCurrentState];
787 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible());
788 EXPECT_GT(layout.other_bookmarks_button_offset, 0);
789 EXPECT_CGFLOAT_EQ(NSWidth(viewFrame) - layout.other_bookmarks_button_offset,
790 offsetFromMaxX);
791 // 150% of the original size
792 viewFrame.size.width = NSWidth(viewFrame) * 3;
793 [[bar_ view] setFrame:viewFrame];
794 layout = [bar_ layoutFromCurrentState];
795 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible());
796 EXPECT_CGFLOAT_EQ(NSWidth(viewFrame) - layout.other_bookmarks_button_offset,
797 offsetFromMaxX);
798 }
799
800 TEST_F(BookmarkBarControllerTest, LayoutBookmarks) {
801 // Apps button shows up by default, first test without it.
802 profile()->GetPrefs()->SetBoolean(
803 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
804
805 // Add some bookmarks.
806 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
807 const BookmarkNode* barNode = model->bookmark_bar_node();
808 GURL gurls[] = {GURL("http://www.google.com/a"),
809 GURL("http://www.google.com/b"),
810 GURL("http://www.google.com/c")};
811 base::string16 titles[] = {ASCIIToUTF16("a"), ASCIIToUTF16("b"),
812 ASCIIToUTF16("c")};
813 for (size_t i = 0; i < arraysize(titles); i++)
814 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]);
815
816 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
817 EXPECT_EQ(layout.VisibleButtonCount(), (size_t)barNode->child_count());
818 EXPECT_FALSE(layout.IsOffTheSideButtonVisible());
819 EXPECT_EQ(layout.button_offsets.size(), (size_t)barNode->child_count());
820 EXPECT_EQ(layout.button_offsets[barNode->GetChild(0)->id()],
821 bookmarks::kBookmarkLeftMargin);
822 // Assert that the buttons are in order.
823 CGFloat lastOffset = 0;
824 for (int i = 0; i < barNode->child_count(); i++) {
825 CGFloat offset = layout.button_offsets[barNode->GetChild(i)->id()];
826 EXPECT_GT(offset, lastOffset);
827 lastOffset = offset;
828 }
829 }
830
831 TEST_F(BookmarkBarControllerTest, NoItemUIHiddenWithBookmarks) {
832 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
833 const BookmarkNode* barNode = model->bookmark_bar_node();
834
835 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
836 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() &&
837 layout.IsImportBookmarksButtonVisible());
838
839 const BookmarkNode* node =
840 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"),
841 GURL("http://www.google.com"));
842 layout = [bar_ layoutFromCurrentState];
843 EXPECT_FALSE(layout.IsNoItemTextFieldVisible() ||
844 layout.IsImportBookmarksButtonVisible());
845
541 model->Remove(node); 846 model->Remove(node);
542 EXPECT_FALSE([noItemContainer isHidden]); 847 layout = [bar_ layoutFromCurrentState];
543 848 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() &&
544 // Now try it using a bookmark from the Other Bookmarks. 849 layout.IsImportBookmarksButtonVisible());
545 const BookmarkNode* otherBookmarks = model->other_node(); 850 }
546 node = model->AddURL(otherBookmarks, otherBookmarks->child_count(), 851
547 ASCIIToUTF16("TheOther"), 852 TEST_F(BookmarkBarControllerTest, LayoutBookmarksResize) {
548 GURL("http://www.other.com")); 853 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
549 EXPECT_FALSE([noItemContainer isHidden]); 854 const BookmarkNode* barNode = model->bookmark_bar_node();
550 // Move it from Other Bookmarks to the bar. 855 for (int i = 0; i < 20; i++) {
551 model->Move(node, bar, 0); 856 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"),
552 EXPECT_TRUE([noItemContainer isHidden]); 857 GURL("http://www.google.com"));
553 // Move it back to Other Bookmarks from the bar. 858 }
554 model->Move(node, otherBookmarks, 0); 859 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
555 EXPECT_FALSE([noItemContainer isHidden]); 860 EXPECT_LT(layout.VisibleButtonCount(), 20U);
861 size_t originalButtonCount = layout.VisibleButtonCount();
862 EXPECT_TRUE(layout.IsOffTheSideButtonVisible());
863
864 CGRect viewFrame = [[bar_ view] frame];
865 // Increase the width of the view. More buttons should be visible.
866 viewFrame.size.width += 200;
867 [[bar_ view] setFrame:viewFrame];
868 layout = [bar_ layoutFromCurrentState];
869 EXPECT_GT(layout.VisibleButtonCount(), originalButtonCount);
870
871 // Decrease the width of the view to below what it was originally.
872 // Less buttons should be visible.
873 viewFrame.size.width -= 400;
874 [[bar_ view] setFrame:viewFrame];
875 layout = [bar_ layoutFromCurrentState];
876 EXPECT_LT(layout.VisibleButtonCount(), originalButtonCount);
877
878 // NB: This part overlaps a little with |OffTheSideButtonHidden|
879 // but we just want to check the layout here, whereas that test
880 // ensures the folder is closed when the button goes away.
881 //
882 // Find the number of buttons at which the off-the-side button disappears.
883 EXPECT_TRUE(layout.IsOffTheSideButtonVisible());
884 bool crossoverPointFound = false;
885
886 // Bound the number of iterations in case the button never
887 // disappears.
888 const int maxToRemove = 20;
889 for (int i = 0; i < maxToRemove; i++) {
890 if (!layout.IsOffTheSideButtonVisible()) {
891 crossoverPointFound = true;
892 break;
893 }
894 model->Remove(barNode->GetChild(barNode->child_count() - 1));
895 layout = [bar_ layoutFromCurrentState];
896 }
897
898 // Either something is broken, or the test needs to be redone.
899 ASSERT_TRUE(crossoverPointFound);
900 EXPECT_FALSE(layout.IsOffTheSideButtonVisible());
901
902 // Add a button and ensure the off the side button appears again.
903 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"),
904 GURL("http://www.google.com"));
905 layout = [bar_ layoutFromCurrentState];
906 EXPECT_TRUE(layout.IsOffTheSideButtonVisible());
907
908 // If the off-the-side button is visible, this means we have more
909 // buttons than we can show, so adding another shouldn't increase
910 // the button count.
911 size_t buttonCountBeforeAdding = layout.VisibleButtonCount();
912 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"),
913 GURL("http://www.google.com"));
914 layout = [bar_ layoutFromCurrentState];
915 EXPECT_EQ(layout.VisibleButtonCount(), buttonCountBeforeAdding);
556 } 916 }
557 917
558 // Confirm off the side button only enabled when reasonable. 918 // Confirm off the side button only enabled when reasonable.
559 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { 919 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) {
560 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 920 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
561 921
562 [bar_ loaded:model]; 922 [bar_ loaded:model];
563 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); 923 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]);
564 924
565 for (int i = 0; i < 2; i++) { 925 for (int i = 0; i < 2; i++) {
566 bookmarks::AddIfNotBookmarked( 926 bookmarks::AddIfNotBookmarked(
567 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); 927 model, GURL("http://www.foo.com"), ASCIIToUTF16("small"));
568 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); 928 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]);
569 } 929 }
570 930
571 const BookmarkNode* parent = model->bookmark_bar_node(); 931 const BookmarkNode* parent = model->bookmark_bar_node();
572 for (int i = 0; i < 20; i++) { 932 for (int i = 0; i < 20; i++) {
573 model->AddURL(parent, parent->child_count(), 933 model->AddURL(parent, parent->child_count(),
574 ASCIIToUTF16("super duper wide title"), 934 ASCIIToUTF16("super duper wide title"),
575 GURL("http://superfriends.hall-of-justice.edu")); 935 GURL("http://superfriends.hall-of-justice.edu"));
576 } 936 }
577 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); 937 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]);
578 938
579 // Open the "off the side" and start deleting nodes. Make sure 939 // Open the "off the side" and start deleting nodes. Make sure
580 // deletion of the last node in "off the side" causes the folder to 940 // deletion of the last node in "off the side" causes the folder to
581 // close. 941 // close.
582 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); 942 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]);
583 NSButton* offTheSideButton = [bar_ offTheSideButton]; 943 NSButton* offTheSideButton = [bar_ offTheSideButton];
584 // Open "off the side" menu. 944 // Open "off the side" menu.
585 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; 945 [bar_ openOffTheSideFolderFromButton:offTheSideButton];
586 BookmarkBarFolderController* bbfc = [bar_ folderController]; 946 BookmarkBarFolderController* bbfc = [bar_ folderController];
587 EXPECT_TRUE(bbfc); 947 EXPECT_TRUE(bbfc);
588 [bbfc setIgnoreAnimations:YES]; 948 [bbfc setIgnoreAnimations:YES];
589 while (!parent->empty()) { 949 while (!parent->empty()) {
590 // We've completed the job so we're done. 950 // We've completed the job so we're done.
591 if ([bar_ offTheSideButtonIsHidden]) 951 if ([[bar_ offTheSideButton] isHidden])
592 break; 952 break;
593 // Delete the last button. 953 // Delete the last button.
594 model->Remove(parent->GetChild(parent->child_count() - 1)); 954 model->Remove(parent->GetChild(parent->child_count() - 1));
595 // If last one make sure the menu is closed and the button is hidden. 955 // If last one make sure the menu is closed and the button is hidden.
596 // Else make sure menu stays open. 956 // Else make sure menu stays open.
597 if ([bar_ offTheSideButtonIsHidden]) { 957 if ([[bar_ offTheSideButton] isHidden]) {
598 EXPECT_FALSE([bar_ folderController]); 958 EXPECT_FALSE([bar_ folderController]);
599 } else { 959 } else {
600 EXPECT_TRUE([bar_ folderController]); 960 EXPECT_TRUE([bar_ folderController]);
601 } 961 }
602 } 962 }
603 } 963 }
604 964
605 // http://crbug.com/46175 is a crash when deleting bookmarks from the 965 // http://crbug.com/46175 is a crash when deleting bookmarks from the
606 // off-the-side menu while it is open. This test tries to bang hard 966 // off-the-side menu while it is open. This test tries to bang hard
607 // in this area to reproduce the crash. 967 // in this area to reproduce the crash.
608 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { 968 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) {
609 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 969 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
610 [bar_ loaded:model]; 970 [bar_ loaded:model];
611 971
612 // Add a lot of bookmarks (per the bug). 972 // Add a lot of bookmarks (per the bug).
613 const BookmarkNode* parent = model->bookmark_bar_node(); 973 const BookmarkNode* parent = model->bookmark_bar_node();
614 for (int i = 0; i < 100; i++) { 974 for (int i = 0; i < 100; i++) {
615 std::ostringstream title; 975 std::ostringstream title;
616 title << "super duper wide title " << i; 976 title << "super duper wide title " << i;
617 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), 977 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()),
618 GURL("http://superfriends.hall-of-justice.edu")); 978 GURL("http://superfriends.hall-of-justice.edu"));
619 } 979 }
620 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); 980 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]);
621 981
622 // Open "off the side" menu. 982 // Open "off the side" menu.
623 NSButton* offTheSideButton = [bar_ offTheSideButton]; 983 NSButton* offTheSideButton = [bar_ offTheSideButton];
624 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; 984 [bar_ openOffTheSideFolderFromButton:offTheSideButton];
625 BookmarkBarFolderController* bbfc = [bar_ folderController]; 985 BookmarkBarFolderController* bbfc = [bar_ folderController];
626 EXPECT_TRUE(bbfc); 986 EXPECT_TRUE(bbfc);
627 [bbfc setIgnoreAnimations:YES]; 987 [bbfc setIgnoreAnimations:YES];
628 988
629 // Start deleting items; try and delete randomish ones in case it 989 // Start deleting items; try and delete randomish ones in case it
630 // makes a difference. 990 // makes a difference.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 [button setCell:cell.get()]; 1038 [button setCell:cell.get()];
679 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; 1039 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]];
680 1040
681 [bar_ openBookmark:button]; 1041 [bar_ openBookmark:button];
682 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); 1042 EXPECT_EQ(noOpenBar()->urls_[0], node->url());
683 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB); 1043 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB);
684 } 1044 }
685 1045
686 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { 1046 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) {
687 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1047 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
688 NSView* buttonView = [bar_ buttonView];
689 EXPECT_EQ(0U, [[bar_ buttons] count]); 1048 EXPECT_EQ(0U, [[bar_ buttons] count]);
690 unsigned int initial_subview_count = [[buttonView subviews] count];
691
692 // Make sure a redundant call doesn't choke
693 [bar_ clearBookmarkBar];
694 EXPECT_EQ(0U, [[bar_ buttons] count]);
695 EXPECT_EQ(initial_subview_count, [[buttonView subviews] count]);
696 1049
697 GURL gurl1("http://superfriends.hall-of-justice.edu"); 1050 GURL gurl1("http://superfriends.hall-of-justice.edu");
698 // Short titles increase the chances of this test succeeding if the view is 1051 // Short titles increase the chances of this test succeeding if the view is
699 // narrow. 1052 // narrow.
700 // TODO(viettrungluu): make the test independent of window/view size, font 1053 // TODO(viettrungluu): make the test independent of window/view size, font
701 // metrics, button size and spacing, and everything else. 1054 // metrics, button size and spacing, and everything else.
702 base::string16 title1(ASCIIToUTF16("x")); 1055 base::string16 title1(ASCIIToUTF16("x"));
703 bookmarks::AddIfNotBookmarked(model, gurl1, title1); 1056 bookmarks::AddIfNotBookmarked(model, gurl1, title1);
704 EXPECT_EQ(1U, [[bar_ buttons] count]); 1057 EXPECT_EQ(1U, [[bar_ buttons] count]);
705 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]);
706 1058
707 GURL gurl2("http://legion-of-doom.gov"); 1059 GURL gurl2("http://legion-of-doom.gov");
708 base::string16 title2(ASCIIToUTF16("y")); 1060 base::string16 title2(ASCIIToUTF16("y"));
709 bookmarks::AddIfNotBookmarked(model, gurl2, title2); 1061 bookmarks::AddIfNotBookmarked(model, gurl2, title2);
710 EXPECT_EQ(2U, [[bar_ buttons] count]); 1062 EXPECT_EQ(2U, [[bar_ buttons] count]);
711 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]);
712 1063
713 for (int i = 0; i < 3; i++) { 1064 for (int i = 0; i < 3; i++) {
714 bookmarks::RemoveAllBookmarks(model, gurl2); 1065 bookmarks::RemoveAllBookmarks(model, gurl2);
715 EXPECT_EQ(1U, [[bar_ buttons] count]); 1066 EXPECT_EQ(1U, [[bar_ buttons] count]);
716 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]);
717 1067
718 // and bring it back 1068 // and bring it back
719 bookmarks::AddIfNotBookmarked(model, gurl2, title2); 1069 bookmarks::AddIfNotBookmarked(model, gurl2, title2);
720 EXPECT_EQ(2U, [[bar_ buttons] count]); 1070 EXPECT_EQ(2U, [[bar_ buttons] count]);
721 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]);
722 } 1071 }
723 1072
724 [bar_ clearBookmarkBar];
725 EXPECT_EQ(0U, [[bar_ buttons] count]);
726 EXPECT_EQ(initial_subview_count, [[buttonView subviews] count]);
727
728 // Explicit test of loaded: since this is a convenient spot 1073 // Explicit test of loaded: since this is a convenient spot
729 [bar_ loaded:model]; 1074 [bar_ loaded:model];
730 EXPECT_EQ(2U, [[bar_ buttons] count]); 1075 EXPECT_EQ(2U, [[bar_ buttons] count]);
731 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]);
732 } 1076 }
733 1077
734 // Make sure we don't create too many buttons; we only really need 1078 // Make sure we don't create too many buttons; we only really need
735 // ones that will be visible. 1079 // ones that will be visible.
736 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { 1080 TEST_F(BookmarkBarControllerTest, TestButtonLimits) {
737 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1081 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
738 EXPECT_EQ(0U, [[bar_ buttons] count]); 1082 EXPECT_EQ(0U, [[bar_ buttons] count]);
739 // Add one; make sure we see it. 1083 // Add one; make sure we see it.
740 const BookmarkNode* parent = model->bookmark_bar_node(); 1084 const BookmarkNode* parent = model->bookmark_bar_node();
741 model->AddURL(parent, parent->child_count(), 1085 model->AddURL(parent, parent->child_count(),
742 ASCIIToUTF16("title"), GURL("http://www.google.com")); 1086 ASCIIToUTF16("title"), GURL("http://www.google.com"));
743 EXPECT_EQ(1U, [[bar_ buttons] count]); 1087 EXPECT_EQ(1U, [[bar_ buttons] count]);
744 1088
745 // Add 30 which we expect to be 'too many'. Make sure we don't see 1089 // Add 30 which we expect to be 'too many'. Make sure we don't see
746 // 30 buttons. 1090 // 30 buttons.
747 model->Remove(parent->GetChild(0)); 1091 model->Remove(parent->GetChild(0));
748 EXPECT_EQ(0U, [[bar_ buttons] count]); 1092 EXPECT_EQ(0U, [[bar_ buttons] count]);
749 for (int i=0; i<30; i++) { 1093 for (int i=0; i<30; i++) {
750 model->AddURL(parent, parent->child_count(), 1094 model->AddURL(parent, parent->child_count(),
751 ASCIIToUTF16("title"), GURL("http://www.google.com")); 1095 ASCIIToUTF16("title"), GURL("http://www.google.com"));
752 } 1096 }
753 int count = [[bar_ buttons] count]; 1097 int count = [[bar_ buttons] count];
754 EXPECT_LT(count, 30L); 1098 EXPECT_LT(count, 30L);
755 1099
756 // Add 10 more (to the front of the list so the on-screen buttons 1100 // Add 10 more (to the front of the list so the on-screen buttons
757 // would change) and make sure the count stays the same. 1101 // would change) and make sure the count stays the same.
758 for (int i=0; i<10; i++) { 1102 for (int i=0; i<10; i++) {
759 model->AddURL(parent, 0, /* index is 0, so front, not end */ 1103 model->AddURL(parent, 0, // index is 0, so front, not end
760 ASCIIToUTF16("title"), GURL("http://www.google.com")); 1104 ASCIIToUTF16("title"), GURL("http://www.google.com"));
761 } 1105 }
762 1106
763 // Finally, grow the view and make sure the button count goes up. 1107 // Finally, grow the view and make sure the button count goes up.
764 NSRect frame = [[bar_ view] frame]; 1108 NSRect frame = [[bar_ view] frame];
765 frame.size.width += 600; 1109 frame.size.width += 600;
766 [[bar_ view] setFrame:frame]; 1110 [[bar_ view] setFrame:frame];
767 int finalcount = [[bar_ buttons] count]; 1111 int finalcount = [[bar_ buttons] count];
768 EXPECT_GT(finalcount, count); 1112 EXPECT_GT(finalcount, count);
769 } 1113 }
770 1114
771 // Make sure that each button we add marches to the right and does not
772 // overlap with the previous one.
773 TEST_F(BookmarkBarControllerTest, TestButtonMarch) {
774 base::scoped_nsobject<NSMutableArray> cells([[NSMutableArray alloc] init]);
775
776 CGFloat widths[] = { 10, 10, 100, 10, 500, 500, 80000, 60000, 1, 345 };
777 for (unsigned int i = 0; i < arraysize(widths); i++) {
778 NSCell* cell = [[CellWithDesiredSize alloc]
779 initTextCell:@"foo"
780 desiredSize:NSMakeSize(widths[i], 30)];
781 [cells addObject:cell];
782 [cell release];
783 }
784
785 int x_offset = 0;
786 CGFloat x_end = x_offset; // end of the previous button
787 for (unsigned int i = 0; i < arraysize(widths); i++) {
788 NSRect r = [bar_ frameForBookmarkButtonFromCell:[cells objectAtIndex:i]
789 xOffset:&x_offset];
790 EXPECT_GE(r.origin.x, x_end);
791 x_end = NSMaxX(r);
792 }
793 }
794
795 TEST_F(BookmarkBarControllerTest, CheckForGrowth) {
796 WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope.
797 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
798 GURL gurl1("http://www.google.com");
799 base::string16 title1(ASCIIToUTF16("x"));
800 bookmarks::AddIfNotBookmarked(model, gurl1, title1);
801
802 GURL gurl2("http://www.google.com/blah");
803 base::string16 title2(ASCIIToUTF16("y"));
804 bookmarks::AddIfNotBookmarked(model, gurl2, title2);
805
806 EXPECT_EQ(2U, [[bar_ buttons] count]);
807 CGFloat width_1 = [[[bar_ buttons] objectAtIndex:0] frame].size.width;
808 CGFloat x_2 = [[[bar_ buttons] objectAtIndex:1] frame].origin.x;
809
810 NSButton* first = [[bar_ buttons] objectAtIndex:0];
811 [[first cell] setTitle:@"This is a really big title; watch out mom!"];
812 [bar_ checkForBookmarkButtonGrowth:first];
813
814 // Make sure the 1st button is now wider, the 2nd one is moved over,
815 // and they don't overlap.
816 NSRect frame_1 = [[[bar_ buttons] objectAtIndex:0] frame];
817 NSRect frame_2 = [[[bar_ buttons] objectAtIndex:1] frame];
818 EXPECT_GT(frame_1.size.width, width_1);
819 EXPECT_GT(frame_2.origin.x, x_2);
820 EXPECT_GE(frame_2.origin.x, frame_1.origin.x + frame_1.size.width);
821 }
822
823 TEST_F(BookmarkBarControllerTest, DeleteBookmark) {
824 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
825
826 const char* urls[] = { "https://secret.url.com",
827 "http://super.duper.web.site.for.doodz.gov",
828 "http://www.foo-bar-baz.com/" };
829 const BookmarkNode* parent = model->bookmark_bar_node();
830 for (unsigned int i = 0; i < arraysize(urls); i++) {
831 model->AddURL(parent, parent->child_count(),
832 ASCIIToUTF16("title"), GURL(urls[i]));
833 }
834 EXPECT_EQ(3, parent->child_count());
835 const BookmarkNode* middle_node = parent->GetChild(1);
836 model->Remove(middle_node);
837
838 EXPECT_EQ(2, parent->child_count());
839 EXPECT_EQ(parent->GetChild(0)->url(), GURL(urls[0]));
840 // node 2 moved into spot 1
841 EXPECT_EQ(parent->GetChild(1)->url(), GURL(urls[2]));
842 }
843
844 // TODO(jrg): write a test to confirm that nodeFaviconLoaded calls
845 // checkForBookmarkButtonGrowth:.
846
847 TEST_F(BookmarkBarControllerTest, Cell) {
848 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
849 [bar_ loaded:model];
850
851 const BookmarkNode* parent = model->bookmark_bar_node();
852 model->AddURL(parent, parent->child_count(),
853 ASCIIToUTF16("supertitle"),
854 GURL("http://superfriends.hall-of-justice.edu"));
855 const BookmarkNode* node = parent->GetChild(0);
856
857 NSCell* cell = [bar_ cellForBookmarkNode:node];
858 EXPECT_TRUE(cell);
859 EXPECT_NSEQ(@"supertitle", [cell title]);
860 EXPECT_EQ(node, [[cell representedObject] pointerValue]);
861 EXPECT_TRUE([cell menu]);
862
863 // Empty cells still have a menu.
864 cell = [bar_ cellForBookmarkNode:nil];
865 EXPECT_TRUE([cell menu]);
866 // Even empty cells have a title (of "(empty)")
867 EXPECT_TRUE([cell title]);
868
869 // cell is autoreleased; no need to release here
870 }
871
872 // Test drawing, mostly to ensure nothing leaks or crashes. 1115 // Test drawing, mostly to ensure nothing leaks or crashes.
873 TEST_F(BookmarkBarControllerTest, Display) { 1116 TEST_F(BookmarkBarControllerTest, Display) {
874 [[bar_ view] display]; 1117 [[bar_ view] display];
875 } 1118 }
876 1119
877 // Test that middle clicking on a bookmark button results in an open action, 1120 // Test that middle clicking on a bookmark button results in an open action,
878 // except for offTheSideButton, as it just opens its folder menu. 1121 // except for offTheSideButton, as it just opens its folder menu.
879 TEST_F(BookmarkBarControllerTest, MiddleClick) { 1122 TEST_F(BookmarkBarControllerTest, MiddleClick) {
880 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
881 GURL gurl1("http://www.google.com/"); 1124 GURL gurl1("http://www.google.com/");
882 base::string16 title1(ASCIIToUTF16("x")); 1125 base::string16 title1(ASCIIToUTF16("x"));
883 bookmarks::AddIfNotBookmarked(model, gurl1, title1); 1126 bookmarks::AddIfNotBookmarked(model, gurl1, title1);
884 1127
885 EXPECT_EQ(1U, [[bar_ buttons] count]); 1128 EXPECT_EQ(1U, [[bar_ buttons] count]);
886 NSButton* first = [[bar_ buttons] objectAtIndex:0]; 1129 NSButton* first = [[bar_ buttons] objectAtIndex:0];
887 EXPECT_TRUE(first); 1130 EXPECT_TRUE(first);
888 1131
889 [first otherMouseUp: 1132 [first otherMouseUp:
890 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; 1133 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)];
891 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); 1134 EXPECT_EQ(noOpenBar()->urls_.size(), 1U);
892 1135
893 // Test for offTheSideButton. 1136 // Test for offTheSideButton.
894 // Add more bookmarks so that offTheSideButton is visible. 1137 // Add more bookmarks so that offTheSideButton is visible.
895 const BookmarkNode* parent = model->bookmark_bar_node(); 1138 const BookmarkNode* parent = model->bookmark_bar_node();
896 for (int i = 0; i < 20; i++) { 1139 for (int i = 0; i < 20; i++) {
897 model->AddURL(parent, parent->child_count(), 1140 model->AddURL(parent, parent->child_count(),
898 ASCIIToUTF16("super duper wide title"), 1141 ASCIIToUTF16("super duper wide title"),
899 GURL("http://superfriends.hall-of-justice.edu")); 1142 GURL("http://superfriends.hall-of-justice.edu"));
900 } 1143 }
901 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]);
902 1144
903 NSButton* offTheSideButton = [bar_ offTheSideButton]; 1145 NSButton* offTheSideButton = [bar_ offTheSideButton];
904 EXPECT_TRUE(offTheSideButton); 1146 EXPECT_TRUE(offTheSideButton);
1147 EXPECT_FALSE([offTheSideButton isHidden]);
905 [offTheSideButton otherMouseUp: 1148 [offTheSideButton otherMouseUp:
906 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; 1149 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)];
907 1150
908 // Middle click on offTheSideButton should not open any bookmarks under it, 1151 // Middle click on offTheSideButton should not open any bookmarks under it,
909 // therefore urls size should still be 1. 1152 // therefore urls size should still be 1.
910 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); 1153 EXPECT_EQ(noOpenBar()->urls_.size(), 1U);
911 1154
912 // Check that folderController should not be NULL since offTheSideButton 1155 // Check that folderController should not be NULL since offTheSideButton
913 // folder is currently open. 1156 // folder is currently open.
914 BookmarkBarFolderController* bbfc = [bar_ folderController]; 1157 BookmarkBarFolderController* bbfc = [bar_ folderController];
915 EXPECT_TRUE(bbfc); 1158 EXPECT_TRUE(bbfc);
916 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); 1159 EXPECT_TRUE([bbfc parentButton] == offTheSideButton);
917 1160
918 // Middle clicking again on it should close the folder. 1161 // Middle clicking again on it should close the folder.
919 [offTheSideButton otherMouseUp: 1162 [offTheSideButton otherMouseUp:
920 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; 1163 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)];
921 bbfc = [bar_ folderController]; 1164 bbfc = [bar_ folderController];
922 EXPECT_FALSE(bbfc); 1165 EXPECT_FALSE(bbfc);
923 } 1166 }
924 1167
925 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { 1168 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) {
926 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1169 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
927 [bar_ loaded:model]; 1170 [bar_ loaded:model];
928 EXPECT_FALSE([[[bar_ buttonView] noItemContainer] isHidden]); 1171 EXPECT_FALSE([[[bar_ buttonView] noItemTextField] isHidden]);
929 } 1172 }
930 1173
931 TEST_F(BookmarkBarControllerTest, HidesHelpMessageWithBookmark) { 1174 TEST_F(BookmarkBarControllerTest, DisplaysImportBookmarksButtonOnEmpty) {
932 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1175 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
933
934 const BookmarkNode* parent = model->bookmark_bar_node();
935 model->AddURL(parent, parent->child_count(),
936 ASCIIToUTF16("title"), GURL("http://one.com"));
937
938 [bar_ loaded:model]; 1176 [bar_ loaded:model];
939 EXPECT_TRUE([[[bar_ buttonView] noItemContainer] isHidden]); 1177 EXPECT_FALSE([[[bar_ buttonView] importBookmarksButton] isHidden]);
940 } 1178 }
941 1179
942 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { 1180 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) {
943 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1181 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
944 1182
945 const BookmarkNode* parent = model->bookmark_bar_node(); 1183 const BookmarkNode* parent = model->bookmark_bar_node();
946 model->AddURL(parent, parent->child_count(), 1184 model->AddURL(parent, parent->child_count(),
947 ASCIIToUTF16("title"), GURL("http://one.com")); 1185 ASCIIToUTF16("title"), GURL("http://one.com"));
948 1186
949 [bar_ loaded:model]; 1187 [bar_ loaded:model];
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 BookmarkBarFolderController* newBBFC = [bar_ folderController]; 1502 BookmarkBarFolderController* newBBFC = [bar_ folderController];
1265 EXPECT_TRUE(newBBFC); 1503 EXPECT_TRUE(newBBFC);
1266 EXPECT_NE(oldBBFC, newBBFC); 1504 EXPECT_NE(oldBBFC, newBBFC);
1267 } 1505 }
1268 1506
1269 // Make sure the "off the side" folder looks like a bookmark folder 1507 // Make sure the "off the side" folder looks like a bookmark folder
1270 // but only contains "off the side" items. 1508 // but only contains "off the side" items.
1271 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { 1509 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) {
1272 1510
1273 // It starts hidden. 1511 // It starts hidden.
1274 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); 1512 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]);
1275 1513
1276 // Create some buttons. 1514 // Create some buttons.
1277 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1515 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1278 const BookmarkNode* parent = model->bookmark_bar_node(); 1516 const BookmarkNode* parent = model->bookmark_bar_node();
1279 for (int x = 0; x < 30; x++) { 1517 for (int x = 0; x < 30; x++) {
1280 model->AddURL(parent, parent->child_count(), 1518 model->AddURL(parent, parent->child_count(),
1281 ASCIIToUTF16("medium-size-title"), 1519 ASCIIToUTF16("medium-size-title"),
1282 GURL("http://framma-lamma.com")); 1520 GURL("http://framma-lamma.com"));
1283 } 1521 }
1284 // Add a couple more so we can delete one and make sure its button goes away. 1522 // Add a couple more so we can delete one and make sure its button goes away.
1285 model->AddURL(parent, parent->child_count(), 1523 model->AddURL(parent, parent->child_count(),
1286 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); 1524 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com"));
1287 model->AddURL(parent, parent->child_count(), 1525 model->AddURL(parent, parent->child_count(),
1288 ASCIIToUTF16("medium-size-title"), 1526 ASCIIToUTF16("medium-size-title"),
1289 GURL("http://framma-lamma.com")); 1527 GURL("http://framma-lamma.com"));
1290 1528
1291 // Should no longer be hidden. 1529 // Should no longer be hidden.
1292 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); 1530 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]);
1293 1531
1294 // Open it; make sure we have a folder controller. 1532 // Open it; make sure we have a folder controller.
1295 EXPECT_FALSE([bar_ folderController]); 1533 EXPECT_FALSE([bar_ folderController]);
1296 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; 1534 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]];
1297 BookmarkBarFolderController* bbfc = [bar_ folderController]; 1535 BookmarkBarFolderController* bbfc = [bar_ folderController];
1298 EXPECT_TRUE(bbfc); 1536 EXPECT_TRUE(bbfc);
1299 1537
1300 // Confirm the contents are only buttons which fell off the side by 1538 // Confirm the contents are only buttons which fell off the side by
1301 // making sure that none of the nodes in the off-the-side folder are 1539 // making sure that none of the nodes in the off-the-side folder are
1302 // found in bar buttons. Be careful since not all the bar buttons 1540 // found in bar buttons. Be careful since not all the bar buttons
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 // Now that we've closed the bookmark bar (with animation) the folder menu 1659 // Now that we've closed the bookmark bar (with animation) the folder menu
1422 // should have been closed thus releasing the folderController. 1660 // should have been closed thus releasing the folderController.
1423 EXPECT_FALSE([bar_ folderController]); 1661 EXPECT_FALSE([bar_ folderController]);
1424 1662
1425 // Stop the pending animation to tear down cleanly. 1663 // Stop the pending animation to tear down cleanly.
1426 [bar_ updateState:BookmarkBar::DETACHED 1664 [bar_ updateState:BookmarkBar::DETACHED
1427 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; 1665 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE];
1428 EXPECT_FALSE([bar_ isAnimationRunning]); 1666 EXPECT_FALSE([bar_ isAnimationRunning]);
1429 } 1667 }
1430 1668
1431 TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) {
1432 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1433 const BookmarkNode* root = model->bookmark_bar_node();
1434 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1435 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1436
1437 // Validate initial model.
1438 std::string actualModelString = bookmarks::test::ModelStringFromNode(root);
1439 EXPECT_EQ(model_string, actualModelString);
1440
1441 // Remember how many buttons are showing.
1442 int oldDisplayedButtons = [bar_ displayedButtonCount];
1443 NSArray* buttons = [bar_ buttons];
1444
1445 // Move a button around a bit.
1446 [bar_ moveButtonFromIndex:0 toIndex:2];
1447 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:0] title]);
1448 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:1] title]);
1449 EXPECT_NSEQ(@"1b", [[buttons objectAtIndex:2] title]);
1450 EXPECT_EQ(oldDisplayedButtons, [bar_ displayedButtonCount]);
1451 [bar_ moveButtonFromIndex:2 toIndex:0];
1452 EXPECT_NSEQ(@"1b", [[buttons objectAtIndex:0] title]);
1453 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:1] title]);
1454 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:2] title]);
1455 EXPECT_EQ(oldDisplayedButtons, [bar_ displayedButtonCount]);
1456
1457 // Add a couple of buttons.
1458 const BookmarkNode* parent = root->GetChild(1); // Purloin an existing node.
1459 const BookmarkNode* node = parent->GetChild(0);
1460 [bar_ addButtonForNode:node atIndex:0];
1461 EXPECT_NSEQ(@"2f1b", [[buttons objectAtIndex:0] title]);
1462 EXPECT_NSEQ(@"1b", [[buttons objectAtIndex:1] title]);
1463 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:2] title]);
1464 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:3] title]);
1465 EXPECT_EQ(oldDisplayedButtons + 1, [bar_ displayedButtonCount]);
1466 node = parent->GetChild(1);
1467 [bar_ addButtonForNode:node atIndex:-1];
1468 EXPECT_NSEQ(@"2f1b", [[buttons objectAtIndex:0] title]);
1469 EXPECT_NSEQ(@"1b", [[buttons objectAtIndex:1] title]);
1470 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:2] title]);
1471 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:3] title]);
1472 EXPECT_NSEQ(@"2f2b", [[buttons objectAtIndex:4] title]);
1473 EXPECT_EQ(oldDisplayedButtons + 2, [bar_ displayedButtonCount]);
1474
1475 // Remove a couple of buttons.
1476 [bar_ removeButton:4 animate:NO];
1477 [bar_ removeButton:1 animate:NO];
1478 EXPECT_NSEQ(@"2f1b", [[buttons objectAtIndex:0] title]);
1479 EXPECT_NSEQ(@"2f", [[buttons objectAtIndex:1] title]);
1480 EXPECT_NSEQ(@"3b", [[buttons objectAtIndex:2] title]);
1481 EXPECT_EQ(oldDisplayedButtons, [bar_ displayedButtonCount]);
1482 }
1483
1484 TEST_F(BookmarkBarControllerTest, ShrinkOrHideView) {
1485 NSRect viewFrame = NSMakeRect(0.0, 0.0, 500.0, 50.0);
1486 NSView* view = [[[NSView alloc] initWithFrame:viewFrame] autorelease];
1487 EXPECT_FALSE([view isHidden]);
1488 [bar_ shrinkOrHideView:view forMaxX:500.0];
1489 EXPECT_EQ(500.0, NSWidth([view frame]));
1490 EXPECT_FALSE([view isHidden]);
1491 [bar_ shrinkOrHideView:view forMaxX:450.0];
1492 EXPECT_EQ(450.0, NSWidth([view frame]));
1493 EXPECT_FALSE([view isHidden]);
1494 [bar_ shrinkOrHideView:view forMaxX:40.0];
1495 EXPECT_EQ(40.0, NSWidth([view frame]));
1496 EXPECT_FALSE([view isHidden]);
1497 [bar_ shrinkOrHideView:view forMaxX:31.0];
1498 EXPECT_EQ(31.0, NSWidth([view frame]));
1499 EXPECT_FALSE([view isHidden]);
1500 [bar_ shrinkOrHideView:view forMaxX:29.0];
1501 EXPECT_TRUE([view isHidden]);
1502 }
1503
1504 // Simulate coarse browser window width change and ensure that the bookmark
1505 // buttons that should be visible are visible.
1506 TEST_F(BookmarkBarControllerTest, RedistributeButtonsOnBarAsNeeded) {
1507 // Hide the apps shortcut.
1508 profile()->GetPrefs()->SetBoolean(
1509 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
1510 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1511
1512 // Add three buttons to the bookmark bar.
1513 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1514 const BookmarkNode* root = model->bookmark_bar_node();
1515 // Make long labels to test coarse resizes. After 16 digits, text eliding
1516 // starts.
1517 const std::string model_string(
1518 "0000000000000000 1111111111111111 2222222222222222 ");
1519 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1520 NSRect frame = [[bar_ view] frame];
1521 frame.size.width = 400; // Typical minimum browser size.
1522 [[bar_ view] setFrame:frame];
1523 EXPECT_EQ(2, [bar_ displayedButtonCount]);
1524
1525 {
1526 base::mac::ScopedNSAutoreleasePool pool;
1527 frame.size.width = 800;
1528 [[bar_ view] setFrame:frame];
1529 EXPECT_EQ(3, [bar_ displayedButtonCount]);
1530
1531 const BookmarkNode* last = model->bookmark_bar_node()->GetChild(2);
1532 EXPECT_TRUE(last);
1533 [bar_ startPulsingBookmarkNode:last];
1534
1535 frame.size.width = 400;
1536 [[bar_ view] setFrame:frame];
1537 EXPECT_EQ(2, [bar_ displayedButtonCount]);
1538 }
1539
1540 // Regression test for http://crbug.com/616051.
1541 [bar_ stopPulsingBookmarkNode];
1542 }
1543
1544 // Simiulate browser window width change and ensure that the bookmark buttons
1545 // that should be visible are visible.
1546 // Appears to fail on Mac 10.11 bot on the waterfall; http://crbug.com/612640.
1547 TEST_F(BookmarkBarControllerTest, DISABLED_LastBookmarkResizeBehavior) {
1548 // Hide the apps shortcut.
1549 profile()->GetPrefs()->SetBoolean(
1550 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
1551 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1552
1553 // Add three buttons to the bookmark bar.
1554 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1555 const BookmarkNode* root = model->bookmark_bar_node();
1556 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1557 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1558 [bar_ frameDidChange];
1559
1560 // Step through simulated window resizings. In resizing from the first width
1561 // to the second, the bookmark bar should transition from displaying one
1562 // button to two. Of the next 5 widths, the third transitions the bar from
1563 // displaying two buttons to three. The next width (200.0) resizes the bar to
1564 // a large width that does not change the number of visible buttons, and the
1565 // remaining widths step through all the previous resizings in reverse, which
1566 // should correspond to the previous number of visible buttons.
1567 //
1568 // To recalibrate this test for new OS releases, etc., determine values for
1569 // |view_widths[1]| and |view_widths[4]| which will cause a visible button
1570 // transition from 1 -> 2 and 2 -> 3, respectively. With those two widths you
1571 // can easily compute all widths from 0 through 6. |view_widths[7]| is always
1572 // 200.0, and the remainder are the reverse of widths 0 through 6. When all
1573 // three buttons are visible, be sure to sanity check with frames (i.e. under
1574 // MD the first button should start at x=10, and there should be 16pt of space
1575 // between the buttons).
1576 //
1577 // The default font changed between OSX Mavericks, OSX Yosemite, and
1578 // OSX El Capitan, so this test requires different widths to trigger the
1579 // appropriate results.
1580 CGFloat view_widths_el_capitan[] =
1581 { 139.0, 140.0, 150.0, 151.0, 152.0, 153.0,
1582 154.0, 200.0, 154.0, 153.0, 152.0, 151.0,
1583 150.0, 140.0, 139.0 };
1584 CGFloat view_widths_yosemite[] =
1585 { 140.0, 141.0, 150.0, 151.0, 152.0, 153.0,
1586 154.0, 200.0, 154.0, 153.0, 152.0, 151.0,
1587 150.0, 141.0, 140.0 };
1588 CGFloat view_widths_rest[] =
1589 { 142.0, 143.0, 153.0, 154.0, 155.0, 156.0,
1590 157.0, 200.0, 157.0, 156.0, 155.0, 154.0,
1591 153.0, 143.0, 142.0 };
1592 CGFloat* view_widths = NULL;
1593 if (base::mac::IsOS10_11()) {
1594 view_widths = view_widths_el_capitan;
1595 } else if (base::mac::IsOS10_10()) {
1596 view_widths = view_widths_yosemite;
1597 } else {
1598 view_widths = view_widths_rest;
1599 }
1600
1601 BOOL off_the_side_button_is_hidden_results[] =
1602 { NO, NO, NO, NO, YES, YES, YES, YES, YES, YES, YES, NO, NO, NO, NO};
1603 int displayed_button_count_results[] =
1604 { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1 };
1605 for (unsigned int i = 0; i < arraysize(view_widths_yosemite); ++i) {
1606 NSRect frame = [[bar_ view] frame];
1607 frame.size.width = view_widths[i] + bookmarks::kBookmarkRightMargin;
1608 [[bar_ view] setFrame:frame];
1609 EXPECT_EQ(off_the_side_button_is_hidden_results[i],
1610 [bar_ offTheSideButtonIsHidden]);
1611 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]);
1612 }
1613 }
1614
1615 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) {
1616 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1617 const BookmarkNode* root = model->bookmark_bar_node();
1618 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1619 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1620 [bar_ frameDidChange];
1621
1622 // Apps page shortcut button should be visible.
1623 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
1624
1625 // Bookmarks should be to the right of the Apps page shortcut button.
1626 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]);
1627 CGFloat right = apps_button_right;
1628 NSArray* buttons = [bar_ buttons];
1629 for (size_t i = 0; i < [buttons count]; ++i) {
1630 EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame]));
1631 right = NSMaxX([[buttons objectAtIndex:i] frame]);
1632 }
1633
1634 // Removing the Apps button should move every bookmark to the left.
1635 profile()->GetPrefs()->SetBoolean(
1636 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
1637 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1638 EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame]));
1639 for (size_t i = 1; i < [buttons count]; ++i) {
1640 EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]),
1641 NSMinX([[buttons objectAtIndex:i] frame]));
1642 }
1643 }
1644
1645 TEST_F(BookmarkBarControllerTest, BookmarksWithoutAppsPageShortcut) {
1646 // The no item containers should be to the right of the Apps button.
1647 ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
1648 CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]);
1649 EXPECT_LE(apps_button_right,
1650 NSMinX([[[bar_ buttonView] noItemTextfield] frame]));
1651 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]),
1652 NSMinX([[[bar_ buttonView] importBookmarksButton] frame]));
1653
1654 // Removing the Apps button should move the no item containers to the left.
1655 profile()->GetPrefs()->SetBoolean(
1656 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
1657 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1658 EXPECT_GT(apps_button_right,
1659 NSMinX([[[bar_ buttonView] noItemTextfield] frame]));
1660 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]),
1661 NSMinX([[[bar_ buttonView] importBookmarksButton] frame]));
1662 }
1663
1664 TEST_F(BookmarkBarControllerTest, ManagedShowAppsShortcutInBookmarksBar) {
1665 // By default the pref is not managed and the apps shortcut is shown.
1666 sync_preferences::TestingPrefServiceSyncable* prefs =
1667 profile()->GetTestingPrefService();
1668 EXPECT_FALSE(prefs->IsManagedPreference(
1669 bookmarks::prefs::kShowAppsShortcutInBookmarkBar));
1670 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
1671
1672 // Hide the apps shortcut by policy, via the managed pref.
1673 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
1674 base::MakeUnique<base::Value>(false));
1675 EXPECT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1676
1677 // And try showing it via policy too.
1678 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
1679 base::MakeUnique<base::Value>(true));
1680 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
1681 }
1682
1683 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { 1669 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest {
1684 public: 1670 public:
1685 void SetUp() override { 1671 void SetUp() override {
1686 BookmarkBarControllerTest::SetUp(); 1672 BookmarkBarControllerTest::SetUp();
1687 ASSERT_TRUE(profile()); 1673 ASSERT_TRUE(profile());
1688 1674
1689 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 1675 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
1690 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); 1676 NSRect parent_frame = NSMakeRect(0, 0, 800, 50);
1691 bar_.reset([[BookmarkBarControllerOpenAllPong alloc] 1677 bar_.reset([[BookmarkBarControllerOpenAllPong alloc]
1692 initWithBrowser:browser() 1678 initWithBrowser:browser()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 1742
1757 resizeDelegate_.reset([[ViewResizerPong alloc] init]); 1743 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
1758 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); 1744 NSRect parent_frame = NSMakeRect(0, 0, 800, 50);
1759 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); 1745 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]);
1760 [parent_view_ setHidden:YES]; 1746 [parent_view_ setHidden:YES];
1761 bar_.reset([[BookmarkBarControllerNotificationPong alloc] 1747 bar_.reset([[BookmarkBarControllerNotificationPong alloc]
1762 initWithBrowser:browser() 1748 initWithBrowser:browser()
1763 initialWidth:NSWidth(parent_frame) 1749 initialWidth:NSWidth(parent_frame)
1764 delegate:nil]); 1750 delegate:nil]);
1765 1751
1766 // Forces loading of the nib. 1752 // Loads the view
1767 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; 1753 [[bar_ controlledView] setResizeDelegate:resizeDelegate_];
1768 // Awkwardness to look like we've been installed. 1754 // Awkwardness to look like we've been installed.
1769 [parent_view_ addSubview:[bar_ view]]; 1755 [parent_view_ addSubview:[bar_ view]];
1770 NSRect frame = [[[bar_ view] superview] frame]; 1756 NSRect frame = [[[bar_ view] superview] frame];
1771 frame.origin.y = 100; 1757 frame.origin.y = 100;
1772 [[[bar_ view] superview] setFrame:frame]; 1758 [[[bar_ view] superview] setFrame:frame];
1773 1759
1774 // Do not add the bar to a window, yet. 1760 // Do not add the bar to a window, yet.
1775 } 1761 }
1776 1762
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " 1820 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] "
1835 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " 1821 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName "
1836 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " 1822 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName "
1837 "11bWithLongName 12bWithLongName 13b "); 1823 "11bWithLongName 12bWithLongName 13b ");
1838 bookmarks::test::AddNodesFromModelString(model, root, model_string); 1824 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1839 1825
1840 // Validate initial model. 1826 // Validate initial model.
1841 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); 1827 std::string actualModelString = bookmarks::test::ModelStringFromNode(root);
1842 EXPECT_EQ(model_string, actualModelString); 1828 EXPECT_EQ(model_string, actualModelString);
1843 1829
1844 // Insure that the off-the-side is not showing. 1830 // Ensure that the off-the-side button is showing.
1845 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); 1831 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
1832 ASSERT_TRUE(layout.IsOffTheSideButtonVisible());
1846 1833
1847 // Remember how many buttons are showing and are available. 1834 // Remember how many buttons are showing and are available.
1848 int oldDisplayedButtons = [bar_ displayedButtonCount]; 1835 int oldDisplayedButtons = layout.VisibleButtonCount();
1849 int oldChildCount = root->child_count(); 1836 int oldChildCount = root->child_count();
1850
1851 // Pop up the off-the-side menu. 1837 // Pop up the off-the-side menu.
1852 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; 1838 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton];
1853 ASSERT_TRUE(otsButton); 1839 ASSERT_TRUE(otsButton);
1854 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) 1840 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1855 withObject:otsButton]; 1841 withObject:otsButton];
1856 BookmarkBarFolderController* otsController = [bar_ folderController]; 1842 BookmarkBarFolderController* otsController = [bar_ folderController];
1857 EXPECT_TRUE(otsController); 1843 EXPECT_TRUE(otsController);
1858 NSWindow* toWindow = [otsController window]; 1844 NSWindow* toWindow = [otsController window];
1859 EXPECT_TRUE(toWindow); 1845 EXPECT_TRUE(toWindow);
1860 BookmarkButton* draggedButton = 1846 BookmarkButton* draggedButton =
1861 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; 1847 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"];
1862 ASSERT_TRUE(draggedButton); 1848 ASSERT_TRUE(draggedButton);
1863 int oldOTSCount = (int)[[otsController buttons] count]; 1849 int oldOTSCount = (int)[[otsController buttons] count];
1864 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); 1850 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons);
1865 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0]; 1851 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0];
1866 ASSERT_TRUE(targetButton); 1852 ASSERT_TRUE(targetButton);
1867 [otsController dragButton:draggedButton 1853 [otsController dragButton:draggedButton
1868 to:[targetButton center] 1854 to:[targetButton center]
1869 copy:YES]; 1855 copy:YES];
1856 // Close
1857 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1858 withObject:otsButton];
1859 // Open
1860 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1861 withObject:otsButton];
1862
1870 // There should still be the same number of buttons in the bar 1863 // There should still be the same number of buttons in the bar
1871 // and off-the-side should have one more. 1864 // and off-the-side should have one more.
1872 int newDisplayedButtons = [bar_ displayedButtonCount]; 1865 layout = [bar_ layoutFromCurrentState];
1866 int newDisplayedButtons = layout.VisibleButtonCount();
1873 int newChildCount = root->child_count(); 1867 int newChildCount = root->child_count();
1874 int newOTSCount = (int)[[otsController buttons] count]; 1868 int newOTSCount = (int)[[[bar_ folderController] buttons] count];
1875 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); 1869 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons);
1876 EXPECT_EQ(oldChildCount + 1, newChildCount); 1870 EXPECT_EQ(oldChildCount + 1, newChildCount);
1877 EXPECT_EQ(oldOTSCount + 1, newOTSCount); 1871 EXPECT_EQ(oldOTSCount + 1, newOTSCount);
1878 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); 1872 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons);
1879 } 1873 }
1880 1874
1881 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { 1875 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) {
1882 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 1876 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
1883 const BookmarkNode* root = model->bookmark_bar_node(); 1877 const BookmarkNode* root = model->bookmark_bar_node();
1884 const std::string model_string("1bWithLongName 2bWithLongName " 1878 const std::string model_string("1bWithLongName 2bWithLongName "
1885 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " 1879 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName "
1886 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " 1880 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName "
1887 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " 1881 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName "
1888 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " 1882 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName "
1889 "19bWithLongName 20bWithLongName "); 1883 "19bWithLongName 20bWithLongName ");
1890 bookmarks::test::AddNodesFromModelString(model, root, model_string); 1884 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1891 1885
1892 const BookmarkNode* other = model->other_node(); 1886 const BookmarkNode* other = model->other_node();
1893 const std::string other_string("1other 2other 3other "); 1887 const std::string other_string("1other 2other 3other ");
1894 bookmarks::test::AddNodesFromModelString(model, other, other_string); 1888 bookmarks::test::AddNodesFromModelString(model, other, other_string);
1895 1889
1896 // Validate initial model. 1890 // Validate initial model.
1897 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); 1891 std::string actualModelString = bookmarks::test::ModelStringFromNode(root);
1898 EXPECT_EQ(model_string, actualModelString); 1892 EXPECT_EQ(model_string, actualModelString);
1899 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other); 1893 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other);
1900 EXPECT_EQ(other_string, actualOtherString); 1894 EXPECT_EQ(other_string, actualOtherString);
1901 1895
1902 // Insure that the off-the-side is showing. 1896 // Ensure that the off-the-side button is showing.
1903 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); 1897 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState];
1898 ASSERT_TRUE(layout.IsOffTheSideButtonVisible());
1904 1899
1905 // Remember how many buttons are showing and are available. 1900 // Remember how many buttons are showing and are available.
1906 int oldDisplayedButtons = [bar_ displayedButtonCount]; 1901 int oldDisplayedButtons = layout.VisibleButtonCount();
1907 int oldRootCount = root->child_count(); 1902 int oldRootCount = root->child_count();
1908 int oldOtherCount = other->child_count(); 1903 int oldOtherCount = other->child_count();
1909 1904
1910 // Pop up the off-the-side menu. 1905 // Pop up the off-the-side menu.
1911 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; 1906 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton];
1912 ASSERT_TRUE(otsButton); 1907 ASSERT_TRUE(otsButton);
1913 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) 1908 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:)
1914 withObject:otsButton]; 1909 withObject:otsButton];
1915 BookmarkBarFolderController* otsController = [bar_ folderController]; 1910 BookmarkBarFolderController* otsController = [bar_ folderController];
1916 EXPECT_TRUE(otsController); 1911 EXPECT_TRUE(otsController);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 2040
2046 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { 2041 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) {
2047 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); 2042 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
2048 const BookmarkNode* root = model->bookmark_bar_node(); 2043 const BookmarkNode* root = model->bookmark_bar_node();
2049 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); 2044 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b ");
2050 bookmarks::test::AddNodesFromModelString(model, root, model_string); 2045 bookmarks::test::AddNodesFromModelString(model, root, model_string);
2051 2046
2052 // Hide the apps shortcut. 2047 // Hide the apps shortcut.
2053 profile()->GetPrefs()->SetBoolean( 2048 profile()->GetPrefs()->SetBoolean(
2054 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); 2049 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
2055 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); 2050 ASSERT_TRUE([[bar_ appsPageShortcutButton] isHidden]);
2056 2051
2057 // Validate initial model. 2052 // Validate initial model.
2058 std::string actualModel = bookmarks::test::ModelStringFromNode(root); 2053 std::string actualModel = bookmarks::test::ModelStringFromNode(root);
2059 EXPECT_EQ(model_string, actualModel); 2054 EXPECT_EQ(model_string, actualModel);
2060 2055
2061 // Test a series of points starting at the right edge of the bar. 2056 // Test a series of points starting at the right edge of the bar.
2062 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; 2057 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"];
2063 ASSERT_TRUE(targetButton); 2058 ASSERT_TRUE(targetButton);
2064 NSPoint targetPoint = [targetButton left]; 2059 NSPoint targetPoint = [targetButton left];
2065 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * 2060 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 *
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 "2f3b ] 4b "); 2148 "2f3b ] 4b ");
2154 actual = bookmarks::test::ModelStringFromNode(root); 2149 actual = bookmarks::test::ModelStringFromNode(root);
2155 EXPECT_EQ(expected, actual); 2150 EXPECT_EQ(expected, actual);
2156 2151
2157 // Verify that the other bookmark folder can't be deleted. 2152 // Verify that the other bookmark folder can't be deleted.
2158 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; 2153 BookmarkButton *otherButton = [bar_ otherBookmarksButton];
2159 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); 2154 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]);
2160 } 2155 }
2161 2156
2162 } // namespace 2157 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698