Chromium Code Reviews| 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 "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/profiles/profiles_state.h" | 12 #include "chrome/browser/profiles/profiles_state.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 15 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 16 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 16 #include "chrome/browser/ui/cocoa/info_bubble_window.h" | 17 #include "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 18 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 41 NSButton* button() { return [controller_ buttonView]; } | 42 NSButton* button() { return [controller_ buttonView]; } |
| 42 | 43 |
| 43 NSView* view() { return [controller_ view]; } | 44 NSView* view() { return [controller_ view]; } |
| 44 | 45 |
| 45 AvatarButtonController* controller() { return controller_.get(); } | 46 AvatarButtonController* controller() { return controller_.get(); } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 base::scoped_nsobject<AvatarButtonController> controller_; | 49 base::scoped_nsobject<AvatarButtonController> controller_; |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 TEST_F(AvatarButtonControllerTest, ButtonShown) { | 52 TEST_F(AvatarButtonControllerTest, GenericButtonShown) { |
| 52 EXPECT_FALSE([view() isHidden]); | 53 EXPECT_FALSE([view() isHidden]); |
| 53 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME), | 54 // We only have one local profile, which means we are displaying the |
| 55 // generic avatar button. | |
| 56 EXPECT_EQ(base::string16(), base::SysNSStringToUTF16([button() title])); | |
| 57 } | |
| 58 | |
| 59 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { | |
| 60 // Create a second profile, to force the button to display the profile name. | |
| 61 testing_profile_manager()->CreateTestingProfile("batman"); | |
| 62 | |
| 63 EXPECT_FALSE([view() isHidden]); | |
| 64 EXPECT_EQ(base::ASCIIToUTF16("Person 1"), | |
| 54 base::SysNSStringToUTF16([button() title])); | 65 base::SysNSStringToUTF16([button() title])); |
| 55 } | 66 } |
| 56 | 67 |
|
groby-ooo-7-16
2014/09/25 22:03:30
Can you add a test for the error case, please?
noms (inactive)
2014/09/26 15:49:10
Done.
| |
| 57 TEST_F(AvatarButtonControllerTest, DoubleOpen) { | 68 TEST_F(AvatarButtonControllerTest, DoubleOpen) { |
| 58 EXPECT_FALSE([controller() menuController]); | 69 EXPECT_FALSE([controller() menuController]); |
| 59 | 70 |
| 60 [button() performClick:button()]; | 71 [button() performClick:button()]; |
| 61 | 72 |
| 62 BaseBubbleController* menu = [controller() menuController]; | 73 BaseBubbleController* menu = [controller() menuController]; |
| 63 EXPECT_TRUE(menu); | 74 EXPECT_TRUE(menu); |
| 64 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]); | 75 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]); |
| 65 | 76 |
| 66 [button() performClick:button()]; | 77 [button() performClick:button()]; |
| 67 EXPECT_EQ(menu, [controller() menuController]); | 78 EXPECT_EQ(menu, [controller() menuController]); |
| 68 | 79 |
| 69 // Do not animate out because that is hard to test around. | 80 // Do not animate out because that is hard to test around. |
| 70 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = | 81 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = |
| 71 info_bubble::kAnimateNone; | 82 info_bubble::kAnimateNone; |
| 72 [menu close]; | 83 [menu close]; |
| 73 EXPECT_FALSE([controller() menuController]); | 84 EXPECT_FALSE([controller() menuController]); |
| 74 } | 85 } |
| OLD | NEW |