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