Index: chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
diff --git a/chrome/browser/chromeos/login/oobe_localization_browsertest.cc b/chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
index 9b9e07547c3cd982054a6df72fa56c62e150445c..aa8b648a9ed3d6451ef7588bc7168c4a3185ec82 100644 |
--- a/chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
+++ b/chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
@@ -11,6 +11,7 @@ |
#include "chrome/browser/chromeos/customization_document.h" |
#include "chrome/browser/chromeos/login/login_display_host_impl.h" |
#include "chrome/browser/chromeos/login/login_wizard.h" |
+#include "chrome/browser/chromeos/login/test/js_checker.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chromeos/system/statistics_provider.h" |
@@ -88,9 +89,6 @@ class OobeLocalizationTest : public InProcessBrowserTest { |
public: |
OobeLocalizationTest(); |
- // Returns true if the expression was successfully executed and returned true. |
- bool JsExecute(const std::string& expression); |
- |
// Verifies that the comma-separated |values| corresponds with the first |
// values in |select_id|, optionally checking for an options group label after |
// the first set of options. |
@@ -101,15 +99,20 @@ class OobeLocalizationTest : public InProcessBrowserTest { |
// Verifies that |value| exists in |select_id|. |
void VerifyOptionExists(const char* select_id, const char* value); |
+ // Dumps OOBE select control (language or keyboard) to string. |
+ std::string DumpOptions(const char* select_id); |
+ |
protected: |
// Runs the test for the given locale and keyboard layout. |
void RunLocalizationTest(const std::string& initial_locale, |
const std::string& keyboard_layout, |
const std::string& expected_locale, |
- const std::string& expected_keyboard_layout); |
+ const std::string& expected_keyboard_layout, |
+ const std::string& expected_keyboard_select_control); |
private: |
scoped_ptr<system::FakeStatisticsProvider> statistics_provider_; |
+ test::JSChecker checker; |
DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); |
}; |
@@ -120,22 +123,6 @@ OobeLocalizationTest::OobeLocalizationTest() { |
system::StatisticsProvider::SetTestProvider(statistics_provider_.get()); |
} |
-bool OobeLocalizationTest::JsExecute(const std::string& expression) { |
- chromeos::LoginDisplayHostImpl* display_host = |
- static_cast<chromeos::LoginDisplayHostImpl*>( |
- chromeos::LoginDisplayHostImpl::default_host()); |
- const std::string js("window.domAutomationController.send(!!(" + |
- expression + "));"); |
- |
- bool result; |
- if (content::ExecuteScriptAndExtractBool( |
- display_host->GetOobeUI()->web_ui()->GetWebContents(), js, &result)) |
- return result; |
- |
- // Execution failed. |
- return false; |
-} |
- |
void OobeLocalizationTest::VerifyInitialOptions(const char* select_id, |
const char* values, |
bool check_separator) { |
@@ -154,7 +141,7 @@ void OobeLocalizationTest::VerifyInitialOptions(const char* select_id, |
" correct = select.children[values.length].tagName === 'OPTGROUP';\n" |
" return correct;\n" |
"})()", select_id, values, check_separator); |
- ASSERT_TRUE(JsExecute(expression)) << expression; |
+ ASSERT_TRUE(checker.GetBool(expression)) << expression; |
} |
void OobeLocalizationTest::VerifyOptionExists(const char* select_id, |
@@ -170,14 +157,58 @@ void OobeLocalizationTest::VerifyOptionExists(const char* select_id, |
" }\n" |
" return false;\n" |
"})()", select_id, value); |
- ASSERT_TRUE(JsExecute(expression)) << expression; |
+ ASSERT_TRUE(checker.GetBool(expression)) << expression; |
+} |
+ |
+std::string OobeLocalizationTest::DumpOptions(const char* select_id) { |
+ const std::string expression = base::StringPrintf( |
+ "\n" |
+ "(function () {\n" |
+ " var selector = '#%s';\n" |
+ " var divider = ',';\n" |
+ " var select = document.querySelector(selector);\n" |
+ " if (!select)\n" |
+ " return 'document.querySelector(' + selector + ') failed.';\n" |
+ " var dumpOptgroup = function(group) {\n" |
+ " var result = '';\n" |
+ " for (var i = 0; i < group.children.length; i++) {\n" |
+ " if (i > 0) {\n" |
+ " result += divider;\n" |
+ " }\n" |
+ " if (group.children[i].value) {\n" |
+ " result += group.children[i].value;\n" |
+ " } else {\n" |
+ " result += '__NO_VALUE__';\n" |
+ " }\n" |
+ " }\n" |
+ " return result;\n" |
+ " };\n" |
+ " var result = '';\n" |
+ " var children = select.children;\n" |
+ " for (var i = 0; i < children.length; i++) {\n" |
+ " if (i > 0) {\n" |
+ " result += divider;\n" |
+ " }\n" |
+ " if (children[i].value) {\n" |
+ " result += children[i].value;\n" |
+ " } else if (children[i].tagName === 'OPTGROUP') {\n" |
+ " result += '[' + dumpOptgroup(children[i]) + ']';\n" |
+ " } else {\n" |
+ " result += '__NO_VALUE__';\n" |
+ " }\n" |
+ " }\n" |
+ " return result;\n" |
+ "})()\n", |
+ select_id); |
+ return checker.GetString(expression); |
} |
void OobeLocalizationTest::RunLocalizationTest( |
const std::string& initial_locale, |
const std::string& keyboard_layout, |
const std::string& expected_locale, |
- const std::string& expected_keyboard_layout) { |
+ const std::string& expected_keyboard_layout, |
+ const std::string& expected_keyboard_select_control) { |
statistics_provider_->set_locale(initial_locale); |
statistics_provider_->set_keyboard_layout(keyboard_layout); |
@@ -191,6 +222,10 @@ void OobeLocalizationTest::RunLocalizationTest( |
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
content::NotificationService::AllSources()).Wait(); |
+ checker.set_web_contents(static_cast<chromeos::LoginDisplayHostImpl*>( |
+ chromeos::LoginDisplayHostImpl::default_host())-> |
+ GetOobeUI()->web_ui()->GetWebContents()); |
+ |
VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true); |
VerifyInitialOptions(kKeyboardSelect, |
expected_keyboard_layout.c_str(), |
@@ -199,6 +234,10 @@ void OobeLocalizationTest::RunLocalizationTest( |
// Make sure we have a fallback keyboard. |
VerifyOptionExists(kKeyboardSelect, kUSLayout); |
+ // Note, that sort order is locale-specific, but is unlikely to change. |
+ // Especially for keyboard layouts. |
+ EXPECT_EQ(expected_keyboard_select_control, DumpOptions(kKeyboardSelect)); |
+ |
// Shut down the display host. |
chromeos::LoginDisplayHostImpl::default_host()->Finalize(); |
base::MessageLoopForUI::current()->RunUntilIdle(); |
@@ -212,37 +251,54 @@ IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenNonLatin) { |
// For a non-Latin keyboard layout like Russian, we expect to see the US |
// keyboard. |
RunLocalizationTest("ru", "xkb:ru::rus", |
- "ru", kUSLayout); |
+ "ru", kUSLayout, |
+ "xkb:us::eng"); |
+ |
+ RunLocalizationTest("ru", "xkb:us::eng,xkb:ru::rus", |
+ "ru", kUSLayout, |
+ "xkb:us::eng"); |
// IMEs do not load at OOBE, so we just expect to see the (Latin) Japanese |
// keyboard. |
RunLocalizationTest("ja", "xkb:jp::jpn", |
- "ja", "xkb:jp::jpn"); |
+ "ja", "xkb:jp::jpn", |
+ "xkb:jp::jpn,[xkb:us::eng]"); |
} |
IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenKeyboardLayout) { |
// We don't use the Icelandic locale but the Icelandic keyboard layout |
// should still be selected when specified as the default. |
RunLocalizationTest("en-US", "xkb:is::ice", |
- "en-US", "xkb:is::ice"); |
+ "en-US", "xkb:is::ice", |
+ "xkb:is::ice,[" |
+ "xkb:us::eng,xkb:us:intl:eng,xkb:us:altgr-intl:eng," |
+ "xkb:us:dvorak:eng,xkb:us:colemak:eng]"); |
} |
IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenFullLatin) { |
// French Swiss keyboard. |
RunLocalizationTest("fr", "xkb:ch:fr:fra", |
- "fr", "xkb:ch:fr:fra"); |
+ "fr", "xkb:ch:fr:fra", |
+ "xkb:ch:fr:fra,[" |
+ "xkb:fr::fra,xkb:be::fra,xkb:ca::fra," |
+ "xkb:ca:multix:fra,xkb:us::eng]"); |
// German Swiss keyboard. |
RunLocalizationTest("de", "xkb:ch::ger", |
- "de", "xkb:ch::ger"); |
+ "de", "xkb:ch::ger", |
+ "xkb:ch::ger,[" |
+ "xkb:de::ger,xkb:de:neo:ger,xkb:be::ger,xkb:us::eng" |
+ "]"); |
} |
IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) { |
- RunLocalizationTest("es,en-US,nl", "xkb:be::nld", |
- "es,en-US,nl", "xkb:be::nld"); |
+ RunLocalizationTest("es,en-US,nl", "xkb:be::nld", |
+ "es,en-US,nl", "xkb:be::nld", |
+ "xkb:be::nld,[xkb:es::spa,xkb:latam::spa,xkb:us::eng]"); |
- RunLocalizationTest("ru,de", "xkb:ru::rus", |
- "ru,de", kUSLayout); |
+ RunLocalizationTest("ru,de", "xkb:ru::rus", |
+ "ru,de", kUSLayout, |
+ "xkb:us::eng"); |
} |
} // namespace chromeos |