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

Side by Side Diff: chrome/browser/ui/views/avatar_menu_button_browsertest.cc

Issue 24647003: Redesign of the avatar menu button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better fix for app/popup browser crash Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/avatar_menu_button.h" 5 #include "chrome/browser/ui/views/avatar_menu_button.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/avatar_menu.h"
12 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h" 11 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" 13 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/profile_chooser_view.h"
18 #include "chrome/browser/ui/views/user_manager_view.h"
19 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/test_switches.h" 18 #include "chrome/test/base/test_switches.h"
23 #include "chrome/test/base/testing_browser_process.h" 19 #include "chrome/test/base/testing_browser_process.h"
24 #include "content/public/test/test_utils.h"
25 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/views/controls/button/label_button.h"
28 21
29 class AvatarMenuButtonTest : public InProcessBrowserTest, 22 class AvatarMenuButtonTest : public InProcessBrowserTest {
30 public testing::WithParamInterface<bool> {
31 public: 23 public:
32 AvatarMenuButtonTest(); 24 AvatarMenuButtonTest();
33 virtual ~AvatarMenuButtonTest(); 25 virtual ~AvatarMenuButtonTest();
34 26
35 protected: 27 protected:
36 virtual void SetUp() OVERRIDE;
37
38 bool UsingNewProfileChooser();
39 void CreateTestingProfile(); 28 void CreateTestingProfile();
40 AvatarMenuButton* GetAvatarMenuButton(); 29 AvatarMenuButton* GetAvatarMenuButton();
41 void StartAvatarMenu(); 30 void StartAvatarMenu();
42 31
43 private: 32 private:
44 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButtonTest); 33 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButtonTest);
45 }; 34 };
46 35
47 AvatarMenuButtonTest::AvatarMenuButtonTest() { 36 AvatarMenuButtonTest::AvatarMenuButtonTest() {
48 } 37 }
49 38
50 AvatarMenuButtonTest::~AvatarMenuButtonTest() { 39 AvatarMenuButtonTest::~AvatarMenuButtonTest() {
51 } 40 }
52 41
53 void AvatarMenuButtonTest::SetUp() {
54 if (GetParam()) {
55 if (!UsingNewProfileChooser()) {
56 CommandLine::ForCurrentProcess()->AppendSwitch(
57 switches::kNewProfileManagement);
58 }
59 DCHECK(UsingNewProfileChooser());
60 } else {
61 DCHECK(!UsingNewProfileChooser());
62 }
63
64 InProcessBrowserTest::SetUp();
65 }
66
67 bool AvatarMenuButtonTest::UsingNewProfileChooser() {
68 return CommandLine::ForCurrentProcess()->HasSwitch(
69 switches::kNewProfileManagement);
70 }
71
72 void AvatarMenuButtonTest::CreateTestingProfile() { 42 void AvatarMenuButtonTest::CreateTestingProfile() {
73 ProfileManager* profile_manager = g_browser_process->profile_manager(); 43 ProfileManager* profile_manager = g_browser_process->profile_manager();
74 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles()); 44 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
75 45
76 // Sign in the default profile
77 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
78 cache.SetUserNameOfProfileAtIndex(0, UTF8ToUTF16("user_name"));
79
80 base::FilePath path; 46 base::FilePath path;
81 PathService::Get(chrome::DIR_USER_DATA, &path); 47 PathService::Get(chrome::DIR_USER_DATA, &path);
82 path = path.AppendASCII("test_profile"); 48 path = path.AppendASCII("test_profile");
83 if (!base::PathExists(path)) 49 if (!base::PathExists(path))
84 ASSERT_TRUE(file_util::CreateDirectory(path)); 50 ASSERT_TRUE(file_util::CreateDirectory(path));
85 Profile* profile = 51 Profile* profile =
86 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 52 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
87 profile_manager->RegisterTestingProfile(profile, true, false); 53 profile_manager->RegisterTestingProfile(profile, true, false);
88 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles()); 54 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
89 } 55 }
90 56
91 AvatarMenuButton* AvatarMenuButtonTest::GetAvatarMenuButton() { 57 AvatarMenuButton* AvatarMenuButtonTest::GetAvatarMenuButton() {
92 BrowserView* browser_view = reinterpret_cast<BrowserView*>( 58 BrowserView* browser_view = reinterpret_cast<BrowserView*>(
93 browser()->window()); 59 browser()->window());
94 return browser_view->frame()->GetAvatarMenuButton(); 60 return browser_view->frame()->GetAvatarMenuButton();
95 } 61 }
96 62
97 void AvatarMenuButtonTest::StartAvatarMenu() { 63 void AvatarMenuButtonTest::StartAvatarMenu() {
98 AvatarMenuButton* button = GetAvatarMenuButton(); 64 AvatarMenuButton* button = GetAvatarMenuButton();
99 ASSERT_TRUE(button); 65 ASSERT_TRUE(button);
100 66
101 AvatarMenuBubbleView::set_close_on_deactivate(false); 67 AvatarMenuBubbleView::set_close_on_deactivate(false);
102 ProfileChooserView::set_close_on_deactivate(false);
103 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked( 68 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked(
104 NULL, gfx::Point()); 69 NULL, gfx::Point());
105 base::MessageLoop::current()->RunUntilIdle(); 70 base::MessageLoop::current()->RunUntilIdle();
106 EXPECT_NE(AvatarMenuBubbleView::IsShowing(), 71 EXPECT_TRUE(AvatarMenuBubbleView::IsShowing());
107 ProfileChooserView::IsShowing());
108 } 72 }
109 73
110 IN_PROC_BROWSER_TEST_P(AvatarMenuButtonTest, HideOnSecondClick) { 74 IN_PROC_BROWSER_TEST_F(AvatarMenuButtonTest, HideOnSecondClick) {
111 #if defined(OS_WIN) && defined(USE_ASH) 75 #if defined(OS_WIN) && defined(USE_ASH)
112 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 76 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
113 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 77 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
114 return; 78 return;
115 #endif 79 #endif
116 80
117 if (!profiles::IsMultipleProfilesEnabled() || 81 // If multiprofile mode is not enabled, you can't switch between profiles.
118 UsingNewProfileChooser()) { 82 if (!profiles::IsMultipleProfilesEnabled())
119 return; 83 return;
120 }
121 84
122 CreateTestingProfile(); 85 CreateTestingProfile();
123 StartAvatarMenu(); 86 ASSERT_NO_FATAL_FAILURE(StartAvatarMenu());
124 87
125 // Verify that clicking again doesn't reshow it. 88 // Verify that clicking again doesn't reshow it.
126 AvatarMenuButton* button = GetAvatarMenuButton(); 89 AvatarMenuButton* button = GetAvatarMenuButton();
127 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked( 90 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked(
128 NULL, gfx::Point()); 91 NULL, gfx::Point());
129 // Hide the bubble manually. In the browser this would normally happen during 92 // Hide the bubble manually. In the browser this would normally happen during
130 // the event processing. 93 // the event processing.
131 AvatarMenuBubbleView::Hide(); 94 AvatarMenuBubbleView::Hide();
132 base::MessageLoop::current()->RunUntilIdle(); 95 base::MessageLoop::current()->RunUntilIdle();
133 EXPECT_FALSE(AvatarMenuBubbleView::IsShowing()); 96 EXPECT_FALSE(AvatarMenuBubbleView::IsShowing());
134 EXPECT_FALSE(ProfileChooserView::IsShowing());
135 } 97 }
136
137 IN_PROC_BROWSER_TEST_P(AvatarMenuButtonTest, NewSignOut) {
138 if (!profiles::IsMultipleProfilesEnabled() ||
139 !UsingNewProfileChooser()) {
140 return;
141 }
142
143 CreateTestingProfile();
144 StartAvatarMenu();
145
146 BrowserList* browser_list =
147 BrowserList::GetInstance(chrome::GetActiveDesktop());
148 EXPECT_EQ(1U, browser_list->size());
149 content::WindowedNotificationObserver window_close_observer(
150 chrome::NOTIFICATION_BROWSER_CLOSED,
151 content::Source<Browser>(browser()));
152
153 AvatarMenu* menu =
154 ProfileChooserView::profile_bubble_->avatar_menu_.get();
155 const AvatarMenu::Item& menu_item_before =
156 menu->GetItemAt(menu->GetActiveProfileIndex());
157 EXPECT_FALSE(menu_item_before.signin_required);
158
159 ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0);
160 menu->SetLogoutURL("about:blank");
161
162 ProfileChooserView::profile_bubble_->LinkClicked(
163 static_cast<views::Link*>(
164 ProfileChooserView::profile_bubble_->signout_current_profile_link_),
165 0);
166
167 EXPECT_TRUE(menu->GetItemAt(menu->GetActiveProfileIndex()).signin_required);
168
169 window_close_observer.Wait(); // Rely on test timeout for failure indication.
170 EXPECT_TRUE(browser_list->empty());
171 }
172
173 INSTANTIATE_TEST_CASE_P(Old, AvatarMenuButtonTest, testing::Values(false));
174 INSTANTIATE_TEST_CASE_P(New, AvatarMenuButtonTest, testing::Values(true));
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_bubble_view.h ('k') | chrome/browser/ui/views/frame/browser_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698