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