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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
7 #include "base/command_line.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/profiles/profiles_state.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #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/info_bubble_window.h"
17 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
18 #include "chrome/common/chrome_switches.h"
20 const char kDefaultProfileName[] = "default";
22 class AvatarButtonControllerTest : public CocoaProfileTest {
24 virtual void SetUp() OVERRIDE {
25 CommandLine::ForCurrentProcess()->AppendSwitch(
26 switches::kNewProfileManagement);
27 DCHECK(profiles::IsMultipleProfilesEnabled());
29 CocoaProfileTest::SetUp();
30 ASSERT_TRUE(browser());
33 [[AvatarButtonController alloc] initWithBrowser:browser()]);
36 virtual void TearDown() OVERRIDE {
37 browser()->window()->Close();
38 CocoaProfileTest::TearDown();
41 NSButton* button() { return [controller_ buttonView]; }
43 NSView* view() { return [controller_ view]; }
45 AvatarButtonController* controller() { return controller_.get(); }
48 base::scoped_nsobject<AvatarButtonController> controller_;
51 TEST_F(AvatarButtonControllerTest, ButtonShown) {
52 EXPECT_FALSE([view() isHidden]);
53 EXPECT_EQ(kDefaultProfileName, base::SysNSStringToUTF8([button() title]));
56 TEST_F(AvatarButtonControllerTest, DoubleOpen) {
57 EXPECT_FALSE([controller() menuController]);
59 [button() performClick:button()];
61 BaseBubbleController* menu = [controller() menuController];
63 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]);
65 [button() performClick:button()];
66 EXPECT_EQ(menu, [controller() menuController]);
68 // Do not animate out because that is hard to test around.
69 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
70 info_bubble::kAnimateNone;
72 EXPECT_FALSE([controller() menuController]);