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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_unittest.mm

Issue 1041313003: MacViews: Remove BrowserWindowController dependency from AppController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@titlebar
Patch Set: Fix tests Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "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/mac/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"
12 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/signin/fake_signin_manager.h"
15 #include "chrome/browser/signin/signin_error_controller_factory.h"
16 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/sync/profile_sync_service_mock.h"
20 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
23 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 16 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
24 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 17 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
25 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 18 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
26 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
27 #include "chrome/browser/ui/host_desktop.h" 20 #include "chrome/browser/ui/host_desktop.h"
28 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/chromium_strings.h"
30 #include "chrome/grit/generated_resources.h"
31 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
32 #include "components/signin/core/browser/fake_auth_status_provider.h"
33 #include "components/signin/core/browser/signin_error_controller.h"
34 #include "components/signin/core/browser/signin_manager.h"
35 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
36 #include "content/public/test/test_utils.h" 24 #include "content/public/test/test_utils.h"
37 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/l10n/l10n_util_mac.h"
40 26
41 using ::testing::Return; 27 using ::testing::Return;
42 28
43 @interface BrowserWindowController (JustForTesting) 29 @interface BrowserWindowController (JustForTesting)
44 // Already defined in BWC. 30 // Already defined in BWC.
45 - (void)saveWindowPositionIfNeeded; 31 - (void)saveWindowPositionIfNeeded;
46 - (void)layoutSubviews; 32 - (void)layoutSubviews;
47 @end 33 @end
48 34
49 @interface BrowserWindowController (ExposedForTesting) 35 @interface BrowserWindowController (ExposedForTesting)
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 [subviews indexOfObject:[controller_ toolbarView]]; 656 [subviews indexOfObject:[controller_ toolbarView]];
671 EXPECT_NE(NSNotFound, toolbar_index); 657 EXPECT_NE(NSNotFound, toolbar_index);
672 NSUInteger bookmark_index = 658 NSUInteger bookmark_index =
673 [subviews indexOfObject:[controller_ bookmarkView]]; 659 [subviews indexOfObject:[controller_ bookmarkView]];
674 EXPECT_NE(NSNotFound, bookmark_index); 660 EXPECT_NE(NSNotFound, bookmark_index);
675 661
676 EXPECT_GT(findBar_index, toolbar_index); 662 EXPECT_GT(findBar_index, toolbar_index);
677 EXPECT_GT(findBar_index, bookmark_index); 663 EXPECT_GT(findBar_index, bookmark_index);
678 } 664 }
679 665
680 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemNoErrors) {
681 base::scoped_nsobject<NSMenuItem> syncMenuItem(
682 [[NSMenuItem alloc] initWithTitle:@""
683 action:@selector(commandDispatch)
684 keyEquivalent:@""]);
685 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
686
687 NSString* startSignin =
688 l10n_util::GetNSStringFWithFixup(
689 IDS_SYNC_MENU_PRE_SYNCED_LABEL,
690 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
691
692 // Make sure shouldShow parameter is obeyed, and we get the default
693 // label if not signed in.
694 [BrowserWindowController updateSigninItem:syncMenuItem
695 shouldShow:YES
696 currentProfile:profile()];
697
698 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]);
699 EXPECT_FALSE([syncMenuItem isHidden]);
700
701 [BrowserWindowController updateSigninItem:syncMenuItem
702 shouldShow:NO
703 currentProfile:profile()];
704 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]);
705 EXPECT_TRUE([syncMenuItem isHidden]);
706
707 // Now sign in.
708 std::string username = "foo@example.com";
709 NSString* alreadySignedIn =
710 l10n_util::GetNSStringFWithFixup(IDS_SYNC_MENU_SYNCED_LABEL,
711 base::UTF8ToUTF16(username));
712 SigninManager* signin = SigninManagerFactory::GetForProfile(profile());
713 signin->SetAuthenticatedUsername(username);
714 ProfileSyncService* sync =
715 ProfileSyncServiceFactory::GetForProfile(profile());
716 sync->SetSyncSetupCompleted();
717 [BrowserWindowController updateSigninItem:syncMenuItem
718 shouldShow:YES
719 currentProfile:profile()];
720 EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]);
721 EXPECT_FALSE([syncMenuItem isHidden]);
722 }
723
724 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemAuthError) {
725 base::scoped_nsobject<NSMenuItem> syncMenuItem(
726 [[NSMenuItem alloc] initWithTitle:@""
727 action:@selector(commandDispatch)
728 keyEquivalent:@""]);
729 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
730
731 // Now sign in.
732 std::string username = "foo@example.com";
733 SigninManager* signin = SigninManagerFactory::GetForProfile(profile());
734 signin->SetAuthenticatedUsername(username);
735 ProfileSyncService* sync =
736 ProfileSyncServiceFactory::GetForProfile(profile());
737 sync->SetSyncSetupCompleted();
738 // Force an auth error.
739 FakeAuthStatusProvider provider(
740 SigninErrorControllerFactory::GetForProfile(profile()));;
741 GoogleServiceAuthError error(
742 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
743 provider.SetAuthError("user@gmail.com", "user@gmail.com", error);
744 [BrowserWindowController updateSigninItem:syncMenuItem
745 shouldShow:YES
746 currentProfile:profile()];
747 NSString* authError =
748 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM);
749 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]);
750 EXPECT_FALSE([syncMenuItem isHidden]);
751
752 }
753
754 // If there's a separator after the signin menu item, make sure it is hidden/
755 // shown when the signin menu item is.
756 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) {
757 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
758 NSMenuItem* signinMenuItem =
759 [menu addItemWithTitle:@""
760 action:@selector(commandDispatch)
761 keyEquivalent:@""];
762 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP];
763 NSMenuItem* followingSeparator = [NSMenuItem separatorItem];
764 [menu addItem:followingSeparator];
765 [signinMenuItem setHidden:NO];
766 [followingSeparator setHidden:NO];
767
768 [BrowserWindowController updateSigninItem:signinMenuItem
769 shouldShow:NO
770 currentProfile:profile()];
771
772 EXPECT_FALSE([followingSeparator isEnabled]);
773 EXPECT_TRUE([signinMenuItem isHidden]);
774 EXPECT_TRUE([followingSeparator isHidden]);
775
776 [BrowserWindowController updateSigninItem:signinMenuItem
777 shouldShow:YES
778 currentProfile:profile()];
779
780 EXPECT_FALSE([followingSeparator isEnabled]);
781 EXPECT_FALSE([signinMenuItem isHidden]);
782 EXPECT_FALSE([followingSeparator isHidden]);
783 }
784
785 // If there's a non-separator item after the signin menu item, it should not
786 // change state when the signin menu item is hidden/shown.
787 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithNonSeparator) {
788 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
789 NSMenuItem* signinMenuItem =
790 [menu addItemWithTitle:@""
791 action:@selector(commandDispatch)
792 keyEquivalent:@""];
793 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP];
794 NSMenuItem* followingNonSeparator =
795 [menu addItemWithTitle:@""
796 action:@selector(commandDispatch)
797 keyEquivalent:@""];
798 [signinMenuItem setHidden:NO];
799 [followingNonSeparator setHidden:NO];
800
801 [BrowserWindowController updateSigninItem:signinMenuItem
802 shouldShow:NO
803 currentProfile:profile()];
804
805 EXPECT_TRUE([followingNonSeparator isEnabled]);
806 EXPECT_TRUE([signinMenuItem isHidden]);
807 EXPECT_FALSE([followingNonSeparator isHidden]);
808
809 [followingNonSeparator setHidden:YES];
810 [BrowserWindowController updateSigninItem:signinMenuItem
811 shouldShow:YES
812 currentProfile:profile()];
813
814 EXPECT_TRUE([followingNonSeparator isEnabled]);
815 EXPECT_FALSE([signinMenuItem isHidden]);
816 EXPECT_TRUE([followingNonSeparator isHidden]);
817 }
818
819 // Verify that hit testing works correctly when the bookmark bar overlaps 666 // Verify that hit testing works correctly when the bookmark bar overlaps
820 // web contents. 667 // web contents.
821 TEST_F(BrowserWindowControllerTest, BookmarkBarHitTest) { 668 TEST_F(BrowserWindowControllerTest, BookmarkBarHitTest) {
822 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); 669 profile()->GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
823 [controller_ browserWindow]->BookmarkBarStateChanged( 670 [controller_ browserWindow]->BookmarkBarStateChanged(
824 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 671 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
825 672
826 NSView* bookmarkView = [controller_ bookmarkView]; 673 NSView* bookmarkView = [controller_ bookmarkView];
827 NSView* contentView = [[controller_ window] contentView]; 674 NSView* contentView = [[controller_ window] contentView];
828 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1) 675 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 775 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
929 styleMask:NSBorderlessWindowMask 776 styleMask:NSBorderlessWindowMask
930 backing:NSBackingStoreBuffered 777 backing:NSBackingStoreBuffered
931 defer:NO]); 778 defer:NO]);
932 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; 779 [[testFullscreenWindow_ contentView] setWantsLayer:YES];
933 return testFullscreenWindow_.get(); 780 return testFullscreenWindow_.get();
934 } 781 }
935 @end 782 @end
936 783
937 /* TODO(???): test other methods of BrowserWindowController */ 784 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.mm ('k') | chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698