1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/profiles/profile_window.h"
10 #include "chrome/browser/ui/user_manager.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile_manager.h"
16 class UserManagerMacTest : public BrowserWithTestWindowTest {
19 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {
22 void SetUp() override {
23 BrowserWithTestWindowTest::SetUp();
24 ASSERT_TRUE(testing_profile_manager_.SetUp());
25 // Pre-load the system profile so we don't have to wait for the User Manager
26 // to asynchronously create it.
27 testing_profile_manager_.CreateSystemProfile();
30 void TearDown() override {
31 testing_profile_manager_.DeleteSystemProfile();
32 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
33 base::RunLoop().RunUntilIdle();
34 BrowserWithTestWindowTest::TearDown();
38 TestingProfileManager testing_profile_manager_;
40 DISALLOW_COPY_AND_ASSIGN(UserManagerMacTest);
43 TEST_F(UserManagerMacTest, ShowUserManager) {
44 // Set the ProfileLastUsed pref so that SetActiveProfileToGuestIfLocked()
45 // uses a last active profile that's in the ProfileInfoCache, not default.
46 g_browser_process->local_state()->SetString(
47 prefs::kProfileLastUsed,
48 g_browser_process->profile_manager()->GetProfileInfoCache().
49 GetPathOfProfileAtIndex(0).BaseName().MaybeAsASCII());
51 EXPECT_FALSE(UserManager::IsShowing());
52 UserManager::Show(base::FilePath(),
53 profiles::USER_MANAGER_NO_TUTORIAL,
54 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
55 EXPECT_TRUE(UserManager::IsShowing());
58 EXPECT_FALSE(UserManager::IsShowing());