Chromium Code Reviews| 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" | 7 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/login/login_wizard.h" | |
| 9 #include "chrome/browser/chromeos/login/startup_utils.h" | 10 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 11 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 10 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 13 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 11 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 12 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "chromeos/chromeos_switches.h" | 19 #include "chromeos/chromeos_switches.h" |
| 17 #include "chromeos/settings/cros_settings_names.h" | 20 #include "chromeos/settings/cros_settings_names.h" |
| 21 #include "components/prefs/pref_service.h" | |
| 22 #include "components/prefs/scoped_user_pref_update.h" | |
| 18 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/ime/chromeos/input_method_manager.h" | 26 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 24 | 29 |
| 25 namespace em = enterprise_management; | 30 namespace em = enterprise_management; |
| 26 | 31 |
| 32 namespace { | |
| 33 const char kTestUser[] = "test-user@example.com"; | |
| 34 } // namespace | |
| 35 | |
| 27 namespace chromeos { | 36 namespace chromeos { |
| 28 | 37 |
| 29 class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { | 38 class LoginScreenPolicyTest : public policy::DevicePolicyCrosBrowserTest { |
| 30 public: | 39 public: |
| 31 void RefreshDevicePolicyAndWaitForSettingChange( | 40 void RefreshDevicePolicyAndWaitForSettingChange( |
| 32 const char* cros_setting_name); | 41 const char* cros_setting_name); |
| 33 | 42 |
| 34 protected: | 43 protected: |
| 35 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 36 command_line->AppendSwitch(switches::kLoginManager); | |
| 37 command_line->AppendSwitch(switches::kForceLoginManagerInTests); | |
|
xiyuan
2017/04/12 19:33:44
This would make the browser test to run in a stub
pmarko
2017/04/12 20:29:32
Done.
| |
| 38 } | |
| 39 | |
| 40 void SetUpInProcessBrowserTestFixture() override { | 44 void SetUpInProcessBrowserTestFixture() override { |
| 41 InstallOwnerKey(); | 45 InstallOwnerKey(); |
| 42 MarkAsEnterpriseOwned(); | 46 MarkAsEnterpriseOwned(); |
| 43 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | 47 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 void TearDownOnMainThread() override { | 50 void TearDownOnMainThread() override { |
| 47 // This shuts down the login UI. | 51 // This shuts down the login UI. |
| 48 base::ThreadTaskRunnerHandle::Get()->PostTask( | 52 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 49 FROM_HERE, base::Bind(&chrome::AttemptExit)); | 53 FROM_HERE, base::Bind(&chrome::AttemptExit)); |
| 50 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
| 51 } | 55 } |
| 56 | |
| 57 void RegisterUser(const std::string& user_id) { | |
| 58 ListPrefUpdate users_pref(g_browser_process->local_state(), | |
| 59 "LoggedInUsers"); | |
| 60 users_pref->AppendIfNotPresent(base::MakeUnique<base::Value>(user_id)); | |
| 61 } | |
| 52 }; | 62 }; |
| 53 | 63 |
| 54 void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange( | 64 void LoginScreenPolicyTest::RefreshDevicePolicyAndWaitForSettingChange( |
| 55 const char* cros_setting_name) { | 65 const char* cros_setting_name) { |
| 56 scoped_refptr<content::MessageLoopRunner> runner( | 66 scoped_refptr<content::MessageLoopRunner> runner( |
| 57 new content::MessageLoopRunner); | 67 new content::MessageLoopRunner); |
| 58 std::unique_ptr<CrosSettings::ObserverSubscription> subscription( | 68 std::unique_ptr<CrosSettings::ObserverSubscription> subscription( |
| 59 chromeos::CrosSettings::Get()->AddSettingsObserver( | 69 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 60 cros_setting_name, runner->QuitClosure())); | 70 cros_setting_name, runner->QuitClosure())); |
| 61 | 71 |
| 62 RefreshDevicePolicy(); | 72 RefreshDevicePolicy(); |
| 63 runner->Run(); | 73 runner->Run(); |
| 64 } | 74 } |
| 65 | 75 |
| 66 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { | 76 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, DisableSupervisedUsers) { |
| 67 EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); | 77 EXPECT_FALSE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
| 68 | 78 |
| 69 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 79 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 70 proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); | 80 proto.mutable_supervised_users_settings()->set_supervised_users_enabled(true); |
| 71 RefreshDevicePolicyAndWaitForSettingChange( | 81 RefreshDevicePolicyAndWaitForSettingChange( |
| 72 chromeos::kAccountsPrefSupervisedUsersEnabled); | 82 chromeos::kAccountsPrefSupervisedUsersEnabled); |
| 73 | 83 |
| 74 EXPECT_TRUE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); | 84 EXPECT_TRUE(user_manager::UserManager::Get()->AreSupervisedUsersAllowed()); |
| 75 } | 85 } |
| 76 | 86 |
| 87 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, PRE_RestrictInputMethods) { | |
| 88 RegisterUser(kTestUser); | |
| 89 StartupUtils::MarkOobeCompleted(); | |
| 90 } | |
| 91 | |
| 77 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, RestrictInputMethods) { | 92 IN_PROC_BROWSER_TEST_F(LoginScreenPolicyTest, RestrictInputMethods) { |
| 93 ShowLoginWizard(OobeScreen::SCREEN_SPECIAL_LOGIN); | |
| 94 OobeScreenWaiter(OobeScreen::SCREEN_ACCOUNT_PICKER).Wait(); | |
| 95 | |
| 78 input_method::InputMethodManager* imm = | 96 input_method::InputMethodManager* imm = |
| 79 input_method::InputMethodManager::Get(); | 97 input_method::InputMethodManager::Get(); |
| 80 ASSERT_TRUE(imm); | 98 ASSERT_TRUE(imm); |
| 81 | 99 |
| 82 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); | 100 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 83 | 101 |
| 84 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 102 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 85 proto.mutable_login_screen_input_methods()->add_login_screen_input_methods( | 103 proto.mutable_login_screen_input_methods()->add_login_screen_input_methods( |
| 86 "xkb:de::ger"); | 104 "xkb:de::ger"); |
| 87 RefreshDevicePolicyAndWaitForSettingChange( | 105 RefreshDevicePolicyAndWaitForSettingChange( |
| 88 chromeos::kDeviceLoginScreenInputMethods); | 106 chromeos::kDeviceLoginScreenInputMethods); |
| 89 | 107 |
| 90 ASSERT_EQ(1U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); | 108 ASSERT_EQ(1U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 91 | 109 |
| 92 // Remove the policy again | 110 // Remove the policy again |
| 93 proto.mutable_login_screen_input_methods() | 111 proto.mutable_login_screen_input_methods() |
| 94 ->clear_login_screen_input_methods(); | 112 ->clear_login_screen_input_methods(); |
| 95 RefreshDevicePolicyAndWaitForSettingChange( | 113 RefreshDevicePolicyAndWaitForSettingChange( |
| 96 chromeos::kDeviceLoginScreenInputMethods); | 114 chromeos::kDeviceLoginScreenInputMethods); |
| 97 | 115 |
| 98 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); | 116 ASSERT_EQ(0U, imm->GetActiveIMEState()->GetAllowedInputMethods().size()); |
| 117 | |
| 118 base::ThreadTaskRunnerHandle::Get()->DeleteSoon( | |
| 119 FROM_HERE, LoginDisplayHost::default_host()); | |
|
xiyuan
2017/04/12 19:33:44
Think this is not necessary.
pmarko
2017/04/12 20:29:32
Done.
| |
| 99 } | 120 } |
| 100 | 121 |
| 101 class LoginScreenLocalePolicyTest : public LoginScreenPolicyTest { | 122 class LoginScreenLocalePolicyTest : public LoginScreenPolicyTest { |
| 102 protected: | 123 protected: |
| 103 LoginScreenLocalePolicyTest() {} | 124 LoginScreenLocalePolicyTest() {} |
| 104 | 125 |
| 105 void SetUpInProcessBrowserTestFixture() override { | 126 void SetUpInProcessBrowserTestFixture() override { |
| 106 LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture(); | 127 LoginScreenPolicyTest::SetUpInProcessBrowserTestFixture(); |
| 107 | 128 |
| 108 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 129 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 126 // Make sure this is really French and differs from the English title. | 147 // Make sure this is really French and differs from the English title. |
| 127 std::string loaded = | 148 std::string loaded = |
| 128 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); | 149 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| 129 EXPECT_EQ("en-US", loaded); | 150 EXPECT_EQ("en-US", loaded); |
| 130 base::string16 english_title = | 151 base::string16 english_title = |
| 131 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); | 152 l10n_util::GetStringUTF16(IDS_LOGIN_POD_SIGNING_IN); |
| 132 EXPECT_NE(french_title, english_title); | 153 EXPECT_NE(french_title, english_title); |
| 133 } | 154 } |
| 134 | 155 |
| 135 } // namespace chromeos | 156 } // namespace chromeos |
| OLD | NEW |