Chromium Code Reviews

Side by Side Diff: chrome/browser/app_controller_mac_browsertest.mm

Issue 239543012: The User Manager should be backed by a special profile, not the guest one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nico's comment + fix tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "apps/app_window_registry.h" 7 #include "apps/app_window_registry.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 116 matching lines...)
127 Profile::CreateStatus status) { 127 Profile::CreateStatus status) {
128 EXPECT_TRUE(profile); 128 EXPECT_TRUE(profile);
129 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); 129 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status);
130 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); 130 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status);
131 // This will be called multiple times. Wait until the profile is initialized 131 // This will be called multiple times. Wait until the profile is initialized
132 // fully to quit the loop. 132 // fully to quit the loop.
133 if (status == Profile::CREATE_STATUS_INITIALIZED) 133 if (status == Profile::CREATE_STATUS_INITIALIZED)
134 quit_closure.Run(); 134 quit_closure.Run();
135 } 135 }
136 136
137 void CreateAndWaitForGuestProfile() { 137 void CreateAndWaitForProfileWithPath(const base::FilePath& path) {
138 ProfileManager::CreateCallback create_callback = 138 ProfileManager::CreateCallback create_callback =
139 base::Bind(&CreateProfileCallback, 139 base::Bind(&CreateProfileCallback,
140 base::MessageLoop::current()->QuitClosure()); 140 base::MessageLoop::current()->QuitClosure());
141 g_browser_process->profile_manager()->CreateProfileAsync( 141 g_browser_process->profile_manager()->CreateProfileAsync(
142 ProfileManager::GetGuestProfilePath(), 142 path,
143 create_callback, 143 create_callback,
144 base::string16(), 144 base::string16(),
145 base::string16(), 145 base::string16(),
146 std::string()); 146 std::string());
147 base::RunLoop().Run(); 147 base::RunLoop().Run();
148 } 148 }
149 149
150 class AppControllerNewProfileManagementBrowserTest 150 class AppControllerNewProfileManagementBrowserTest
151 : public InProcessBrowserTest { 151 : public InProcessBrowserTest {
152 protected: 152 protected:
(...skipping 17 matching lines...)
170 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; 170 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
171 171
172 EXPECT_FALSE(result); 172 EXPECT_FALSE(result);
173 EXPECT_EQ(2u, active_browser_list_->size()); 173 EXPECT_EQ(2u, active_browser_list_->size());
174 EXPECT_FALSE(UserManagerMac::IsShowing()); 174 EXPECT_FALSE(UserManagerMac::IsShowing());
175 } 175 }
176 176
177 // Test that for a locked last profile, a reopen event opens the User Manager. 177 // Test that for a locked last profile, a reopen event opens the User Manager.
178 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, 178 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
179 LockedProfileReopenWithNoWindows) { 179 LockedProfileReopenWithNoWindows) {
180 // The User Manager uses the guest profile as its underlying profile. To 180 // The User Manager uses a special profile as its underlying profile. To
181 // minimize flakiness due to the scheduling/descheduling of tasks on the 181 // minimize flakiness due to the scheduling/descheduling of tasks on the
182 // different threads, pre-initialize the guest profile before it is needed. 182 // different threads, pre-initialize this profile before it is needed.
183 CreateAndWaitForGuestProfile(); 183 CreateAndWaitForProfileWithPath(ProfileManager::GetUserManagerProfilePath());
184 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); 184 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
185 185
186 // Lock the active profile. 186 // Lock the active profile.
187 Profile* profile = [ac lastProfile]; 187 Profile* profile = [ac lastProfile];
188 ProfileInfoCache& cache = 188 ProfileInfoCache& cache =
189 g_browser_process->profile_manager()->GetProfileInfoCache(); 189 g_browser_process->profile_manager()->GetProfileInfoCache();
190 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 190 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
191 cache.SetProfileSigninRequiredAtIndex(profile_index, true); 191 cache.SetProfileSigninRequiredAtIndex(profile_index, true);
192 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index)); 192 EXPECT_TRUE(cache.ProfileIsSigninRequiredAtIndex(profile_index));
193 193
194 EXPECT_EQ(1u, active_browser_list_->size()); 194 EXPECT_EQ(1u, active_browser_list_->size());
195 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; 195 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
196 EXPECT_FALSE(result); 196 EXPECT_FALSE(result);
197 197
198 base::RunLoop().RunUntilIdle(); 198 base::RunLoop().RunUntilIdle();
199 EXPECT_EQ(1u, active_browser_list_->size()); 199 EXPECT_EQ(1u, active_browser_list_->size());
200 EXPECT_TRUE(UserManagerMac::IsShowing()); 200 EXPECT_TRUE(UserManagerMac::IsShowing());
201 UserManagerMac::Hide(); 201 UserManagerMac::Hide();
202 } 202 }
203 203
204 // Test that for a guest last profile, a reopen event opens the User Manager. 204 // Test that for a guest last profile, a reopen event opens the User Manager.
205 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest, 205 IN_PROC_BROWSER_TEST_F(AppControllerNewProfileManagementBrowserTest,
206 GuestProfileReopenWithNoWindows) { 206 GuestProfileReopenWithNoWindows) {
207 // Create the guest profile, and set it as the last used profile so the 207 // Create the guest profile, and set it as the last used profile so the
208 // app controller can use it on init. 208 // app controller can use it on init.
209 CreateAndWaitForGuestProfile(); 209 CreateAndWaitForProfileWithPath(ProfileManager::GetGuestProfilePath());
210 PrefService* local_state = g_browser_process->local_state(); 210 PrefService* local_state = g_browser_process->local_state();
211 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir); 211 local_state->SetString(prefs::kProfileLastUsed, chrome::kGuestProfileDir);
212 212
213 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); 213 base::scoped_nsobject<AppController> ac([[AppController alloc] init]);
214 214
215 Profile* profile = [ac lastProfile]; 215 Profile* profile = [ac lastProfile];
216 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath()); 216 EXPECT_EQ(ProfileManager::GetGuestProfilePath(), profile->GetPath());
217 EXPECT_TRUE(profile->IsGuestSession()); 217 EXPECT_TRUE(profile->IsGuestSession());
218 218
219 EXPECT_EQ(1u, active_browser_list_->size()); 219 EXPECT_EQ(1u, active_browser_list_->size());
220 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; 220 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO];
221 EXPECT_FALSE(result); 221 EXPECT_FALSE(result);
222 222
223 base::RunLoop().RunUntilIdle(); 223 base::RunLoop().RunUntilIdle();
224 224
225 EXPECT_EQ(1u, active_browser_list_->size()); 225 EXPECT_EQ(1u, active_browser_list_->size());
226 EXPECT_TRUE(UserManagerMac::IsShowing()); 226 EXPECT_TRUE(UserManagerMac::IsShowing());
227 UserManagerMac::Hide(); 227 UserManagerMac::Hide();
228 } 228 }
229 229
230 } // namespace 230 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profiles/profile_manager.h » ('j') | no next file with comments »

Powered by Google App Engine