#include "base/command_line.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
-#include "chrome/browser/profiles/profiles_state.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"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/base_bubble_controller.h"
#include "chrome/browser/ui/cocoa/info_bubble_window.h"
#import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/grit/generated_resources.h"
#include "components/signin/core/common/profile_management_switches.h"
-#include "grit/generated_resources.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:
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) {