| 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 // Loads the view. | 316 // In OSX 10.10, the owner of a nib file is retain/autoreleased during the |
| 317 [[bar controlledView] setResizeDelegate:resizeDelegate_]; | 317 // initialization of the nib. Wrapping the nib loading in an |
| 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 } |
| 318 // Awkwardness to look like we've been installed. | 324 // Awkwardness to look like we've been installed. |
| 319 for (NSView* subView in [parent_view_ subviews]) | 325 for (NSView* subView in [parent_view_ subviews]) |
| 320 [subView removeFromSuperview]; | 326 [subView removeFromSuperview]; |
| 321 [parent_view_ addSubview:[bar view]]; | 327 [parent_view_ addSubview:[bar view]]; |
| 322 NSRect frame = [[[bar view] superview] frame]; | 328 NSRect frame = [[[bar view] superview] frame]; |
| 323 frame.origin.y = 100; | 329 frame.origin.y = 100; |
| 324 [[[bar view] superview] setFrame:frame]; | 330 [[[bar view] superview] setFrame:frame]; |
| 325 | 331 |
| 326 // Make sure it's on in a window so viewDidMoveToWindow is called | 332 // Make sure it's on in a window so viewDidMoveToWindow is called |
| 327 NSView* contentView = [test_window() contentView]; | 333 NSView* contentView = [test_window() contentView]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 355 // are no outstanding references to bar_, and that calling bar_.reset() will | 361 // are no outstanding references to bar_, and that calling bar_.reset() will |
| 356 // synchronously destroy bar_. | 362 // synchronously destroy bar_. |
| 357 base::RunLoop().RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
| 358 } | 364 } |
| 359 | 365 |
| 360 virtual void AddCommandLineSwitches() {} | 366 virtual void AddCommandLineSwitches() {} |
| 361 | 367 |
| 362 BookmarkBarControllerNoOpen* noOpenBar() { | 368 BookmarkBarControllerNoOpen* noOpenBar() { |
| 363 return (BookmarkBarControllerNoOpen*)bar_.get(); | 369 return (BookmarkBarControllerNoOpen*)bar_.get(); |
| 364 } | 370 } |
| 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 } | |
| 408 }; | 371 }; |
| 409 | 372 |
| 410 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) { | 373 TEST_F(BookmarkBarControllerTest, ShowWhenShowBookmarkBarTrue) { |
| 411 [bar_ updateState:BookmarkBar::SHOW | 374 [bar_ updateState:BookmarkBar::SHOW |
| 412 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 375 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
| 413 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]); | 376 EXPECT_TRUE([bar_ isInState:BookmarkBar::SHOW]); |
| 414 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]); | 377 EXPECT_FALSE([bar_ isInState:BookmarkBar::DETACHED]); |
| 415 EXPECT_TRUE([bar_ isVisible]); | 378 EXPECT_TRUE([bar_ isVisible]); |
| 416 EXPECT_FALSE([bar_ isAnimationRunning]); | 379 EXPECT_FALSE([bar_ isAnimationRunning]); |
| 417 EXPECT_FALSE([[bar_ view] isHidden]); | 380 EXPECT_FALSE([[bar_ view] isHidden]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 447 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { | 410 TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { |
| 448 [bar_ updateState:BookmarkBar::DETACHED | 411 [bar_ updateState:BookmarkBar::DETACHED |
| 449 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 412 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
| 450 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]); | 413 EXPECT_FALSE([bar_ isInState:BookmarkBar::SHOW]); |
| 451 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]); | 414 EXPECT_TRUE([bar_ isInState:BookmarkBar::DETACHED]); |
| 452 EXPECT_TRUE([bar_ isVisible]); | 415 EXPECT_TRUE([bar_ isVisible]); |
| 453 EXPECT_FALSE([bar_ isAnimationRunning]); | 416 EXPECT_FALSE([bar_ isAnimationRunning]); |
| 454 EXPECT_FALSE([[bar_ view] isHidden]); | 417 EXPECT_FALSE([[bar_ view] isHidden]); |
| 455 EXPECT_GT([resizeDelegate_ height], 0); | 418 EXPECT_GT([resizeDelegate_ height], 0); |
| 456 EXPECT_GT([[bar_ view] frame].size.height, 0); | 419 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 } |
| 457 } | 452 } |
| 458 | 453 |
| 459 // Test whether |-updateState:...| sets currentState as expected. Make | 454 // Test whether |-updateState:...| sets currentState as expected. Make |
| 460 // sure things don't crash. | 455 // sure things don't crash. |
| 461 TEST_F(BookmarkBarControllerTest, StateChanges) { | 456 TEST_F(BookmarkBarControllerTest, StateChanges) { |
| 462 // First, go in one-at-a-time cycle. | 457 // First, go in one-at-a-time cycle. |
| 463 [bar_ updateState:BookmarkBar::HIDDEN | 458 [bar_ updateState:BookmarkBar::HIDDEN |
| 464 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 459 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
| 465 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]); | 460 EXPECT_EQ(BookmarkBar::HIDDEN, [bar_ currentState]); |
| 466 EXPECT_FALSE([bar_ isVisible]); | 461 EXPECT_FALSE([bar_ isVisible]); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 InstallAndToggleBar(bar.get()); | 514 InstallAndToggleBar(bar.get()); |
| 520 | 515 |
| 521 // Send a frame did change notification for the pong's view. | 516 // Send a frame did change notification for the pong's view. |
| 522 [[NSNotificationCenter defaultCenter] | 517 [[NSNotificationCenter defaultCenter] |
| 523 postNotificationName:NSViewFrameDidChangeNotification | 518 postNotificationName:NSViewFrameDidChangeNotification |
| 524 object:[bar view]]; | 519 object:[bar view]]; |
| 525 | 520 |
| 526 EXPECT_GT([bar toggles], 0); | 521 EXPECT_GT([bar toggles], 0); |
| 527 } | 522 } |
| 528 | 523 |
| 529 TEST_F(BookmarkBarControllerTest, ApplyLayoutNoItemTextField) { | 524 // Confirm our "no items" container goes away when we add the 1st |
| 530 NSTextField* text_field = [[bar_ buttonView] noItemTextField]; | 525 // bookmark, and comes back when we delete the bookmark. |
| 526 TEST_F(BookmarkBarControllerTest, NoItemContainerGoesAway) { |
| 527 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 528 const BookmarkNode* bar = model->bookmark_bar_node(); |
| 531 | 529 |
| 532 bookmarks::BookmarkBarLayout layout = {}; | 530 [bar_ loaded:model]; |
| 533 layout.visible_elements |= bookmarks::kVisibleElementsMaskNoItemTextField; | 531 BookmarkBarView* view = [bar_ buttonView]; |
| 534 layout.no_item_textfield_offset = 10; | 532 DCHECK(view); |
| 535 layout.no_item_textfield_width = 20; | 533 NSView* noItemContainer = [view noItemContainer]; |
| 534 DCHECK(noItemContainer); |
| 536 | 535 |
| 537 VerifyViewLayout(text_field, layout, 10, 20, true); | 536 EXPECT_FALSE([noItemContainer isHidden]); |
| 538 } | 537 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), |
| 538 ASCIIToUTF16("title"), |
| 539 GURL("http://www.google.com")); |
| 540 EXPECT_TRUE([noItemContainer isHidden]); |
| 541 model->Remove(node); |
| 542 EXPECT_FALSE([noItemContainer isHidden]); |
| 539 | 543 |
| 540 TEST_F(BookmarkBarControllerTest, ApplyLayoutImportBookmarksButton) { | 544 // Now try it using a bookmark from the Other Bookmarks. |
| 541 NSButton* button = [[bar_ buttonView] importBookmarksButton]; | |
| 542 | |
| 543 bookmarks::BookmarkBarLayout layout = {}; | |
| 544 // This button never appears without the no item text field appearing, so | |
| 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(); | 545 const BookmarkNode* otherBookmarks = model->other_node(); |
| 773 model->AddURL(otherBookmarks, otherBookmarks->child_count(), | 546 node = model->AddURL(otherBookmarks, otherBookmarks->child_count(), |
| 774 ASCIIToUTF16("TheOther"), GURL("http://www.other.com")); | 547 ASCIIToUTF16("TheOther"), |
| 775 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | 548 GURL("http://www.other.com")); |
| 776 EXPECT_TRUE(layout.IsOtherBookmarksButtonVisible()); | 549 EXPECT_FALSE([noItemContainer isHidden]); |
| 777 EXPECT_EQ(layout.VisibleButtonCount(), 0U); | 550 // Move it from Other Bookmarks to the bar. |
| 778 EXPECT_GT(layout.other_bookmarks_button_offset, 0); | 551 model->Move(node, bar, 0); |
| 779 CGFloat offsetFromMaxX = | 552 EXPECT_TRUE([noItemContainer isHidden]); |
| 780 NSWidth([[bar_ view] frame]) - layout.other_bookmarks_button_offset; | 553 // Move it back to Other Bookmarks from the bar. |
| 781 // Resize the view and ensure the button stays pinned to the right edge. | 554 model->Move(node, otherBookmarks, 0); |
| 782 CGRect viewFrame = [[bar_ view] frame]; | 555 EXPECT_FALSE([noItemContainer isHidden]); |
| 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 | |
| 846 model->Remove(node); | |
| 847 layout = [bar_ layoutFromCurrentState]; | |
| 848 EXPECT_TRUE(layout.IsNoItemTextFieldVisible() && | |
| 849 layout.IsImportBookmarksButtonVisible()); | |
| 850 } | |
| 851 | |
| 852 TEST_F(BookmarkBarControllerTest, LayoutBookmarksResize) { | |
| 853 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
| 854 const BookmarkNode* barNode = model->bookmark_bar_node(); | |
| 855 for (int i = 0; i < 20; i++) { | |
| 856 model->AddURL(barNode, barNode->child_count(), ASCIIToUTF16("title"), | |
| 857 GURL("http://www.google.com")); | |
| 858 } | |
| 859 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | |
| 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); | |
| 916 } | 556 } |
| 917 | 557 |
| 918 // Confirm off the side button only enabled when reasonable. | 558 // Confirm off the side button only enabled when reasonable. |
| 919 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { | 559 TEST_F(BookmarkBarControllerTest, OffTheSideButtonHidden) { |
| 920 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 560 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 921 | 561 |
| 922 [bar_ loaded:model]; | 562 [bar_ loaded:model]; |
| 923 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); | 563 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
| 924 | 564 |
| 925 for (int i = 0; i < 2; i++) { | 565 for (int i = 0; i < 2; i++) { |
| 926 bookmarks::AddIfNotBookmarked( | 566 bookmarks::AddIfNotBookmarked( |
| 927 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); | 567 model, GURL("http://www.foo.com"), ASCIIToUTF16("small")); |
| 928 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); | 568 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
| 929 } | 569 } |
| 930 | 570 |
| 931 const BookmarkNode* parent = model->bookmark_bar_node(); | 571 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 932 for (int i = 0; i < 20; i++) { | 572 for (int i = 0; i < 20; i++) { |
| 933 model->AddURL(parent, parent->child_count(), | 573 model->AddURL(parent, parent->child_count(), |
| 934 ASCIIToUTF16("super duper wide title"), | 574 ASCIIToUTF16("super duper wide title"), |
| 935 GURL("http://superfriends.hall-of-justice.edu")); | 575 GURL("http://superfriends.hall-of-justice.edu")); |
| 936 } | 576 } |
| 937 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); | 577 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 938 | 578 |
| 939 // Open the "off the side" and start deleting nodes. Make sure | 579 // Open the "off the side" and start deleting nodes. Make sure |
| 940 // deletion of the last node in "off the side" causes the folder to | 580 // deletion of the last node in "off the side" causes the folder to |
| 941 // close. | 581 // close. |
| 942 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); | 582 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 943 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 583 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
| 944 // Open "off the side" menu. | 584 // Open "off the side" menu. |
| 945 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; | 585 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; |
| 946 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 586 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
| 947 EXPECT_TRUE(bbfc); | 587 EXPECT_TRUE(bbfc); |
| 948 [bbfc setIgnoreAnimations:YES]; | 588 [bbfc setIgnoreAnimations:YES]; |
| 949 while (!parent->empty()) { | 589 while (!parent->empty()) { |
| 950 // We've completed the job so we're done. | 590 // We've completed the job so we're done. |
| 951 if ([[bar_ offTheSideButton] isHidden]) | 591 if ([bar_ offTheSideButtonIsHidden]) |
| 952 break; | 592 break; |
| 953 // Delete the last button. | 593 // Delete the last button. |
| 954 model->Remove(parent->GetChild(parent->child_count() - 1)); | 594 model->Remove(parent->GetChild(parent->child_count() - 1)); |
| 955 // If last one make sure the menu is closed and the button is hidden. | 595 // If last one make sure the menu is closed and the button is hidden. |
| 956 // Else make sure menu stays open. | 596 // Else make sure menu stays open. |
| 957 if ([[bar_ offTheSideButton] isHidden]) { | 597 if ([bar_ offTheSideButtonIsHidden]) { |
| 958 EXPECT_FALSE([bar_ folderController]); | 598 EXPECT_FALSE([bar_ folderController]); |
| 959 } else { | 599 } else { |
| 960 EXPECT_TRUE([bar_ folderController]); | 600 EXPECT_TRUE([bar_ folderController]); |
| 961 } | 601 } |
| 962 } | 602 } |
| 963 } | 603 } |
| 964 | 604 |
| 965 // http://crbug.com/46175 is a crash when deleting bookmarks from the | 605 // http://crbug.com/46175 is a crash when deleting bookmarks from the |
| 966 // off-the-side menu while it is open. This test tries to bang hard | 606 // off-the-side menu while it is open. This test tries to bang hard |
| 967 // in this area to reproduce the crash. | 607 // in this area to reproduce the crash. |
| 968 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { | 608 TEST_F(BookmarkBarControllerTest, DeleteFromOffTheSideWhileItIsOpen) { |
| 969 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 609 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 970 [bar_ loaded:model]; | 610 [bar_ loaded:model]; |
| 971 | 611 |
| 972 // Add a lot of bookmarks (per the bug). | 612 // Add a lot of bookmarks (per the bug). |
| 973 const BookmarkNode* parent = model->bookmark_bar_node(); | 613 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 974 for (int i = 0; i < 100; i++) { | 614 for (int i = 0; i < 100; i++) { |
| 975 std::ostringstream title; | 615 std::ostringstream title; |
| 976 title << "super duper wide title " << i; | 616 title << "super duper wide title " << i; |
| 977 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), | 617 model->AddURL(parent, parent->child_count(), ASCIIToUTF16(title.str()), |
| 978 GURL("http://superfriends.hall-of-justice.edu")); | 618 GURL("http://superfriends.hall-of-justice.edu")); |
| 979 } | 619 } |
| 980 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); | 620 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 981 | 621 |
| 982 // Open "off the side" menu. | 622 // Open "off the side" menu. |
| 983 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 623 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
| 984 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; | 624 [bar_ openOffTheSideFolderFromButton:offTheSideButton]; |
| 985 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 625 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
| 986 EXPECT_TRUE(bbfc); | 626 EXPECT_TRUE(bbfc); |
| 987 [bbfc setIgnoreAnimations:YES]; | 627 [bbfc setIgnoreAnimations:YES]; |
| 988 | 628 |
| 989 // Start deleting items; try and delete randomish ones in case it | 629 // Start deleting items; try and delete randomish ones in case it |
| 990 // makes a difference. | 630 // makes a difference. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 [button setCell:cell.get()]; | 678 [button setCell:cell.get()]; |
| 1039 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; | 679 [cell setRepresentedObject:[NSValue valueWithPointer:node.get()]]; |
| 1040 | 680 |
| 1041 [bar_ openBookmark:button]; | 681 [bar_ openBookmark:button]; |
| 1042 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); | 682 EXPECT_EQ(noOpenBar()->urls_[0], node->url()); |
| 1043 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB); | 683 EXPECT_EQ(noOpenBar()->dispositions_[0], WindowOpenDisposition::CURRENT_TAB); |
| 1044 } | 684 } |
| 1045 | 685 |
| 1046 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { | 686 TEST_F(BookmarkBarControllerTest, TestAddRemoveAndClear) { |
| 1047 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 687 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 688 NSView* buttonView = [bar_ buttonView]; |
| 1048 EXPECT_EQ(0U, [[bar_ buttons] count]); | 689 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]); |
| 1049 | 696 |
| 1050 GURL gurl1("http://superfriends.hall-of-justice.edu"); | 697 GURL gurl1("http://superfriends.hall-of-justice.edu"); |
| 1051 // Short titles increase the chances of this test succeeding if the view is | 698 // Short titles increase the chances of this test succeeding if the view is |
| 1052 // narrow. | 699 // narrow. |
| 1053 // TODO(viettrungluu): make the test independent of window/view size, font | 700 // TODO(viettrungluu): make the test independent of window/view size, font |
| 1054 // metrics, button size and spacing, and everything else. | 701 // metrics, button size and spacing, and everything else. |
| 1055 base::string16 title1(ASCIIToUTF16("x")); | 702 base::string16 title1(ASCIIToUTF16("x")); |
| 1056 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 703 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
| 1057 EXPECT_EQ(1U, [[bar_ buttons] count]); | 704 EXPECT_EQ(1U, [[bar_ buttons] count]); |
| 705 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]); |
| 1058 | 706 |
| 1059 GURL gurl2("http://legion-of-doom.gov"); | 707 GURL gurl2("http://legion-of-doom.gov"); |
| 1060 base::string16 title2(ASCIIToUTF16("y")); | 708 base::string16 title2(ASCIIToUTF16("y")); |
| 1061 bookmarks::AddIfNotBookmarked(model, gurl2, title2); | 709 bookmarks::AddIfNotBookmarked(model, gurl2, title2); |
| 1062 EXPECT_EQ(2U, [[bar_ buttons] count]); | 710 EXPECT_EQ(2U, [[bar_ buttons] count]); |
| 711 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); |
| 1063 | 712 |
| 1064 for (int i = 0; i < 3; i++) { | 713 for (int i = 0; i < 3; i++) { |
| 1065 bookmarks::RemoveAllBookmarks(model, gurl2); | 714 bookmarks::RemoveAllBookmarks(model, gurl2); |
| 1066 EXPECT_EQ(1U, [[bar_ buttons] count]); | 715 EXPECT_EQ(1U, [[bar_ buttons] count]); |
| 716 EXPECT_EQ(1+initial_subview_count, [[buttonView subviews] count]); |
| 1067 | 717 |
| 1068 // and bring it back | 718 // and bring it back |
| 1069 bookmarks::AddIfNotBookmarked(model, gurl2, title2); | 719 bookmarks::AddIfNotBookmarked(model, gurl2, title2); |
| 1070 EXPECT_EQ(2U, [[bar_ buttons] count]); | 720 EXPECT_EQ(2U, [[bar_ buttons] count]); |
| 721 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); |
| 1071 } | 722 } |
| 1072 | 723 |
| 724 [bar_ clearBookmarkBar]; |
| 725 EXPECT_EQ(0U, [[bar_ buttons] count]); |
| 726 EXPECT_EQ(initial_subview_count, [[buttonView subviews] count]); |
| 727 |
| 1073 // Explicit test of loaded: since this is a convenient spot | 728 // Explicit test of loaded: since this is a convenient spot |
| 1074 [bar_ loaded:model]; | 729 [bar_ loaded:model]; |
| 1075 EXPECT_EQ(2U, [[bar_ buttons] count]); | 730 EXPECT_EQ(2U, [[bar_ buttons] count]); |
| 731 EXPECT_EQ(2+initial_subview_count, [[buttonView subviews] count]); |
| 1076 } | 732 } |
| 1077 | 733 |
| 1078 // Make sure we don't create too many buttons; we only really need | 734 // Make sure we don't create too many buttons; we only really need |
| 1079 // ones that will be visible. | 735 // ones that will be visible. |
| 1080 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { | 736 TEST_F(BookmarkBarControllerTest, TestButtonLimits) { |
| 1081 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 737 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1082 EXPECT_EQ(0U, [[bar_ buttons] count]); | 738 EXPECT_EQ(0U, [[bar_ buttons] count]); |
| 1083 // Add one; make sure we see it. | 739 // Add one; make sure we see it. |
| 1084 const BookmarkNode* parent = model->bookmark_bar_node(); | 740 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 1085 model->AddURL(parent, parent->child_count(), | 741 model->AddURL(parent, parent->child_count(), |
| 1086 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 742 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
| 1087 EXPECT_EQ(1U, [[bar_ buttons] count]); | 743 EXPECT_EQ(1U, [[bar_ buttons] count]); |
| 1088 | 744 |
| 1089 // Add 30 which we expect to be 'too many'. Make sure we don't see | 745 // Add 30 which we expect to be 'too many'. Make sure we don't see |
| 1090 // 30 buttons. | 746 // 30 buttons. |
| 1091 model->Remove(parent->GetChild(0)); | 747 model->Remove(parent->GetChild(0)); |
| 1092 EXPECT_EQ(0U, [[bar_ buttons] count]); | 748 EXPECT_EQ(0U, [[bar_ buttons] count]); |
| 1093 for (int i=0; i<30; i++) { | 749 for (int i=0; i<30; i++) { |
| 1094 model->AddURL(parent, parent->child_count(), | 750 model->AddURL(parent, parent->child_count(), |
| 1095 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 751 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
| 1096 } | 752 } |
| 1097 int count = [[bar_ buttons] count]; | 753 int count = [[bar_ buttons] count]; |
| 1098 EXPECT_LT(count, 30L); | 754 EXPECT_LT(count, 30L); |
| 1099 | 755 |
| 1100 // Add 10 more (to the front of the list so the on-screen buttons | 756 // Add 10 more (to the front of the list so the on-screen buttons |
| 1101 // would change) and make sure the count stays the same. | 757 // would change) and make sure the count stays the same. |
| 1102 for (int i=0; i<10; i++) { | 758 for (int i=0; i<10; i++) { |
| 1103 model->AddURL(parent, 0, // index is 0, so front, not end | 759 model->AddURL(parent, 0, /* index is 0, so front, not end */ |
| 1104 ASCIIToUTF16("title"), GURL("http://www.google.com")); | 760 ASCIIToUTF16("title"), GURL("http://www.google.com")); |
| 1105 } | 761 } |
| 1106 | 762 |
| 1107 // Finally, grow the view and make sure the button count goes up. | 763 // Finally, grow the view and make sure the button count goes up. |
| 1108 NSRect frame = [[bar_ view] frame]; | 764 NSRect frame = [[bar_ view] frame]; |
| 1109 frame.size.width += 600; | 765 frame.size.width += 600; |
| 1110 [[bar_ view] setFrame:frame]; | 766 [[bar_ view] setFrame:frame]; |
| 1111 int finalcount = [[bar_ buttons] count]; | 767 int finalcount = [[bar_ buttons] count]; |
| 1112 EXPECT_GT(finalcount, count); | 768 EXPECT_GT(finalcount, count); |
| 1113 } | 769 } |
| 1114 | 770 |
| 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 |
| 1115 // Test drawing, mostly to ensure nothing leaks or crashes. | 872 // Test drawing, mostly to ensure nothing leaks or crashes. |
| 1116 TEST_F(BookmarkBarControllerTest, Display) { | 873 TEST_F(BookmarkBarControllerTest, Display) { |
| 1117 [[bar_ view] display]; | 874 [[bar_ view] display]; |
| 1118 } | 875 } |
| 1119 | 876 |
| 1120 // Test that middle clicking on a bookmark button results in an open action, | 877 // Test that middle clicking on a bookmark button results in an open action, |
| 1121 // except for offTheSideButton, as it just opens its folder menu. | 878 // except for offTheSideButton, as it just opens its folder menu. |
| 1122 TEST_F(BookmarkBarControllerTest, MiddleClick) { | 879 TEST_F(BookmarkBarControllerTest, MiddleClick) { |
| 1123 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 880 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1124 GURL gurl1("http://www.google.com/"); | 881 GURL gurl1("http://www.google.com/"); |
| 1125 base::string16 title1(ASCIIToUTF16("x")); | 882 base::string16 title1(ASCIIToUTF16("x")); |
| 1126 bookmarks::AddIfNotBookmarked(model, gurl1, title1); | 883 bookmarks::AddIfNotBookmarked(model, gurl1, title1); |
| 1127 | 884 |
| 1128 EXPECT_EQ(1U, [[bar_ buttons] count]); | 885 EXPECT_EQ(1U, [[bar_ buttons] count]); |
| 1129 NSButton* first = [[bar_ buttons] objectAtIndex:0]; | 886 NSButton* first = [[bar_ buttons] objectAtIndex:0]; |
| 1130 EXPECT_TRUE(first); | 887 EXPECT_TRUE(first); |
| 1131 | 888 |
| 1132 [first otherMouseUp: | 889 [first otherMouseUp: |
| 1133 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 890 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
| 1134 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); | 891 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); |
| 1135 | 892 |
| 1136 // Test for offTheSideButton. | 893 // Test for offTheSideButton. |
| 1137 // Add more bookmarks so that offTheSideButton is visible. | 894 // Add more bookmarks so that offTheSideButton is visible. |
| 1138 const BookmarkNode* parent = model->bookmark_bar_node(); | 895 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 1139 for (int i = 0; i < 20; i++) { | 896 for (int i = 0; i < 20; i++) { |
| 1140 model->AddURL(parent, parent->child_count(), | 897 model->AddURL(parent, parent->child_count(), |
| 1141 ASCIIToUTF16("super duper wide title"), | 898 ASCIIToUTF16("super duper wide title"), |
| 1142 GURL("http://superfriends.hall-of-justice.edu")); | 899 GURL("http://superfriends.hall-of-justice.edu")); |
| 1143 } | 900 } |
| 901 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 1144 | 902 |
| 1145 NSButton* offTheSideButton = [bar_ offTheSideButton]; | 903 NSButton* offTheSideButton = [bar_ offTheSideButton]; |
| 1146 EXPECT_TRUE(offTheSideButton); | 904 EXPECT_TRUE(offTheSideButton); |
| 1147 EXPECT_FALSE([offTheSideButton isHidden]); | |
| 1148 [offTheSideButton otherMouseUp: | 905 [offTheSideButton otherMouseUp: |
| 1149 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 906 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
| 1150 | 907 |
| 1151 // Middle click on offTheSideButton should not open any bookmarks under it, | 908 // Middle click on offTheSideButton should not open any bookmarks under it, |
| 1152 // therefore urls size should still be 1. | 909 // therefore urls size should still be 1. |
| 1153 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); | 910 EXPECT_EQ(noOpenBar()->urls_.size(), 1U); |
| 1154 | 911 |
| 1155 // Check that folderController should not be NULL since offTheSideButton | 912 // Check that folderController should not be NULL since offTheSideButton |
| 1156 // folder is currently open. | 913 // folder is currently open. |
| 1157 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 914 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
| 1158 EXPECT_TRUE(bbfc); | 915 EXPECT_TRUE(bbfc); |
| 1159 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); | 916 EXPECT_TRUE([bbfc parentButton] == offTheSideButton); |
| 1160 | 917 |
| 1161 // Middle clicking again on it should close the folder. | 918 // Middle clicking again on it should close the folder. |
| 1162 [offTheSideButton otherMouseUp: | 919 [offTheSideButton otherMouseUp: |
| 1163 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; | 920 cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0)]; |
| 1164 bbfc = [bar_ folderController]; | 921 bbfc = [bar_ folderController]; |
| 1165 EXPECT_FALSE(bbfc); | 922 EXPECT_FALSE(bbfc); |
| 1166 } | 923 } |
| 1167 | 924 |
| 1168 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { | 925 TEST_F(BookmarkBarControllerTest, DisplaysHelpMessageOnEmpty) { |
| 1169 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 926 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1170 [bar_ loaded:model]; | 927 [bar_ loaded:model]; |
| 1171 EXPECT_FALSE([[[bar_ buttonView] noItemTextField] isHidden]); | 928 EXPECT_FALSE([[[bar_ buttonView] noItemContainer] isHidden]); |
| 1172 } | 929 } |
| 1173 | 930 |
| 1174 TEST_F(BookmarkBarControllerTest, DisplaysImportBookmarksButtonOnEmpty) { | 931 TEST_F(BookmarkBarControllerTest, HidesHelpMessageWithBookmark) { |
| 1175 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 932 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 |
| 1176 [bar_ loaded:model]; | 938 [bar_ loaded:model]; |
| 1177 EXPECT_FALSE([[[bar_ buttonView] importBookmarksButton] isHidden]); | 939 EXPECT_TRUE([[[bar_ buttonView] noItemContainer] isHidden]); |
| 1178 } | 940 } |
| 1179 | 941 |
| 1180 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { | 942 TEST_F(BookmarkBarControllerTest, BookmarkButtonSizing) { |
| 1181 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 943 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1182 | 944 |
| 1183 const BookmarkNode* parent = model->bookmark_bar_node(); | 945 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 1184 model->AddURL(parent, parent->child_count(), | 946 model->AddURL(parent, parent->child_count(), |
| 1185 ASCIIToUTF16("title"), GURL("http://one.com")); | 947 ASCIIToUTF16("title"), GURL("http://one.com")); |
| 1186 | 948 |
| 1187 [bar_ loaded:model]; | 949 [bar_ loaded:model]; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 BookmarkBarFolderController* newBBFC = [bar_ folderController]; | 1264 BookmarkBarFolderController* newBBFC = [bar_ folderController]; |
| 1503 EXPECT_TRUE(newBBFC); | 1265 EXPECT_TRUE(newBBFC); |
| 1504 EXPECT_NE(oldBBFC, newBBFC); | 1266 EXPECT_NE(oldBBFC, newBBFC); |
| 1505 } | 1267 } |
| 1506 | 1268 |
| 1507 // Make sure the "off the side" folder looks like a bookmark folder | 1269 // Make sure the "off the side" folder looks like a bookmark folder |
| 1508 // but only contains "off the side" items. | 1270 // but only contains "off the side" items. |
| 1509 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { | 1271 TEST_F(BookmarkBarControllerTest, OffTheSideFolder) { |
| 1510 | 1272 |
| 1511 // It starts hidden. | 1273 // It starts hidden. |
| 1512 EXPECT_TRUE([[bar_ offTheSideButton] isHidden]); | 1274 EXPECT_TRUE([bar_ offTheSideButtonIsHidden]); |
| 1513 | 1275 |
| 1514 // Create some buttons. | 1276 // Create some buttons. |
| 1515 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1277 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1516 const BookmarkNode* parent = model->bookmark_bar_node(); | 1278 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 1517 for (int x = 0; x < 30; x++) { | 1279 for (int x = 0; x < 30; x++) { |
| 1518 model->AddURL(parent, parent->child_count(), | 1280 model->AddURL(parent, parent->child_count(), |
| 1519 ASCIIToUTF16("medium-size-title"), | 1281 ASCIIToUTF16("medium-size-title"), |
| 1520 GURL("http://framma-lamma.com")); | 1282 GURL("http://framma-lamma.com")); |
| 1521 } | 1283 } |
| 1522 // Add a couple more so we can delete one and make sure its button goes away. | 1284 // Add a couple more so we can delete one and make sure its button goes away. |
| 1523 model->AddURL(parent, parent->child_count(), | 1285 model->AddURL(parent, parent->child_count(), |
| 1524 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); | 1286 ASCIIToUTF16("DELETE_ME"), GURL("http://ashton-tate.com")); |
| 1525 model->AddURL(parent, parent->child_count(), | 1287 model->AddURL(parent, parent->child_count(), |
| 1526 ASCIIToUTF16("medium-size-title"), | 1288 ASCIIToUTF16("medium-size-title"), |
| 1527 GURL("http://framma-lamma.com")); | 1289 GURL("http://framma-lamma.com")); |
| 1528 | 1290 |
| 1529 // Should no longer be hidden. | 1291 // Should no longer be hidden. |
| 1530 EXPECT_FALSE([[bar_ offTheSideButton] isHidden]); | 1292 EXPECT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 1531 | 1293 |
| 1532 // Open it; make sure we have a folder controller. | 1294 // Open it; make sure we have a folder controller. |
| 1533 EXPECT_FALSE([bar_ folderController]); | 1295 EXPECT_FALSE([bar_ folderController]); |
| 1534 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; | 1296 [bar_ openOffTheSideFolderFromButton:[bar_ offTheSideButton]]; |
| 1535 BookmarkBarFolderController* bbfc = [bar_ folderController]; | 1297 BookmarkBarFolderController* bbfc = [bar_ folderController]; |
| 1536 EXPECT_TRUE(bbfc); | 1298 EXPECT_TRUE(bbfc); |
| 1537 | 1299 |
| 1538 // Confirm the contents are only buttons which fell off the side by | 1300 // Confirm the contents are only buttons which fell off the side by |
| 1539 // making sure that none of the nodes in the off-the-side folder are | 1301 // making sure that none of the nodes in the off-the-side folder are |
| 1540 // found in bar buttons. Be careful since not all the bar buttons | 1302 // 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... |
| 1659 // Now that we've closed the bookmark bar (with animation) the folder menu | 1421 // Now that we've closed the bookmark bar (with animation) the folder menu |
| 1660 // should have been closed thus releasing the folderController. | 1422 // should have been closed thus releasing the folderController. |
| 1661 EXPECT_FALSE([bar_ folderController]); | 1423 EXPECT_FALSE([bar_ folderController]); |
| 1662 | 1424 |
| 1663 // Stop the pending animation to tear down cleanly. | 1425 // Stop the pending animation to tear down cleanly. |
| 1664 [bar_ updateState:BookmarkBar::DETACHED | 1426 [bar_ updateState:BookmarkBar::DETACHED |
| 1665 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; | 1427 changeType:BookmarkBar::DONT_ANIMATE_STATE_CHANGE]; |
| 1666 EXPECT_FALSE([bar_ isAnimationRunning]); | 1428 EXPECT_FALSE([bar_ isAnimationRunning]); |
| 1667 } | 1429 } |
| 1668 | 1430 |
| 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 |
| 1669 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { | 1683 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { |
| 1670 public: | 1684 public: |
| 1671 void SetUp() override { | 1685 void SetUp() override { |
| 1672 BookmarkBarControllerTest::SetUp(); | 1686 BookmarkBarControllerTest::SetUp(); |
| 1673 ASSERT_TRUE(profile()); | 1687 ASSERT_TRUE(profile()); |
| 1674 | 1688 |
| 1675 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 1689 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| 1676 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 1690 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
| 1677 bar_.reset([[BookmarkBarControllerOpenAllPong alloc] | 1691 bar_.reset([[BookmarkBarControllerOpenAllPong alloc] |
| 1678 initWithBrowser:browser() | 1692 initWithBrowser:browser() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 | 1756 |
| 1743 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 1757 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
| 1744 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 1758 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
| 1745 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); | 1759 parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]); |
| 1746 [parent_view_ setHidden:YES]; | 1760 [parent_view_ setHidden:YES]; |
| 1747 bar_.reset([[BookmarkBarControllerNotificationPong alloc] | 1761 bar_.reset([[BookmarkBarControllerNotificationPong alloc] |
| 1748 initWithBrowser:browser() | 1762 initWithBrowser:browser() |
| 1749 initialWidth:NSWidth(parent_frame) | 1763 initialWidth:NSWidth(parent_frame) |
| 1750 delegate:nil]); | 1764 delegate:nil]); |
| 1751 | 1765 |
| 1752 // Loads the view | 1766 // Forces loading of the nib. |
| 1753 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; | 1767 [[bar_ controlledView] setResizeDelegate:resizeDelegate_]; |
| 1754 // Awkwardness to look like we've been installed. | 1768 // Awkwardness to look like we've been installed. |
| 1755 [parent_view_ addSubview:[bar_ view]]; | 1769 [parent_view_ addSubview:[bar_ view]]; |
| 1756 NSRect frame = [[[bar_ view] superview] frame]; | 1770 NSRect frame = [[[bar_ view] superview] frame]; |
| 1757 frame.origin.y = 100; | 1771 frame.origin.y = 100; |
| 1758 [[[bar_ view] superview] setFrame:frame]; | 1772 [[[bar_ view] superview] setFrame:frame]; |
| 1759 | 1773 |
| 1760 // Do not add the bar to a window, yet. | 1774 // Do not add the bar to a window, yet. |
| 1761 } | 1775 } |
| 1762 | 1776 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " | 1834 "2f2f2bWithLongName 2f2f3bWithLongName 2f4b ] 2f3bWithLongName ] " |
| 1821 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1835 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
| 1822 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1836 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
| 1823 "11bWithLongName 12bWithLongName 13b "); | 1837 "11bWithLongName 12bWithLongName 13b "); |
| 1824 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1838 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
| 1825 | 1839 |
| 1826 // Validate initial model. | 1840 // Validate initial model. |
| 1827 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1841 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
| 1828 EXPECT_EQ(model_string, actualModelString); | 1842 EXPECT_EQ(model_string, actualModelString); |
| 1829 | 1843 |
| 1830 // Ensure that the off-the-side button is showing. | 1844 // Insure that the off-the-side is not showing. |
| 1831 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | 1845 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 1832 ASSERT_TRUE(layout.IsOffTheSideButtonVisible()); | |
| 1833 | 1846 |
| 1834 // Remember how many buttons are showing and are available. | 1847 // Remember how many buttons are showing and are available. |
| 1835 int oldDisplayedButtons = layout.VisibleButtonCount(); | 1848 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
| 1836 int oldChildCount = root->child_count(); | 1849 int oldChildCount = root->child_count(); |
| 1850 |
| 1837 // Pop up the off-the-side menu. | 1851 // Pop up the off-the-side menu. |
| 1838 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; | 1852 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; |
| 1839 ASSERT_TRUE(otsButton); | 1853 ASSERT_TRUE(otsButton); |
| 1840 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | 1854 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) |
| 1841 withObject:otsButton]; | 1855 withObject:otsButton]; |
| 1842 BookmarkBarFolderController* otsController = [bar_ folderController]; | 1856 BookmarkBarFolderController* otsController = [bar_ folderController]; |
| 1843 EXPECT_TRUE(otsController); | 1857 EXPECT_TRUE(otsController); |
| 1844 NSWindow* toWindow = [otsController window]; | 1858 NSWindow* toWindow = [otsController window]; |
| 1845 EXPECT_TRUE(toWindow); | 1859 EXPECT_TRUE(toWindow); |
| 1846 BookmarkButton* draggedButton = | 1860 BookmarkButton* draggedButton = |
| 1847 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; | 1861 [bar_ buttonWithTitleEqualTo:@"3bWithLongName"]; |
| 1848 ASSERT_TRUE(draggedButton); | 1862 ASSERT_TRUE(draggedButton); |
| 1849 int oldOTSCount = (int)[[otsController buttons] count]; | 1863 int oldOTSCount = (int)[[otsController buttons] count]; |
| 1850 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); | 1864 EXPECT_EQ(oldOTSCount, oldChildCount - oldDisplayedButtons); |
| 1851 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0]; | 1865 BookmarkButton* targetButton = [[otsController buttons] objectAtIndex:0]; |
| 1852 ASSERT_TRUE(targetButton); | 1866 ASSERT_TRUE(targetButton); |
| 1853 [otsController dragButton:draggedButton | 1867 [otsController dragButton:draggedButton |
| 1854 to:[targetButton center] | 1868 to:[targetButton center] |
| 1855 copy:YES]; | 1869 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 | |
| 1863 // There should still be the same number of buttons in the bar | 1870 // There should still be the same number of buttons in the bar |
| 1864 // and off-the-side should have one more. | 1871 // and off-the-side should have one more. |
| 1865 layout = [bar_ layoutFromCurrentState]; | 1872 int newDisplayedButtons = [bar_ displayedButtonCount]; |
| 1866 int newDisplayedButtons = layout.VisibleButtonCount(); | |
| 1867 int newChildCount = root->child_count(); | 1873 int newChildCount = root->child_count(); |
| 1868 int newOTSCount = (int)[[[bar_ folderController] buttons] count]; | 1874 int newOTSCount = (int)[[otsController buttons] count]; |
| 1869 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); | 1875 EXPECT_EQ(oldDisplayedButtons, newDisplayedButtons); |
| 1870 EXPECT_EQ(oldChildCount + 1, newChildCount); | 1876 EXPECT_EQ(oldChildCount + 1, newChildCount); |
| 1871 EXPECT_EQ(oldOTSCount + 1, newOTSCount); | 1877 EXPECT_EQ(oldOTSCount + 1, newOTSCount); |
| 1872 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); | 1878 EXPECT_EQ(newOTSCount, newChildCount - newDisplayedButtons); |
| 1873 } | 1879 } |
| 1874 | 1880 |
| 1875 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { | 1881 TEST_F(BookmarkBarControllerDragDropTest, DragOffTheSideToOther) { |
| 1876 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1882 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 1877 const BookmarkNode* root = model->bookmark_bar_node(); | 1883 const BookmarkNode* root = model->bookmark_bar_node(); |
| 1878 const std::string model_string("1bWithLongName 2bWithLongName " | 1884 const std::string model_string("1bWithLongName 2bWithLongName " |
| 1879 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " | 1885 "3bWithLongName 4bWithLongName 5bWithLongName 6bWithLongName " |
| 1880 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " | 1886 "7bWithLongName 8bWithLongName 9bWithLongName 10bWithLongName " |
| 1881 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " | 1887 "11bWithLongName 12bWithLongName 13bWithLongName 14bWithLongName " |
| 1882 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " | 1888 "15bWithLongName 16bWithLongName 17bWithLongName 18bWithLongName " |
| 1883 "19bWithLongName 20bWithLongName "); | 1889 "19bWithLongName 20bWithLongName "); |
| 1884 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 1890 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
| 1885 | 1891 |
| 1886 const BookmarkNode* other = model->other_node(); | 1892 const BookmarkNode* other = model->other_node(); |
| 1887 const std::string other_string("1other 2other 3other "); | 1893 const std::string other_string("1other 2other 3other "); |
| 1888 bookmarks::test::AddNodesFromModelString(model, other, other_string); | 1894 bookmarks::test::AddNodesFromModelString(model, other, other_string); |
| 1889 | 1895 |
| 1890 // Validate initial model. | 1896 // Validate initial model. |
| 1891 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); | 1897 std::string actualModelString = bookmarks::test::ModelStringFromNode(root); |
| 1892 EXPECT_EQ(model_string, actualModelString); | 1898 EXPECT_EQ(model_string, actualModelString); |
| 1893 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other); | 1899 std::string actualOtherString = bookmarks::test::ModelStringFromNode(other); |
| 1894 EXPECT_EQ(other_string, actualOtherString); | 1900 EXPECT_EQ(other_string, actualOtherString); |
| 1895 | 1901 |
| 1896 // Ensure that the off-the-side button is showing. | 1902 // Insure that the off-the-side is showing. |
| 1897 bookmarks::BookmarkBarLayout layout = [bar_ layoutFromCurrentState]; | 1903 ASSERT_FALSE([bar_ offTheSideButtonIsHidden]); |
| 1898 ASSERT_TRUE(layout.IsOffTheSideButtonVisible()); | |
| 1899 | 1904 |
| 1900 // Remember how many buttons are showing and are available. | 1905 // Remember how many buttons are showing and are available. |
| 1901 int oldDisplayedButtons = layout.VisibleButtonCount(); | 1906 int oldDisplayedButtons = [bar_ displayedButtonCount]; |
| 1902 int oldRootCount = root->child_count(); | 1907 int oldRootCount = root->child_count(); |
| 1903 int oldOtherCount = other->child_count(); | 1908 int oldOtherCount = other->child_count(); |
| 1904 | 1909 |
| 1905 // Pop up the off-the-side menu. | 1910 // Pop up the off-the-side menu. |
| 1906 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; | 1911 BookmarkButton* otsButton = (BookmarkButton*)[bar_ offTheSideButton]; |
| 1907 ASSERT_TRUE(otsButton); | 1912 ASSERT_TRUE(otsButton); |
| 1908 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) | 1913 [[otsButton target] performSelector:@selector(openOffTheSideFolderFromButton:) |
| 1909 withObject:otsButton]; | 1914 withObject:otsButton]; |
| 1910 BookmarkBarFolderController* otsController = [bar_ folderController]; | 1915 BookmarkBarFolderController* otsController = [bar_ folderController]; |
| 1911 EXPECT_TRUE(otsController); | 1916 EXPECT_TRUE(otsController); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2040 | 2045 |
| 2041 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { | 2046 TEST_F(BookmarkBarControllerDragDropTest, DropPositionIndicator) { |
| 2042 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 2047 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 2043 const BookmarkNode* root = model->bookmark_bar_node(); | 2048 const BookmarkNode* root = model->bookmark_bar_node(); |
| 2044 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); | 2049 const std::string model_string("1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b "); |
| 2045 bookmarks::test::AddNodesFromModelString(model, root, model_string); | 2050 bookmarks::test::AddNodesFromModelString(model, root, model_string); |
| 2046 | 2051 |
| 2047 // Hide the apps shortcut. | 2052 // Hide the apps shortcut. |
| 2048 profile()->GetPrefs()->SetBoolean( | 2053 profile()->GetPrefs()->SetBoolean( |
| 2049 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); | 2054 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); |
| 2050 ASSERT_TRUE([[bar_ appsPageShortcutButton] isHidden]); | 2055 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 2051 | 2056 |
| 2052 // Validate initial model. | 2057 // Validate initial model. |
| 2053 std::string actualModel = bookmarks::test::ModelStringFromNode(root); | 2058 std::string actualModel = bookmarks::test::ModelStringFromNode(root); |
| 2054 EXPECT_EQ(model_string, actualModel); | 2059 EXPECT_EQ(model_string, actualModel); |
| 2055 | 2060 |
| 2056 // Test a series of points starting at the right edge of the bar. | 2061 // Test a series of points starting at the right edge of the bar. |
| 2057 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 2062 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
| 2058 ASSERT_TRUE(targetButton); | 2063 ASSERT_TRUE(targetButton); |
| 2059 NSPoint targetPoint = [targetButton left]; | 2064 NSPoint targetPoint = [targetButton left]; |
| 2060 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * | 2065 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 "2f3b ] 4b "); | 2153 "2f3b ] 4b "); |
| 2149 actual = bookmarks::test::ModelStringFromNode(root); | 2154 actual = bookmarks::test::ModelStringFromNode(root); |
| 2150 EXPECT_EQ(expected, actual); | 2155 EXPECT_EQ(expected, actual); |
| 2151 | 2156 |
| 2152 // Verify that the other bookmark folder can't be deleted. | 2157 // Verify that the other bookmark folder can't be deleted. |
| 2153 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2158 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
| 2154 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2159 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
| 2155 } | 2160 } |
| 2156 | 2161 |
| 2157 } // namespace | 2162 } // namespace |
| OLD | NEW |