| 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/info_bubble_window.h" | 16 #include "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 17 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 18 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 18 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.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 "chrome/grit/theme_resources.h" | 21 #include "chrome/grit/theme_resources.h" |
| 22 #include "components/signin/core/common/profile_management_switches.h" | 22 #include "components/signin/core/common/profile_management_switches.h" |
| 23 #import "testing/gtest_mac.h" | 23 #import "testing/gtest_mac.h" |
| 24 #include "ui/base/material_design/material_design_controller.h" | 24 #include "ui/base/material_design/material_design_controller.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 | 26 |
| 27 // Defined in the AvatarButtonController implementation. | 27 // Defined in the AvatarButtonController implementation. |
| 28 @interface AvatarButtonController (ExposedForTesting) | 28 @interface AvatarButtonController (ExposedForTesting) |
| 29 - (void)setErrorStatus:(BOOL)hasError; | 29 - (void)setErrorStatus:(BOOL)hasError; |
| 30 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
| 31 @end |
| 32 |
| 33 // Mocks the AvatarButtonController class so that we can mock its browser |
| 34 // window's frame color. |
| 35 @interface MockAvatarButtonController : AvatarButtonController { |
| 36 // True if the frame color is dark. |
| 37 BOOL isFrameDark_; |
| 38 } |
| 39 |
| 40 - (void)setIsFrameDark:(BOOL)isDark; |
| 41 |
| 42 @end |
| 43 |
| 44 @implementation MockAvatarButtonController |
| 45 |
| 46 - (void)setIsFrameDark:(BOOL)isDark { |
| 47 isFrameDark_ = isDark; |
| 48 } |
| 49 |
| 50 - (BOOL)isFrameColorDark { |
| 51 return isFrameDark_; |
| 52 } |
| 53 |
| 30 @end | 54 @end |
| 31 | 55 |
| 32 class AvatarButtonControllerTest : public CocoaProfileTest { | 56 class AvatarButtonControllerTest : public CocoaProfileTest { |
| 33 public: | 57 public: |
| 34 void SetUp() override { | 58 void SetUp() override { |
| 35 DCHECK(profiles::IsMultipleProfilesEnabled()); | 59 DCHECK(profiles::IsMultipleProfilesEnabled()); |
| 36 | 60 |
| 37 CocoaProfileTest::SetUp(); | 61 CocoaProfileTest::SetUp(); |
| 38 ASSERT_TRUE(browser()); | 62 ASSERT_TRUE(browser()); |
| 39 | 63 |
| 40 controller_.reset( | 64 controller_.reset([[MockAvatarButtonController alloc] |
| 41 [[AvatarButtonController alloc] initWithBrowser:browser()]); | 65 initWithBrowser:browser() |
| 66 window:nil]); |
| 42 } | 67 } |
| 43 | 68 |
| 44 void TearDown() override { | 69 void TearDown() override { |
| 45 browser()->window()->Close(); | 70 browser()->window()->Close(); |
| 46 CocoaProfileTest::TearDown(); | 71 CocoaProfileTest::TearDown(); |
| 47 } | 72 } |
| 48 | 73 |
| 49 NSButton* button() { return [controller_ buttonView]; } | 74 NSButton* button() { return [controller_ buttonView]; } |
| 50 | 75 |
| 51 NSView* view() { return [controller_ view]; } | 76 NSView* view() { return [controller_ view]; } |
| 52 | 77 |
| 53 AvatarButtonController* controller() { return controller_.get(); } | 78 MockAvatarButtonController* controller() { return controller_.get(); } |
| 54 | 79 |
| 55 private: | 80 private: |
| 56 base::scoped_nsobject<AvatarButtonController> controller_; | 81 base::scoped_nsobject<MockAvatarButtonController> controller_; |
| 57 }; | 82 }; |
| 58 | 83 |
| 59 TEST_F(AvatarButtonControllerTest, GenericButtonShown) { | 84 TEST_F(AvatarButtonControllerTest, GenericButtonShown) { |
| 60 ASSERT_FALSE([view() isHidden]); | 85 ASSERT_FALSE([view() isHidden]); |
| 61 // There is only one local profile, which means displaying the generic | 86 // There is only one local profile, which means displaying the generic |
| 62 // avatar button. | 87 // avatar button. |
| 63 EXPECT_NSEQ(@"", [button() title]); | 88 EXPECT_NSEQ(@"", [button() title]); |
| 64 } | 89 } |
| 65 | 90 |
| 66 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { | 91 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 97 | 122 |
| 98 [button() performClick:button()]; | 123 [button() performClick:button()]; |
| 99 EXPECT_EQ(menu, [controller() menuController]); | 124 EXPECT_EQ(menu, [controller() menuController]); |
| 100 | 125 |
| 101 // Do not animate out because that is hard to test around. | 126 // Do not animate out because that is hard to test around. |
| 102 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = | 127 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = |
| 103 info_bubble::kAnimateNone; | 128 info_bubble::kAnimateNone; |
| 104 [menu close]; | 129 [menu close]; |
| 105 EXPECT_FALSE([controller() menuController]); | 130 EXPECT_FALSE([controller() menuController]); |
| 106 } | 131 } |
| 132 |
| 133 TEST_F(AvatarButtonControllerTest, TitleColor) { |
| 134 // Create a second profile, to force the button to display the profile name. |
| 135 testing_profile_manager()->CreateTestingProfile("batman"); |
| 136 |
| 137 // Set the frame color to be not dark. The button's title color should be |
| 138 // black. |
| 139 [controller() setIsFrameDark:NO]; |
| 140 [controller() updateAvatarButtonAndLayoutParent:NO]; |
| 141 NSColor* titleColor = |
| 142 [[button() attributedTitle] attribute:NSForegroundColorAttributeName |
| 143 atIndex:0 |
| 144 effectiveRange:nil]; |
| 145 DCHECK_EQ(titleColor, [NSColor blackColor]); |
| 146 |
| 147 // Set the frame color to be dark. The button's title color should be white. |
| 148 [controller() setIsFrameDark:YES]; |
| 149 [controller() updateAvatarButtonAndLayoutParent:NO]; |
| 150 titleColor = |
| 151 [[button() attributedTitle] attribute:NSForegroundColorAttributeName |
| 152 atIndex:0 |
| 153 effectiveRange:nil]; |
| 154 DCHECK_EQ(titleColor, [NSColor whiteColor]); |
| 155 } |
| OLD | NEW |