Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/chromeos/login/login_screen_policy_browsertest.cc

Issue 2652793003: Add login screen locale and input method device policies (Closed)
Patch Set: Cleanup, display IME Tray even for a single IME when managed. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
83 0U,
84 imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size());
85
86 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
87 proto.mutable_login_screen_input_methods()->add_login_screen_input_methods(
88 "xkb:de::ger");
89 RefreshDevicePolicyAndWaitForSettingChange(
90 chromeos::kDeviceLoginScreenInputMethods);
91
92 ASSERT_EQ(
93 1U,
94 imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size());
95
96 // Remove the policy again
97 proto.mutable_login_screen_input_methods()
98 ->clear_login_screen_input_methods();
99 RefreshDevicePolicyAndWaitForSettingChange(
100 chromeos::kDeviceLoginScreenInputMethods);
101
102 ASSERT_EQ(
103 0U,
104 imm->GetActiveIMEState()->GetAllowedKeyboardLayoutInputMethods().size());
105 }
106
107 class LoginScreenLocalePolicyTest : public LoginScreenPolicyTest {
108 protected:
109 LoginScreenLocalePolicyTest() {}
110
111 void SetUpInProcessBrowserTestFixture() override {
112 LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture();
113
114 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
115 proto.mutable_login_screen_locales()->add_login_screen_locales("fr-FR");
116 RefreshDevicePolicy();
117
118 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.
119 }
120 };
121
122 IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest,
123 PRE_LoginLocaleEnforcedByPolicy) {
124 chromeos::StartupUtils::MarkOobeCompleted();
125 }
126
127 IN_PROC_BROWSER_TEST_F(LoginScreenLocalePolicyTest,
128 LoginLocaleEnforcedByPolicy) {
129 // Verifies that the default locale can be overridden with policy.
130 EXPECT_EQ("fr", g_browser_process->GetApplicationLocale());
131 base::string16 french_title =
132 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN);
133
134 // Make sure this is really French and differs from the English title.
135 std::string loaded =
136 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US");
137 EXPECT_EQ("en-US", loaded);
138 base::string16 english_title =
139 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN);
140 EXPECT_NE(french_title, english_title);
141 }
142
52 } // namespace chromeos 143 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698