Commit 2ea681be authored by Denis Kuznetsov's avatar Denis Kuznetsov Committed by Commit Bot

[USB-Enrollment] support setting language and input method.

If language is changed, this change should be performed before rest
of OOBE configuration is applied (e.g. input method value can be only
relevant for new language, so setting it before language change is
resolved would not be possible)

Bug: 854101
Change-Id: Ib7e7db058470683d649bfb775c65276141e226fc
Reviewed-on: https://chromium-review.googlesource.com/c/1350892
Commit-Queue: Denis Kuznetsov <antrim@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611224}
parent 273d06b6
...@@ -18,6 +18,12 @@ namespace configuration { ...@@ -18,6 +18,12 @@ namespace configuration {
// automatically. // automatically.
const char kWelcomeNext[] = "welcomeNext"; const char kWelcomeNext[] = "welcomeNext";
// String value that contains preferred input method.
const char kInputMethod[] = "inputMethod";
// String value that contains preferred input method.
const char kLanguage[] = "language";
// Boolean value indicating if device should automatically run the demo mode // Boolean value indicating if device should automatically run the demo mode
// setup flow. // setup flow.
const char kEnableDemoMode[] = "enableDemoMode"; const char kEnableDemoMode[] = "enableDemoMode";
...@@ -96,6 +102,8 @@ constexpr struct { ...@@ -96,6 +102,8 @@ constexpr struct {
ConfigurationHandlerSide side; ConfigurationHandlerSide side;
} kAllConfigurationKeys[] = { } kAllConfigurationKeys[] = {
{kWelcomeNext, ValueType::BOOLEAN, ConfigurationHandlerSide::HANDLER_JS}, {kWelcomeNext, ValueType::BOOLEAN, ConfigurationHandlerSide::HANDLER_JS},
{kLanguage, ValueType::STRING, ConfigurationHandlerSide::HANDLER_JS},
{kInputMethod, ValueType::STRING, ConfigurationHandlerSide::HANDLER_JS},
{kNetworkSelectGUID, ValueType::STRING, {kNetworkSelectGUID, ValueType::STRING,
ConfigurationHandlerSide::HANDLER_JS}, ConfigurationHandlerSide::HANDLER_JS},
{kEULASendUsageStatistics, ValueType::BOOLEAN, {kEULASendUsageStatistics, ValueType::BOOLEAN,
......
...@@ -12,6 +12,8 @@ namespace configuration { ...@@ -12,6 +12,8 @@ namespace configuration {
// Configuration keys that are used to automate OOBE screens go here. // Configuration keys that are used to automate OOBE screens go here.
// Please keep keys grouped by screens and ordered according to OOBE flow. // Please keep keys grouped by screens and ordered according to OOBE flow.
extern const char kLanguage[];
extern const char kInputMethod[];
extern const char kWelcomeNext[]; extern const char kWelcomeNext[];
extern const char kEnableDemoMode[]; extern const char kEnableDemoMode[];
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/string_escape.h" #include "base/json/string_escape.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h" #include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h"
...@@ -32,8 +33,12 @@ ...@@ -32,8 +33,12 @@
#include "chromeos/dbus/shill_manager_client.h" #include "chromeos/dbus/shill_manager_client.h"
#include "chromeos/dbus/upstart_client.h" #include "chromeos/dbus/upstart_client.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_util.h"
using chromeos::test::SetupDummyOfflinePolicyDir; using chromeos::test::SetupDummyOfflinePolicyDir;
using testing::_; using testing::_;
...@@ -962,6 +967,29 @@ IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentConfigurationTest, ...@@ -962,6 +967,29 @@ IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentConfigurationTest,
OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait();
} }
// Check that language and input methods are set correctly.
IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentConfigurationTest,
TestSwitchLanguageIME) {
LoadConfiguration();
OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait();
chromeos::input_method::InputMethodManager* imm =
chromeos::input_method::InputMethodManager::Get();
// Configuration specified in TestSwitchLanguageIME.json sets non-default
// input method fo German (xkb:de:neo:ger) to ensure that input method value
// is propagated correctly. We need to migrate public IME name to internal
// scheme to be able to compare them.
const std::string ime_id =
imm->GetInputMethodUtil()->MigrateInputMethod("xkb:de:neo:ger");
EXPECT_EQ(ime_id, imm->GetActiveIMEState()->GetCurrentInputMethod().id());
const std::string language_code = g_browser_process->local_state()->GetString(
language::prefs::kApplicationLocale);
EXPECT_EQ("de", language_code);
}
// Check that configuration lets correctly start Demo mode setup. // Check that configuration lets correctly start Demo mode setup.
IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentConfigurationTest, IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentConfigurationTest,
TestEnableDemoMode) { TestEnableDemoMode) {
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "chrome/browser/chromeos/login/configuration_keys.h" #include "chrome/browser/chromeos/login/configuration_keys.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/oobe_configuration_client.h" #include "chromeos/dbus/oobe_configuration_client.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_util.h"
namespace chromeos { namespace chromeos {
...@@ -92,10 +94,24 @@ void OobeConfiguration::OnConfigurationCheck(bool has_configuration, ...@@ -92,10 +94,24 @@ void OobeConfiguration::OnConfigurationCheck(bool has_configuration,
LOG(ERROR) << "Invalid OOBE configuration"; LOG(ERROR) << "Invalid OOBE configuration";
} else { } else {
configuration_ = std::move(value); configuration_ = std::move(value);
UpdateConfigurationValues();
} }
NotifyObservers(); NotifyObservers();
} }
void OobeConfiguration::UpdateConfigurationValues() {
auto* ime_value = configuration_->FindKeyOfType(configuration::kInputMethod,
base::Value::Type::STRING);
if (ime_value) {
chromeos::input_method::InputMethodManager* imm =
chromeos::input_method::InputMethodManager::Get();
configuration_->SetKey(
configuration::kInputMethod,
base::Value(imm->GetInputMethodUtil()->MigrateInputMethod(
ime_value->GetString())));
}
}
void OobeConfiguration::NotifyObservers() { void OobeConfiguration::NotifyObservers() {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnOobeConfigurationChanged(); observer.OnOobeConfigurationChanged();
......
...@@ -52,6 +52,8 @@ class OobeConfiguration { ...@@ -52,6 +52,8 @@ class OobeConfiguration {
const std::string& configuration); const std::string& configuration);
void NotifyObservers(); void NotifyObservers();
void UpdateConfigurationValues();
// Pointer to the existing OobeConfiguration instance (if any). // Pointer to the existing OobeConfiguration instance (if any).
// Set in ctor, reset in dtor. Not owned since we need to control the lifetime // Set in ctor, reset in dtor. Not owned since we need to control the lifetime
// externally. // externally.
......
...@@ -69,6 +69,8 @@ OobeTypes.TimezoneDsc; ...@@ -69,6 +69,8 @@ OobeTypes.TimezoneDsc;
* OOBE configuration, allows automation during OOBE. * OOBE configuration, allows automation during OOBE.
* Keys are also listed in chrome/browser/chromeos/login/configuration_keys.h * Keys are also listed in chrome/browser/chromeos/login/configuration_keys.h
* @typedef {{ * @typedef {{
* language: string|undefined,
* inputMethod: string|undefined,
* welcomeNext: boolean|undefined, * welcomeNext: boolean|undefined,
* enableDemoMode: boolean|undefined, * enableDemoMode: boolean|undefined,
* demoPreferencesNext: boolean|undefined, * demoPreferencesNext: boolean|undefined,
......
...@@ -120,14 +120,24 @@ Polymer({ ...@@ -120,14 +120,24 @@ Polymer({
this.$.welcomeScreen.i18nUpdateLocale(); this.$.welcomeScreen.i18nUpdateLocale();
this.i18nUpdateLocale(); this.i18nUpdateLocale();
var currentLanguage = loadTimeData.getString('language');
// We might have changed language via configuration. In this case
// we need to proceed with rest of configuration after language change
// was fully resolved.
var configuration = Oobe.getInstance().getOobeConfiguration();
if (configuration && configuration.language &&
configuration.language == currentLanguage) {
window.setTimeout(this.applyOobeConfiguration_.bind(this), 0);
}
}, },
/** Called when OOBE configuration is loaded. /**
* Called when OOBE configuration is loaded.
* @param {!OobeTypes.OobeConfiguration} configuration * @param {!OobeTypes.OobeConfiguration} configuration
*/ */
updateOobeConfiguration: function(configuration) { updateOobeConfiguration: function(configuration) {
if (!this.is_shown_)
return;
if (!this.configuration_applied_) if (!this.configuration_applied_)
window.setTimeout(this.applyOobeConfiguration_.bind(this), 0); window.setTimeout(this.applyOobeConfiguration_.bind(this), 0);
}, },
...@@ -137,13 +147,25 @@ Polymer({ ...@@ -137,13 +147,25 @@ Polymer({
* @private * @private
*/ */
applyOobeConfiguration_: function() { applyOobeConfiguration_: function() {
// TODO(antrim): apply a11y options, language selection
if (this.configuration_applied_) if (this.configuration_applied_)
return; return;
var configuration = Oobe.getInstance().getOobeConfiguration(); var configuration = Oobe.getInstance().getOobeConfiguration();
if (!configuration) if (!configuration)
return; return;
if (configuration.language) {
var currentLanguage = loadTimeData.getString('language');
if (currentLanguage != configuration.language) {
this.screen.onLanguageSelected_(configuration.language);
// Trigger language change without marking it as applied.
// applyOobeConfiguration will be called again once language change
// was applied.
return;
}
}
if (configuration.inputMethod)
this.screen.onKeyboardSelected_(configuration.inputMethod);
if (configuration.welcomeNext) if (configuration.welcomeNext)
this.onWelcomeNextButtonClicked_(); this.onWelcomeNextButtonClicked_();
......
{
"welcomeNext": true,
"language": "de",
"inputMethod": "xkb:de:neo:ger",
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment