Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4531)

Unified Diff: chrome/browser/profiles/avatar_menu_model_browsertest.cc

Issue 16104008: First try at a user management screen for the desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and review comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/avatar_menu_model_browsertest.cc
diff --git a/chrome/browser/profiles/avatar_menu_model_browsertest.cc b/chrome/browser/profiles/avatar_menu_model_browsertest.cc
index 634fe754fd570ba73102a41e1cc2f1fd1be29995..9fa315c7a8e22237cdfcc46fe28c239c530e2513 100644
--- a/chrome/browser/profiles/avatar_menu_model_browsertest.cc
+++ b/chrome/browser/profiles/avatar_menu_model_browsertest.cc
@@ -16,6 +16,14 @@
namespace {
+// An observer that returns back to test code after a new profile is
+// initialized.
+void OnUnblockOnProfileCreation(Profile* profile,
+ Profile::CreateStatus status) {
+ if (status == Profile::CREATE_STATUS_INITIALIZED)
+ base::MessageLoop::current()->Quit();
+}
+
typedef InProcessBrowserTest AvatarMenuModelTest;
IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SignOut) {
@@ -45,4 +53,48 @@ IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SignOut) {
EXPECT_EQ(0U, browser_list->size());
}
+IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SwitchToProfile) {
+ if (!ProfileManager::IsMultipleProfilesEnabled())
+ return;
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ Profile* current_profile = browser()->profile();
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
+ base::FilePath path_profile1 = current_profile->GetPath();
+ base::FilePath user_dir = cache.GetUserDataDir();
+
+ // Create an additional profile.
+ base::FilePath path_profile2 = user_dir.Append(
+ FILE_PATH_LITERAL("New Profile 2"));
+ profile_manager->CreateProfileAsync(path_profile2,
+ base::Bind(&OnUnblockOnProfileCreation),
+ string16(), string16(), false);
+
+ // Spin to allow profile creation to take place, loop is terminated
+ // by OnUnblockOnProfileCreation when the profile is created.
+ content::RunMessageLoop();
+ ASSERT_EQ(cache.GetNumberOfProfiles(), 2U);
+
+ AvatarMenuModel model(&cache, NULL, browser());
+ BrowserList* browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ EXPECT_EQ(1U, browser_list->size());
+ EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
+
+ // Open a browser window for the first profile.
+ model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false);
+ EXPECT_EQ(1U, browser_list->size());
+ EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
+
+ // Open a browser window for the second profile.
+ model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile2), false);
+ EXPECT_EQ(2U, browser_list->size());
+
+ // Switch to the first profile without opening a new window.
+ model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false);
+ EXPECT_EQ(2U, browser_list->size());
+ EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
+ EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
+
+}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698