Chromium Code Reviews| 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..4a2caa66a0e57d9cb58d029c7e5843f2d7733008 100644 |
| --- a/chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
| +++ b/chrome/browser/chromeos/login/oobe_localization_browsertest.cc |
| @@ -91,6 +91,10 @@ class OobeLocalizationTest : public InProcessBrowserTest { |
| // Returns true if the expression was successfully executed and returned true. |
| bool JsExecute(const std::string& expression); |
| + // Returns true if the expression was successfully executed. |
| + // Stored expression result to 'result'. |
| + bool JsExecute(const std::string& expression, std::string* result); |
| + |
| // 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,12 +105,16 @@ 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_; |
| @@ -136,6 +144,18 @@ bool OobeLocalizationTest::JsExecute(const std::string& expression) { |
| return false; |
| } |
| +bool OobeLocalizationTest::JsExecute(const std::string& expression, |
|
dzhioev (left Google)
2014/02/18 01:37:49
Don't you want to use JSChecker from chrome/browse
Alexander Alekseev
2014/02/18 13:38:43
Done.
|
| + std::string* out) { |
| + chromeos::LoginDisplayHostImpl* display_host = |
| + static_cast<chromeos::LoginDisplayHostImpl*>( |
| + chromeos::LoginDisplayHostImpl::default_host()); |
| + const std::string js("window.domAutomationController.send(" + expression + |
| + ");"); |
| + |
| + return content::ExecuteScriptAndExtractString( |
| + display_host->GetOobeUI()->web_ui()->GetWebContents(), js, out); |
| +} |
| + |
| void OobeLocalizationTest::VerifyInitialOptions(const char* select_id, |
| const char* values, |
| bool check_separator) { |
| @@ -173,11 +193,60 @@ void OobeLocalizationTest::VerifyOptionExists(const char* select_id, |
| ASSERT_TRUE(JsExecute(expression)) << expression; |
| } |
| +std::string OobeLocalizationTest::DumpOptions(const char* select_id) { |
| + const std::string expression = base::StringPrintf( |
| + "\n" |
|
dzhioev (left Google)
2014/02/18 01:37:49
I think it's better to define method (named dumpOp
Alexander Alekseev
2014/02/18 13:38:43
Discussed offline and decided to leave as it is fo
|
| + "(function () {\n" |
| + " var selector = '#%s';\n" |
| + " var divider = ',';\n" |
| + " var select = document.querySelector(selector);\n" |
| + " if (!select)\n" |
| + " throw 'document.querySelector(' + selector + ') failed.';\n" |
|
michaelpg
2014/02/17 22:39:10
If this throws, the test will hang until killed. C
Alexander Alekseev
2014/02/18 13:38:43
Done.
|
| + " 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); |
| + std::string result; |
| + if (!JsExecute(expression, &result)) { |
| + return std::string("Expression '") + expression + "' failed (result='" + |
| + result + "')."; |
| + } |
| + return result; |
| +} |
| + |
| 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); |
| @@ -199,6 +268,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 +285,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 |
|
michaelpg
2014/02/17 22:39:10
comma
Alexander Alekseev
2014/02/18 13:38:43
Done.
|
| + "xkb:us::eng"); |
| } |
| } // namespace chromeos |