Index: chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm b/chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm |
index 635697807076b15bf3ae00af4c569de2368d14d1..75119e5ed739a699f918c7ddaa562aed9813e3a0 100644 |
--- a/chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm |
+++ b/chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm |
@@ -7,6 +7,7 @@ |
#include "base/command_line.h" |
#include "base/mac/scoped_nsobject.h" |
#include "base/strings/sys_string_conversions.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/profiles/profiles_state.h" |
#include "chrome/browser/ui/browser.h" |
@@ -18,7 +19,15 @@ |
#include "chrome/common/chrome_switches.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/signin/core/common/profile_management_switches.h" |
+#include "grit/theme_resources.h" |
+#import "testing/gtest_mac.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+ |
+// Defined in the AvatarButtonController implementation. |
+@interface AvatarButtonController (ExposedForTesting) |
+- (void)updateErrorStatus:(BOOL)hasError; |
+@end |
class AvatarButtonControllerTest : public CocoaProfileTest { |
public: |
@@ -48,10 +57,35 @@ class AvatarButtonControllerTest : public CocoaProfileTest { |
base::scoped_nsobject<AvatarButtonController> controller_; |
}; |
-TEST_F(AvatarButtonControllerTest, ButtonShown) { |
- EXPECT_FALSE([view() isHidden]); |
- EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME), |
- base::SysNSStringToUTF16([button() title])); |
+TEST_F(AvatarButtonControllerTest, GenericButtonShown) { |
+ ASSERT_FALSE([view() isHidden]); |
+ // There is only one local profile, which means displaying the generic |
+ // avatar button. |
+ EXPECT_NSEQ(@"", [button() title]); |
+} |
+ |
+TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { |
+ // Create a second profile, to force the button to display the profile name. |
+ testing_profile_manager()->CreateTestingProfile("batman"); |
+ |
+ ASSERT_FALSE([view() isHidden]); |
+ EXPECT_NSEQ(@"Person 1", [button() title]); |
+} |
+ |
+TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) { |
+ // Create a second profile, to force the button to display the profile name. |
+ testing_profile_manager()->CreateTestingProfile("batman"); |
+ |
+ EXPECT_EQ(0, [button() image].size.width); |
+ [controller() updateErrorStatus:true]; |
+ |
+ ASSERT_FALSE([view() isHidden]); |
+ EXPECT_NSEQ(@"Person 1", [button() title]); |
+ |
+ // If the button has an authentication error, it should display an error icon. |
+ int errorWidth = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
+ IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).Width(); |
+ EXPECT_EQ(errorWidth, [button() image].size.width); |
} |
TEST_F(AvatarButtonControllerTest, DoubleOpen) { |