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" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | |
20 #include "chrome/browser/chromeos/login/login_manager_test.h" | 21 #include "chrome/browser/chromeos/login/login_manager_test.h" |
21 #include "chrome/browser/chromeos/login/startup_utils.h" | 22 #include "chrome/browser/chromeos/login/startup_utils.h" |
22 #include "chrome/browser/chromeos/login/user.h" | 23 #include "chrome/browser/chromeos/login/user.h" |
23 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
24 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 25 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
25 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h" | 26 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h" |
26 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" | 28 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" |
28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chromeos/chromeos_paths.h" | 32 #include "chromeos/chromeos_paths.h" |
32 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
33 #include "chromeos/dbus/cryptohome_client.h" | 34 #include "chromeos/dbus/cryptohome_client.h" |
34 #include "chromeos/dbus/dbus_thread_manager.h" | 35 #include "chromeos/dbus/dbus_thread_manager.h" |
35 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 36 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
36 #include "chromeos/dbus/fake_session_manager_client.h" | 37 #include "chromeos/dbus/fake_session_manager_client.h" |
37 #include "chromeos/dbus/session_manager_client.h" | 38 #include "chromeos/dbus/session_manager_client.h" |
38 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 39 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
39 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 40 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
40 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 41 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
41 #include "components/policy/core/common/cloud/policy_builder.h" | 42 #include "components/policy/core/common/cloud/policy_builder.h" |
43 #include "content/public/test/browser_test_utils.h" | |
42 #include "crypto/rsa_private_key.h" | 44 #include "crypto/rsa_private_key.h" |
43 #include "net/test/embedded_test_server/embedded_test_server.h" | 45 #include "net/test/embedded_test_server/embedded_test_server.h" |
44 #include "policy/proto/cloud_policy.pb.h" | 46 #include "policy/proto/cloud_policy.pb.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
46 #include "third_party/skia/include/core/SkBitmap.h" | 48 #include "third_party/skia/include/core/SkBitmap.h" |
47 #include "third_party/skia/include/core/SkColor.h" | 49 #include "third_party/skia/include/core/SkColor.h" |
48 #include "ui/gfx/image/image_skia.h" | 50 #include "ui/gfx/image/image_skia.h" |
49 #include "url/gurl.h" | 51 #include "url/gurl.h" |
50 | 52 |
51 namespace chromeos { | 53 namespace chromeos { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 175 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
174 } | 176 } |
175 | 177 |
176 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 178 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
177 // Set the same switches as LoginManagerTest, except that kMultiProfiles is | 179 // Set the same switches as LoginManagerTest, except that kMultiProfiles is |
178 // only set when GetParam() is true and except that kLoginProfile is set | 180 // only set when GetParam() is true and except that kLoginProfile is set |
179 // when GetParam() is false. The latter seems to be required for the sane | 181 // when GetParam() is false. The latter seems to be required for the sane |
180 // start-up of user profiles. | 182 // start-up of user profiles. |
181 command_line->AppendSwitch(switches::kLoginManager); | 183 command_line->AppendSwitch(switches::kLoginManager); |
182 command_line->AppendSwitch(switches::kForceLoginManagerInTests); | 184 command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
183 if (GetParam()) | 185 if (GetParam()) { |
184 command_line->AppendSwitch(::switches::kMultiProfiles); | 186 command_line->AppendSwitch(::switches::kMultiProfiles); |
185 else | 187 } else { |
186 command_line->AppendSwitchASCII(switches::kLoginProfile, kTestUsers[0]); | 188 const ::testing::TestInfo* test_info = |
189 ::testing::UnitTest::GetInstance()->current_test_info(); | |
190 if (std::string(test_info->name()) == "PRE_WallpaperOnLoginScreen/0") { | |
Nikita (slow)
2014/04/15 13:41:27
Is there a way to avoid such kind of hacks?
Thiemo Nagel
2014/04/15 13:50:31
Yes. That's precisely the reason for my changes t
| |
191 // Avoid breakage of cloud policy injection if username is different | |
192 // from login profile. | |
193 command_line->AppendSwitchASCII(switches::kLoginProfile, kTestUsers[1]); | |
194 } else { | |
195 command_line->AppendSwitchASCII(switches::kLoginProfile, kTestUsers[0]); | |
196 } | |
197 } | |
187 } | 198 } |
188 | 199 |
189 virtual void SetUpOnMainThread() OVERRIDE { | 200 virtual void SetUpOnMainThread() OVERRIDE { |
190 LoginManagerTest::SetUpOnMainThread(); | 201 LoginManagerTest::SetUpOnMainThread(); |
191 ash::Shell::GetInstance()-> | 202 ash::Shell::GetInstance()-> |
192 desktop_background_controller()->AddObserver(this); | 203 desktop_background_controller()->AddObserver(this); |
193 | 204 |
194 // Set up policy signing. | 205 // Set up policy signing. |
195 user_policy_builders_[0] = GetUserPolicyBuilder(kTestUsers[0]); | 206 user_policy_builders_[0] = GetUserPolicyBuilder(kTestUsers[0]); |
196 user_policy_builders_[1] = GetUserPolicyBuilder(kTestUsers[1]); | 207 user_policy_builders_[1] = GetUserPolicyBuilder(kTestUsers[1]); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 GetUserWallpaperInfo(0, &info); | 331 GetUserWallpaperInfo(0, &info); |
321 ASSERT_EQ(User::DEFAULT, info.type); | 332 ASSERT_EQ(User::DEFAULT, info.type); |
322 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); | 333 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); |
323 | 334 |
324 // Check wallpaper change count to ensure that setting the second user's | 335 // Check wallpaper change count to ensure that setting the second user's |
325 // wallpaper didn't have any effect. | 336 // wallpaper didn't have any effect. |
326 ASSERT_EQ(4, wallpaper_change_count_); | 337 ASSERT_EQ(4, wallpaper_change_count_); |
327 } | 338 } |
328 | 339 |
329 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, | 340 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, |
341 PRE_PRE_PRE_WallpaperOnLoginScreen) { | |
342 RegisterUser(kTestUsers[0]); | |
343 RegisterUser(kTestUsers[1]); | |
344 StartupUtils::MarkOobeCompleted(); | |
345 } | |
346 | |
347 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, | |
330 PRE_PRE_WallpaperOnLoginScreen) { | 348 PRE_PRE_WallpaperOnLoginScreen) { |
331 RegisterUser(kTestUsers[0]); | |
332 StartupUtils::MarkOobeCompleted(); | |
333 } | |
334 | |
335 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, PRE_WallpaperOnLoginScreen) { | |
336 LoginUser(kTestUsers[0]); | 349 LoginUser(kTestUsers[0]); |
337 | 350 |
338 // Wait until default wallpaper has been loaded. | 351 // Wait until default wallpaper has been loaded. |
339 RunUntilWallpaperChangeCount(1); | 352 RunUntilWallpaperChangeCount(1); |
340 | 353 |
341 // Set wallpaper policy to red image. | 354 // Set wallpaper policy to red image. |
342 InjectPolicy(0, kRedImageFileName); | 355 InjectPolicy(0, kRedImageFileName); |
343 | 356 |
344 // Run until wallpaper has changed. | 357 // Run until wallpaper has changed. |
345 RunUntilWallpaperChangeCount(2); | 358 RunUntilWallpaperChangeCount(2); |
359 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | |
360 } | |
361 | |
362 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, PRE_WallpaperOnLoginScreen) { | |
363 LoginUser(kTestUsers[1]); | |
364 | |
365 // Wait until default wallpaper has been loaded. | |
366 RunUntilWallpaperChangeCount(1); | |
367 | |
368 // Set wallpaper policy to red image. | |
369 InjectPolicy(1, kGreenImageFileName); | |
370 | |
371 // Run until wallpaper has changed. | |
372 RunUntilWallpaperChangeCount(2); | |
373 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); | |
346 } | 374 } |
347 | 375 |
348 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, WallpaperOnLoginScreen) { | 376 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, WallpaperOnLoginScreen) { |
349 // Wait for active pod's wallpaper to be loaded. | 377 // Wait for active pod's wallpaper to be loaded. |
350 RunUntilWallpaperChangeCount(1); | 378 RunUntilWallpaperChangeCount(1); |
379 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); | |
380 | |
381 // Select the second pod (belonging to user 1). | |
382 ASSERT_TRUE(content::ExecuteScript( | |
383 static_cast<chromeos::LoginDisplayHostImpl*>( | |
384 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()-> | |
385 web_ui()->GetWebContents(), | |
386 "document.getElementsByClassName('pod')[1].focus();")); | |
387 RunUntilWallpaperChangeCount(2); | |
351 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 388 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
352 } | 389 } |
353 | 390 |
391 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, PRE_PRE_PersistOverLogout) { | |
392 RegisterUser(kTestUsers[0]); | |
393 StartupUtils::MarkOobeCompleted(); | |
394 } | |
395 | |
396 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, PRE_PersistOverLogout) { | |
397 LoginUser(kTestUsers[0]); | |
398 | |
399 // Wait until default wallpaper has been loaded. | |
400 RunUntilWallpaperChangeCount(1); | |
401 | |
402 // Set wallpaper policy to red image. | |
403 InjectPolicy(0, kRedImageFileName); | |
404 | |
405 // Run until wallpaper has changed. | |
406 RunUntilWallpaperChangeCount(2); | |
407 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | |
408 } | |
409 | |
410 IN_PROC_BROWSER_TEST_P(WallpaperManagerPolicyTest, PersistOverLogout) { | |
411 LoginUser(kTestUsers[0]); | |
412 | |
413 // Wait until wallpaper has been loaded. | |
414 RunUntilWallpaperChangeCount(1); | |
415 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | |
416 } | |
417 | |
354 INSTANTIATE_TEST_CASE_P(WallpaperManagerPolicyTestInstantiation, | 418 INSTANTIATE_TEST_CASE_P(WallpaperManagerPolicyTestInstantiation, |
355 WallpaperManagerPolicyTest, testing::Bool()); | 419 WallpaperManagerPolicyTest, testing::Bool()); |
356 | 420 |
357 } // namespace chromeos | 421 } // namespace chromeos |
OLD | NEW |