| 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 "chrome/browser/profiles/avatar_menu_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // An observer that returns back to test code after a new profile is |
| 21 // initialized. |
| 22 void OnUnblockOnProfileCreation(Profile* profile, |
| 23 Profile::CreateStatus status) { |
| 24 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 25 base::MessageLoop::current()->Quit(); |
| 26 } |
| 27 |
| 20 typedef InProcessBrowserTest AvatarMenuModelTest; | 28 typedef InProcessBrowserTest AvatarMenuModelTest; |
| 21 | 29 |
| 22 IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SignOut) { | 30 IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SignOut) { |
| 23 if (!profiles::IsMultipleProfilesEnabled()) | 31 if (!profiles::IsMultipleProfilesEnabled()) |
| 24 return; | 32 return; |
| 25 | 33 |
| 26 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 34 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 27 Profile* current_profile = browser()->profile(); | 35 Profile* current_profile = browser()->profile(); |
| 28 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 36 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 29 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); | 37 size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath()); |
| 30 | 38 |
| 31 AvatarMenuModel model(&cache, NULL, browser()); | 39 AvatarMenuModel model(&cache, NULL, browser()); |
| 32 | 40 |
| 33 BrowserList* browser_list = | 41 BrowserList* browser_list = |
| 34 BrowserList::GetInstance(chrome::GetActiveDesktop()); | 42 BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 35 EXPECT_EQ(1U, browser_list->size()); | 43 EXPECT_EQ(1U, browser_list->size()); |
| 36 content::WindowedNotificationObserver window_close_observer( | 44 content::WindowedNotificationObserver window_close_observer( |
| 37 chrome::NOTIFICATION_BROWSER_CLOSED, | 45 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 38 content::Source<Browser>(browser())); | 46 content::Source<Browser>(browser())); |
| 39 | 47 |
| 40 EXPECT_FALSE(cache.ProfileIsSigninRequiredAtIndex(index)); | 48 EXPECT_FALSE(cache.ProfileIsSigninRequiredAtIndex(index)); |
| 41 model.SetLogoutURL("about:blank"); | 49 model.SetLogoutURL("about:blank"); |
| 42 model.BeginSignOut(); | 50 model.BeginSignOut(); |
| 43 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(index)); | 51 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(index)); |
| 44 | 52 |
| 45 window_close_observer.Wait(); // rely on test time-out for failure indication | 53 window_close_observer.Wait(); // rely on test time-out for failure indication |
| 46 EXPECT_EQ(0U, browser_list->size()); | 54 EXPECT_EQ(0U, browser_list->size()); |
| 47 } | 55 } |
| 48 | 56 |
| 57 IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SwitchToProfile) { |
| 58 if (!ProfileManager::IsMultipleProfilesEnabled()) |
| 59 return; |
| 60 |
| 61 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 62 Profile* current_profile = browser()->profile(); |
| 63 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 64 base::FilePath path_profile1 = current_profile->GetPath(); |
| 65 base::FilePath user_dir = cache.GetUserDataDir(); |
| 66 |
| 67 // Create an additional profile. |
| 68 base::FilePath path_profile2 = user_dir.Append( |
| 69 FILE_PATH_LITERAL("New Profile 2")); |
| 70 profile_manager->CreateProfileAsync(path_profile2, |
| 71 base::Bind(&OnUnblockOnProfileCreation), |
| 72 string16(), string16(), false); |
| 73 |
| 74 // Spin to allow profile creation to take place, loop is terminated |
| 75 // by OnUnblockOnProfileCreation when the profile is created. |
| 76 content::RunMessageLoop(); |
| 77 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); |
| 78 |
| 79 AvatarMenuModel model(&cache, NULL, browser()); |
| 80 BrowserList* browser_list = |
| 81 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 82 EXPECT_EQ(1U, browser_list->size()); |
| 83 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 84 |
| 85 // Open a browser window for the first profile. |
| 86 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false); |
| 87 EXPECT_EQ(1U, browser_list->size()); |
| 88 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 89 |
| 90 // Open a browser window for the second profile. |
| 91 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile2), false); |
| 92 EXPECT_EQ(2U, browser_list->size()); |
| 93 |
| 94 // Switch to the first profile without opening a new window. |
| 95 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false); |
| 96 EXPECT_EQ(2U, browser_list->size()); |
| 97 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 98 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 99 |
| 100 } |
| 49 } // namespace | 101 } // namespace |
| OLD | NEW |