Chromium Code Reviews| Index: chrome/browser/chromeos/login/login_screen_policy_browsertest.cc |
| diff --git a/chrome/browser/chromeos/login/login_screen_policy_browsertest.cc b/chrome/browser/chromeos/login/login_screen_policy_browsertest.cc |
| index 53534afe5008fa35442317dd15d5cbb88c2b934b..a75778e78a92ac3e002ee2c41e4ed9eee20837a8 100644 |
| --- a/chrome/browser/chromeos/login/login_screen_policy_browsertest.cc |
| +++ b/chrome/browser/chromeos/login/login_screen_policy_browsertest.cc |
| @@ -4,23 +4,37 @@ |
| #include "base/command_line.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/login/startup_utils.h" |
| #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chrome/browser/lifetime/application_lifetime.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| #include "chromeos/chromeos_switches.h" |
| #include "chromeos/settings/cros_settings_names.h" |
| #include "components/user_manager/user_manager.h" |
| -#include "content/public/test/test_utils.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/ime/chromeos/input_method_manager.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| namespace em = enterprise_management; |
| namespace chromeos { |
| class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { |
| + public: |
| + void RefreshDevicePolicyAndWaitForSettingChange( |
| + const char* cros_setting_name); |
| + |
| + protected: |
| void SetUpCommandLine(base::CommandLine* command_line) override { |
| command_line->AppendSwitch(switches::kLoginManager); |
| + command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
| } |
| void SetUpInProcessBrowserTestFixture() override { |
| @@ -28,25 +42,102 @@ class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { |
| MarkAsEnterpriseOwned(); |
| DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
| } |
| -}; |
| -IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { |
| - EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
| + void TearDownOnMainThread() override { |
| + // This shuts down the login UI. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&chrome::AttemptExit)); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| +}; |
| +void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange( |
| + const char* cros_setting_name) { |
| scoped_refptr<content::MessageLoopRunner> runner( |
| new content::MessageLoopRunner); |
| std::unique_ptr<CrosSettings::ObserverSubscription> subscription( |
| chromeos::CrosSettings::Get()->AddSettingsObserver( |
| - chromeos::kAccountsPrefSupervisedUsersEnabled, |
| - runner->QuitClosure())); |
| + cros_setting_name, runner->QuitClosure())); |
| - em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| - proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); |
| RefreshDevicePolicy(); |
| - |
| runner->Run(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { |
| + EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
| + |
| + em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| + proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); |
| + RefreshDevicePolicyAndWaitForSettingChange( |
| + chromeos::kAccountsPrefSupervisedUsersEnabled); |
| EXPECT_TRUE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
| } |
| +IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, RestrictInputMethods) { |
| + input_method::InputMethodManager* imm = |
| + input_method::InputMethodManager::Get(); |
| + ASSERT_TRUE(imm); |
| + |
| + ASSERT_EQ( |
| + 0U, |
| + imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size()); |
| + |
| + em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| + proto.mutable_login_screen_input_methods()->add_login_screen_input_methods( |
| + "xkb:de::ger"); |
| + RefreshDevicePolicyAndWaitForSettingChange( |
| + chromeos::kDeviceLoginScreenInputMethods); |
| + |
| + ASSERT_EQ( |
| + 1U, |
| + imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size()); |
| + |
| + // Remove the policy again |
| + proto.mutable_login_screen_input_methods() |
| + ->clear_login_screen_input_methods(); |
| + RefreshDevicePolicyAndWaitForSettingChange( |
| + chromeos::kDeviceLoginScreenInputMethods); |
| + |
| + ASSERT_EQ( |
| + 0U, |
| + imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size()); |
| +} |
| + |
| +class LoginScreenLocalePolicyTest : public LoginScreenPolicyTest { |
| + protected: |
| + LoginScreenLocalePolicyTest() {} |
| + |
| + void SetUpInProcessBrowserTestFixture() override { |
| + LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture(); |
| + |
| + em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| + proto.mutable_login_screen_locales()->add_login_screen_locales("fr-FR"); |
| + RefreshDevicePolicy(); |
| + |
| + ResourceBundle::CleanupSharedInstance(); |
|
xiyuan
2017/01/25 19:24:14
Is this necessary? If so, could we comment why it
pmarko
2017/01/26 12:32:58
You're right, we don't. Removed.
|
| + } |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest, |
| + PRE_LoginLocaleEnforcedByPolicy) { |
| + chromeos::StartupUtils::MarkOobeCompleted(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest, |
| + LoginLocaleEnforcedByPolicy) { |
| + // Verifies that the default locale can be overridden with policy. |
| + EXPECT_EQ("fr", g_browser_process->GetApplicationLocale()); |
| + base::string16 french_title = |
| + l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); |
| + |
| + // Make sure this is really French and differs from the English title. |
| + std::string loaded = |
| + ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| + EXPECT_EQ("en-US", loaded); |
| + base::string16 english_title = |
| + l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); |
| + EXPECT_NE(french_title, english_title); |
| +} |
| + |
| } // namespace chromeos |