OLD | NEW |
---|---|
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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 258 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
259 | 259 |
260 // Now close all browser windows. | 260 // Now close all browser windows. |
261 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 261 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
262 for (std::vector<Profile*>::const_iterator it = profiles.begin(); | 262 for (std::vector<Profile*>::const_iterator it = profiles.begin(); |
263 it != profiles.end(); ++it) { | 263 it != profiles.end(); ++it) { |
264 BrowserList::CloseAllBrowsersWithProfile(*it); | 264 BrowserList::CloseAllBrowsersWithProfile(*it); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 base::FilePath GetNonSigninProfileAt(const ProfileInfoCache& cache, | |
269 size_t index) { | |
270 base::FilePath result; | |
271 size_t i, profile_num = cache.GetNumberOfProfiles(); | |
272 for (i = 0; i != profile_num; ++i) { | |
273 base::FilePath path = cache.GetPathOfProfileAtIndex(i); | |
274 #if defined(OS_CHROMEOS) | |
mtomasz
2015/02/20 02:00:42
On OS different than Chrome OS, this loop is unnec
Ivan Podogov
2015/02/24 11:43:17
Done.
| |
275 if (path.BaseName().value() == chrome::kInitialProfile) | |
276 continue; | |
277 #endif | |
278 if (index-- == 0) | |
279 return path; | |
280 } | |
281 return result; | |
282 } | |
283 | |
268 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, | 284 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, |
269 SwitchToProfile) { | 285 SwitchToProfile) { |
270 #if defined(OS_WIN) && defined(USE_ASH) | 286 #if defined(OS_WIN) && defined(USE_ASH) |
271 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 287 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
272 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 288 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
273 switches::kAshBrowserTests)) | 289 switches::kAshBrowserTests)) |
274 return; | 290 return; |
275 #endif | 291 #endif |
276 | 292 |
277 // If multiprofile mode is not enabled, you can't switch between profiles. | 293 // If multiprofile mode is not enabled, you can't switch between profiles. |
278 if (!profiles::IsMultipleProfilesEnabled()) | 294 if (!profiles::IsMultipleProfilesEnabled()) |
279 return; | 295 return; |
280 | 296 |
281 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 297 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
282 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 298 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
283 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); | 299 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); |
300 base::FilePath path_profile1 = GetNonSigninProfileAt(cache, 0); | |
284 | 301 |
285 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); | 302 ASSERT_NE(0U, initial_profile_count); |
286 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 303 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
287 | 304 |
288 // Create an additional profile. | 305 // Create an additional profile. |
289 base::FilePath path_profile2 = | 306 base::FilePath path_profile2 = |
290 profile_manager->GenerateNextProfileDirectoryPath(); | 307 profile_manager->GenerateNextProfileDirectoryPath(); |
291 profile_manager->CreateProfileAsync(path_profile2, | 308 profile_manager->CreateProfileAsync(path_profile2, |
292 base::Bind(&OnUnblockOnProfileCreation), | 309 base::Bind(&OnUnblockOnProfileCreation), |
293 base::string16(), base::string16(), | 310 base::string16(), base::string16(), |
294 std::string()); | 311 std::string()); |
295 | 312 |
296 // Spin to allow profile creation to take place, loop is terminated | 313 // Spin to allow profile creation to take place, loop is terminated |
297 // by OnUnblockOnProfileCreation when the profile is created. | 314 // by OnUnblockOnProfileCreation when the profile is created. |
298 content::RunMessageLoop(); | 315 content::RunMessageLoop(); |
299 | 316 |
300 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 317 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
301 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); | 318 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); |
302 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | 319 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles()); |
303 EXPECT_EQ(1U, browser_list->size()); | 320 EXPECT_EQ(1U, browser_list->size()); |
304 | 321 |
305 // Open a browser window for the first profile. | 322 // Open a browser window for the first profile. |
306 profiles::SwitchToProfile(path_profile1, desktop_type, false, | 323 profiles::SwitchToProfile(path_profile1, desktop_type, false, |
307 kOnProfileSwitchDoNothing, | 324 kOnProfileSwitchDoNothing, |
308 ProfileMetrics::SWITCH_PROFILE_ICON); | 325 ProfileMetrics::SWITCH_PROFILE_ICON); |
309 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 326 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
310 EXPECT_EQ(1U, browser_list->size()); | 327 EXPECT_EQ(1U, browser_list->size()); |
311 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 328 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
312 | 329 |
313 // Open a browser window for the second profile. | 330 // Open a browser window for the second profile. |
314 profiles::SwitchToProfile(path_profile2, desktop_type, false, | 331 profiles::SwitchToProfile(path_profile2, desktop_type, false, |
315 kOnProfileSwitchDoNothing, | 332 kOnProfileSwitchDoNothing, |
316 ProfileMetrics::SWITCH_PROFILE_ICON); | 333 ProfileMetrics::SWITCH_PROFILE_ICON); |
317 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 334 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); |
318 EXPECT_EQ(2U, browser_list->size()); | 335 EXPECT_EQ(2U, browser_list->size()); |
319 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 336 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
320 | 337 |
321 // Switch to the first profile without opening a new window. | 338 // Switch to the first profile without opening a new window. |
322 profiles::SwitchToProfile(path_profile1, desktop_type, false, | 339 profiles::SwitchToProfile(path_profile1, desktop_type, false, |
323 kOnProfileSwitchDoNothing, | 340 kOnProfileSwitchDoNothing, |
324 ProfileMetrics::SWITCH_PROFILE_ICON); | 341 ProfileMetrics::SWITCH_PROFILE_ICON); |
325 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 342 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); |
326 EXPECT_EQ(2U, browser_list->size()); | 343 EXPECT_EQ(2U, browser_list->size()); |
327 | 344 |
328 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 345 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
329 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 346 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
330 } | 347 } |
331 | 348 |
332 // Flakes on Windows: http://crbug.com/314905 | 349 // Flakes on Windows: http://crbug.com/314905 |
333 #if defined(OS_WIN) | 350 #if defined(OS_WIN) |
334 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile | 351 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile |
335 #else | 352 #else |
336 #define MAYBE_EphemeralProfile EphemeralProfile | 353 #define MAYBE_EphemeralProfile EphemeralProfile |
337 #endif | 354 #endif |
338 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { | 355 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { |
339 #if defined(OS_WIN) && defined(USE_ASH) | 356 #if defined(OS_WIN) && defined(USE_ASH) |
340 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 357 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
341 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 358 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
342 switches::kAshBrowserTests)) | 359 switches::kAshBrowserTests)) |
343 return; | 360 return; |
344 #endif | 361 #endif |
345 | 362 |
346 // If multiprofile mode is not enabled, you can't switch between profiles. | 363 // If multiprofile mode is not enabled, you can't switch between profiles. |
347 if (!profiles::IsMultipleProfilesEnabled()) | 364 if (!profiles::IsMultipleProfilesEnabled()) |
348 return; | 365 return; |
349 | 366 |
350 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 367 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
351 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 368 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
352 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); | 369 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); |
370 base::FilePath path_profile1 = GetNonSigninProfileAt(cache, 0); | |
353 | 371 |
354 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 372 ASSERT_NE(0U, initial_profile_count); |
355 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); | 373 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
356 | 374 |
357 // Create an ephemeral profile. | 375 // Create an ephemeral profile. |
358 base::FilePath path_profile2 = | 376 base::FilePath path_profile2 = |
359 profile_manager->GenerateNextProfileDirectoryPath(); | 377 profile_manager->GenerateNextProfileDirectoryPath(); |
360 profile_manager->CreateProfileAsync( | 378 profile_manager->CreateProfileAsync( |
361 path_profile2, | 379 path_profile2, |
362 base::Bind(&EphemeralProfileCreationComplete), | 380 base::Bind(&EphemeralProfileCreationComplete), |
363 base::string16(), base::string16(), std::string()); | 381 base::string16(), base::string16(), std::string()); |
364 | 382 |
365 // Spin to allow profile creation to take place. | 383 // Spin to allow profile creation to take place. |
366 content::RunMessageLoop(); | 384 content::RunMessageLoop(); |
367 | 385 |
368 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 386 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
369 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); | 387 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); |
370 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); | 388 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles()); |
371 EXPECT_EQ(1U, browser_list->size()); | 389 EXPECT_EQ(1U, browser_list->size()); |
372 | 390 |
373 // Open a browser window for the second profile. | 391 // Open a browser window for the second profile. |
374 profiles::SwitchToProfile(path_profile2, desktop_type, false, | 392 profiles::SwitchToProfile(path_profile2, desktop_type, false, |
375 kOnProfileSwitchDoNothing, | 393 kOnProfileSwitchDoNothing, |
376 ProfileMetrics::SWITCH_PROFILE_ICON); | 394 ProfileMetrics::SWITCH_PROFILE_ICON); |
377 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); | 395 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); |
378 EXPECT_EQ(2U, browser_list->size()); | 396 EXPECT_EQ(2U, browser_list->size()); |
379 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 397 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
380 | 398 |
381 // Create a second window for the ephemeral profile. | 399 // Create a second window for the ephemeral profile. |
382 profiles::SwitchToProfile(path_profile2, desktop_type, true, | 400 profiles::SwitchToProfile(path_profile2, desktop_type, true, |
383 kOnProfileSwitchDoNothing, | 401 kOnProfileSwitchDoNothing, |
384 ProfileMetrics::SWITCH_PROFILE_ICON); | 402 ProfileMetrics::SWITCH_PROFILE_ICON); |
385 EXPECT_EQ(3U, chrome::GetTotalBrowserCount()); | 403 EXPECT_EQ(3U, chrome::GetTotalBrowserCount()); |
386 EXPECT_EQ(3U, browser_list->size()); | 404 EXPECT_EQ(3U, browser_list->size()); |
387 | 405 |
388 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 406 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
389 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 407 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
390 EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath()); | 408 EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath()); |
391 | 409 |
392 // Closing the first window of the ephemeral profile should not delete it. | 410 // Closing the first window of the ephemeral profile should not delete it. |
393 browser_list->get(2)->window()->Close(); | 411 browser_list->get(2)->window()->Close(); |
394 content::RunAllPendingInMessageLoop(); | 412 content::RunAllPendingInMessageLoop(); |
395 EXPECT_EQ(2U, browser_list->size()); | 413 EXPECT_EQ(2U, browser_list->size()); |
396 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); | 414 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles()); |
397 | 415 |
398 // The second should though. | 416 // The second should though. |
399 browser_list->get(1)->window()->Close(); | 417 browser_list->get(1)->window()->Close(); |
400 content::RunAllPendingInMessageLoop(); | 418 content::RunAllPendingInMessageLoop(); |
401 EXPECT_EQ(1U, browser_list->size()); | 419 EXPECT_EQ(1U, browser_list->size()); |
402 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); | 420 EXPECT_EQ(initial_profile_count, cache.GetNumberOfProfiles()); |
403 } | 421 } |
404 | 422 |
405 // The test makes sense on those platforms where the keychain exists. | 423 // The test makes sense on those platforms where the keychain exists. |
406 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 424 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
407 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { | 425 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { |
408 Profile* profile = ProfileManager::GetActiveUserProfile(); | 426 Profile* profile = ProfileManager::GetActiveUserProfile(); |
409 ASSERT_TRUE(profile); | 427 ASSERT_TRUE(profile); |
410 | 428 |
411 autofill::PasswordForm form; | 429 autofill::PasswordForm form; |
412 form.scheme = autofill::PasswordForm::SCHEME_HTML; | 430 form.scheme = autofill::PasswordForm::SCHEME_HTML; |
(...skipping 30 matching lines...) Expand all Loading... | |
443 run_loop.QuitClosure()); | 461 run_loop.QuitClosure()); |
444 EXPECT_TRUE(password_store->ScheduleTask(task)); | 462 EXPECT_TRUE(password_store->ScheduleTask(task)); |
445 run_loop.Run(); | 463 run_loop.Run(); |
446 | 464 |
447 EXPECT_TRUE(verify_add.IsCalled()); | 465 EXPECT_TRUE(verify_add.IsCalled()); |
448 EXPECT_EQ(1u, verify_add.GetPasswords().size()); | 466 EXPECT_EQ(1u, verify_add.GetPasswords().size()); |
449 EXPECT_TRUE(verify_delete.IsCalled()); | 467 EXPECT_TRUE(verify_delete.IsCalled()); |
450 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); | 468 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); |
451 } | 469 } |
452 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 470 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
OLD | NEW |