Chromium Code Reviews| 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(ProfileInfoCache& cache, size_t index) { | |
|
mtomasz
2015/02/18 03:13:06
ProfileInfoCache& -> const ProfileInfoCache&
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 269 base::FilePath result; | |
| 270 size_t i, idx = 0, profile_num = cache.GetNumberOfProfiles(); | |
|
mtomasz
2015/02/18 03:13:06
We have here i, idx, index. It's really difficult
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 271 for (i = 0; i != profile_num; ++i) { | |
| 272 base::FilePath path = cache.GetPathOfProfileAtIndex(i); | |
| 273 #if defined(OS_CHROMEOS) | |
| 274 if (path.BaseName().value() == chrome::kInitialProfile) | |
| 275 continue; | |
| 276 #endif | |
| 277 if (idx == index) | |
|
Mr4D (OOO till 08-26)
2015/02/17 15:46:51
You could do a "idx++" here to eliminate line 279.
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 278 return path; | |
| 279 ++idx; | |
| 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 unsigned int initial_profile_count = profile_manager->GetNumberOfProfiles(); |
|
mtomasz
2015/02/18 03:13:07
Is number of profiles "unsigned int" or "size_t"?
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 300 base::FilePath path_profile1 = GetNonSigninProfileAt(cache, 0); | |
| 284 | 301 |
| 285 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); | 302 ASSERT_NE(initial_profile_count, 0U); |
|
mtomasz
2015/02/18 03:13:06
Opposite argument order. Should be:
ASSERT(expecte
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 286 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 303 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 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(cache.GetNumberOfProfiles(), initial_profile_count + 1); |
| 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(chrome::GetTotalBrowserCount(), 1U); |
| 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 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 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 unsigned int initial_profile_count = profile_manager->GetNumberOfProfiles(); |
|
mtomasz
2015/02/18 03:13:07
ditto
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 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 ASSERT_EQ(initial_profile_count, cache.GetNumberOfProfiles()); |
|
mtomasz
2015/02/18 03:13:06
This can be EXPECT. AFAIK ASSERT should be used on
Ivan Podogov
2015/02/24 11:43:16
Done.
| |
| 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 |