| 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/memory/scoped_nsobject.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/signin/fake_auth_status_provider.h" |
| 13 #include "chrome/browser/signin/signin_global_error.h" | 14 #include "chrome/browser/signin/signin_global_error.h" |
| 14 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 15 #include "chrome/browser/signin/signin_manager_fake.h" | 16 #include "chrome/browser/signin/signin_manager_fake.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 17 #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.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_mock.h" | 19 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/sync/sync_global_error.h" | 21 #include "chrome/browser/sync/sync_global_error.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 24 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 24 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 25 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 25 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 26 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/test/test_utils.h" | 31 #include "content/public/test/test_utils.h" |
| 31 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| 32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/l10n/l10n_util_mac.h" | 36 #include "ui/base/l10n/l10n_util_mac.h" |
| 36 | 37 |
| 37 using ::testing::Return; | 38 using ::testing::Return; |
| 38 | 39 |
| 39 namespace { | |
| 40 class FakeAuthStatusProvider : public SigninGlobalError::AuthStatusProvider { | |
| 41 public: | |
| 42 FakeAuthStatusProvider() : auth_error_(GoogleServiceAuthError::None()) {} | |
| 43 | |
| 44 // AuthStatusProvider implementation. | |
| 45 GoogleServiceAuthError GetAuthStatus() const OVERRIDE { return auth_error_; } | |
| 46 | |
| 47 void set_auth_error(const GoogleServiceAuthError& error) { | |
| 48 auth_error_ = error; | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 GoogleServiceAuthError auth_error_; | |
| 53 }; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 @interface BrowserWindowController (JustForTesting) | 40 @interface BrowserWindowController (JustForTesting) |
| 58 // Already defined in BWC. | 41 // Already defined in BWC. |
| 59 - (void)saveWindowPositionIfNeeded; | 42 - (void)saveWindowPositionIfNeeded; |
| 60 - (void)layoutSubviews; | 43 - (void)layoutSubviews; |
| 61 @end | 44 @end |
| 62 | 45 |
| 63 @interface BrowserWindowController (ExposedForTesting) | 46 @interface BrowserWindowController (ExposedForTesting) |
| 64 // Implementations are below. | 47 // Implementations are below. |
| 65 - (NSView*)infoBarContainerView; | 48 - (NSView*)infoBarContainerView; |
| 66 - (NSView*)toolbarView; | 49 - (NSView*)toolbarView; |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 698 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
| 716 | 699 |
| 717 // Now sign in. | 700 // Now sign in. |
| 718 std::string username = "foo@example.com"; | 701 std::string username = "foo@example.com"; |
| 719 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); | 702 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); |
| 720 signin->SetAuthenticatedUsername(username); | 703 signin->SetAuthenticatedUsername(username); |
| 721 ProfileSyncService* sync = | 704 ProfileSyncService* sync = |
| 722 ProfileSyncServiceFactory::GetForProfile(profile()); | 705 ProfileSyncServiceFactory::GetForProfile(profile()); |
| 723 sync->SetSyncSetupCompleted(); | 706 sync->SetSyncSetupCompleted(); |
| 724 // Force an auth error. | 707 // Force an auth error. |
| 725 FakeAuthStatusProvider provider; | 708 FakeAuthStatusProvider provider(signin->signin_global_error()); |
| 726 GoogleServiceAuthError error( | 709 GoogleServiceAuthError error( |
| 727 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 710 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 728 provider.set_auth_error(error); | 711 provider.set_auth_error(error); |
| 729 signin->signin_global_error()->AddProvider(&provider); | |
| 730 [BrowserWindowController updateSigninItem:syncMenuItem | 712 [BrowserWindowController updateSigninItem:syncMenuItem |
| 731 shouldShow:YES | 713 shouldShow:YES |
| 732 currentProfile:profile()]; | 714 currentProfile:profile()]; |
| 733 NSString* authError = | 715 NSString* authError = |
| 734 l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 716 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); |
| 735 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); | 717 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); |
| 736 EXPECT_FALSE([syncMenuItem isHidden]); | 718 EXPECT_FALSE([syncMenuItem isHidden]); |
| 737 | 719 |
| 738 signin->signin_global_error()->RemoveProvider(&provider); | |
| 739 } | 720 } |
| 740 | 721 |
| 741 // If there's a separator after the signin menu item, make sure it is hidden/ | 722 // If there's a separator after the signin menu item, make sure it is hidden/ |
| 742 // shown when the signin menu item is. | 723 // shown when the signin menu item is. |
| 743 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { | 724 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { |
| 744 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 725 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 745 NSMenuItem* signinMenuItem = | 726 NSMenuItem* signinMenuItem = |
| 746 [menu addItemWithTitle:@"" | 727 [menu addItemWithTitle:@"" |
| 747 action:@selector(commandDispatch) | 728 action:@selector(commandDispatch) |
| 748 keyEquivalent:@""]; | 729 keyEquivalent:@""]; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 testFullscreenWindow_.reset( | 878 testFullscreenWindow_.reset( |
| 898 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 879 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
| 899 styleMask:NSBorderlessWindowMask | 880 styleMask:NSBorderlessWindowMask |
| 900 backing:NSBackingStoreBuffered | 881 backing:NSBackingStoreBuffered |
| 901 defer:NO]); | 882 defer:NO]); |
| 902 return testFullscreenWindow_.get(); | 883 return testFullscreenWindow_.get(); |
| 903 } | 884 } |
| 904 @end | 885 @end |
| 905 | 886 |
| 906 /* TODO(???): test other methods of BrowserWindowController */ | 887 /* TODO(???): test other methods of BrowserWindowController */ |
| OLD | NEW |