OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/login/startup_utils.h" |
7 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 10 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
8 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 11 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
9 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" |
10 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
11 #include "chromeos/settings/cros_settings_names.h" | 17 #include "chromeos/settings/cros_settings_names.h" |
12 #include "components/user_manager/user_manager.h" | 18 #include "components/user_manager/user_manager.h" |
13 #include "content/public/test/test_utils.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" |
16 | 24 |
17 namespace em = enterprise_management; | 25 namespace em = enterprise_management; |
18 | 26 |
19 namespace chromeos { | 27 namespace chromeos { |
20 | 28 |
21 class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { | 29 class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { |
| 30 public: |
| 31 void RefreshDevicePolicyAndWaitForSettingChange( |
| 32 const char* cros_setting_name); |
| 33 |
| 34 protected: |
22 void SetUpCommandLine(base::CommandLine* command_line) override { | 35 void SetUpCommandLine(base::CommandLine* command_line) override { |
23 command_line->AppendSwitch(switches::kLoginManager); | 36 command_line->AppendSwitch(switches::kLoginManager); |
| 37 command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
24 } | 38 } |
25 | 39 |
26 void SetUpInProcessBrowserTestFixture() override { | 40 void SetUpInProcessBrowserTestFixture() override { |
27 InstallOwnerKey(); | 41 InstallOwnerKey(); |
28 MarkAsEnterpriseOwned(); | 42 MarkAsEnterpriseOwned(); |
29 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | 43 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
30 } | 44 } |
| 45 |
| 46 void TearDownOnMainThread() override { |
| 47 // This shuts down the login UI. |
| 48 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 49 FROM_HERE, base::Bind(&chrome::AttemptExit)); |
| 50 base::RunLoop().RunUntilIdle(); |
| 51 } |
31 }; | 52 }; |
32 | 53 |
| 54 void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange( |
| 55 const char* cros_setting_name) { |
| 56 scoped_refptr<content::MessageLoopRunner> runner( |
| 57 new content::MessageLoopRunner); |
| 58 std::unique_ptr<CrosSettings::ObserverSubscription> subscription( |
| 59 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 60 cros_setting_name, runner->QuitClosure())); |
| 61 |
| 62 RefreshDevicePolicy(); |
| 63 runner->Run(); |
| 64 } |
| 65 |
33 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { | 66 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { |
34 EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); | 67 EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
35 | 68 |
36 scoped_refptr<content::MessageLoopRunner> runner( | |
37 new content::MessageLoopRunner); | |
38 std::unique_ptr<CrosSettings::ObserverSubscription> subscription( | |
39 chromeos::CrosSettings::Get()->AddSettingsObserver( | |
40 chromeos::kAccountsPrefSupervisedUsersEnabled, | |
41 runner->QuitClosure())); | |
42 | |
43 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 69 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
44 proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); | 70 proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); |
45 RefreshDevicePolicy(); | 71 RefreshDevicePolicyAndWaitForSettingChange( |
46 | 72 chromeos::kAccountsPrefSupervisedUsersEnabled); |
47 runner->Run(); | |
48 | 73 |
49 EXPECT_TRUE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); | 74 EXPECT_TRUE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
50 } | 75 } |
51 | 76 |
| 77 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, RestrictInputMethods) { |
| 78 input_method::InputMethodManager* imm = |
| 79 input_method::InputMethodManager::Get(); |
| 80 ASSERT_TRUE(imm); |
| 81 |
| 82 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 83 |
| 84 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 85 proto.mutable_login_screen_input_methods()->add_login_screen_input_methods( |
| 86 "xkb:de::ger"); |
| 87 RefreshDevicePolicyAndWaitForSettingChange( |
| 88 chromeos::kDeviceLoginScreenInputMethods); |
| 89 |
| 90 ASSERT_EQ(1U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 91 |
| 92 // Remove the policy again |
| 93 proto.mutable_login_screen_input_methods() |
| 94 ->clear_login_screen_input_methods(); |
| 95 RefreshDevicePolicyAndWaitForSettingChange( |
| 96 chromeos::kDeviceLoginScreenInputMethods); |
| 97 |
| 98 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 99 } |
| 100 |
| 101 class LoginScreenLocalePolicyTest : public LoginScreenPolicyTest { |
| 102 protected: |
| 103 LoginScreenLocalePolicyTest() {} |
| 104 |
| 105 void SetUpInProcessBrowserTestFixture() override { |
| 106 LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture(); |
| 107 |
| 108 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 109 proto.mutable_login_screen_locales()->add_login_screen_locales("fr-FR"); |
| 110 RefreshDevicePolicy(); |
| 111 } |
| 112 }; |
| 113 |
| 114 IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest, |
| 115 PRE_LoginLocaleEnforcedByPolicy) { |
| 116 chromeos::StartupUtils::MarkOobeCompleted(); |
| 117 } |
| 118 |
| 119 IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest, |
| 120 LoginLocaleEnforcedByPolicy) { |
| 121 // Verifies that the default locale can be overridden with policy. |
| 122 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); |
| 123 base::string16 french_title = |
| 124 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); |
| 125 |
| 126 // Make sure this is really French and differs from the English title. |
| 127 std::string loaded = |
| 128 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| 129 EXPECT_EQ("en-US", loaded); |
| 130 base::string16 english_title = |
| 131 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); |
| 132 EXPECT_NE(french_title, english_title); |
| 133 } |
| 134 |
52 } // namespace chromeos | 135 } // namespace chromeos |
OLD | NEW |