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 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profiles_state.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/test_switches.h"
19 #include "chrome/test/base/testing_browser_process.h"
21 class AvatarMenuButtonTest
: public InProcessBrowserTest
{
23 AvatarMenuButtonTest();
24 ~AvatarMenuButtonTest() override
;
27 void CreateTestingProfile();
28 AvatarMenuButton
* GetAvatarMenuButton();
29 void StartAvatarMenu();
32 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButtonTest
);
35 AvatarMenuButtonTest::AvatarMenuButtonTest() {
38 AvatarMenuButtonTest::~AvatarMenuButtonTest() {
41 void AvatarMenuButtonTest::CreateTestingProfile() {
42 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
43 EXPECT_EQ(1u, profile_manager
->GetNumberOfProfiles());
46 PathService::Get(chrome::DIR_USER_DATA
, &path
);
47 path
= path
.AppendASCII("test_profile");
48 if (!base::PathExists(path
))
49 ASSERT_TRUE(base::CreateDirectory(path
));
51 Profile::CreateProfile(path
, NULL
, Profile::CREATE_MODE_SYNCHRONOUS
);
52 profile_manager
->RegisterTestingProfile(profile
, true, false);
53 EXPECT_EQ(2u, profile_manager
->GetNumberOfProfiles());
56 AvatarMenuButton
* AvatarMenuButtonTest::GetAvatarMenuButton() {
57 BrowserView
* browser_view
= reinterpret_cast<BrowserView
*>(
59 return browser_view
->frame()->GetAvatarMenuButton();
62 void AvatarMenuButtonTest::StartAvatarMenu() {
63 AvatarMenuButton
* button
= GetAvatarMenuButton();
66 AvatarMenuBubbleView::clear_close_on_deactivate_for_testing();
67 static_cast<views::MenuButtonListener
*>(button
)->OnMenuButtonClicked(
69 base::MessageLoop::current()->RunUntilIdle();
70 EXPECT_TRUE(AvatarMenuBubbleView::IsShowing());
73 // See http://crbug.com/315732
75 #define MAYBE_HideOnSecondClick DISABLED_HideOnSecondClick
76 #elif defined(OS_CHROMEOS)
77 // This test doesn't make sense for ChromeOS since it has a different
78 // multi-profiles menu in the system tray instead.
79 #define MAYBE_HideOnSecondClick DISABLED_HideOnSecondClick
81 #define MAYBE_HideOnSecondClick HideOnSecondClick
84 IN_PROC_BROWSER_TEST_F(AvatarMenuButtonTest
, MAYBE_HideOnSecondClick
) {
85 #if defined(OS_WIN) && defined(USE_ASH)
86 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
87 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
88 switches::kAshBrowserTests
))
92 // If multiprofile mode is not enabled, you can't switch between profiles.
93 if (!profiles::IsMultipleProfilesEnabled())
96 CreateTestingProfile();
97 ASSERT_NO_FATAL_FAILURE(StartAvatarMenu());
99 // Verify that clicking again doesn't reshow it.
100 AvatarMenuButton
* button
= GetAvatarMenuButton();
101 static_cast<views::MenuButtonListener
*>(button
)->OnMenuButtonClicked(
103 // Hide the bubble manually. In the browser this would normally happen during
104 // the event processing.
105 AvatarMenuBubbleView::Hide();
106 base::MessageLoop::current()->RunUntilIdle();
107 EXPECT_FALSE(AvatarMenuBubbleView::IsShowing());