| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/avatar_button_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/profiles/profiles_state.h" | 12 #include "chrome/browser/profiles/profiles_state.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 15 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 16 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 16 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 17 #include "chrome/browser/ui/cocoa/info_bubble_window.h" | 17 #include "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 18 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 18 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/signin/core/common/profile_management_switches.h" | 21 #include "components/signin/core/common/profile_management_switches.h" |
| 22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 23 #import "testing/gtest_mac.h" | 23 #import "testing/gtest_mac.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/material_design/material_design_controller.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 | 27 |
| 27 // Defined in the AvatarButtonController implementation. | 28 // Defined in the AvatarButtonController implementation. |
| 28 @interface AvatarButtonController (ExposedForTesting) | 29 @interface AvatarButtonController (ExposedForTesting) |
| 29 - (void)setErrorStatus:(BOOL)hasError; | 30 - (void)setErrorStatus:(BOOL)hasError; |
| 30 @end | 31 @end |
| 31 | 32 |
| 32 // Subclassing AvatarButtonController to be able to control the state of | 33 // Subclassing AvatarButtonController to be able to control the state of |
| 33 // keyboard modifierFlags. | 34 // keyboard modifierFlags. |
| 34 @interface AvatarButtonControllerForTesting : AvatarButtonController { | 35 @interface AvatarButtonControllerForTesting : AvatarButtonController { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) { | 101 TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) { |
| 101 // Create a second profile, to force the button to display the profile name. | 102 // Create a second profile, to force the button to display the profile name. |
| 102 testing_profile_manager()->CreateTestingProfile("batman"); | 103 testing_profile_manager()->CreateTestingProfile("batman"); |
| 103 | 104 |
| 104 EXPECT_EQ(0, [button() image].size.width); | 105 EXPECT_EQ(0, [button() image].size.width); |
| 105 [controller() setErrorStatus:true]; | 106 [controller() setErrorStatus:true]; |
| 106 | 107 |
| 107 ASSERT_FALSE([view() isHidden]); | 108 ASSERT_FALSE([view() isHidden]); |
| 108 EXPECT_NSEQ(@"Person 1", [button() title]); | 109 EXPECT_NSEQ(@"Person 1", [button() title]); |
| 109 | 110 |
| 110 // If the button has an authentication error, it should display an error icon. | 111 // If the button has an authentication error, it should display an error |
| 111 int errorWidth = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 112 // icon. If in the MD, the icon size should be 16. |
| 112 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).Width(); | 113 int errorWidth = |
| 114 ui::MaterialDesignController::IsModeMaterial() |
| 115 ? 16 |
| 116 : ui::ResourceBundle::GetSharedInstance() |
| 117 .GetNativeImageNamed(IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR) |
| 118 .Width(); |
| 119 |
| 113 EXPECT_EQ(errorWidth, [button() image].size.width); | 120 EXPECT_EQ(errorWidth, [button() image].size.width); |
| 114 } | 121 } |
| 115 | 122 |
| 116 TEST_F(AvatarButtonControllerTest, DoubleOpen) { | 123 TEST_F(AvatarButtonControllerTest, DoubleOpen) { |
| 117 EXPECT_FALSE([controller() menuController]); | 124 EXPECT_FALSE([controller() menuController]); |
| 118 | 125 |
| 119 [button() performClick:button()]; | 126 [button() performClick:button()]; |
| 120 | 127 |
| 121 BaseBubbleController* menu = [controller() menuController]; | 128 BaseBubbleController* menu = [controller() menuController]; |
| 122 EXPECT_TRUE(menu); | 129 EXPECT_TRUE(menu); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 BaseBubbleController* menu = [controller() menuController]; | 160 BaseBubbleController* menu = [controller() menuController]; |
| 154 EXPECT_TRUE(menu); | 161 EXPECT_TRUE(menu); |
| 155 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]); | 162 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]); |
| 156 | 163 |
| 157 // Do not animate out because that is hard to test around. | 164 // Do not animate out because that is hard to test around. |
| 158 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = | 165 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = |
| 159 info_bubble::kAnimateNone; | 166 info_bubble::kAnimateNone; |
| 160 [menu close]; | 167 [menu close]; |
| 161 EXPECT_FALSE([controller() menuController]); | 168 EXPECT_FALSE([controller() menuController]); |
| 162 } | 169 } |
| OLD | NEW |