| 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | 695 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
| 713 | 696 |
| 714 // Now sign in. | 697 // Now sign in. |
| 715 std::string username = "foo@example.com"; | 698 std::string username = "foo@example.com"; |
| 716 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); | 699 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); |
| 717 signin->SetAuthenticatedUsername(username); | 700 signin->SetAuthenticatedUsername(username); |
| 718 ProfileSyncService* sync = | 701 ProfileSyncService* sync = |
| 719 ProfileSyncServiceFactory::GetForProfile(profile()); | 702 ProfileSyncServiceFactory::GetForProfile(profile()); |
| 720 sync->SetSyncSetupCompleted(); | 703 sync->SetSyncSetupCompleted(); |
| 721 // Force an auth error. | 704 // Force an auth error. |
| 722 FakeAuthStatusProvider provider; | 705 FakeAuthStatusProvider provider(signin->signin_global_error()); |
| 723 GoogleServiceAuthError error( | 706 GoogleServiceAuthError error( |
| 724 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 707 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 725 provider.set_auth_error(error); | 708 provider.SetAuthError(error); |
| 726 signin->signin_global_error()->AddProvider(&provider); | |
| 727 [BrowserWindowController updateSigninItem:syncMenuItem | 709 [BrowserWindowController updateSigninItem:syncMenuItem |
| 728 shouldShow:YES | 710 shouldShow:YES |
| 729 currentProfile:profile()]; | 711 currentProfile:profile()]; |
| 730 NSString* authError = | 712 NSString* authError = |
| 731 l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 713 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); |
| 732 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); | 714 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); |
| 733 EXPECT_FALSE([syncMenuItem isHidden]); | 715 EXPECT_FALSE([syncMenuItem isHidden]); |
| 734 | 716 |
| 735 signin->signin_global_error()->RemoveProvider(&provider); | |
| 736 } | 717 } |
| 737 | 718 |
| 738 // If there's a separator after the signin menu item, make sure it is hidden/ | 719 // If there's a separator after the signin menu item, make sure it is hidden/ |
| 739 // shown when the signin menu item is. | 720 // shown when the signin menu item is. |
| 740 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { | 721 TEST_F(BrowserWindowControllerTest, TestSigninMenuItemWithSeparator) { |
| 741 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 722 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 742 NSMenuItem* signinMenuItem = | 723 NSMenuItem* signinMenuItem = |
| 743 [menu addItemWithTitle:@"" | 724 [menu addItemWithTitle:@"" |
| 744 action:@selector(commandDispatch) | 725 action:@selector(commandDispatch) |
| 745 keyEquivalent:@""]; | 726 keyEquivalent:@""]; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 testFullscreenWindow_.reset( | 890 testFullscreenWindow_.reset( |
| 910 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 891 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
| 911 styleMask:NSBorderlessWindowMask | 892 styleMask:NSBorderlessWindowMask |
| 912 backing:NSBackingStoreBuffered | 893 backing:NSBackingStoreBuffered |
| 913 defer:NO]); | 894 defer:NO]); |
| 914 return testFullscreenWindow_.get(); | 895 return testFullscreenWindow_.get(); |
| 915 } | 896 } |
| 916 @end | 897 @end |
| 917 | 898 |
| 918 /* TODO(???): test other methods of BrowserWindowController */ | 899 /* TODO(???): test other methods of BrowserWindowController */ |
| OLD | NEW |