| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
| 7 #include "chrome/browser/profiles/avatar_menu.h" | 7 #include "chrome/browser/profiles/avatar_menu.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/profiles/profile_window.h" | 9 #include "chrome/browser/profiles/profile_window.h" |
| 10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 if (status == Profile::CREATE_STATUS_INITIALIZED) | 26 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 27 base::MessageLoop::current()->Quit(); | 27 base::MessageLoop::current()->Quit(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 class ProfileListDesktopBrowserTest : public InProcessBrowserTest { | 32 class ProfileListDesktopBrowserTest : public InProcessBrowserTest { |
| 33 public: | 33 public: |
| 34 ProfileListDesktopBrowserTest() {} | 34 ProfileListDesktopBrowserTest() {} |
| 35 | 35 |
| 36 scoped_ptr<AvatarMenu> CreateAvatarMenu(ProfileInfoCache* cache) { | 36 scoped_ptr<AvatarMenu> CreateAvatarMenu(ProfileAttributesStorage* storage) { |
| 37 return scoped_ptr<AvatarMenu>(new AvatarMenu(cache, NULL, browser())); | 37 return scoped_ptr<AvatarMenu>(new AvatarMenu(storage, NULL, browser())); |
| 38 } | 38 } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 scoped_ptr<AvatarMenu> avatar_menu_; | 41 scoped_ptr<AvatarMenu> avatar_menu_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(ProfileListDesktopBrowserTest); | 43 DISALLOW_COPY_AND_ASSIGN(ProfileListDesktopBrowserTest); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 47 // SignOut is flaky. So far only observed on Windows. crbug.com/357329. | 47 // SignOut is flaky. So far only observed on Windows. crbug.com/357329. |
| 48 #define MAYBE_SignOut DISABLED_SignOut | 48 #define MAYBE_SignOut DISABLED_SignOut |
| 49 #elif defined(OS_CHROMEOS) | 49 #elif defined(OS_CHROMEOS) |
| 50 // This test doesn't make sense for Chrome OS since it has a different | 50 // This test doesn't make sense for Chrome OS since it has a different |
| 51 // multi-profiles menu in the system tray instead. | 51 // multi-profiles menu in the system tray instead. |
| 52 #define MAYBE_SignOut DISABLED_SignOut | 52 #define MAYBE_SignOut DISABLED_SignOut |
| 53 #else | 53 #else |
| 54 #define MAYBE_SignOut SignOut | 54 #define MAYBE_SignOut SignOut |
| 55 #endif | 55 #endif |
| 56 IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SignOut) { | 56 IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SignOut) { |
| 57 if (!profiles::IsMultipleProfilesEnabled()) | 57 if (!profiles::IsMultipleProfilesEnabled()) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 60 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 61 Profile* current_profile = browser()->profile(); | 61 Profile* current_profile = browser()->profile(); |
| 62 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 62 ProfileAttributesStorage& storage = |
| 63 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); | 63 profile_manager->GetProfileAttributesStorage(); |
| 64 | 64 |
| 65 scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&cache); | 65 scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&storage); |
| 66 menu->RebuildMenu(); | 66 menu->RebuildMenu(); |
| 67 | 67 |
| 68 BrowserList* browser_list = | 68 BrowserList* browser_list = |
| 69 BrowserList::GetInstance(chrome::GetActiveDesktop()); | 69 BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 70 EXPECT_EQ(1U, browser_list->size()); | 70 EXPECT_EQ(1U, browser_list->size()); |
| 71 content::WindowedNotificationObserver window_close_observer( | 71 content::WindowedNotificationObserver window_close_observer( |
| 72 chrome::NOTIFICATION_BROWSER_CLOSED, | 72 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 73 content::Source<Browser>(browser())); | 73 content::Source<Browser>(browser())); |
| 74 | 74 |
| 75 EXPECT_FALSE(cache.ProfileIsSigninRequiredAtIndex(index)); | 75 ProfileAttributesEntry* entry; |
| 76 ASSERT_TRUE( |
| 77 storage.GetProfileAttributesWithPath(current_profile->GetPath(), &entry)); |
| 78 EXPECT_FALSE(entry->IsSigninRequired()); |
| 76 profiles::LockProfile(current_profile); | 79 profiles::LockProfile(current_profile); |
| 77 window_close_observer.Wait(); // rely on test time-out for failure indication | 80 window_close_observer.Wait(); // rely on test time-out for failure indication |
| 78 | 81 |
| 79 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(index)); | 82 EXPECT_TRUE(entry->IsSigninRequired()); |
| 80 EXPECT_EQ(0U, browser_list->size()); | 83 EXPECT_EQ(0U, browser_list->size()); |
| 81 | 84 |
| 82 // Signing out brings up the User Manager which we should close before exit. | 85 // Signing out brings up the User Manager which we should close before exit. |
| 83 UserManager::Hide(); | 86 UserManager::Hide(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
| 87 // This test doesn't make sense for Chrome OS since it has a different | 90 // This test doesn't make sense for Chrome OS since it has a different |
| 88 // multi-profiles menu in the system tray instead. | 91 // multi-profiles menu in the system tray instead. |
| 89 #define MAYBE_SwitchToProfile DISABLED_SwitchToProfile | 92 #define MAYBE_SwitchToProfile DISABLED_SwitchToProfile |
| 90 #else | 93 #else |
| 91 #define MAYBE_SwitchToProfile SwitchToProfile | 94 #define MAYBE_SwitchToProfile SwitchToProfile |
| 92 #endif | 95 #endif |
| 93 IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SwitchToProfile) { | 96 IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SwitchToProfile) { |
| 94 #if defined(OS_WIN) && defined(USE_ASH) | 97 #if defined(OS_WIN) && defined(USE_ASH) |
| 95 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 98 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 96 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 99 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 97 switches::kAshBrowserTests)) | 100 switches::kAshBrowserTests)) |
| 98 return; | 101 return; |
| 99 #endif | 102 #endif |
| 100 | 103 |
| 101 if (!profiles::IsMultipleProfilesEnabled()) | 104 if (!profiles::IsMultipleProfilesEnabled()) |
| 102 return; | 105 return; |
| 103 | 106 |
| 104 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 107 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 105 Profile* current_profile = browser()->profile(); | 108 Profile* current_profile = browser()->profile(); |
| 106 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 109 ProfileAttributesStorage& storage = |
| 110 profile_manager->GetProfileAttributesStorage(); |
| 107 base::FilePath path_profile1 = current_profile->GetPath(); | 111 base::FilePath path_profile1 = current_profile->GetPath(); |
| 108 base::FilePath user_dir = cache.GetUserDataDir(); | 112 base::FilePath user_dir = storage.GetUserDataDir(); |
| 109 | 113 |
| 110 // Create an additional profile. | 114 // Create an additional profile. |
| 111 base::FilePath path_profile2 = user_dir.Append( | 115 base::FilePath path_profile2 = user_dir.Append( |
| 112 FILE_PATH_LITERAL("New Profile 2")); | 116 FILE_PATH_LITERAL("New Profile 2")); |
| 113 profile_manager->CreateProfileAsync(path_profile2, | 117 profile_manager->CreateProfileAsync(path_profile2, |
| 114 base::Bind(&OnUnblockOnProfileCreation), | 118 base::Bind(&OnUnblockOnProfileCreation), |
| 115 base::string16(), base::string16(), | 119 base::string16(), base::string16(), |
| 116 std::string()); | 120 std::string()); |
| 117 | 121 |
| 118 // Spin to allow profile creation to take place, loop is terminated | 122 // Spin to allow profile creation to take place, loop is terminated |
| 119 // by OnUnblockOnProfileCreation when the profile is created. | 123 // by OnUnblockOnProfileCreation when the profile is created. |
| 120 content::RunMessageLoop(); | 124 content::RunMessageLoop(); |
| 121 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | 125 ASSERT_EQ(storage.GetNumberOfProfiles(), 2U); |
| 122 | 126 |
| 123 scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&cache); | 127 scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&storage); |
| 124 menu->RebuildMenu(); | 128 menu->RebuildMenu(); |
| 125 BrowserList* browser_list = | 129 BrowserList* browser_list = |
| 126 BrowserList::GetInstance(chrome::GetActiveDesktop()); | 130 BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 127 EXPECT_EQ(1U, browser_list->size()); | 131 EXPECT_EQ(1U, browser_list->size()); |
| 128 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 132 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 129 | 133 |
| 130 // Open a browser window for the first profile. | 134 // Open a browser window for the first profile. |
| 131 menu->SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), | 135 menu->SwitchToProfile(menu->GetIndexOfItemWithProfilePath(path_profile1), |
| 132 false, ProfileMetrics::SWITCH_PROFILE_ICON); | 136 false, ProfileMetrics::SWITCH_PROFILE_ICON); |
| 133 EXPECT_EQ(1U, browser_list->size()); | 137 EXPECT_EQ(1U, browser_list->size()); |
| 134 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 138 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 135 | 139 |
| 136 // Open a browser window for the second profile. | 140 // Open a browser window for the second profile. |
| 137 menu->SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile2), | 141 menu->SwitchToProfile(menu->GetIndexOfItemWithProfilePath(path_profile2), |
| 138 false, ProfileMetrics::SWITCH_PROFILE_ICON); | 142 false, ProfileMetrics::SWITCH_PROFILE_ICON); |
| 139 EXPECT_EQ(2U, browser_list->size()); | 143 EXPECT_EQ(2U, browser_list->size()); |
| 140 | 144 |
| 141 // Switch to the first profile without opening a new window. | 145 // Switch to the first profile without opening a new window. |
| 142 menu->SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), | 146 menu->SwitchToProfile(menu->GetIndexOfItemWithProfilePath(path_profile1), |
| 143 false, ProfileMetrics::SWITCH_PROFILE_ICON); | 147 false, ProfileMetrics::SWITCH_PROFILE_ICON); |
| 144 EXPECT_EQ(2U, browser_list->size()); | 148 EXPECT_EQ(2U, browser_list->size()); |
| 145 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 149 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 146 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 150 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 147 } | 151 } |
| OLD | NEW |