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