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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
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::GetActiveDesktop()); 41 BrowserList::GetInstance(chrome::GetActiveDesktop());
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.SetLogoutURL("about:blank"); 48 model.SetLogoutURL("about:blank");
41 model.BeginSignOut(); 49 model.BeginSignOut();
42 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(index)); 50 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(index));
43 51
44 window_close_observer.Wait(); // rely on test time-out for failure indication 52 window_close_observer.Wait(); // rely on test time-out for failure indication
45 EXPECT_EQ(0U, browser_list->size()); 53 EXPECT_EQ(0U, browser_list->size());
46 } 54 }
47 55
56 IN_PROC_BROWSER_TEST_F(AvatarMenuModelTest, SwitchToProfile) {
57 if (!ProfileManager::IsMultipleProfilesEnabled())
58 return;
59
60 ProfileManager* profile_manager = g_browser_process->profile_manager();
61 Profile* current_profile = browser()->profile();
62 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
63 base::FilePath path_profile1 = current_profile->GetPath();
64 base::FilePath user_dir = cache.GetUserDataDir();
65
66 // Create an additional profile.
67 base::FilePath path_profile2 = user_dir.Append(
68 FILE_PATH_LITERAL("New Profile 2"));
69 profile_manager->CreateProfileAsync(path_profile2,
70 base::Bind(&OnUnblockOnProfileCreation),
71 string16(), string16(), false);
72
73 // Spin to allow profile creation to take place, loop is terminated
74 // by OnUnblockOnProfileCreation when the profile is created.
75 content::RunMessageLoop();
76 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U);
77
78 AvatarMenuModel model(&cache, NULL, browser());
79 BrowserList* browser_list =
80 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
81 EXPECT_EQ(1U, browser_list->size());
82 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
83
84 // Open a browser window for the first profile.
85 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false);
86 EXPECT_EQ(1U, browser_list->size());
87 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
88
89 // Open a browser window for the second profile.
90 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile2), false);
91 EXPECT_EQ(2U, browser_list->size());
92
93 // Switch to the first profile without opening a new window.
94 model.SwitchToProfile(cache.GetIndexOfProfileWithPath(path_profile1), false);
95 EXPECT_EQ(2U, browser_list->size());
96 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
97 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
98
99 }
48 } // namespace 100 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698