Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/avatar_button_controller_unittest.mm

Issue 605803002: [Mac] Redesign the new avatar button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a \n. >.< Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
20 #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"
21 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h"
22 25
23 class AvatarButtonControllerTest : public CocoaProfileTest { 26 class AvatarButtonControllerTest : public CocoaProfileTest {
24 public: 27 public:
25 virtual void SetUp() OVERRIDE { 28 virtual void SetUp() OVERRIDE {
26 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); 29 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
27 DCHECK(profiles::IsMultipleProfilesEnabled()); 30 DCHECK(profiles::IsMultipleProfilesEnabled());
28 31
29 CocoaProfileTest::SetUp(); 32 CocoaProfileTest::SetUp();
30 ASSERT_TRUE(browser()); 33 ASSERT_TRUE(browser());
31 34
32 controller_.reset( 35 controller_.reset(
33 [[AvatarButtonController alloc] initWithBrowser:browser()]); 36 [[AvatarButtonController alloc] initWithBrowser:browser()]);
34 } 37 }
35 38
36 virtual void TearDown() OVERRIDE { 39 virtual void TearDown() OVERRIDE {
37 browser()->window()->Close(); 40 browser()->window()->Close();
38 CocoaProfileTest::TearDown(); 41 CocoaProfileTest::TearDown();
39 } 42 }
40 43
41 NSButton* button() { return [controller_ buttonView]; } 44 NSButton* button() { return [controller_ buttonView]; }
42 45
43 NSView* view() { return [controller_ view]; } 46 NSView* view() { return [controller_ view]; }
44 47
45 AvatarButtonController* controller() { return controller_.get(); } 48 AvatarButtonController* controller() { return controller_.get(); }
46 49
47 private: 50 private:
48 base::scoped_nsobject<AvatarButtonController> controller_; 51 base::scoped_nsobject<AvatarButtonController> controller_;
49 }; 52 };
50 53
51 TEST_F(AvatarButtonControllerTest, ButtonShown) { 54 TEST_F(AvatarButtonControllerTest, GenericButtonShown) {
52 EXPECT_FALSE([view() isHidden]); 55 EXPECT_FALSE([view() isHidden]);
53 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME), 56 // We only have one local profile, which means we are displaying the
groby-ooo-7-16 2014/09/29 17:55:43 Nit: un-"we", if possible?
noms (inactive) 2014/09/29 19:21:57 Done.
57 // generic avatar button.
58 EXPECT_EQ(base::string16(), base::SysNSStringToUTF16([button() title]));
groby-ooo-7-16 2014/09/29 17:55:43 EXPECT_NSEQ(@"", [button() title]);
noms (inactive) 2014/09/29 19:21:57 Oh, cool! Done. On 2014/09/29 17:55:43, groby wrot
59 }
60
61 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) {
62 // Create a second profile, to force the button to display the profile name.
63 testing_profile_manager()->CreateTestingProfile("batman");
64
65 EXPECT_FALSE([view() isHidden]);
groby-ooo-7-16 2014/09/29 17:55:43 Why is that an expect? Should that be ASSERT_FALSE
noms (inactive) 2014/09/29 19:21:57 Done.
66 EXPECT_EQ(base::ASCIIToUTF16("Person 1"),
groby-ooo-7-16 2014/09/29 17:55:43 EXPECT_NSEQ - here and elsewhere
noms (inactive) 2014/09/29 19:21:57 Done.
54 base::SysNSStringToUTF16([button() title])); 67 base::SysNSStringToUTF16([button() title]));
55 } 68 }
56 69
70 TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) {
71 // Create a second profile, to force the button to display the profile name.
72 testing_profile_manager()->CreateTestingProfile("batman");
73
74 EXPECT_EQ(0, [button() image].size.width);
75 [controller() updateErrorStatus:true];
76
77 EXPECT_FALSE([view() isHidden]);
78 EXPECT_EQ(base::ASCIIToUTF16("Person 1"),
79 base::SysNSStringToUTF16([button() title]));
80
81 // If the button has an authentication error, it should display an error icon.
82 int errorWidth = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
83 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).Width();
84 EXPECT_LT(0, [button() image].size.width);
groby-ooo-7-16 2014/09/29 17:55:43 Isn't that encapsulated in the EXPECT_EQ?
noms (inactive) 2014/09/29 19:21:57 I was really paranoid that maybe IDR_ICON.. would
85 EXPECT_EQ(errorWidth, [button() image].size.width);
86 }
87
57 TEST_F(AvatarButtonControllerTest, DoubleOpen) { 88 TEST_F(AvatarButtonControllerTest, DoubleOpen) {
58 EXPECT_FALSE([controller() menuController]); 89 EXPECT_FALSE([controller() menuController]);
59 90
60 [button() performClick:button()]; 91 [button() performClick:button()];
61 92
62 BaseBubbleController* menu = [controller() menuController]; 93 BaseBubbleController* menu = [controller() menuController];
63 EXPECT_TRUE(menu); 94 EXPECT_TRUE(menu);
64 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]); 95 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]);
65 96
66 [button() performClick:button()]; 97 [button() performClick:button()];
67 EXPECT_EQ(menu, [controller() menuController]); 98 EXPECT_EQ(menu, [controller() menuController]);
68 99
69 // Do not animate out because that is hard to test around. 100 // Do not animate out because that is hard to test around.
70 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = 101 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
71 info_bubble::kAnimateNone; 102 info_bubble::kAnimateNone;
72 [menu close]; 103 [menu close];
73 EXPECT_FALSE([controller() menuController]); 104 EXPECT_FALSE([controller() menuController]);
74 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698