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 "chrome/browser/ui/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #import "base/memory/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/signin/fake_auth_status_provider.h" | 13 #include "chrome/browser/signin/fake_auth_status_provider.h" |
14 #include "chrome/browser/signin/fake_signin_manager.h" | 14 #include "chrome/browser/signin/fake_signin_manager.h" |
15 #include "chrome/browser/signin/signin_global_error.h" | 15 #include "chrome/browser/signin/signin_global_error.h" |
16 #include "chrome/browser/signin/signin_manager.h" | 16 #include "chrome/browser/signin/signin_manager.h" |
17 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #include "chrome/browser/signin/signin_manager_factory.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 EXPECT_GT(findBar_index, bookmark_index); | 634 EXPECT_GT(findBar_index, bookmark_index); |
635 } | 635 } |
636 | 636 |
637 // Tests that status bubble's base frame does move when devTools are docked. | 637 // Tests that status bubble's base frame does move when devTools are docked. |
638 TEST_F(BrowserWindowControllerTest, TestStatusBubblePositioning) { | 638 TEST_F(BrowserWindowControllerTest, TestStatusBubblePositioning) { |
639 ASSERT_EQ(1U, [[[controller_ devToolsView] subviews] count]); | 639 ASSERT_EQ(1U, [[[controller_ devToolsView] subviews] count]); |
640 | 640 |
641 NSPoint bubbleOrigin = [controller_ statusBubbleBaseFrame].origin; | 641 NSPoint bubbleOrigin = [controller_ statusBubbleBaseFrame].origin; |
642 | 642 |
643 // Add a fake subview to devToolsView to emulate docked devTools. | 643 // Add a fake subview to devToolsView to emulate docked devTools. |
644 scoped_nsobject<NSView> view( | 644 base::scoped_nsobject<NSView> view( |
645 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)]); | 645 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)]); |
646 [[controller_ devToolsView] addSubview:view]; | 646 [[controller_ devToolsView] addSubview:view]; |
647 [[controller_ devToolsView] adjustSubviews]; | 647 [[controller_ devToolsView] adjustSubviews]; |
648 | 648 |
649 NSPoint bubbleOriginWithDevTools = [controller_ statusBubbleBaseFrame].origin; | 649 NSPoint bubbleOriginWithDevTools = [controller_ statusBubbleBaseFrame].origin; |
650 | 650 |
651 // Make sure that status bubble frame is moved. | 651 // Make sure that status bubble frame is moved. |
652 EXPECT_FALSE(NSEqualPoints(bubbleOrigin, bubbleOriginWithDevTools)); | 652 EXPECT_FALSE(NSEqualPoints(bubbleOrigin, bubbleOriginWithDevTools)); |
653 } | 653 } |
654 | 654 |
655 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemNoErrors) { | 655 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemNoErrors) { |
656 scoped_nsobject<NSMenuItem> syncMenuItem( | 656 base::scoped_nsobject<NSMenuItem> syncMenuItem( |
657 [[NSMenuItem alloc] initWithTitle:@"" | 657 [[NSMenuItem alloc] initWithTitle:@"" |
658 action:@selector(commandDispatch) | 658 action:@selector(commandDispatch) |
659 keyEquivalent:@""]); | 659 keyEquivalent:@""]); |
660 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 660 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
661 | 661 |
662 NSString* startSignin = | 662 NSString* startSignin = |
663 l10n_util::GetNSStringFWithFixup( | 663 l10n_util::GetNSStringFWithFixup( |
664 IDS_SYNC_MENU_PRE_SYNCED_LABEL, | 664 IDS_SYNC_MENU_PRE_SYNCED_LABEL, |
665 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 665 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
666 | 666 |
(...skipping 23 matching lines...) Expand all Loading... |
690 ProfileSyncServiceFactory::GetForProfile(profile()); | 690 ProfileSyncServiceFactory::GetForProfile(profile()); |
691 sync->SetSyncSetupCompleted(); | 691 sync->SetSyncSetupCompleted(); |
692 [BrowserWindowController updateSigninItem:syncMenuItem | 692 [BrowserWindowController updateSigninItem:syncMenuItem |
693 shouldShow:YES | 693 shouldShow:YES |
694 currentProfile:profile()]; | 694 currentProfile:profile()]; |
695 EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]); | 695 EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]); |
696 EXPECT_FALSE([syncMenuItem isHidden]); | 696 EXPECT_FALSE([syncMenuItem isHidden]); |
697 } | 697 } |
698 | 698 |
699 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemAuthError) { | 699 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemAuthError) { |
700 scoped_nsobject<NSMenuItem> syncMenuItem( | 700 base::scoped_nsobject<NSMenuItem> syncMenuItem( |
701 [[NSMenuItem alloc] initWithTitle:@"" | 701 [[NSMenuItem alloc] initWithTitle:@"" |
702 action:@selector(commandDispatch) | 702 action:@selector(commandDispatch) |
703 keyEquivalent:@""]); | 703 keyEquivalent:@""]); |
704 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 704 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
705 | 705 |
706 // Now sign in. | 706 // Now sign in. |
707 std::string username = "foo@example.com"; | 707 std::string username = "foo@example.com"; |
708 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); | 708 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); |
709 signin->SetAuthenticatedUsername(username); | 709 signin->SetAuthenticatedUsername(username); |
710 ProfileSyncService* sync = | 710 ProfileSyncService* sync = |
(...skipping 10 matching lines...) Expand all Loading... |
721 NSString* authError = | 721 NSString* authError = |
722 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); | 722 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); |
723 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); | 723 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); |
724 EXPECT_FALSE([syncMenuItem isHidden]); | 724 EXPECT_FALSE([syncMenuItem isHidden]); |
725 | 725 |
726 } | 726 } |
727 | 727 |
728 // If there's a separator after the signin menu item, make sure it is hidden/ | 728 // If there's a separator after the signin menu item, make sure it is hidden/ |
729 // shown when the signin menu item is. | 729 // shown when the signin menu item is. |
730 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { | 730 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { |
731 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 731 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
732 NSMenuItem* signinMenuItem = | 732 NSMenuItem* signinMenuItem = |
733 [menu addItemWithTitle:@"" | 733 [menu addItemWithTitle:@"" |
734 action:@selector(commandDispatch) | 734 action:@selector(commandDispatch) |
735 keyEquivalent:@""]; | 735 keyEquivalent:@""]; |
736 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 736 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
737 NSMenuItem* followingSeparator = [NSMenuItem separatorItem]; | 737 NSMenuItem* followingSeparator = [NSMenuItem separatorItem]; |
738 [menu addItem:followingSeparator]; | 738 [menu addItem:followingSeparator]; |
739 [signinMenuItem setHidden:NO]; | 739 [signinMenuItem setHidden:NO]; |
740 [followingSeparator setHidden:NO]; | 740 [followingSeparator setHidden:NO]; |
741 | 741 |
(...skipping 10 matching lines...) Expand all Loading... |
752 currentProfile:profile()]; | 752 currentProfile:profile()]; |
753 | 753 |
754 EXPECT_FALSE([followingSeparator isEnabled]); | 754 EXPECT_FALSE([followingSeparator isEnabled]); |
755 EXPECT_FALSE([signinMenuItem isHidden]); | 755 EXPECT_FALSE([signinMenuItem isHidden]); |
756 EXPECT_FALSE([followingSeparator isHidden]); | 756 EXPECT_FALSE([followingSeparator isHidden]); |
757 } | 757 } |
758 | 758 |
759 // If there's a non-separator item after the signin menu item, it should not | 759 // If there's a non-separator item after the signin menu item, it should not |
760 // change state when the signin menu item is hidden/shown. | 760 // change state when the signin menu item is hidden/shown. |
761 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithNonSeparator) { | 761 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithNonSeparator) { |
762 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 762 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
763 NSMenuItem* signinMenuItem = | 763 NSMenuItem* signinMenuItem = |
764 [menu addItemWithTitle:@"" | 764 [menu addItemWithTitle:@"" |
765 action:@selector(commandDispatch) | 765 action:@selector(commandDispatch) |
766 keyEquivalent:@""]; | 766 keyEquivalent:@""]; |
767 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 767 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
768 NSMenuItem* followingNonSeparator = | 768 NSMenuItem* followingNonSeparator = |
769 [menu addItemWithTitle:@"" | 769 [menu addItemWithTitle:@"" |
770 action:@selector(commandDispatch) | 770 action:@selector(commandDispatch) |
771 keyEquivalent:@""]; | 771 keyEquivalent:@""]; |
772 [signinMenuItem setHidden:NO]; | 772 [signinMenuItem setHidden:NO]; |
(...skipping 29 matching lines...) Expand all Loading... |
802 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1) | 802 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1) |
803 toView:[contentView superview]]; | 803 toView:[contentView superview]]; |
804 | 804 |
805 EXPECT_TRUE([[contentView hitTest:point] isDescendantOf:bookmarkView]); | 805 EXPECT_TRUE([[contentView hitTest:point] isDescendantOf:bookmarkView]); |
806 } | 806 } |
807 | 807 |
808 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { | 808 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { |
809 @private | 809 @private |
810 // We release the window ourselves, so we don't have to rely on the unittest | 810 // We release the window ourselves, so we don't have to rely on the unittest |
811 // doing it for us. | 811 // doing it for us. |
812 scoped_nsobject<NSWindow> testFullscreenWindow_; | 812 base::scoped_nsobject<NSWindow> testFullscreenWindow_; |
813 } | 813 } |
814 @end | 814 @end |
815 | 815 |
816 class BrowserWindowFullScreenControllerTest : public CocoaProfileTest { | 816 class BrowserWindowFullScreenControllerTest : public CocoaProfileTest { |
817 public: | 817 public: |
818 virtual void SetUp() { | 818 virtual void SetUp() { |
819 CocoaProfileTest::SetUp(); | 819 CocoaProfileTest::SetUp(); |
820 ASSERT_TRUE(browser()); | 820 ASSERT_TRUE(browser()); |
821 | 821 |
822 controller_ = | 822 controller_ = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 testFullscreenWindow_.reset( | 899 testFullscreenWindow_.reset( |
900 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 900 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
901 styleMask:NSBorderlessWindowMask | 901 styleMask:NSBorderlessWindowMask |
902 backing:NSBackingStoreBuffered | 902 backing:NSBackingStoreBuffered |
903 defer:NO]); | 903 defer:NO]); |
904 return testFullscreenWindow_.get(); | 904 return testFullscreenWindow_.get(); |
905 } | 905 } |
906 @end | 906 @end |
907 | 907 |
908 /* TODO(???): test other methods of BrowserWindowController */ | 908 /* TODO(???): test other methods of BrowserWindowController */ |
OLD | NEW |