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

Side by Side Diff: chrome/browser/profiles/profile_manager_browsertest.cc

Issue 933503004: Always load signin profile on Chrome OS startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 years, 10 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) 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"
11 #include "chrome/browser/profiles/profile_info_cache_observer.h" 11 #include "chrome/browser/profiles/profile_info_cache_observer.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profile_window.h" 13 #include "chrome/browser/profiles/profile_window.h"
14 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/host_desktop.h" 18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h" 21 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
23 #include "components/autofill/core/common/password_form.h" 23 #include "components/autofill/core/common/password_form.h"
24 #include "components/password_manager/core/browser/password_store.h" 24 #include "components/password_manager/core/browser/password_store.h"
25 #include "components/password_manager/core/browser/password_store_consumer.h" 25 #include "components/password_manager/core/browser/password_store_consumer.h"
26 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 27
28 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
29 #include "base/path_service.h" 29 #include "base/path_service.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
30 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_paths.h" 32 #include "chrome/common/chrome_paths.h"
32 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 #endif 35 #endif
35 36
36 namespace { 37 namespace {
37 38
38 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing; 39 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing;
39 40
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 bool IsCalled() const { return called_; } 106 bool IsCalled() const { return called_; }
106 107
107 const std::vector<autofill::PasswordForm*>& GetPasswords() const { 108 const std::vector<autofill::PasswordForm*>& GetPasswords() const {
108 return password_entries_.get(); 109 return password_entries_.get();
109 } 110 }
110 private: 111 private:
111 ScopedVector<autofill::PasswordForm> password_entries_; 112 ScopedVector<autofill::PasswordForm> password_entries_;
112 bool called_; 113 bool called_;
113 }; 114 };
114 115
116 static base::FilePath GetFirstNonSigninProfile(
117 const ProfileInfoCache& cache) {
118 #if defined(OS_CHROMEOS)
119 base::FilePath signin = chromeos::ProfileHelper::GetSigninProfileDir();
mtomasz 2015/02/26 04:27:50 nit: This can be const nit: Variable names shouldn
Ivan Podogov 2015/02/26 11:02:08 Done.
120 size_t i, profile_num = cache.GetNumberOfProfiles();
121 for (i = 0; i != profile_num; ++i) {
122 base::FilePath path = cache.GetPathOfProfileAtIndex(i);
123 if (path != signin)
124 return path;
125 }
126 return base::FilePath();
127 #else
128 return cache.GetPathOfProfileAtIndex(0);
129 #endif
130 }
131
115 } // namespace 132 } // namespace
116 133
117 // This file contains tests for the ProfileManager that require a heavyweight 134 // This file contains tests for the ProfileManager that require a heavyweight
118 // InProcessBrowserTest. These include tests involving profile deletion. 135 // InProcessBrowserTest. These include tests involving profile deletion.
119 136
120 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all 137 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all
121 // platforms. 138 // platforms.
122 class ProfileManagerBrowserTest : public InProcessBrowserTest { 139 class ProfileManagerBrowserTest : public InProcessBrowserTest {
123 protected: 140 protected:
124 void SetUpCommandLine(base::CommandLine* command_line) override { 141 void SetUpCommandLine(base::CommandLine* command_line) override {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 switches::kAshBrowserTests)) 290 switches::kAshBrowserTests))
274 return; 291 return;
275 #endif 292 #endif
276 293
277 // If multiprofile mode is not enabled, you can't switch between profiles. 294 // If multiprofile mode is not enabled, you can't switch between profiles.
278 if (!profiles::IsMultipleProfilesEnabled()) 295 if (!profiles::IsMultipleProfilesEnabled())
279 return; 296 return;
280 297
281 ProfileManager* profile_manager = g_browser_process->profile_manager(); 298 ProfileManager* profile_manager = g_browser_process->profile_manager();
282 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 299 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
283 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); 300 size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
301 base::FilePath path_profile1 = GetFirstNonSigninProfile(cache);
284 302
285 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); 303 ASSERT_NE(0U, initial_profile_count);
286 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 304 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
287 305
288 // Create an additional profile. 306 // Create an additional profile.
289 base::FilePath path_profile2 = 307 base::FilePath path_profile2 =
290 profile_manager->GenerateNextProfileDirectoryPath(); 308 profile_manager->GenerateNextProfileDirectoryPath();
291 profile_manager->CreateProfileAsync(path_profile2, 309 profile_manager->CreateProfileAsync(path_profile2,
292 base::Bind(&OnUnblockOnProfileCreation), 310 base::Bind(&OnUnblockOnProfileCreation),
293 base::string16(), base::string16(), 311 base::string16(), base::string16(),
294 std::string()); 312 std::string());
295 313
296 // Spin to allow profile creation to take place, loop is terminated 314 // Spin to allow profile creation to take place, loop is terminated
297 // by OnUnblockOnProfileCreation when the profile is created. 315 // by OnUnblockOnProfileCreation when the profile is created.
298 content::RunMessageLoop(); 316 content::RunMessageLoop();
299 317
300 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 318 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
301 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); 319 BrowserList* browser_list = BrowserList::GetInstance(desktop_type);
302 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); 320 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
303 EXPECT_EQ(1U, browser_list->size()); 321 EXPECT_EQ(1U, browser_list->size());
304 322
305 // Open a browser window for the first profile. 323 // Open a browser window for the first profile.
306 profiles::SwitchToProfile(path_profile1, desktop_type, false, 324 profiles::SwitchToProfile(path_profile1, desktop_type, false,
307 kOnProfileSwitchDoNothing, 325 kOnProfileSwitchDoNothing,
308 ProfileMetrics::SWITCH_PROFILE_ICON); 326 ProfileMetrics::SWITCH_PROFILE_ICON);
309 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 327 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
310 EXPECT_EQ(1U, browser_list->size()); 328 EXPECT_EQ(1U, browser_list->size());
311 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 329 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
312 330
313 // Open a browser window for the second profile. 331 // Open a browser window for the second profile.
314 profiles::SwitchToProfile(path_profile2, desktop_type, false, 332 profiles::SwitchToProfile(path_profile2, desktop_type, false,
315 kOnProfileSwitchDoNothing, 333 kOnProfileSwitchDoNothing,
316 ProfileMetrics::SWITCH_PROFILE_ICON); 334 ProfileMetrics::SWITCH_PROFILE_ICON);
317 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); 335 EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
318 EXPECT_EQ(2U, browser_list->size()); 336 EXPECT_EQ(2U, browser_list->size());
319 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 337 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
320 338
321 // Switch to the first profile without opening a new window. 339 // Switch to the first profile without opening a new window.
322 profiles::SwitchToProfile(path_profile1, desktop_type, false, 340 profiles::SwitchToProfile(path_profile1, desktop_type, false,
323 kOnProfileSwitchDoNothing, 341 kOnProfileSwitchDoNothing,
324 ProfileMetrics::SWITCH_PROFILE_ICON); 342 ProfileMetrics::SWITCH_PROFILE_ICON);
325 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); 343 EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
326 EXPECT_EQ(2U, browser_list->size()); 344 EXPECT_EQ(2U, browser_list->size());
327 345
328 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 346 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
329 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 347 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
330 } 348 }
331 349
332 // Flakes on Windows: http://crbug.com/314905 350 // Flakes on Windows: http://crbug.com/314905
333 #if defined(OS_WIN) 351 #if defined(OS_WIN)
334 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile 352 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile
335 #else 353 #else
336 #define MAYBE_EphemeralProfile EphemeralProfile 354 #define MAYBE_EphemeralProfile EphemeralProfile
337 #endif 355 #endif
338 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { 356 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) {
339 #if defined(OS_WIN) && defined(USE_ASH) 357 #if defined(OS_WIN) && defined(USE_ASH)
340 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 358 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
341 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 359 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
342 switches::kAshBrowserTests)) 360 switches::kAshBrowserTests))
343 return; 361 return;
344 #endif 362 #endif
345 363
346 // If multiprofile mode is not enabled, you can't switch between profiles. 364 // If multiprofile mode is not enabled, you can't switch between profiles.
347 if (!profiles::IsMultipleProfilesEnabled()) 365 if (!profiles::IsMultipleProfilesEnabled())
348 return; 366 return;
349 367
350 ProfileManager* profile_manager = g_browser_process->profile_manager(); 368 ProfileManager* profile_manager = g_browser_process->profile_manager();
351 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 369 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
352 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); 370 size_t initial_profile_count = profile_manager->GetNumberOfProfiles();
371 base::FilePath path_profile1 = GetFirstNonSigninProfile(cache);
353 372
354 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); 373 ASSERT_NE(0U, initial_profile_count);
355 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 374 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
356 375
357 // Create an ephemeral profile. 376 // Create an ephemeral profile.
358 base::FilePath path_profile2 = 377 base::FilePath path_profile2 =
359 profile_manager->GenerateNextProfileDirectoryPath(); 378 profile_manager->GenerateNextProfileDirectoryPath();
360 profile_manager->CreateProfileAsync( 379 profile_manager->CreateProfileAsync(
361 path_profile2, 380 path_profile2,
362 base::Bind(&EphemeralProfileCreationComplete), 381 base::Bind(&EphemeralProfileCreationComplete),
363 base::string16(), base::string16(), std::string()); 382 base::string16(), base::string16(), std::string());
364 383
365 // Spin to allow profile creation to take place. 384 // Spin to allow profile creation to take place.
366 content::RunMessageLoop(); 385 content::RunMessageLoop();
367 386
368 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 387 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
369 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); 388 BrowserList* browser_list = BrowserList::GetInstance(desktop_type);
370 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); 389 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
371 EXPECT_EQ(1U, browser_list->size()); 390 EXPECT_EQ(1U, browser_list->size());
372 391
373 // Open a browser window for the second profile. 392 // Open a browser window for the second profile.
374 profiles::SwitchToProfile(path_profile2, desktop_type, false, 393 profiles::SwitchToProfile(path_profile2, desktop_type, false,
375 kOnProfileSwitchDoNothing, 394 kOnProfileSwitchDoNothing,
376 ProfileMetrics::SWITCH_PROFILE_ICON); 395 ProfileMetrics::SWITCH_PROFILE_ICON);
377 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); 396 EXPECT_EQ(2U, chrome::GetTotalBrowserCount());
378 EXPECT_EQ(2U, browser_list->size()); 397 EXPECT_EQ(2U, browser_list->size());
379 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 398 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
380 399
381 // Create a second window for the ephemeral profile. 400 // Create a second window for the ephemeral profile.
382 profiles::SwitchToProfile(path_profile2, desktop_type, true, 401 profiles::SwitchToProfile(path_profile2, desktop_type, true,
383 kOnProfileSwitchDoNothing, 402 kOnProfileSwitchDoNothing,
384 ProfileMetrics::SWITCH_PROFILE_ICON); 403 ProfileMetrics::SWITCH_PROFILE_ICON);
385 EXPECT_EQ(3U, chrome::GetTotalBrowserCount()); 404 EXPECT_EQ(3U, chrome::GetTotalBrowserCount());
386 EXPECT_EQ(3U, browser_list->size()); 405 EXPECT_EQ(3U, browser_list->size());
387 406
388 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 407 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath());
389 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 408 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath());
390 EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath()); 409 EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath());
391 410
392 // Closing the first window of the ephemeral profile should not delete it. 411 // Closing the first window of the ephemeral profile should not delete it.
393 browser_list->get(2)->window()->Close(); 412 browser_list->get(2)->window()->Close();
394 content::RunAllPendingInMessageLoop(); 413 content::RunAllPendingInMessageLoop();
395 EXPECT_EQ(2U, browser_list->size()); 414 EXPECT_EQ(2U, browser_list->size());
396 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); 415 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles());
mtomasz 2015/02/26 04:27:50 nit: Can this be EXPECT_EQ? ASSERT should be used
Ivan Podogov 2015/02/26 11:02:08 Done.
397 416
398 // The second should though. 417 // The second should though.
399 browser_list->get(1)->window()->Close(); 418 browser_list->get(1)->window()->Close();
400 content::RunAllPendingInMessageLoop(); 419 content::RunAllPendingInMessageLoop();
401 EXPECT_EQ(1U, browser_list->size()); 420 EXPECT_EQ(1U, browser_list->size());
402 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); 421 EXPECT_EQ(initial_profile_count, cache.GetNumberOfProfiles());
403 } 422 }
404 423
405 // The test makes sense on those platforms where the keychain exists. 424 // The test makes sense on those platforms where the keychain exists.
406 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 425 #if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
407 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { 426 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) {
408 Profile* profile = ProfileManager::GetActiveUserProfile(); 427 Profile* profile = ProfileManager::GetActiveUserProfile();
409 ASSERT_TRUE(profile); 428 ASSERT_TRUE(profile);
410 429
411 autofill::PasswordForm form; 430 autofill::PasswordForm form;
412 form.scheme = autofill::PasswordForm::SCHEME_HTML; 431 form.scheme = autofill::PasswordForm::SCHEME_HTML;
(...skipping 30 matching lines...) Expand all
443 run_loop.QuitClosure()); 462 run_loop.QuitClosure());
444 EXPECT_TRUE(password_store->ScheduleTask(task)); 463 EXPECT_TRUE(password_store->ScheduleTask(task));
445 run_loop.Run(); 464 run_loop.Run();
446 465
447 EXPECT_TRUE(verify_add.IsCalled()); 466 EXPECT_TRUE(verify_add.IsCalled());
448 EXPECT_EQ(1u, verify_add.GetPasswords().size()); 467 EXPECT_EQ(1u, verify_add.GetPasswords().size());
449 EXPECT_TRUE(verify_delete.IsCalled()); 468 EXPECT_TRUE(verify_delete.IsCalled());
450 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); 469 EXPECT_EQ(0u, verify_delete.GetPasswords().size());
451 } 470 }
452 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 471 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698