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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 9 #include "ash/desktop_background/desktop_background_controller_observer.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } // namespace | 127 } // namespace |
128 | 128 |
129 class WallpaperManagerPolicyTest | 129 class WallpaperManagerPolicyTest |
130 : public LoginManagerTest, | 130 : public LoginManagerTest, |
131 public ash::DesktopBackgroundControllerObserver { | 131 public ash::DesktopBackgroundControllerObserver { |
132 protected: | 132 protected: |
133 WallpaperManagerPolicyTest() | 133 WallpaperManagerPolicyTest() |
134 : LoginManagerTest(true), | 134 : LoginManagerTest(true), |
135 wallpaper_change_count_(0), | 135 wallpaper_change_count_(0), |
136 fake_session_manager_client_(new FakeSessionManagerClient) { | 136 fake_session_manager_client_(new FakeSessionManagerClient) { |
137 testUsers_[0] = LoginManagerTest::kEnterpriseUser1; | 137 testUsers_.push_back( |
138 testUsers_[1] = LoginManagerTest::kEnterpriseUser2; | 138 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser1)); |
| 139 testUsers_.push_back( |
| 140 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser2)); |
139 } | 141 } |
140 | 142 |
141 scoped_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder( | 143 scoped_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder( |
142 const std::string& user_id) { | 144 const AccountId& account_id) { |
143 scoped_ptr<policy::UserPolicyBuilder> | 145 scoped_ptr<policy::UserPolicyBuilder> |
144 user_policy_builder(new policy::UserPolicyBuilder()); | 146 user_policy_builder(new policy::UserPolicyBuilder()); |
145 base::FilePath user_keys_dir; | 147 base::FilePath user_keys_dir; |
146 EXPECT_TRUE(PathService::Get(DIR_USER_POLICY_KEYS, &user_keys_dir)); | 148 EXPECT_TRUE(PathService::Get(DIR_USER_POLICY_KEYS, &user_keys_dir)); |
147 const std::string sanitized_user_id = | 149 const std::string sanitized_user_id = |
148 CryptohomeClient::GetStubSanitizedUsername(user_id); | 150 CryptohomeClient::GetStubSanitizedUsername(account_id.GetUserEmail()); |
149 const base::FilePath user_key_file = | 151 const base::FilePath user_key_file = |
150 user_keys_dir.AppendASCII(sanitized_user_id) | 152 user_keys_dir.AppendASCII(sanitized_user_id) |
151 .AppendASCII("policy.pub"); | 153 .AppendASCII("policy.pub"); |
152 std::vector<uint8> user_key_bits; | 154 std::vector<uint8> user_key_bits; |
153 EXPECT_TRUE(user_policy_builder->GetSigningKey()-> | 155 EXPECT_TRUE(user_policy_builder->GetSigningKey()-> |
154 ExportPublicKey(&user_key_bits)); | 156 ExportPublicKey(&user_key_bits)); |
155 EXPECT_TRUE(base::CreateDirectory(user_key_file.DirName())); | 157 EXPECT_TRUE(base::CreateDirectory(user_key_file.DirName())); |
156 EXPECT_EQ(base::WriteFile( | 158 EXPECT_EQ(base::WriteFile( |
157 user_key_file, | 159 user_key_file, |
158 reinterpret_cast<const char*>(user_key_bits.data()), | 160 reinterpret_cast<const char*>(user_key_bits.data()), |
159 user_key_bits.size()), | 161 user_key_bits.size()), |
160 static_cast<int>(user_key_bits.size())); | 162 static_cast<int>(user_key_bits.size())); |
161 user_policy_builder->policy_data().set_username(user_id); | 163 user_policy_builder->policy_data().set_username(account_id.GetUserEmail()); |
162 return user_policy_builder.Pass(); | 164 return user_policy_builder.Pass(); |
163 } | 165 } |
164 | 166 |
165 // LoginManagerTest: | 167 // LoginManagerTest: |
166 void SetUpInProcessBrowserTestFixture() override { | 168 void SetUpInProcessBrowserTestFixture() override { |
167 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 169 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
168 scoped_ptr<SessionManagerClient>(fake_session_manager_client_)); | 170 scoped_ptr<SessionManagerClient>(fake_session_manager_client_)); |
169 | 171 |
170 LoginManagerTest::SetUpInProcessBrowserTestFixture(); | 172 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
171 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 173 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 .spec(), | 228 .spec(), |
227 image_data), | 229 image_data), |
228 &policy); | 230 &policy); |
229 return policy; | 231 return policy; |
230 } | 232 } |
231 | 233 |
232 // Inject |filename| as wallpaper policy for test user |user_number|. Set | 234 // Inject |filename| as wallpaper policy for test user |user_number|. Set |
233 // empty |filename| to clear policy. | 235 // empty |filename| to clear policy. |
234 void InjectPolicy(int user_number, const std::string& filename) { | 236 void InjectPolicy(int user_number, const std::string& filename) { |
235 ASSERT_TRUE(user_number == 0 || user_number == 1); | 237 ASSERT_TRUE(user_number == 0 || user_number == 1); |
236 const std::string user_id = testUsers_[user_number]; | 238 const AccountId& account_id = testUsers_[user_number]; |
237 policy::UserPolicyBuilder* builder = | 239 policy::UserPolicyBuilder* builder = |
238 user_policy_builders_[user_number].get(); | 240 user_policy_builders_[user_number].get(); |
239 if (!filename.empty()) { | 241 if (!filename.empty()) { |
240 builder->payload(). | 242 builder->payload(). |
241 mutable_wallpaperimage()->set_value(ConstructPolicy(filename)); | 243 mutable_wallpaperimage()->set_value(ConstructPolicy(filename)); |
242 } else { | 244 } else { |
243 builder->payload().Clear(); | 245 builder->payload().Clear(); |
244 } | 246 } |
245 builder->Build(); | 247 builder->Build(); |
246 fake_session_manager_client_->set_user_policy(user_id, builder->GetBlob()); | 248 fake_session_manager_client_->set_user_policy(account_id.GetUserEmail(), |
247 const user_manager::User* user = user_manager::UserManager::Get()->FindUser( | 249 builder->GetBlob()); |
248 AccountId::FromUserEmail(user_id)); | 250 const user_manager::User* user = |
| 251 user_manager::UserManager::Get()->FindUser(account_id); |
249 ASSERT_TRUE(user); | 252 ASSERT_TRUE(user); |
250 policy::CloudPolicyStore* store = GetStoreForUser(user); | 253 policy::CloudPolicyStore* store = GetStoreForUser(user); |
251 ASSERT_TRUE(store); | 254 ASSERT_TRUE(store); |
252 store->Load(); | 255 store->Load(); |
253 ASSERT_EQ(policy::CloudPolicyStore::STATUS_OK, store->status()); | 256 ASSERT_EQ(policy::CloudPolicyStore::STATUS_OK, store->status()); |
254 ASSERT_EQ(policy::CloudPolicyValidatorBase::VALIDATION_OK, | 257 ASSERT_EQ(policy::CloudPolicyValidatorBase::VALIDATION_OK, |
255 store->validation_status()); | 258 store->validation_status()); |
256 } | 259 } |
257 | 260 |
258 // Obtain WallpaperInfo for |user_number| from WallpaperManager. | 261 // Obtain WallpaperInfo for |user_number| from WallpaperManager. |
259 void GetUserWallpaperInfo(int user_number, | 262 void GetUserWallpaperInfo(int user_number, |
260 wallpaper::WallpaperInfo* wallpaper_info) { | 263 wallpaper::WallpaperInfo* wallpaper_info) { |
261 WallpaperManager::Get()->GetUserWallpaperInfo(testUsers_[user_number], | 264 WallpaperManager::Get()->GetUserWallpaperInfo(testUsers_[user_number], |
262 wallpaper_info); | 265 wallpaper_info); |
263 } | 266 } |
264 | 267 |
265 base::FilePath test_data_dir_; | 268 base::FilePath test_data_dir_; |
266 scoped_ptr<base::RunLoop> run_loop_; | 269 scoped_ptr<base::RunLoop> run_loop_; |
267 int wallpaper_change_count_; | 270 int wallpaper_change_count_; |
268 scoped_ptr<policy::UserPolicyBuilder> user_policy_builders_[2]; | 271 scoped_ptr<policy::UserPolicyBuilder> user_policy_builders_[2]; |
269 FakeSessionManagerClient* fake_session_manager_client_; | 272 FakeSessionManagerClient* fake_session_manager_client_; |
270 const char* testUsers_[2]; | 273 std::vector<AccountId> testUsers_; |
271 | 274 |
272 private: | 275 private: |
273 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerPolicyTest); | 276 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerPolicyTest); |
274 }; | 277 }; |
275 | 278 |
276 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_SetResetClear) { | 279 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_SetResetClear) { |
277 RegisterUser(testUsers_[0]); | 280 RegisterUser(testUsers_[0].GetUserEmail()); |
278 RegisterUser(testUsers_[1]); | 281 RegisterUser(testUsers_[1].GetUserEmail()); |
279 StartupUtils::MarkOobeCompleted(); | 282 StartupUtils::MarkOobeCompleted(); |
280 } | 283 } |
281 | 284 |
282 // Verifies that the wallpaper can be set and re-set through policy and that | 285 // Verifies that the wallpaper can be set and re-set through policy and that |
283 // setting policy for a user that is not logged in doesn't affect the current | 286 // setting policy for a user that is not logged in doesn't affect the current |
284 // user. Also verifies that after the policy has been cleared, the wallpaper | 287 // user. Also verifies that after the policy has been cleared, the wallpaper |
285 // reverts to default. | 288 // reverts to default. |
286 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, SetResetClear) { | 289 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, SetResetClear) { |
287 wallpaper::WallpaperInfo info; | 290 wallpaper::WallpaperInfo info; |
288 LoginUser(testUsers_[0]); | 291 LoginUser(testUsers_[0].GetUserEmail()); |
289 base::RunLoop().RunUntilIdle(); | 292 base::RunLoop().RunUntilIdle(); |
290 | 293 |
291 // First user: Wait until default wallpaper has been loaded (happens | 294 // First user: Wait until default wallpaper has been loaded (happens |
292 // automatically) and store color to recognize it later. | 295 // automatically) and store color to recognize it later. |
293 RunUntilWallpaperChangeCount(1); | 296 RunUntilWallpaperChangeCount(1); |
294 const SkColor original_background_color = GetAverageBackgroundColor(); | 297 const SkColor original_background_color = GetAverageBackgroundColor(); |
295 | 298 |
296 // Second user: Set wallpaper policy to blue image. This should not result in | 299 // Second user: Set wallpaper policy to blue image. This should not result in |
297 // a wallpaper change, which is checked at the very end of this test. | 300 // a wallpaper change, which is checked at the very end of this test. |
298 InjectPolicy(1, kBlueImageFileName); | 301 InjectPolicy(1, kBlueImageFileName); |
(...skipping 20 matching lines...) Expand all Loading... |
319 ASSERT_EQ(user_manager::User::DEFAULT, info.type); | 322 ASSERT_EQ(user_manager::User::DEFAULT, info.type); |
320 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); | 323 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); |
321 | 324 |
322 // Check wallpaper change count to ensure that setting the second user's | 325 // Check wallpaper change count to ensure that setting the second user's |
323 // wallpaper didn't have any effect. | 326 // wallpaper didn't have any effect. |
324 ASSERT_EQ(4, wallpaper_change_count_); | 327 ASSERT_EQ(4, wallpaper_change_count_); |
325 } | 328 } |
326 | 329 |
327 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, | 330 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, |
328 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) { | 331 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) { |
329 RegisterUser(testUsers_[0]); | 332 RegisterUser(testUsers_[0].GetUserEmail()); |
330 RegisterUser(testUsers_[1]); | 333 RegisterUser(testUsers_[1].GetUserEmail()); |
331 StartupUtils::MarkOobeCompleted(); | 334 StartupUtils::MarkOobeCompleted(); |
332 } | 335 } |
333 | 336 |
334 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, | 337 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, |
335 DISABLED_PRE_PRE_WallpaperOnLoginScreen) { | 338 DISABLED_PRE_PRE_WallpaperOnLoginScreen) { |
336 LoginUser(testUsers_[0]); | 339 LoginUser(testUsers_[0].GetUserEmail()); |
337 | 340 |
338 // Wait until default wallpaper has been loaded. | 341 // Wait until default wallpaper has been loaded. |
339 RunUntilWallpaperChangeCount(1); | 342 RunUntilWallpaperChangeCount(1); |
340 | 343 |
341 // Set wallpaper policy to red image. | 344 // Set wallpaper policy to red image. |
342 InjectPolicy(0, kRedImageFileName); | 345 InjectPolicy(0, kRedImageFileName); |
343 | 346 |
344 // Run until wallpaper has changed. | 347 // Run until wallpaper has changed. |
345 RunUntilWallpaperChangeCount(2); | 348 RunUntilWallpaperChangeCount(2); |
346 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 349 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
347 } | 350 } |
348 | 351 |
349 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, | 352 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, |
350 DISABLED_PRE_WallpaperOnLoginScreen) { | 353 DISABLED_PRE_WallpaperOnLoginScreen) { |
351 LoginUser(testUsers_[1]); | 354 LoginUser(testUsers_[1].GetUserEmail()); |
352 | 355 |
353 // Wait until default wallpaper has been loaded. | 356 // Wait until default wallpaper has been loaded. |
354 RunUntilWallpaperChangeCount(1); | 357 RunUntilWallpaperChangeCount(1); |
355 | 358 |
356 // Set wallpaper policy to green image. | 359 // Set wallpaper policy to green image. |
357 InjectPolicy(1, kGreenImageFileName); | 360 InjectPolicy(1, kGreenImageFileName); |
358 | 361 |
359 // Run until wallpaper has changed. | 362 // Run until wallpaper has changed. |
360 RunUntilWallpaperChangeCount(2); | 363 RunUntilWallpaperChangeCount(2); |
361 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); | 364 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); |
(...skipping 10 matching lines...) Expand all Loading... |
372 ASSERT_TRUE(content::ExecuteScript( | 375 ASSERT_TRUE(content::ExecuteScript( |
373 static_cast<chromeos::LoginDisplayHostImpl*>( | 376 static_cast<chromeos::LoginDisplayHostImpl*>( |
374 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()-> | 377 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()-> |
375 web_ui()->GetWebContents(), | 378 web_ui()->GetWebContents(), |
376 "document.getElementsByClassName('pod')[1].focus();")); | 379 "document.getElementsByClassName('pod')[1].focus();")); |
377 RunUntilWallpaperChangeCount(2); | 380 RunUntilWallpaperChangeCount(2); |
378 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 381 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
379 } | 382 } |
380 | 383 |
381 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PRE_PersistOverLogout) { | 384 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PRE_PersistOverLogout) { |
382 RegisterUser(testUsers_[0]); | 385 RegisterUser(testUsers_[0].GetUserEmail()); |
383 StartupUtils::MarkOobeCompleted(); | 386 StartupUtils::MarkOobeCompleted(); |
384 } | 387 } |
385 | 388 |
386 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PersistOverLogout) { | 389 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PersistOverLogout) { |
387 LoginUser(testUsers_[0]); | 390 LoginUser(testUsers_[0].GetUserEmail()); |
388 | 391 |
389 // Wait until default wallpaper has been loaded. | 392 // Wait until default wallpaper has been loaded. |
390 RunUntilWallpaperChangeCount(1); | 393 RunUntilWallpaperChangeCount(1); |
391 | 394 |
392 // Set wallpaper policy to red image. | 395 // Set wallpaper policy to red image. |
393 InjectPolicy(0, kRedImageFileName); | 396 InjectPolicy(0, kRedImageFileName); |
394 | 397 |
395 // Run until wallpaper has changed. | 398 // Run until wallpaper has changed. |
396 RunUntilWallpaperChangeCount(2); | 399 RunUntilWallpaperChangeCount(2); |
397 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 400 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
398 } | 401 } |
399 | 402 |
400 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { | 403 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { |
401 LoginUser(testUsers_[0]); | 404 LoginUser(testUsers_[0].GetUserEmail()); |
402 | 405 |
403 // Wait until wallpaper has been loaded. | 406 // Wait until wallpaper has been loaded. |
404 RunUntilWallpaperChangeCount(1); | 407 RunUntilWallpaperChangeCount(1); |
405 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 408 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
406 } | 409 } |
407 | 410 |
408 } // namespace chromeos | 411 } // namespace chromeos |
OLD | NEW |