OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 } | |
371 }; | 376 }; |
372 | 377 |
373 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) { | 378 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) { |
374 [bar_ updateState:BookmarkBar::SHOW | 379 [bar_ updateState:BookmarkBar::SHOW |
375 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 380 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
376 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]); | 381 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]); |
377 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]); | 382 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]); |
378 EXPECT_TRUE([bar_ isVisible]); | 383 EXPECT_TRUE([bar_ isVisible]); |
379 EXPECT_FALSE([bar_ isAnimationRunning]); | 384 EXPECT_FALSE([bar_ isAnimationRunning]); |
380 EXPECT_FALSE([[bar_ view] isHidden]); | 385 EXPECT_FALSE([[bar_ view] isHidden]); |
(...skipping 29 matching lines...) Expand all Loading... | |
410 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { | 415 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { |
411 [bar_ updateState:BookmarkBar::DETACHED | 416 [bar_ updateState:BookmarkBar::DETACHED |
412 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 417 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
413 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]); | 418 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]); |
414 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]); | 419 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]); |
415 EXPECT_TRUE([bar_ isVisible]); | 420 EXPECT_TRUE([bar_ isVisible]); |
416 EXPECT_FALSE([bar_ isAnimationRunning]); | 421 EXPECT_FALSE([bar_ isAnimationRunning]); |
417 EXPECT_FALSE([[bar_ view] isHidden]); | 422 EXPECT_FALSE([[bar_ view] isHidden]); |
418 EXPECT_GT([resizeDelegate_ height], 0); | 423 EXPECT_GT([resizeDelegate_ height], 0); |
419 EXPECT_GT([[bar_ view] frame].size.height, 0); | 424 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 } | 425 } |
453 | 426 |
454 // Test whether |-updateState:...| sets currentState as expected. Make | 427 // Test whether |-updateState:...| sets currentState as expected. Make |
455 // sure things don't crash. | 428 // sure things don't crash. |
456 TEST_F(BookmarkBarControllerTest, StateChanges) { | 429 TEST_F(BookmarkBarControllerTest, StateChanges) { |
457 // First, go in one-at-a-time cycle. | 430 // First, go in one-at-a-time cycle. |
458 [bar_ updateState:BookmarkBar::HIDDEN | 431 [bar_ updateState:BookmarkBar::HIDDEN |
459 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 432 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
460 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]); | 433 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]); |
461 EXPECT_FALSE([bar_ isVisible]); | 434 EXPECT_FALSE([bar_ isVisible]); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 InstallAndToggleBar(bar.get()); | 487 InstallAndToggleBar(bar.get()); |
515 | 488 |
516 // Send a frame did change notification for the pong's view. | 489 // Send a frame did change notification for the pong's view. |
517 [[NSNotificationCenter defaultCenter] | 490 [[NSNotificationCenter defaultCenter] |
518 postNotificationName:NSViewFrameDidChangeNotification | 491 postNotificationName:NSViewFrameDidChangeNotification |
519 object:[bar view]]; | 492 object:[bar view]]; |
520 | 493 |
521 EXPECT_GT([bar toggles], 0); | 494 EXPECT_GT([bar toggles], 0); |
522 } | 495 } |
523 | 496 |
524 // Confirm our "no items" container goes away when we add the 1st | 497 TEST_F(BookmarkBarControllerTest, ApplyLayoutNoItemTextField) { |
525 // bookmark, and comes back when we delete the bookmark. | 498 bookmarks::BookmarkBarLayout layout = {}; |
526 TEST_F(BookmarkBarControllerTest, NoItemContainerGoesAway) { | 499 |
500 [bar_ applyLayout:layout animated:NO]; | |
501 NSTextField* textField = [[bar_ buttonView] noItemTextField]; | |
502 EXPECT_TRUE([textField isHidden]); | |
503 | |
504 layout.visible_elements |= bookmarks::kVisibleElementsMaskNoItemTextField; | |
505 layout.no_item_textfield_offset = 10; | |
506 layout.no_item_textfield_width = 20; | |
507 [bar_ applyLayout:layout animated:NO]; | |
508 EXPECT_FALSE([textField isHidden]); | |
509 EXPECT_CGFLOAT_EQ(NSMinX([textField frame]), 10); | |
510 EXPECT_CGFLOAT_EQ(NSWidth([textField frame]), 20); | |
511 } | |
512 | |
513 TEST_F(BookmarkBarControllerTest, ApplyLayoutImportBookmarksButton) { | |
514 bookmarks::BookmarkBarLayout layout = {}; | |
515 | |
516 [bar_ applyLayout:layout animated:NO]; | |
517 NSButton* button = [[bar_ buttonView] importBookmarksButton]; | |
518 EXPECT_TRUE([button isHidden]); | |
519 | |
520 // This button never appears without the no item text field appearing, so | |
521 // show that too. | |
522 layout.visible_elements |= bookmarks::kVisibleElementsMaskNoItemTextField; | |
523 layout.no_item_textfield_offset = 10; | |
524 layout.no_item_textfield_width = 20; | |
525 layout.visible_elements |= | |
526 bookmarks::kVisibleElementsMaskImportBookmarksButton; | |
527 layout.import_bookmarks_button_offset = 30; | |
528 layout.import_bookmarks_button_width = 40; | |
529 [bar_ applyLayout:layout animated:NO]; | |
530 EXPECT_FALSE([button isHidden]); | |
531 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 30); | |
532 EXPECT_CGFLOAT_EQ(NSWidth([button frame]), 40); | |
533 } | |
534 | |
535 TEST_F(BookmarkBarControllerTest, ApplyLayoutSupervisedButton) { | |
536 bookmarks::BookmarkBarLayout layout = {}; | |
537 | |
538 [bar_ applyLayout:layout animated:NO]; | |
539 NSButton* button = [bar_ supervisedBookmarksButton]; | |
540 EXPECT_TRUE([button isHidden]); | |
541 | |
542 layout.visible_elements |= | |
543 bookmarks::kVisibleElementsMaskSupervisedBookmarksButton; | |
544 layout.supervised_bookmarks_button_offset = 40; | |
545 [bar_ applyLayout:layout animated:NO]; | |
546 EXPECT_FALSE([button isHidden]); | |
547 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 40); | |
548 EXPECT_GT(NSWidth([button frame]), 0); | |
549 } | |
550 TEST_F(BookmarkBarControllerTest, ApplyLayoutManagedButton) { | |
551 bookmarks::BookmarkBarLayout layout = {}; | |
552 | |
553 [bar_ applyLayout:layout animated:NO]; | |
554 NSButton* button = [bar_ managedBookmarksButton]; | |
555 EXPECT_TRUE([button isHidden]); | |
556 | |
557 layout.visible_elements |= | |
558 bookmarks::kVisibleElementsMaskManagedBookmarksButton; | |
559 layout.managed_bookmarks_button_offset = 50; | |
560 [bar_ applyLayout:layout animated:NO]; | |
561 EXPECT_FALSE([button isHidden]); | |
562 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 50); | |
563 EXPECT_GT(NSWidth([button frame]), 0); | |
564 } | |
565 | |
566 TEST_F(BookmarkBarControllerTest, ApplyLayoutOffTheSideButton) { | |
567 bookmarks::BookmarkBarLayout layout = {}; | |
568 | |
569 [bar_ applyLayout:layout animated:NO]; | |
570 NSButton* button = [bar_ offTheSideButton]; | |
571 EXPECT_TRUE([button isHidden]); | |
572 | |
573 layout.visible_elements |= bookmarks::kVisibleElementsMaskOffTheSideButton; | |
574 layout.off_the_side_button_offset = 100; | |
575 [bar_ applyLayout:layout animated:NO]; | |
576 EXPECT_FALSE([button isHidden]); | |
577 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 100); | |
578 EXPECT_GT(NSWidth([button frame]), 0); | |
579 } | |
580 | |
581 TEST_F(BookmarkBarControllerTest, ApplyLayoutOtherBookmarksButton) { | |
582 bookmarks::BookmarkBarLayout layout = {}; | |
583 | |
584 [bar_ applyLayout:layout animated:NO]; | |
585 NSButton* button = [bar_ otherBookmarksButton]; | |
586 EXPECT_TRUE([button isHidden]); | |
587 | |
588 layout.visible_elements |= | |
589 bookmarks::kVisibleElementsMaskOtherBookmarksButton; | |
590 layout.other_bookmarks_button_offset = 110; | |
591 [bar_ applyLayout:layout animated:NO]; | |
592 EXPECT_FALSE([button isHidden]); | |
593 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 110); | |
594 EXPECT_GT(NSWidth([button frame]), 0); | |
595 } | |
596 | |
597 TEST_F(BookmarkBarControllerTest, ApplyLayoutAppsButton) { | |
598 bookmarks::BookmarkBarLayout layout = {}; | |
599 | |
600 [bar_ applyLayout:layout animated:NO]; | |
601 NSButton* button = [bar_ appsPageShortcutButton]; | |
602 EXPECT_TRUE([button isHidden]); | |
603 | |
604 layout.visible_elements |= bookmarks::kVisibleElementsMaskAppsButton; | |
605 layout.apps_button_offset = 5; | |
606 [bar_ applyLayout:layout animated:NO]; | |
607 EXPECT_FALSE([button isHidden]); | |
608 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), 5); | |
609 EXPECT_GT(NSWidth([button frame]), 0); | |
610 } | |
611 | |
612 TEST_F(BookmarkBarControllerTest, ApplyLayoutBookmarkButtons) { | |
613 // Add some bookmarks | |
527 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 614 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
528 const BookmarkNode* bar = model->bookmark_bar_node(); | 615 GURL gurls[] = { |
529 | 616 GURL("http://www.google.com/a"), GURL("http://www.google.com/b"), |
530 [bar_ loaded:model]; | 617 GURL("http://www.google.com/c"), GURL("http://www.google.com/d")}; |
531 BookmarkBarView* view = [bar_ buttonView]; | 618 |
532 DCHECK(view); | 619 base::string16 titles[] = {ASCIIToUTF16("a"), ASCIIToUTF16("b"), |
533 NSView* noItemContainer = [view noItemContainer]; | 620 ASCIIToUTF16("c"), ASCIIToUTF16("d")}; |
534 DCHECK(noItemContainer); | 621 for (size_t i = 0; i < arraysize(titles); i++) |
535 | 622 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); |
536 EXPECT_FALSE([noItemContainer isHidden]); | 623 |
537 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), | 624 // Apply an empty layout. This should clear the buttons. |
538 ASCIIToUTF16("title"), | 625 bookmarks::BookmarkBarLayout layout = {}; |
539 GURL("http://www.google.com")); | 626 [bar_ applyLayout:layout animated:NO]; |
540 EXPECT_TRUE([noItemContainer isHidden]); | 627 EXPECT_EQ([[bar_ buttons] count], 0U); |
628 | |
629 const BookmarkNode* parentNode = model->bookmark_bar_node(); | |
630 EXPECT_EQ(parentNode->child_count(), 4); | |
631 // Ask the layout to show the first 2 nodes | |
632 for (int i = 0; i < 3; i++) { | |
633 const BookmarkNode* node = parentNode->GetChild(i); | |
634 layout.button_offsets[node->id()] = | |
635 bookmarks::kDefaultBookmarkWidth * (i + 1); | |
636 } | |
637 [bar_ applyLayout:layout animated:NO]; | |
638 EXPECT_EQ([[bar_ buttons] count], 3U); | |
639 CGFloat lastMax = 0; | |
640 for (int i = 0; i < 3; i++) { | |
641 const BookmarkNode* node = parentNode->GetChild(i); | |
642 BookmarkButton* button = [[bar_ buttons] objectAtIndex:i]; | |
643 EXPECT_EQ([button bookmarkNode], node); | |
644 EXPECT_CGFLOAT_EQ(NSMinX([button frame]), | |
645 bookmarks::kDefaultBookmarkWidth * (i + 1)); | |
646 EXPECT_GT(NSWidth([button frame]), 0); | |
647 EXPECT_EQ([button superview], [bar_ buttonView]); | |
648 // Ensure buttons don't overlap. | |
649 EXPECT_GT(NSMinX([button frame]), lastMax); | |
650 lastMax = NSMaxX([button frame]); | |
651 } | |
652 VerifyButtonTitles(parentNode); | |
653 } | |
654 // TODO(lgrey): Add tests for RTL in a follow-up. | |
655 // crbug.com/648554 | |
656 | |
657 TEST_F(BookmarkBarControllerTest, LayoutNoBookmarks) { | |
658 // With no apps button, or managed/supervised buttons: | |
659 profile()->GetPrefs()->SetBoolean( | |
660 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | |
661 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
662 // Only the no item text field and import bookmarks button are showing. | |
663 EXPECT_EQ( | |
664 layout.visible_elements, | |
665 (unsigned int)(bookmarks::kVisibleElementsMaskImportBookmarksButton | | |
666 bookmarks::kVisibleElementsMaskNoItemTextField)); | |
667 | |
668 EXPECT_EQ(layout.VisibleButtonCount(), 0U); | |
669 | |
670 // The import bookmarks button is after the no item text field and they don't | |
671 // overlap | |
672 EXPECT_GT(layout.import_bookmarks_button_offset, | |
673 layout.no_item_textfield_offset + layout.no_item_textfield_width); | |
674 // And they both have a width | |
675 EXPECT_GT(layout.no_item_textfield_width, 0); | |
676 EXPECT_GT(layout.import_bookmarks_button_width, 0); | |
677 // And start at the correct offset | |
678 EXPECT_EQ(layout.no_item_textfield_offset, | |
679 bookmarks::kBookmarkLeftMargin + | |
680 bookmarks::kInitialNoItemTextFieldXOrigin); | |
681 // With apps button: | |
682 profile()->GetPrefs()->SetBoolean( | |
683 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, true); | |
684 layout = [bar_ layoutFromCurrentState]; | |
685 | |
686 // Only the apps button, no item text field and import bookmarks button are | |
687 // showing. | |
688 EXPECT_EQ( | |
689 layout.visible_elements, | |
690 (unsigned int)(bookmarks::kVisibleElementsMaskImportBookmarksButton | | |
691 bookmarks::kVisibleElementsMaskNoItemTextField | | |
692 bookmarks::kVisibleElementsMaskAppsButton)); | |
693 EXPECT_EQ(layout.VisibleButtonCount(), 0U); | |
694 // The no item text field is after the apps button | |
695 EXPECT_GT(layout.no_item_textfield_offset, layout.apps_button_offset); | |
696 | |
697 // And the apps button is at the correct offset | |
698 EXPECT_EQ(layout.apps_button_offset, bookmarks::kBookmarkLeftMargin); | |
699 | |
700 // TODO(lgrey): It seems prohibitively difficult/maybe impossible | |
701 // to test the managed/supervised buttons at this time. | |
702 } | |
703 | |
704 TEST_F(BookmarkBarControllerTest, LayoutManagedAppsButton) { | |
705 // By default the pref is not managed and the apps shortcut is shown. | |
706 sync_preferences::TestingPrefServiceSyncable* prefs = | |
707 profile()->GetTestingPrefService(); | |
708 EXPECT_FALSE(prefs->IsManagedPreference( | |
709 bookmarks::prefs::kShowAppsShortcutInBookmarkBar)); | |
710 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
711 EXPECT_TRUE(layout.IsAppsButtonVisible()); | |
712 | |
713 // Hide the apps shortcut by policy, via the managed pref. | |
714 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | |
715 base::MakeUnique<base::Value>(false)); | |
716 layout = [bar_ layoutFromCurrentState]; | |
717 EXPECT_FALSE(layout.IsAppsButtonVisible()); | |
718 | |
719 // And try showing it via policy too. | |
720 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | |
721 base::MakeUnique<base::Value>(true)); | |
722 layout = [bar_ layoutFromCurrentState]; | |
723 EXPECT_TRUE(layout.IsAppsButtonVisible()); | |
724 } | |
725 | |
726 TEST_F(BookmarkBarControllerTest, NoItemsResizing) { | |
727 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
728 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && | |
729 layout.IsImportBookmarksButtonVisible()); | |
730 CGFloat oldOffset = layout.import_bookmarks_button_offset; | |
731 CGFloat oldWidth = layout.import_bookmarks_button_width; | |
732 CGRect viewFrame = [[bar_ view] frame]; | |
733 CGFloat originalViewWidth = NSWidth(viewFrame); | |
734 // Assert that the import bookmarks button fits. | |
735 EXPECT_GT(originalViewWidth, oldOffset + oldWidth); | |
736 // Resize the view to cut the import bookmarks button in half. | |
737 viewFrame.size.width = oldOffset + oldWidth * 0.5; | |
738 [[bar_ view] setFrame:viewFrame]; | |
739 layout = [bar_ layoutFromCurrentState]; | |
740 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && | |
741 layout.IsImportBookmarksButtonVisible()); | |
742 EXPECT_CGFLOAT_EQ(layout.import_bookmarks_button_offset, oldOffset); | |
743 EXPECT_LT(layout.import_bookmarks_button_width, oldWidth); | |
744 // Resize the view to cut off the import bookmarks button entirely. | |
745 viewFrame.size.width = layout.import_bookmarks_button_offset - 1; | |
746 [[bar_ view] setFrame:viewFrame]; | |
747 layout = [bar_ layoutFromCurrentState]; | |
748 EXPECT_FALSE(layout.IsImportBookmarksButtonVisible()); | |
749 EXPECT_TRUE(layout.IsNoItemTextFieldVisible()); | |
750 // Now, cut the text field in half | |
751 oldOffset = layout.no_item_textfield_offset; | |
752 oldWidth = layout.no_item_textfield_width; | |
753 viewFrame.size.width = oldOffset + oldWidth * 0.5; | |
754 [[bar_ view] setFrame:viewFrame]; | |
755 layout = [bar_ layoutFromCurrentState]; | |
756 EXPECT_TRUE(layout.IsNoItemTextFieldVisible()); | |
757 EXPECT_CGFLOAT_EQ(layout.no_item_textfield_offset, oldOffset); | |
758 EXPECT_LT(layout.no_item_textfield_width, oldWidth); | |
759 // Make the view too small to fit either. | |
760 viewFrame.size.width = bookmarks::kBookmarkLeftMargin; | |
761 [[bar_ view] setFrame:viewFrame]; | |
762 layout = [bar_ layoutFromCurrentState]; | |
763 EXPECT_FALSE(layout.IsNoItemTextFieldVisible() || | |
764 layout.IsImportBookmarksButtonVisible()); | |
765 // Sanity check | |
766 viewFrame.size.width = originalViewWidth; | |
767 [[bar_ view] setFrame:viewFrame]; | |
768 layout = [bar_ layoutFromCurrentState]; | |
769 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && | |
770 layout.IsImportBookmarksButtonVisible()); | |
771 } | |
772 | |
773 TEST_F(BookmarkBarControllerTest, LayoutOtherBookmarks) { | |
774 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
775 const BookmarkNode* otherBookmarks = model->other_node(); | |
776 model->AddURL(otherBookmarks, otherBookmarks->child_count(), | |
777 ASCIIToUTF16("TheOther"), GURL("http://www.other.com")); | |
778 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
779 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible()); | |
780 EXPECT_EQ(layout.VisibleButtonCount(), 0U); | |
781 EXPECT_GT(layout.other_bookmarks_button_offset, 0); | |
782 CGFloat offsetFromMaxX = | |
783 NSWidth([[bar_ view] frame]) - layout.other_bookmarks_button_offset; | |
784 // Resize the view and ensure the button stays pinned to the right edge. | |
785 CGRect viewFrame = [[bar_ view] frame]; | |
786 // Half of the original size | |
787 viewFrame.size.width = std::ceil(NSWidth(viewFrame) * 0.5); | |
788 [[bar_ view] setFrame:viewFrame]; | |
789 layout = [bar_ layoutFromCurrentState]; | |
790 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible()); | |
791 EXPECT_GT(layout.other_bookmarks_button_offset, 0); | |
792 EXPECT_CGFLOAT_EQ(NSWidth(viewFrame) - layout.other_bookmarks_button_offset, | |
793 offsetFromMaxX); | |
794 // 150% of the original size | |
795 viewFrame.size.width = NSWidth(viewFrame) * 3; | |
796 [[bar_ view] setFrame:viewFrame]; | |
797 layout = [bar_ layoutFromCurrentState]; | |
798 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible()); | |
799 EXPECT_CGFLOAT_EQ(NSWidth(viewFrame) - layout.other_bookmarks_button_offset, | |
800 offsetFromMaxX); | |
801 } | |
802 | |
803 TEST_F(BookmarkBarControllerTest, LayoutBookmarks) { | |
804 // Apps button shows up by default, first test without it. | |
805 profile()->GetPrefs()->SetBoolean( | |
806 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | |
807 | |
808 // Add some bookmarks. | |
809 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
810 const BookmarkNode* barNode = model->bookmark_bar_node(); | |
811 GURL gurls[] = {GURL("http://www.google.com/a"), | |
812 GURL("http://www.google.com/b"), | |
813 GURL("http://www.google.com/c")}; | |
814 base::string16 titles[] = {ASCIIToUTF16("a"), ASCIIToUTF16("b"), | |
815 ASCIIToUTF16("c")}; | |
816 for (size_t i = 0; i < arraysize(titles); i++) | |
817 bookmarks::AddIfNotBookmarked(model, gurls[i], titles[i]); | |
818 | |
819 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
820 EXPECT_EQ(layout.VisibleButtonCount(), (size_t)barNode->child_count()); | |
821 EXPECT_FALSE(layout.IsOffTheSideButtonVisible()); | |
822 EXPECT_EQ(layout.button_offsets.size(), (size_t)barNode->child_count()); | |
823 EXPECT_EQ(layout.button_offsets[barNode->GetChild(0)->id()], | |
824 bookmarks::kBookmarkLeftMargin); | |
825 // Assert that the buttons are in order. | |
826 CGFloat lastOffset = 0; | |
827 for (int i = 0; i < barNode->child_count(); i++) { | |
828 CGFloat offset = layout.button_offsets[barNode->GetChild(i)->id()]; | |
829 EXPECT_GT(offset, lastOffset); | |
830 lastOffset = offset; | |
831 } | |
832 } | |
833 | |
834 TEST_F(BookmarkBarControllerTest, NoItemUIHiddenWithBookmarks) { | |
835 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
836 const BookmarkNode* barNode = model->bookmark_bar_node(); | |
837 | |
838 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
839 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && | |
840 layout.IsImportBookmarksButtonVisible()); | |
841 | |
842 const BookmarkNode* node = | |
843 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"), | |
844 GURL("http://www.google.com")); | |
845 layout = [bar_ layoutFromCurrentState]; | |
846 EXPECT_FALSE(layout.IsNoItemTextFieldVisible() || | |
847 layout.IsImportBookmarksButtonVisible()); | |
848 | |
541 model->Remove(node); | 849 model->Remove(node); |
542 EXPECT_FALSE([noItemContainer isHidden]); | 850 layout = [bar_ layoutFromCurrentState]; |
543 | 851 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && |
544 // Now try it using a bookmark from the Other Bookmarks. | 852 layout.IsImportBookmarksButtonVisible()); |
545 const BookmarkNode* otherBookmarks = model->other_node(); | 853 } |
546 node = model->AddURL(otherBookmarks, otherBookmarks->child_count(), | 854 |
547 ASCIIToUTF16("TheOther"), | 855 TEST_F(BookmarkBarControllerTest, LayoutBookmarksResize) { |
548 GURL("http://www.other.com")); | 856 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
549 EXPECT_FALSE([noItemContainer isHidden]); | 857 const BookmarkNode* barNode = model->bookmark_bar_node(); |
550 // Move it from Other Bookmarks to the bar. | 858 for (int i = 0; i < 20; i++) { |
551 model->Move(node, bar, 0); | 859 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"), |
552 EXPECT_TRUE([noItemContainer isHidden]); | 860 GURL("http://www.google.com")); |
553 // Move it back to Other Bookmarks from the bar. | 861 } |
554 model->Move(node, otherBookmarks, 0); | 862 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; |
555 EXPECT_FALSE([noItemContainer isHidden]); | 863 EXPECT_LT(layout.VisibleButtonCount(), 20U); |
864 size_t originalButtonCount = layout.VisibleButtonCount(); | |
865 EXPECT_TRUE(layout.IsOffTheSideButtonVisible()); | |
866 CGRect viewFrame = [[bar_ view] frame]; | |
867 viewFrame.size.width += 200; | |
868 [[bar_ view] setFrame:viewFrame]; | |
869 layout = [bar_ layoutFromCurrentState]; | |
870 EXPECT_GT(layout.VisibleButtonCount(), originalButtonCount); | |
871 viewFrame.size.width -= 400; | |
872 [[bar_ view] setFrame:viewFrame]; | |
873 layout = [bar_ layoutFromCurrentState]; | |
874 EXPECT_LT(layout.VisibleButtonCount(), originalButtonCount); | |
875 // NB: This part overlaps a little with |OffTheSideButtonHidden| | |
876 // but we just want to check the layout here, whereas that test | |
877 // ensures the folder is closed when the button goes away. | |
878 // Find the number of buttons at which the off-the-side button disappears. | |
879 EXPECT_TRUE(layout.IsOffTheSideButtonVisible()); | |
880 bool crossoverPointFound = false; | |
881 // Bound the number of iterations in case the button never | |
882 // disappears. | |
883 const int maxToRemove = 20; | |
884 for (int i = 0; i < maxToRemove; i++) { | |
885 if (!layout.IsOffTheSideButtonVisible()) { | |
886 crossoverPointFound = true; | |
887 break; | |
888 } | |
889 model->Remove(barNode->GetChild(barNode->child_count() - 1)); | |
890 layout = [bar_ layoutFromCurrentState]; | |
891 } | |
892 // Either something is broken, or the test needs to be redone. | |
893 ASSERT_TRUE(crossoverPointFound); | |
894 EXPECT_FALSE(layout.IsOffTheSideButtonVisible()); | |
895 // Add a button and ensure the off the side button appears again. | |
896 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"), | |
897 GURL("http://www.google.com")); | |
898 layout = [bar_ layoutFromCurrentState]; | |
899 EXPECT_TRUE(layout.IsOffTheSideButtonVisible()); | |
900 // If the off-the-side button is visible, this means we have more | |
901 // buttons than we can show, so adding another shouldn't increase | |
902 // the button count. | |
903 size_t buttonCountBeforeAdding = layout.VisibleButtonCount(); | |
904 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"), | |
905 GURL("http://www.google.com")); | |
906 layout = [bar_ layoutFromCurrentState]; | |
907 EXPECT_EQ(layout.VisibleButtonCount(), buttonCountBeforeAdding); | |
Avi (use Gerrit)
2017/04/26 20:25:42
You may want to space this out. At least a blank l
lgrey
2017/04/27 17:35:33
Done.
| |
556 } | 908 } |
557 | 909 |
558 // Confirm off the side button only enabled when reasonable. | 910 // Confirm off the side button only enabled when reasonable. |
559 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { | 911 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { |
560 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 912 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
561 | 913 |
562 [bar_ loaded:model]; | 914 [bar_ loaded:model]; |
563 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 915 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); |
564 | 916 |
565 for (int i = 0; i < 2; i++) { | 917 for (int i = 0; i < 2; i++) { |
566 bookmarks::AddIfNotBookmarked( | 918 bookmarks::AddIfNotBookmarked( |
567 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); | 919 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); |
568 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 920 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); |
569 } | 921 } |
570 | 922 |
571 const BookmarkNode* parent = model->bookmark_bar_node(); | 923 const BookmarkNode* parent = model->bookmark_bar_node(); |
572 for (int i = 0; i < 20; i++) { | 924 for (int i = 0; i < 20; i++) { |
573 model->AddURL(parent, parent->child_count(), | 925 model->AddURL(parent, parent->child_count(), |
574 ASCIIToUTF16("super duper wide title"), | 926 ASCIIToUTF16("super duper wide title"), |
575 GURL("http://superfriends.hall-of-justice.edu")); | 927 GURL("http://superfriends.hall-of-justice.edu")); |
576 } | 928 } |
577 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); | 929 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); |
578 | 930 |
579 // Open the "off the side" and start deleting nodes. Make sure | 931 // 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 | 932 // deletion of the last node in "off the side" causes the folder to |
581 // close. | 933 // close. |
582 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); | 934 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); |
583 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 935 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
584 // Open "off the side" menu. | 936 // Open "off the side" menu. |
585 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; | 937 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; |
586 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 938 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
587 EXPECT_TRUE(bbfc); | 939 EXPECT_TRUE(bbfc); |
588 [bbfc setIgnoreAnimations:YES]; | 940 [bbfc setIgnoreAnimations:YES]; |
589 while (!parent->empty()) { | 941 while (!parent->empty()) { |
590 // We've completed the job so we're done. | 942 // We've completed the job so we're done. |
591 if ([bar_ offTheSideButtonIsHidden]) | 943 if ([[bar_ offTheSideButton] isHidden]) |
592 break; | 944 break; |
593 // Delete the last button. | 945 // Delete the last button. |
594 model->Remove(parent->GetChild(parent->child_count() - 1)); | 946 model->Remove(parent->GetChild(parent->child_count() - 1)); |
595 // If last one make sure the menu is closed and the button is hidden. | 947 // If last one make sure the menu is closed and the button is hidden. |
596 // Else make sure menu stays open. | 948 // Else make sure menu stays open. |
597 if ([bar_ offTheSideButtonIsHidden]) { | 949 if ([[bar_ offTheSideButton] isHidden]) { |
598 EXPECT_FALSE([bar_ folderController]); | 950 EXPECT_FALSE([bar_ folderController]); |
599 } else { | 951 } else { |
600 EXPECT_TRUE([bar_ folderController]); | 952 EXPECT_TRUE([bar_ folderController]); |
601 } | 953 } |
602 } | 954 } |
603 } | 955 } |
604 | 956 |
605 // http://crbug.com/46175 is a crash when deleting bookmarks from the | 957 // 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 | 958 // off-the-side menu while it is open. This test tries to bang hard |
607 // in this area to reproduce the crash. | 959 // in this area to reproduce the crash. |
608 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { | 960 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { |
609 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 961 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
610 [bar_ loaded:model]; | 962 [bar_ loaded:model]; |
611 | 963 |
612 // Add a lot of bookmarks (per the bug). | 964 // Add a lot of bookmarks (per the bug). |
613 const BookmarkNode* parent = model->bookmark_bar_node(); | 965 const BookmarkNode* parent = model->bookmark_bar_node(); |
614 for (int i = 0; i < 100; i++) { | 966 for (int i = 0; i < 100; i++) { |
615 std::ostringstream title; | 967 std::ostringstream title; |
616 title << "super duper wide title " << i; | 968 title << "super duper wide title " << i; |
617 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), | 969 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), |
618 GURL("http://superfriends.hall-of-justice.edu")); | 970 GURL("http://superfriends.hall-of-justice.edu")); |
619 } | 971 } |
620 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); | 972 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); |
621 | 973 |
622 // Open "off the side" menu. | 974 // Open "off the side" menu. |
623 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 975 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
624 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; | 976 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; |
625 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 977 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
626 EXPECT_TRUE(bbfc); | 978 EXPECT_TRUE(bbfc); |
627 [bbfc setIgnoreAnimations:YES]; | 979 [bbfc setIgnoreAnimations:YES]; |
628 | 980 |
629 // Start deleting items; try and delete randomish ones in case it | 981 // Start deleting items; try and delete randomish ones in case it |
630 // makes a difference. | 982 // makes a difference. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 [button setCell:cell.get()]; | 1030 [button setCell:cell.get()]; |
679 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; | 1031 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; |
680 | 1032 |
681 [bar_ openBookmark:button]; | 1033 [bar_ openBookmark:button]; |
682 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); | 1034 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); |
683 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB); | 1035 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB); |
684 } | 1036 } |
685 | 1037 |
686 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { | 1038 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { |
687 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1039 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
688 NSView* buttonView = [bar_ buttonView]; | |
689 EXPECT_EQ(0U, [[bar_ buttons] count]); | 1040 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 | 1041 |
697 GURL gurl1("http://superfriends.hall-of-justice.edu"); | 1042 GURL gurl1("http://superfriends.hall-of-justice.edu"); |
698 // Short titles increase the chances of this test succeeding if the view is | 1043 // Short titles increase the chances of this test succeeding if the view is |
699 // narrow. | 1044 // narrow. |
700 // TODO(viettrungluu): make the test independent of window/view size, font | 1045 // TODO(viettrungluu): make the test independent of window/view size, font |
701 // metrics, button size and spacing, and everything else. | 1046 // metrics, button size and spacing, and everything else. |
702 base::string16 title1(ASCIIToUTF16("x")); | 1047 base::string16 title1(ASCIIToUTF16("x")); |
703 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 1048 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
704 EXPECT_EQ(1U, [[bar_ buttons] count]); | 1049 EXPECT_EQ(1U, [[bar_ buttons] count]); |
705 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]); | |
706 | 1050 |
707 GURL gurl2("http://legion-of-doom.gov"); | 1051 GURL gurl2("http://legion-of-doom.gov"); |
708 base::string16 title2(ASCIIToUTF16("y")); | 1052 base::string16 title2(ASCIIToUTF16("y")); |
709 bookmarks::AddIfNotBookmarked(model, gurl2, title2); | 1053 bookmarks::AddIfNotBookmarked(model, gurl2, title2); |
710 EXPECT_EQ(2U, [[bar_ buttons] count]); | 1054 EXPECT_EQ(2U, [[bar_ buttons] count]); |
711 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); | |
712 | 1055 |
713 for (int i = 0; i < 3; i++) { | 1056 for (int i = 0; i < 3; i++) { |
714 bookmarks::RemoveAllBookmarks(model, gurl2); | 1057 bookmarks::RemoveAllBookmarks(model, gurl2); |
715 EXPECT_EQ(1U, [[bar_ buttons] count]); | 1058 EXPECT_EQ(1U, [[bar_ buttons] count]); |
716 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]); | |
717 | 1059 |
718 // and bring it back | 1060 // and bring it back |
719 bookmarks::AddIfNotBookmarked(model, gurl2, title2); | 1061 bookmarks::AddIfNotBookmarked(model, gurl2, title2); |
720 EXPECT_EQ(2U, [[bar_ buttons] count]); | 1062 EXPECT_EQ(2U, [[bar_ buttons] count]); |
721 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); | |
722 } | 1063 } |
723 | 1064 |
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 | 1065 // Explicit test of loaded: since this is a convenient spot |
729 [bar_ loaded:model]; | 1066 [bar_ loaded:model]; |
730 EXPECT_EQ(2U, [[bar_ buttons] count]); | 1067 EXPECT_EQ(2U, [[bar_ buttons] count]); |
731 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); | |
732 } | 1068 } |
733 | 1069 |
734 // Make sure we don't create too many buttons; we only really need | 1070 // Make sure we don't create too many buttons; we only really need |
735 // ones that will be visible. | 1071 // ones that will be visible. |
736 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { | 1072 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { |
737 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1073 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
738 EXPECT_EQ(0U, [[bar_ buttons] count]); | 1074 EXPECT_EQ(0U, [[bar_ buttons] count]); |
739 // Add one; make sure we see it. | 1075 // Add one; make sure we see it. |
740 const BookmarkNode* parent = model->bookmark_bar_node(); | 1076 const BookmarkNode* parent = model->bookmark_bar_node(); |
741 model->AddURL(parent, parent->child_count(), | 1077 model->AddURL(parent, parent->child_count(), |
742 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 1078 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
743 EXPECT_EQ(1U, [[bar_ buttons] count]); | 1079 EXPECT_EQ(1U, [[bar_ buttons] count]); |
744 | 1080 |
745 // Add 30 which we expect to be 'too many'. Make sure we don't see | 1081 // Add 30 which we expect to be 'too many'. Make sure we don't see |
746 // 30 buttons. | 1082 // 30 buttons. |
747 model->Remove(parent->GetChild(0)); | 1083 model->Remove(parent->GetChild(0)); |
748 EXPECT_EQ(0U, [[bar_ buttons] count]); | 1084 EXPECT_EQ(0U, [[bar_ buttons] count]); |
749 for (int i=0; i<30; i++) { | 1085 for (int i=0; i<30; i++) { |
750 model->AddURL(parent, parent->child_count(), | 1086 model->AddURL(parent, parent->child_count(), |
751 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 1087 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
752 } | 1088 } |
753 int count = [[bar_ buttons] count]; | 1089 int count = [[bar_ buttons] count]; |
754 EXPECT_LT(count, 30L); | 1090 EXPECT_LT(count, 30L); |
755 | 1091 |
756 // Add 10 more (to the front of the list so the on-screen buttons | 1092 // 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. | 1093 // would change) and make sure the count stays the same. |
758 for (int i=0; i<10; i++) { | 1094 for (int i=0; i<10; i++) { |
759 model->AddURL(parent, 0, /* index is 0, so front, not end */ | 1095 model->AddURL(parent, 0, // index is 0, so front, not end |
760 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 1096 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
761 } | 1097 } |
762 | 1098 |
763 // Finally, grow the view and make sure the button count goes up. | 1099 // Finally, grow the view and make sure the button count goes up. |
764 NSRect frame = [[bar_ view] frame]; | 1100 NSRect frame = [[bar_ view] frame]; |
765 frame.size.width += 600; | 1101 frame.size.width += 600; |
766 [[bar_ view] setFrame:frame]; | 1102 [[bar_ view] setFrame:frame]; |
767 int finalcount = [[bar_ buttons] count]; | 1103 int finalcount = [[bar_ buttons] count]; |
768 EXPECT_GT(finalcount, count); | 1104 EXPECT_GT(finalcount, count); |
769 } | 1105 } |
770 | 1106 |
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. | 1107 // Test drawing, mostly to ensure nothing leaks or crashes. |
873 TEST_F(BookmarkBarControllerTest, Display) { | 1108 TEST_F(BookmarkBarControllerTest, Display) { |
874 [[bar_ view] display]; | 1109 [[bar_ view] display]; |
875 } | 1110 } |
876 | 1111 |
877 // Test that middle clicking on a bookmark button results in an open action, | 1112 // Test that middle clicking on a bookmark button results in an open action, |
878 // except for offTheSideButton, as it just opens its folder menu. | 1113 // except for offTheSideButton, as it just opens its folder menu. |
879 TEST_F(BookmarkBarControllerTest, MiddleClick) { | 1114 TEST_F(BookmarkBarControllerTest, MiddleClick) { |
880 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1115 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
881 GURL gurl1("http://www.google.com/"); | 1116 GURL gurl1("http://www.google.com/"); |
882 base::string16 title1(ASCIIToUTF16("x")); | 1117 base::string16 title1(ASCIIToUTF16("x")); |
883 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 1118 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
884 | 1119 |
885 EXPECT_EQ(1U, [[bar_ buttons] count]); | 1120 EXPECT_EQ(1U, [[bar_ buttons] count]); |
886 NSButton* first = [[bar_ buttons] objectAtIndex:0]; | 1121 NSButton* first = [[bar_ buttons] objectAtIndex:0]; |
887 EXPECT_TRUE(first); | 1122 EXPECT_TRUE(first); |
888 | 1123 |
889 [first otherMouseUp: | 1124 [first otherMouseUp: |
890 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 1125 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
891 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); | 1126 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); |
892 | 1127 |
893 // Test for offTheSideButton. | 1128 // Test for offTheSideButton. |
894 // Add more bookmarks so that offTheSideButton is visible. | 1129 // Add more bookmarks so that offTheSideButton is visible. |
895 const BookmarkNode* parent = model->bookmark_bar_node(); | 1130 const BookmarkNode* parent = model->bookmark_bar_node(); |
896 for (int i = 0; i < 20; i++) { | 1131 for (int i = 0; i < 20; i++) { |
897 model->AddURL(parent, parent->child_count(), | 1132 model->AddURL(parent, parent->child_count(), |
898 ASCIIToUTF16("super duper wide title"), | 1133 ASCIIToUTF16("super duper wide title"), |
899 GURL("http://superfriends.hall-of-justice.edu")); | 1134 GURL("http://superfriends.hall-of-justice.edu")); |
900 } | 1135 } |
901 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); | |
902 | 1136 |
903 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 1137 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
904 EXPECT_TRUE(offTheSideButton); | 1138 EXPECT_TRUE(offTheSideButton); |
1139 EXPECT_FALSE([offTheSideButton isHidden]); | |
905 [offTheSideButton otherMouseUp: | 1140 [offTheSideButton otherMouseUp: |
906 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 1141 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
907 | 1142 |
908 // Middle click on offTheSideButton should not open any bookmarks under it, | 1143 // Middle click on offTheSideButton should not open any bookmarks under it, |
909 // therefore urls size should still be 1. | 1144 // therefore urls size should still be 1. |
910 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); | 1145 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); |
911 | 1146 |
912 // Check that folderController should not be NULL since offTheSideButton | 1147 // Check that folderController should not be NULL since offTheSideButton |
913 // folder is currently open. | 1148 // folder is currently open. |
914 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 1149 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
915 EXPECT_TRUE(bbfc); | 1150 EXPECT_TRUE(bbfc); |
916 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); | 1151 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); |
917 | 1152 |
918 // Middle clicking again on it should close the folder. | 1153 // Middle clicking again on it should close the folder. |
919 [offTheSideButton otherMouseUp: | 1154 [offTheSideButton otherMouseUp: |
920 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 1155 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
921 bbfc = [bar_ folderController]; | 1156 bbfc = [bar_ folderController]; |
922 EXPECT_FALSE(bbfc); | 1157 EXPECT_FALSE(bbfc); |
923 } | 1158 } |
924 | 1159 |
925 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { | 1160 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { |
926 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1161 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
927 [bar_ loaded:model]; | 1162 [bar_ loaded:model]; |
928 EXPECT_FALSE([[[bar_ buttonView] noItemContainer] isHidden]); | 1163 EXPECT_FALSE([[[bar_ buttonView] noItemTextField] isHidden]); |
929 } | 1164 } |
930 | 1165 |
931 TEST_F(BookmarkBarControllerTest, HidesHelpMessageWithBookmark) { | 1166 TEST_F(BookmarkBarControllerTest, DisplaysImportBookmarksButtonOnEmpty) { |
932 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1167 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]; | 1168 [bar_ loaded:model]; |
939 EXPECT_TRUE([[[bar_ buttonView] noItemContainer] isHidden]); | 1169 EXPECT_FALSE([[[bar_ buttonView] importBookmarksButton] isHidden]); |
940 } | 1170 } |
941 | 1171 |
942 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { | 1172 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { |
943 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1173 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
944 | 1174 |
945 const BookmarkNode* parent = model->bookmark_bar_node(); | 1175 const BookmarkNode* parent = model->bookmark_bar_node(); |
946 model->AddURL(parent, parent->child_count(), | 1176 model->AddURL(parent, parent->child_count(), |
947 ASCIIToUTF16("title"), GURL("http://one.com")); | 1177 ASCIIToUTF16("title"), GURL("http://one.com")); |
948 | 1178 |
949 [bar_ loaded:model]; | 1179 [bar_ loaded:model]; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 BookmarkBarFolderController* newBBFC = [bar_ folderController]; | 1494 BookmarkBarFolderController* newBBFC = [bar_ folderController]; |
1265 EXPECT_TRUE(newBBFC); | 1495 EXPECT_TRUE(newBBFC); |
1266 EXPECT_NE(oldBBFC, newBBFC); | 1496 EXPECT_NE(oldBBFC, newBBFC); |
1267 } | 1497 } |
1268 | 1498 |
1269 // Make sure the "off the side" folder looks like a bookmark folder | 1499 // Make sure the "off the side" folder looks like a bookmark folder |
1270 // but only contains "off the side" items. | 1500 // but only contains "off the side" items. |
1271 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { | 1501 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { |
1272 | 1502 |
1273 // It starts hidden. | 1503 // It starts hidden. |
1274 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); | 1504 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); |
1275 | 1505 |
1276 // Create some buttons. | 1506 // Create some buttons. |
1277 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1507 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1278 const BookmarkNode* parent = model->bookmark_bar_node(); | 1508 const BookmarkNode* parent = model->bookmark_bar_node(); |
1279 for (int x = 0; x < 30; x++) { | 1509 for (int x = 0; x < 30; x++) { |
1280 model->AddURL(parent, parent->child_count(), | 1510 model->AddURL(parent, parent->child_count(), |
1281 ASCIIToUTF16("medium-size-title"), | 1511 ASCIIToUTF16("medium-size-title"), |
1282 GURL("http://framma-lamma.com")); | 1512 GURL("http://framma-lamma.com")); |
1283 } | 1513 } |
1284 // Add a couple more so we can delete one and make sure its button goes away. | 1514 // Add a couple more so we can delete one and make sure its button goes away. |
1285 model->AddURL(parent, parent->child_count(), | 1515 model->AddURL(parent, parent->child_count(), |
1286 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); | 1516 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); |
1287 model->AddURL(parent, parent->child_count(), | 1517 model->AddURL(parent, parent->child_count(), |
1288 ASCIIToUTF16("medium-size-title"), | 1518 ASCIIToUTF16("medium-size-title"), |
1289 GURL("http://framma-lamma.com")); | 1519 GURL("http://framma-lamma.com")); |
1290 | 1520 |
1291 // Should no longer be hidden. | 1521 // Should no longer be hidden. |
1292 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); | 1522 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); |
1293 | 1523 |
1294 // Open it; make sure we have a folder controller. | 1524 // Open it; make sure we have a folder controller. |
1295 EXPECT_FALSE([bar_ folderController]); | 1525 EXPECT_FALSE([bar_ folderController]); |
1296 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; | 1526 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; |
1297 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 1527 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
1298 EXPECT_TRUE(bbfc); | 1528 EXPECT_TRUE(bbfc); |
1299 | 1529 |
1300 // Confirm the contents are only buttons which fell off the side by | 1530 // 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 | 1531 // 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 | 1532 // found in bar buttons. Be careful since not all the bar buttons |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1421 // Now that we've closed the bookmark bar (with animation) the folder menu | 1651 // Now that we've closed the bookmark bar (with animation) the folder menu |
1422 // should have been closed thus releasing the folderController. | 1652 // should have been closed thus releasing the folderController. |
1423 EXPECT_FALSE([bar_ folderController]); | 1653 EXPECT_FALSE([bar_ folderController]); |
1424 | 1654 |
1425 // Stop the pending animation to tear down cleanly. | 1655 // Stop the pending animation to tear down cleanly. |
1426 [bar_ updateState:BookmarkBar::DETACHED | 1656 [bar_ updateState:BookmarkBar::DETACHED |
1427 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 1657 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
1428 EXPECT_FALSE([bar_ isAnimationRunning]); | 1658 EXPECT_FALSE([bar_ isAnimationRunning]); |
1429 } | 1659 } |
1430 | 1660 |
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 { | 1661 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { |
1684 public: | 1662 public: |
1685 void SetUp() override { | 1663 void SetUp() override { |
1686 BookmarkBarControllerTest::SetUp(); | 1664 BookmarkBarControllerTest::SetUp(); |
1687 ASSERT_TRUE(profile()); | 1665 ASSERT_TRUE(profile()); |
1688 | 1666 |
1689 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 1667 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
1690 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 1668 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
1691 bar_.reset([[BookmarkBarControllerOpenAllPong alloc] | 1669 bar_.reset([[BookmarkBarControllerOpenAllPong alloc] |
1692 initWithBrowser:browser() | 1670 initWithBrowser:browser() |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1756 | 1734 |
1757 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 1735 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
1758 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 1736 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
1759 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); | 1737 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); |
1760 [parent_view_ setHidden:YES]; | 1738 [parent_view_ setHidden:YES]; |
1761 bar_.reset([[BookmarkBarControllerNotificationPong alloc] | 1739 bar_.reset([[BookmarkBarControllerNotificationPong alloc] |
1762 initWithBrowser:browser() | 1740 initWithBrowser:browser() |
1763 initialWidth:NSWidth(parent_frame) | 1741 initialWidth:NSWidth(parent_frame) |
1764 delegate:nil]); | 1742 delegate:nil]); |
1765 | 1743 |
1766 // Forces loading of the nib. | 1744 // Loads the view |
1767 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; | 1745 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; |
1768 // Awkwardness to look like we've been installed. | 1746 // Awkwardness to look like we've been installed. |
1769 [parent_view_ addSubview:[bar_ view]]; | 1747 [parent_view_ addSubview:[bar_ view]]; |
1770 NSRect frame = [[[bar_ view] superview] frame]; | 1748 NSRect frame = [[[bar_ view] superview] frame]; |
1771 frame.origin.y = 100; | 1749 frame.origin.y = 100; |
1772 [[[bar_ view] superview] setFrame:frame]; | 1750 [[[bar_ view] superview] setFrame:frame]; |
1773 | 1751 |
1774 // Do not add the bar to a window, yet. | 1752 // Do not add the bar to a window, yet. |
1775 } | 1753 } |
1776 | 1754 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1834 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " | 1812 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " |
1835 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1813 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1836 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1814 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1837 "11bWithLongName 12bWithLongName 13b "); | 1815 "11bWithLongName 12bWithLongName 13b "); |
1838 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1816 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1839 | 1817 |
1840 // Validate initial model. | 1818 // Validate initial model. |
1841 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1819 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
1842 EXPECT_EQ(model_string, actualModelString); | 1820 EXPECT_EQ(model_string, actualModelString); |
1843 | 1821 |
1844 // Insure that the off-the-side is not showing. | 1822 // Ensure that the off-the-side button is showing. |
1845 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); | 1823 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; |
1824 ASSERT_TRUE(layout.IsOffTheSideButtonVisible()); | |
1846 | 1825 |
1847 // Remember how many buttons are showing and are available. | 1826 // Remember how many buttons are showing and are available. |
1848 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1827 int oldDisplayedButtons = layout.VisibleButtonCount(); |
1849 int oldChildCount = root->child_count(); | 1828 int oldChildCount = root->child_count(); |
1850 | |
1851 // Pop up the off-the-side menu. | 1829 // Pop up the off-the-side menu. |
1852 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; | 1830 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; |
1853 ASSERT_TRUE(otsButton); | 1831 ASSERT_TRUE(otsButton); |
1854 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | 1832 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) |
1855 withObject:otsButton]; | 1833 withObject:otsButton]; |
1856 BookmarkBarFolderController* otsController = [bar_ folderController]; | 1834 BookmarkBarFolderController* otsController = [bar_ folderController]; |
1857 EXPECT_TRUE(otsController); | 1835 EXPECT_TRUE(otsController); |
1858 NSWindow* toWindow = [otsController window]; | 1836 NSWindow* toWindow = [otsController window]; |
1859 EXPECT_TRUE(toWindow); | 1837 EXPECT_TRUE(toWindow); |
1860 BookmarkButton* draggedButton = | 1838 BookmarkButton* draggedButton = |
1861 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; | 1839 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; |
1862 ASSERT_TRUE(draggedButton); | 1840 ASSERT_TRUE(draggedButton); |
1863 int oldOTSCount = (int)[[otsController buttons] count]; | 1841 int oldOTSCount = (int)[[otsController buttons] count]; |
1864 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); | 1842 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); |
1865 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0]; | 1843 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0]; |
1866 ASSERT_TRUE(targetButton); | 1844 ASSERT_TRUE(targetButton); |
1867 [otsController dragButton:draggedButton | 1845 [otsController dragButton:draggedButton |
1868 to:[targetButton center] | 1846 to:[targetButton center] |
1869 copy:YES]; | 1847 copy:YES]; |
1848 // Close | |
1849 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | |
1850 withObject:otsButton]; | |
1851 // Open | |
1852 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | |
1853 withObject:otsButton]; | |
1854 | |
1870 // There should still be the same number of buttons in the bar | 1855 // There should still be the same number of buttons in the bar |
1871 // and off-the-side should have one more. | 1856 // and off-the-side should have one more. |
1872 int newDisplayedButtons = [bar_ displayedButtonCount]; | 1857 layout = [bar_ layoutFromCurrentState]; |
1858 int newDisplayedButtons = layout.VisibleButtonCount(); | |
1873 int newChildCount = root->child_count(); | 1859 int newChildCount = root->child_count(); |
1874 int newOTSCount = (int)[[otsController buttons] count]; | 1860 int newOTSCount = (int)[[[bar_ folderController] buttons] count]; |
1875 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); | 1861 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); |
1876 EXPECT_EQ(oldChildCount + 1, newChildCount); | 1862 EXPECT_EQ(oldChildCount + 1, newChildCount); |
1877 EXPECT_EQ(oldOTSCount + 1, newOTSCount); | 1863 EXPECT_EQ(oldOTSCount + 1, newOTSCount); |
1878 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); | 1864 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); |
1879 } | 1865 } |
1880 | 1866 |
1881 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { | 1867 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { |
1882 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1868 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1883 const BookmarkNode* root = model->bookmark_bar_node(); | 1869 const BookmarkNode* root = model->bookmark_bar_node(); |
1884 const std::string model_string("1bWithLongName 2bWithLongName " | 1870 const std::string model_string("1bWithLongName 2bWithLongName " |
1885 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1871 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
1886 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1872 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
1887 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " | 1873 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " |
1888 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " | 1874 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " |
1889 "19bWithLongName 20bWithLongName "); | 1875 "19bWithLongName 20bWithLongName "); |
1890 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1876 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
1891 | 1877 |
1892 const BookmarkNode* other = model->other_node(); | 1878 const BookmarkNode* other = model->other_node(); |
1893 const std::string other_string("1other 2other 3other "); | 1879 const std::string other_string("1other 2other 3other "); |
1894 bookmarks::test::AddNodesFromModelString(model, other, other_string); | 1880 bookmarks::test::AddNodesFromModelString(model, other, other_string); |
1895 | 1881 |
1896 // Validate initial model. | 1882 // Validate initial model. |
1897 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1883 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
1898 EXPECT_EQ(model_string, actualModelString); | 1884 EXPECT_EQ(model_string, actualModelString); |
1899 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other); | 1885 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other); |
1900 EXPECT_EQ(other_string, actualOtherString); | 1886 EXPECT_EQ(other_string, actualOtherString); |
1901 | 1887 |
1902 // Insure that the off-the-side is showing. | 1888 // Ensure that the off-the-side button is showing. |
1903 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); | 1889 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; |
1890 ASSERT_TRUE(layout.IsOffTheSideButtonVisible()); | |
1904 | 1891 |
1905 // Remember how many buttons are showing and are available. | 1892 // Remember how many buttons are showing and are available. |
1906 int oldDisplayedButtons = [bar_ displayedButtonCount]; | 1893 int oldDisplayedButtons = layout.VisibleButtonCount(); |
1907 int oldRootCount = root->child_count(); | 1894 int oldRootCount = root->child_count(); |
1908 int oldOtherCount = other->child_count(); | 1895 int oldOtherCount = other->child_count(); |
1909 | 1896 |
1910 // Pop up the off-the-side menu. | 1897 // Pop up the off-the-side menu. |
1911 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; | 1898 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; |
1912 ASSERT_TRUE(otsButton); | 1899 ASSERT_TRUE(otsButton); |
1913 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | 1900 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) |
1914 withObject:otsButton]; | 1901 withObject:otsButton]; |
1915 BookmarkBarFolderController* otsController = [bar_ folderController]; | 1902 BookmarkBarFolderController* otsController = [bar_ folderController]; |
1916 EXPECT_TRUE(otsController); | 1903 EXPECT_TRUE(otsController); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2045 | 2032 |
2046 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 2033 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
2047 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 2034 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2048 const BookmarkNode* root = model->bookmark_bar_node(); | 2035 const BookmarkNode* root = model->bookmark_bar_node(); |
2049 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 2036 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
2050 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2037 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
2051 | 2038 |
2052 // Hide the apps shortcut. | 2039 // Hide the apps shortcut. |
2053 profile()->GetPrefs()->SetBoolean( | 2040 profile()->GetPrefs()->SetBoolean( |
2054 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | 2041 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
2055 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 2042 ASSERT_TRUE([[bar_ appsPageShortcutButton] isHidden]); |
2056 | 2043 |
2057 // Validate initial model. | 2044 // Validate initial model. |
2058 std::string actualModel = bookmarks::test::ModelStringFromNode(root); | 2045 std::string actualModel = bookmarks::test::ModelStringFromNode(root); |
2059 EXPECT_EQ(model_string, actualModel); | 2046 EXPECT_EQ(model_string, actualModel); |
2060 | 2047 |
2061 // Test a series of points starting at the right edge of the bar. | 2048 // Test a series of points starting at the right edge of the bar. |
2062 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 2049 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
2063 ASSERT_TRUE(targetButton); | 2050 ASSERT_TRUE(targetButton); |
2064 NSPoint targetPoint = [targetButton left]; | 2051 NSPoint targetPoint = [targetButton left]; |
2065 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * | 2052 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2153 "2f3b ] 4b "); | 2140 "2f3b ] 4b "); |
2154 actual = bookmarks::test::ModelStringFromNode(root); | 2141 actual = bookmarks::test::ModelStringFromNode(root); |
2155 EXPECT_EQ(expected, actual); | 2142 EXPECT_EQ(expected, actual); |
2156 | 2143 |
2157 // Verify that the other bookmark folder can't be deleted. | 2144 // Verify that the other bookmark folder can't be deleted. |
2158 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2145 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
2159 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2146 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
2160 } | 2147 } |
2161 | 2148 |
2162 } // namespace | 2149 } // namespace |
OLD | NEW |