OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
bartfab (slow)
2015/03/31 14:12:40
Nit: No longer used.
| |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" | 16 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" |
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 18 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/settings_provider_test_base.h" |
20 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
21 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
bartfab (slow)
2015/03/31 14:12:40
Nit: Still used in line 128 and others.
| |
22 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
23 #include "chrome/test/base/scoped_testing_local_state.h" | 21 #include "chrome/test/base/scoped_testing_local_state.h" |
24 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
25 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
26 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
27 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
28 #include "chromeos/settings/cros_settings_names.h" | 26 #include "chromeos/settings/cros_settings_names.h" |
29 #include "chromeos/settings/cros_settings_provider.h" | |
30 #include "components/user_manager/user.h" | 27 #include "components/user_manager/user.h" |
31 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
32 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
33 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
35 | 32 |
36 namespace chromeos { | 33 namespace chromeos { |
37 | 34 |
38 class UnittestProfileManager : public ::ProfileManagerWithoutInit { | 35 class UnittestProfileManager : public ::ProfileManagerWithoutInit { |
39 public: | 36 public: |
40 explicit UnittestProfileManager(const base::FilePath& user_data_dir) | 37 explicit UnittestProfileManager(const base::FilePath& user_data_dir) |
41 : ::ProfileManagerWithoutInit(user_data_dir) {} | 38 : ::ProfileManagerWithoutInit(user_data_dir) {} |
42 | 39 |
43 protected: | 40 protected: |
44 Profile* CreateProfileHelper(const base::FilePath& file_path) override { | 41 Profile* CreateProfileHelper(const base::FilePath& file_path) override { |
45 if (!base::PathExists(file_path)) { | 42 if (!base::PathExists(file_path)) { |
46 if (!base::CreateDirectory(file_path)) | 43 if (!base::CreateDirectory(file_path)) |
47 return NULL; | 44 return NULL; |
48 } | 45 } |
49 return new TestingProfile(file_path, NULL); | 46 return new TestingProfile(file_path, NULL); |
50 } | 47 } |
51 }; | 48 }; |
52 | 49 |
53 | 50 class UserManagerTest : public testing::Test, public SettingsProviderTestBase { |
54 class UserManagerTest : public testing::Test { | |
55 protected: | 51 protected: |
56 void SetUp() override { | 52 void SetUp() override { |
57 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); | 53 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
58 command_line.AppendSwitch(::switches::kTestType); | 54 command_line.AppendSwitch(::switches::kTestType); |
59 command_line.AppendSwitch( | 55 command_line.AppendSwitch( |
60 chromeos::switches::kIgnoreUserProfileMappingForTests); | 56 chromeos::switches::kIgnoreUserProfileMappingForTests); |
61 | 57 |
62 cros_settings_ = CrosSettings::Get(); | 58 ReplaceProvider(kDeviceOwner); |
63 | |
64 // Replace the real DeviceSettingsProvider with a stub. | |
65 device_settings_provider_ = | |
66 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); | |
67 EXPECT_TRUE(device_settings_provider_); | |
68 EXPECT_TRUE( | |
69 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); | |
70 cros_settings_->AddSettingsProvider(&stub_settings_provider_); | |
71 | 59 |
72 // Populate the stub DeviceSettingsProvider with valid values. | 60 // Populate the stub DeviceSettingsProvider with valid values. |
73 SetDeviceSettings(false, "", false); | 61 SetDeviceSettings(false, "", false); |
74 | 62 |
75 // Register an in-memory local settings instance. | 63 // Register an in-memory local settings instance. |
76 local_state_.reset( | 64 local_state_.reset( |
77 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); | 65 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); |
78 | 66 |
79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
80 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 68 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
81 new UnittestProfileManager(temp_dir_.path())); | 69 new UnittestProfileManager(temp_dir_.path())); |
82 | 70 |
83 chromeos::DBusThreadManager::Initialize(); | 71 chromeos::DBusThreadManager::Initialize(); |
84 | 72 |
85 ResetUserManager(); | 73 ResetUserManager(); |
86 WallpaperManager::Initialize(); | 74 WallpaperManager::Initialize(); |
87 } | 75 } |
88 | 76 |
89 void TearDown() override { | 77 void TearDown() override { |
90 // Unregister the in-memory local settings instance. | 78 // Unregister the in-memory local settings instance. |
91 local_state_.reset(); | 79 local_state_.reset(); |
92 | 80 |
93 // Restore the real DeviceSettingsProvider. | 81 RestoreProvider(); |
94 EXPECT_TRUE( | |
95 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); | |
96 cros_settings_->AddSettingsProvider(device_settings_provider_); | |
97 | 82 |
98 // Shut down the DeviceSettingsService. | 83 // Shut down the DeviceSettingsService. |
99 DeviceSettingsService::Get()->UnsetSessionManager(); | 84 DeviceSettingsService::Get()->UnsetSessionManager(); |
100 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 85 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
101 | 86 |
102 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
103 chromeos::DBusThreadManager::Shutdown(); | 88 chromeos::DBusThreadManager::Shutdown(); |
104 WallpaperManager::Shutdown(); | 89 WallpaperManager::Shutdown(); |
105 } | 90 } |
106 | 91 |
(...skipping 26 matching lines...) Expand all Loading... | |
133 user_manager_enabler_.reset( | 118 user_manager_enabler_.reset( |
134 new ScopedUserManagerEnabler(new ChromeUserManagerImpl)); | 119 new ScopedUserManagerEnabler(new ChromeUserManagerImpl)); |
135 | 120 |
136 // ChromeUserManagerImpl ctor posts a task to reload policies. | 121 // ChromeUserManagerImpl ctor posts a task to reload policies. |
137 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
138 } | 123 } |
139 | 124 |
140 void SetDeviceSettings(bool ephemeral_users_enabled, | 125 void SetDeviceSettings(bool ephemeral_users_enabled, |
141 const std::string &owner, | 126 const std::string &owner, |
142 bool supervised_users_enabled) { | 127 bool supervised_users_enabled) { |
143 base::FundamentalValue | 128 stub_settings_provider_.SetBoolean(kAccountsPrefEphemeralUsersEnabled, |
144 ephemeral_users_enabled_value(ephemeral_users_enabled); | 129 ephemeral_users_enabled); |
145 stub_settings_provider_.Set(kAccountsPrefEphemeralUsersEnabled, | 130 stub_settings_provider_.SetString(kDeviceOwner, owner); |
146 ephemeral_users_enabled_value); | 131 stub_settings_provider_.SetBoolean(kAccountsPrefSupervisedUsersEnabled, |
147 base::StringValue owner_value(owner); | 132 supervised_users_enabled); |
148 stub_settings_provider_.Set(kDeviceOwner, owner_value); | |
149 stub_settings_provider_.Set(kAccountsPrefSupervisedUsersEnabled, | |
150 base::FundamentalValue(supervised_users_enabled)); | |
151 } | 133 } |
152 | 134 |
153 void RetrieveTrustedDevicePolicies() { | 135 void RetrieveTrustedDevicePolicies() { |
154 GetChromeUserManager()->RetrieveTrustedDevicePolicies(); | 136 GetChromeUserManager()->RetrieveTrustedDevicePolicies(); |
155 } | 137 } |
156 | 138 |
157 protected: | 139 protected: |
158 content::TestBrowserThreadBundle thread_bundle_; | 140 content::TestBrowserThreadBundle thread_bundle_; |
159 | 141 |
160 CrosSettings* cros_settings_; | |
161 CrosSettingsProvider* device_settings_provider_; | |
162 StubCrosSettingsProvider stub_settings_provider_; | |
163 scoped_ptr<ScopedTestingLocalState> local_state_; | 142 scoped_ptr<ScopedTestingLocalState> local_state_; |
164 | 143 |
165 ScopedTestDeviceSettingsService test_device_settings_service_; | |
166 ScopedTestCrosSettings test_cros_settings_; | |
167 | |
168 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 144 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
169 base::ScopedTempDir temp_dir_; | 145 base::ScopedTempDir temp_dir_; |
170 }; | 146 }; |
171 | 147 |
172 TEST_F(UserManagerTest, RetrieveTrustedDevicePolicies) { | 148 TEST_F(UserManagerTest, RetrieveTrustedDevicePolicies) { |
173 SetUserManagerEphemeralUsersEnabled(true); | 149 SetUserManagerEphemeralUsersEnabled(true); |
174 SetUserManagerOwnerEmail(""); | 150 SetUserManagerOwnerEmail(""); |
175 | 151 |
176 SetDeviceSettings(false, "owner@invalid.domain", false); | 152 SetDeviceSettings(false, "owner@invalid.domain", false); |
177 RetrieveTrustedDevicePolicies(); | 153 RetrieveTrustedDevicePolicies(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 "user0@invalid.domain", "user0@invalid.domain", false); | 193 "user0@invalid.domain", "user0@invalid.domain", false); |
218 ResetUserManager(); | 194 ResetUserManager(); |
219 | 195 |
220 const user_manager::UserList* users = | 196 const user_manager::UserList* users = |
221 &user_manager::UserManager::Get()->GetUsers(); | 197 &user_manager::UserManager::Get()->GetUsers(); |
222 EXPECT_EQ(1U, users->size()); | 198 EXPECT_EQ(1U, users->size()); |
223 EXPECT_EQ((*users)[0]->email(), "owner@invalid.domain"); | 199 EXPECT_EQ((*users)[0]->email(), "owner@invalid.domain"); |
224 } | 200 } |
225 | 201 |
226 } // namespace chromeos | 202 } // namespace chromeos |
OLD | NEW |