| OLD | NEW |
| 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 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
| 17 #include "chrome/browser/profiles/profiles_state.h" | 17 #include "chrome/browser/profiles/profiles_state.h" |
| 18 #include "chrome/browser/ui/browser_commands.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/user_manager.h" | 20 #include "chrome/browser/ui/user_manager.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 22 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| 22 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" | 23 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
| 23 #include "chrome/browser/ui/views/profiles/user_manager_view.h" | 24 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
| 24 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "components/signin/core/common/profile_management_switches.h" | 28 #include "components/signin/core/common/profile_management_switches.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII(); | 44 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII(); |
| 44 | 45 |
| 45 Profile* profile = | 46 Profile* profile = |
| 46 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); | 47 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| 47 profile_manager->RegisterTestingProfile(profile, true, false); | 48 profile_manager->RegisterTestingProfile(profile, true, false); |
| 48 EXPECT_EQ(starting_number_of_profiles + 1, | 49 EXPECT_EQ(starting_number_of_profiles + 1, |
| 49 profile_manager->GetNumberOfProfiles()); | 50 profile_manager->GetNumberOfProfiles()); |
| 50 return profile; | 51 return profile; |
| 51 } | 52 } |
| 52 | 53 |
| 54 Profile* CreateProfileOutsideUserDataDir() { |
| 55 base::FilePath path; |
| 56 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), &path)) |
| 57 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII(); |
| 58 //PathService::Get(chrome::DIR_USER_DATA, &path); |
| 59 //path = path.AppendASCII("testing"); |
| 60 |
| 61 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 62 Profile* profile = |
| 63 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); |
| 64 profile_manager->RegisterTestingProfile(profile, true, false); |
| 65 return profile; |
| 66 } |
| 67 |
| 68 void CloseBrowser(Browser* browser) { |
| 69 content::WindowedNotificationObserver close_observer( |
| 70 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 71 content::Source<Browser>(browser)); |
| 72 chrome::CloseWindow(browser); |
| 73 close_observer.Wait(); |
| 74 } |
| 75 |
| 53 // Set up the profiles to enable Lock. Takes as parameter a profile that will be | 76 // Set up the profiles to enable Lock. Takes as parameter a profile that will be |
| 54 // signed in, and also creates a supervised user (necessary for lock). | 77 // signed in, and also creates a supervised user (necessary for lock). |
| 55 void SetupProfilesForLock(Profile* signed_in) { | 78 void SetupProfilesForLock(Profile* signed_in) { |
| 56 const char* signed_in_email = "me@google.com"; | 79 const char* signed_in_email = "me@google.com"; |
| 57 Profile* supervised = CreateTestingProfile("supervised"); | 80 Profile* supervised = CreateTestingProfile("supervised"); |
| 58 ProfileInfoCache* cache = &g_browser_process->profile_manager()-> | 81 ProfileInfoCache* cache = &g_browser_process->profile_manager()-> |
| 59 GetProfileInfoCache(); | 82 GetProfileInfoCache(); |
| 60 cache->SetAuthInfoOfProfileAtIndex(cache->GetIndexOfProfileWithPath( | 83 cache->SetAuthInfoOfProfileAtIndex(cache->GetIndexOfProfileWithPath( |
| 61 signed_in->GetPath()), "12345", base::UTF8ToUTF16(signed_in_email)); | 84 signed_in->GetPath()), "12345", base::UTF8ToUTF16(signed_in_email)); |
| 62 signed_in->GetPrefs()-> | 85 signed_in->GetPrefs()-> |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 current_profile_bubble()->avatar_menu_.get()); | 200 current_profile_bubble()->avatar_menu_.get()); |
| 178 base::MessageLoop::current()->RunUntilIdle(); | 201 base::MessageLoop::current()->RunUntilIdle(); |
| 179 } | 202 } |
| 180 | 203 |
| 181 private: | 204 private: |
| 182 scoped_ptr<content::WindowedNotificationObserver> window_close_observer_; | 205 scoped_ptr<content::WindowedNotificationObserver> window_close_observer_; |
| 183 | 206 |
| 184 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewExtensionsTest); | 207 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewExtensionsTest); |
| 185 }; | 208 }; |
| 186 | 209 |
| 210 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, |
| 211 NoProfileChooserOnOutsideUserDataDirProfiles) { |
| 212 // Test that the profile chooser view should be deleted when the browser is |
| 213 // deleted. Even if the profile is not in user_data_dir. |
| 214 Profile* new_profile = CreateProfileOutsideUserDataDir(); |
| 215 Browser* browser = CreateBrowser(new_profile); |
| 216 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 217 BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN, |
| 218 signin::ManageAccountsParams()); |
| 219 ASSERT_FALSE(ProfileChooserView::IsShowing()); |
| 220 CloseBrowser(browser); |
| 221 } |
| 222 |
| 187 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, SigninButtonHasFocus) { | 223 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, SigninButtonHasFocus) { |
| 188 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); | 224 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); |
| 189 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView(browser())); | 225 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView(browser())); |
| 190 | 226 |
| 191 EXPECT_TRUE(signin_current_profile_link()->HasFocus()); | 227 EXPECT_TRUE(signin_current_profile_link()->HasFocus()); |
| 192 } | 228 } |
| 193 | 229 |
| 194 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, ContentAreaHasFocus) { | 230 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, ContentAreaHasFocus) { |
| 195 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); | 231 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); |
| 196 | 232 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); | 324 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); |
| 289 | 325 |
| 290 WaitForUserManager(); | 326 WaitForUserManager(); |
| 291 // Assert that the first profile's extensions are not blocked. | 327 // Assert that the first profile's extensions are not blocked. |
| 292 ASSERT_EQ(total_enabled_extensions, registry->enabled_extensions().size()); | 328 ASSERT_EQ(total_enabled_extensions, registry->enabled_extensions().size()); |
| 293 ASSERT_EQ(0U, registry->blocked_extensions().size()); | 329 ASSERT_EQ(0U, registry->blocked_extensions().size()); |
| 294 | 330 |
| 295 // We need to hide the User Manager or else the process can't die. | 331 // We need to hide the User Manager or else the process can't die. |
| 296 UserManager::Hide(); | 332 UserManager::Hide(); |
| 297 } | 333 } |
| OLD | NEW |