| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/task_runner.h" | 8 #include "base/task_runner.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 " } else {\n" | 205 " } else {\n" |
| 206 " result += '__NO_VALUE__';\n" | 206 " result += '__NO_VALUE__';\n" |
| 207 " }\n" | 207 " }\n" |
| 208 " }\n" | 208 " }\n" |
| 209 " return result;\n" | 209 " return result;\n" |
| 210 "})()\n", | 210 "})()\n", |
| 211 select_id); | 211 select_id); |
| 212 return checker.GetString(expression); | 212 return checker.GetString(expression); |
| 213 } | 213 } |
| 214 | 214 |
| 215 std::string TranslateXKB2Extension(const std::string& src) { |
| 216 std::string result(src); |
| 217 if (!extension_ime_util::UseWrappedExtensionKeyboardLayouts()) |
| 218 return result; |
| 219 // Modifies the expected keyboard select control options for the new |
| 220 // extension based xkb id. |
| 221 size_t pos = 0; |
| 222 std::string repl_old = "xkb:"; |
| 223 std::string repl_new = |
| 224 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:"); |
| 225 while ((pos = result.find(repl_old, pos)) != std::string::npos) { |
| 226 result.replace(pos, repl_old.length(), repl_new); |
| 227 pos += repl_new.length(); |
| 228 } |
| 229 return result; |
| 230 } |
| 231 |
| 215 void OobeLocalizationTest::RunLocalizationTest( | 232 void OobeLocalizationTest::RunLocalizationTest( |
| 216 const std::string& initial_locale, | 233 const std::string& initial_locale, |
| 217 const std::string& keyboard_layout, | 234 const std::string& keyboard_layout, |
| 218 const std::string& expected_locale, | 235 const std::string& expected_locale, |
| 219 const std::string& expected_keyboard_layout, | 236 const std::string& expected_keyboard_layout, |
| 220 const std::string& expected_keyboard_select_control) { | 237 const std::string& expected_keyboard_select_control) { |
| 221 statistics_provider_->set_locale(initial_locale); | 238 statistics_provider_->set_locale(initial_locale); |
| 222 statistics_provider_->set_keyboard_layout(keyboard_layout); | 239 statistics_provider_->set_keyboard_layout(keyboard_layout); |
| 223 | 240 |
| 224 // Initialize StartupCustomizationDocument with fake statistics provider. | 241 // Initialize StartupCustomizationDocument with fake statistics provider. |
| 225 StartupCustomizationDocument::GetInstance()->Init( | 242 StartupCustomizationDocument::GetInstance()->Init( |
| 226 statistics_provider_.get()); | 243 statistics_provider_.get()); |
| 227 | 244 |
| 228 g_browser_process->local_state()->SetString( | 245 g_browser_process->local_state()->SetString( |
| 229 prefs::kHardwareKeyboardLayout, keyboard_layout); | 246 prefs::kHardwareKeyboardLayout, keyboard_layout); |
| 230 | 247 |
| 231 input_method::InputMethodManager::Get() | 248 input_method::InputMethodManager::Get() |
| 232 ->GetInputMethodUtil() | 249 ->GetInputMethodUtil() |
| 233 ->InitXkbInputMethodsForTesting(); | 250 ->InitXkbInputMethodsForTesting(); |
| 234 | 251 |
| 235 std::string expected_keyboard_select = expected_keyboard_select_control; | 252 const std::string expected_keyboard_select = |
| 236 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { | 253 TranslateXKB2Extension(expected_keyboard_select_control); |
| 237 // Modifies the expected keyboard select control options for the new | |
| 238 // extension based xkb id. | |
| 239 size_t pos = 0; | |
| 240 std::string repl_old = "xkb:"; | |
| 241 std::string repl_new = | |
| 242 extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:"); | |
| 243 while ((pos = expected_keyboard_select.find(repl_old, pos)) != | |
| 244 std::string::npos) { | |
| 245 expected_keyboard_select.replace(pos, repl_old.length(), repl_new); | |
| 246 pos += repl_new.length(); | |
| 247 } | |
| 248 } | |
| 249 | 254 |
| 250 // Bring up the OOBE network screen. | 255 // Bring up the OOBE network screen. |
| 251 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName); | 256 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName); |
| 252 content::WindowedNotificationObserver( | 257 content::WindowedNotificationObserver( |
| 253 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 258 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 254 content::NotificationService::AllSources()).Wait(); | 259 content::NotificationService::AllSources()).Wait(); |
| 255 | 260 |
| 256 checker.set_web_contents(static_cast<chromeos::LoginDisplayHostImpl*>( | 261 checker.set_web_contents(static_cast<chromeos::LoginDisplayHostImpl*>( |
| 257 chromeos::LoginDisplayHostImpl::default_host())-> | 262 chromeos::LoginDisplayHostImpl::default_host())-> |
| 258 GetOobeUI()->web_ui()->GetWebContents()); | 263 GetOobeUI()->web_ui()->GetWebContents()); |
| 259 | 264 |
| 260 VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true); | 265 VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true); |
| 261 VerifyInitialOptions(kKeyboardSelect, | 266 VerifyInitialOptions(kKeyboardSelect, |
| 262 extension_ime_util::GetInputMethodIDByKeyboardLayout( | 267 TranslateXKB2Extension(expected_keyboard_layout).c_str(), |
| 263 expected_keyboard_layout).c_str(), | |
| 264 false); | 268 false); |
| 265 | 269 |
| 266 // Make sure we have a fallback keyboard. | 270 // Make sure we have a fallback keyboard. |
| 267 VerifyOptionExists( | 271 VerifyOptionExists( |
| 268 kKeyboardSelect, | 272 kKeyboardSelect, |
| 269 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSLayout).c_str()); | 273 extension_ime_util::GetInputMethodIDByKeyboardLayout(kUSLayout).c_str()); |
| 270 | 274 |
| 271 // Note, that sort order is locale-specific, but is unlikely to change. | 275 // Note, that sort order is locale-specific, but is unlikely to change. |
| 272 // Especially for keyboard layouts. | 276 // Especially for keyboard layouts. |
| 273 EXPECT_EQ(expected_keyboard_select, DumpOptions(kKeyboardSelect)); | 277 EXPECT_EQ(expected_keyboard_select, DumpOptions(kKeyboardSelect)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) { | 332 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) { |
| 329 RunLocalizationTest("es,en-US,nl", "xkb:be::nld", | 333 RunLocalizationTest("es,en-US,nl", "xkb:be::nld", |
| 330 "es,en-US,nl", "xkb:be::nld", | 334 "es,en-US,nl", "xkb:be::nld", |
| 331 "xkb:be::nld,[xkb:es::spa,xkb:latam::spa,xkb:us::eng]"); | 335 "xkb:be::nld,[xkb:es::spa,xkb:latam::spa,xkb:us::eng]"); |
| 332 | 336 |
| 333 RunLocalizationTest("ru,de", "xkb:ru::rus", | 337 RunLocalizationTest("ru,de", "xkb:ru::rus", |
| 334 "ru,de", kUSLayout, | 338 "ru,de", kUSLayout, |
| 335 "xkb:us::eng"); | 339 "xkb:us::eng"); |
| 336 } | 340 } |
| 337 | 341 |
| 342 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenRegionalLocales) { |
| 343 RunLocalizationTest("fr-CH,it-CH,de-CH", |
| 344 "xkb:fr::fra,xkb:it::ita,xkb:de::ger", |
| 345 "fr-CH,it-CH,de-CH", |
| 346 "xkb:fr::fra,xkb:it::ita,xkb:de::ger", |
| 347 "xkb:fr::fra,xkb:it::ita,xkb:de::ger,[" |
| 348 "xkb:be::fra,xkb:ca::fra,xkb:ch:fr:fra," |
| 349 "xkb:ca:multix:fra,xkb:us::eng" |
| 350 "]"); |
| 351 } |
| 352 |
| 338 } // namespace chromeos | 353 } // namespace chromeos |
| OLD | NEW |