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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_unittest.cc

Issue 271533004: Turning on MultiProfile by default for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 <cstdlib> 5 #include <cstdlib>
6 #include <cstring> 6 #include <cstring>
7 7
8 #include "base/command_line.h"
9 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/login/user.h" 15 #include "chrome/browser/chromeos/login/user.h"
14 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/chromeos/login/user_manager_impl.h" 17 #include "chrome/browser/chromeos/login/user_manager_impl.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 18 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "chrome/browser/chromeos/settings/device_settings_service.h" 19 #include "chrome/browser/chromeos/settings/device_settings_service.h"
18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 20 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
21 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/test/base/scoped_testing_local_state.h" 22 #include "chrome/test/base/scoped_testing_local_state.h"
20 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
24 #include "chrome/test/base/testing_profile.h"
25 #include "chromeos/chromeos_switches.h"
26 #include "chromeos/dbus/dbus_thread_manager.h"
27 #include "chromeos/dbus/fake_dbus_thread_manager.h"
21 #include "chromeos/settings/cros_settings_names.h" 28 #include "chromeos/settings/cros_settings_names.h"
22 #include "chromeos/settings/cros_settings_provider.h" 29 #include "chromeos/settings/cros_settings_provider.h"
30 #include "content/public/common/content_switches.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
25 33
26 namespace chromeos { 34 namespace chromeos {
27 35
36 class UnittestProfileManager : public ::ProfileManagerWithoutInit {
37 public:
38 explicit UnittestProfileManager(const base::FilePath& user_data_dir)
39 : ::ProfileManagerWithoutInit(user_data_dir) {}
40
41 protected:
42 virtual Profile* CreateProfileHelper(
43 const base::FilePath& file_path) OVERRIDE {
44 if (!base::PathExists(file_path)) {
45 if (!base::CreateDirectory(file_path))
46 return NULL;
47 }
48 return new TestingProfile(file_path, NULL);
49 }
50 };
51
52
28 class UserManagerTest : public testing::Test { 53 class UserManagerTest : public testing::Test {
29 protected: 54 protected:
30 virtual void SetUp() OVERRIDE { 55 virtual void SetUp() OVERRIDE {
56 CommandLine& command_line = *CommandLine::ForCurrentProcess();
57 command_line.AppendSwitch(::switches::kTestType);
58 command_line.AppendSwitch(
59 chromeos::switches::kIgnoreUserProfileMappingForTests);
60
31 cros_settings_ = CrosSettings::Get(); 61 cros_settings_ = CrosSettings::Get();
32 62
33 // Replace the real DeviceSettingsProvider with a stub. 63 // Replace the real DeviceSettingsProvider with a stub.
34 device_settings_provider_ = 64 device_settings_provider_ =
35 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); 65 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo);
36 EXPECT_TRUE(device_settings_provider_); 66 EXPECT_TRUE(device_settings_provider_);
37 EXPECT_TRUE( 67 EXPECT_TRUE(
38 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); 68 cros_settings_->RemoveSettingsProvider(device_settings_provider_));
39 cros_settings_->AddSettingsProvider(&stub_settings_provider_); 69 cros_settings_->AddSettingsProvider(&stub_settings_provider_);
40 70
41 // Populate the stub DeviceSettingsProvider with valid values. 71 // Populate the stub DeviceSettingsProvider with valid values.
42 SetDeviceSettings(false, "", false); 72 SetDeviceSettings(false, "", false);
43 73
44 // Register an in-memory local settings instance. 74 // Register an in-memory local settings instance.
45 local_state_.reset( 75 local_state_.reset(
46 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); 76 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal()));
47 77
78 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
79 TestingBrowserProcess::GetGlobal()->SetProfileManager(
80 new UnittestProfileManager(temp_dir_.path()));
81
82 chromeos::FakeDBusThreadManager* dbus_manager =
83 new chromeos::FakeDBusThreadManager();
84 chromeos::DBusThreadManager::InitializeForTesting(dbus_manager);
85
48 ResetUserManager(); 86 ResetUserManager();
49 } 87 }
50 88
51 virtual void TearDown() OVERRIDE { 89 virtual void TearDown() OVERRIDE {
52 // Unregister the in-memory local settings instance. 90 // Unregister the in-memory local settings instance.
53 local_state_.reset(); 91 local_state_.reset();
54 92
55 // Restore the real DeviceSettingsProvider. 93 // Restore the real DeviceSettingsProvider.
56 EXPECT_TRUE( 94 EXPECT_TRUE(
57 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); 95 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_));
58 cros_settings_->AddSettingsProvider(device_settings_provider_); 96 cros_settings_->AddSettingsProvider(device_settings_provider_);
59 97
60 // Shut down the DeviceSettingsService. 98 // Shut down the DeviceSettingsService.
61 DeviceSettingsService::Get()->UnsetSessionManager(); 99 DeviceSettingsService::Get()->UnsetSessionManager();
100 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
62 101
63 base::RunLoop().RunUntilIdle(); 102 base::RunLoop().RunUntilIdle();
103 chromeos::DBusThreadManager::Shutdown();
64 } 104 }
65 105
66 UserManagerImpl* GetUserManagerImpl() const { 106 UserManagerImpl* GetUserManagerImpl() const {
67 return static_cast<UserManagerImpl*>(UserManager::Get()); 107 return static_cast<UserManagerImpl*>(UserManager::Get());
68 } 108 }
69 109
70 bool GetUserManagerEphemeralUsersEnabled() const { 110 bool GetUserManagerEphemeralUsersEnabled() const {
71 return GetUserManagerImpl()->ephemeral_users_enabled_; 111 return GetUserManagerImpl()->ephemeral_users_enabled_;
72 } 112 }
73 113
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 153
114 CrosSettings* cros_settings_; 154 CrosSettings* cros_settings_;
115 CrosSettingsProvider* device_settings_provider_; 155 CrosSettingsProvider* device_settings_provider_;
116 StubCrosSettingsProvider stub_settings_provider_; 156 StubCrosSettingsProvider stub_settings_provider_;
117 scoped_ptr<ScopedTestingLocalState> local_state_; 157 scoped_ptr<ScopedTestingLocalState> local_state_;
118 158
119 ScopedTestDeviceSettingsService test_device_settings_service_; 159 ScopedTestDeviceSettingsService test_device_settings_service_;
120 ScopedTestCrosSettings test_cros_settings_; 160 ScopedTestCrosSettings test_cros_settings_;
121 161
122 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; 162 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
163 base::ScopedTempDir temp_dir_;
123 }; 164 };
124 165
125 TEST_F(UserManagerTest, RetrieveTrustedDevicePolicies) { 166 TEST_F(UserManagerTest, RetrieveTrustedDevicePolicies) {
126 SetUserManagerEphemeralUsersEnabled(true); 167 SetUserManagerEphemeralUsersEnabled(true);
127 SetUserManagerOwnerEmail(""); 168 SetUserManagerOwnerEmail("");
128 169
129 SetDeviceSettings(false, "owner@invalid.domain", false); 170 SetDeviceSettings(false, "owner@invalid.domain", false);
130 RetrieveTrustedDevicePolicies(); 171 RetrieveTrustedDevicePolicies();
131 172
132 EXPECT_FALSE(GetUserManagerEphemeralUsersEnabled()); 173 EXPECT_FALSE(GetUserManagerEphemeralUsersEnabled());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 UserManager::Get()->UserLoggedIn( 209 UserManager::Get()->UserLoggedIn(
169 "user0@invalid.domain", "user0@invalid.domain", false); 210 "user0@invalid.domain", "user0@invalid.domain", false);
170 ResetUserManager(); 211 ResetUserManager();
171 212
172 const UserList* users = &UserManager::Get()->GetUsers(); 213 const UserList* users = &UserManager::Get()->GetUsers();
173 EXPECT_EQ(1U, users->size()); 214 EXPECT_EQ(1U, users->size());
174 EXPECT_EQ((*users)[0]->email(), "owner@invalid.domain"); 215 EXPECT_EQ((*users)[0]->email(), "owner@invalid.domain");
175 } 216 }
176 217
177 } // namespace chromeos 218 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.cc ('k') | chrome/browser/chromeos/login/wallpaper_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698