Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/chromeos/login/oobe_localization_browsertest.cc

Issue 167013004: Add support for multiply values in keyboard_layouts to OobeLocalizationTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 } // namespace system 85 } // namespace system
86 86
87 class OobeLocalizationTest : public InProcessBrowserTest { 87 class OobeLocalizationTest : public InProcessBrowserTest {
88 public: 88 public:
89 OobeLocalizationTest(); 89 OobeLocalizationTest();
90 90
91 // Returns true if the expression was successfully executed and returned true. 91 // Returns true if the expression was successfully executed and returned true.
92 bool JsExecute(const std::string& expression); 92 bool JsExecute(const std::string& expression);
93 93
94 // Returns true if the expression was successfully executed.
95 // Stored expression result to 'result'.
96 bool JsExecute(const std::string& expression, std::string* result);
97
94 // Verifies that the comma-separated |values| corresponds with the first 98 // Verifies that the comma-separated |values| corresponds with the first
95 // values in |select_id|, optionally checking for an options group label after 99 // values in |select_id|, optionally checking for an options group label after
96 // the first set of options. 100 // the first set of options.
97 void VerifyInitialOptions(const char* select_id, 101 void VerifyInitialOptions(const char* select_id,
98 const char* values, 102 const char* values,
99 bool check_separator); 103 bool check_separator);
100 104
101 // Verifies that |value| exists in |select_id|. 105 // Verifies that |value| exists in |select_id|.
102 void VerifyOptionExists(const char* select_id, const char* value); 106 void VerifyOptionExists(const char* select_id, const char* value);
103 107
108 // Dumps OOBE select control (language or keyboard) to string.
109 std::string DumpOptions(const char* select_id);
110
104 protected: 111 protected:
105 // Runs the test for the given locale and keyboard layout. 112 // Runs the test for the given locale and keyboard layout.
106 void RunLocalizationTest(const std::string& initial_locale, 113 void RunLocalizationTest(const std::string& initial_locale,
107 const std::string& keyboard_layout, 114 const std::string& keyboard_layout,
108 const std::string& expected_locale, 115 const std::string& expected_locale,
109 const std::string& expected_keyboard_layout); 116 const std::string& expected_keyboard_layout,
117 const std::string& expected_keyboard_select_control);
110 118
111 private: 119 private:
112 scoped_ptr<system::FakeStatisticsProvider> statistics_provider_; 120 scoped_ptr<system::FakeStatisticsProvider> statistics_provider_;
113 121
114 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest); 122 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest);
115 }; 123 };
116 124
117 OobeLocalizationTest::OobeLocalizationTest() { 125 OobeLocalizationTest::OobeLocalizationTest() {
118 statistics_provider_.reset(new system::FakeStatisticsProvider()); 126 statistics_provider_.reset(new system::FakeStatisticsProvider());
119 // Set the instance returned by GetInstance() for testing. 127 // Set the instance returned by GetInstance() for testing.
120 system::StatisticsProvider::SetTestProvider(statistics_provider_.get()); 128 system::StatisticsProvider::SetTestProvider(statistics_provider_.get());
121 } 129 }
122 130
123 bool OobeLocalizationTest::JsExecute(const std::string& expression) { 131 bool OobeLocalizationTest::JsExecute(const std::string& expression) {
124 chromeos::LoginDisplayHostImpl* display_host = 132 chromeos::LoginDisplayHostImpl* display_host =
125 static_cast<chromeos::LoginDisplayHostImpl*>( 133 static_cast<chromeos::LoginDisplayHostImpl*>(
126 chromeos::LoginDisplayHostImpl::default_host()); 134 chromeos::LoginDisplayHostImpl::default_host());
127 const std::string js("window.domAutomationController.send(!!(" + 135 const std::string js("window.domAutomationController.send(!!(" +
128 expression + "));"); 136 expression + "));");
129 137
130 bool result; 138 bool result;
131 if (content::ExecuteScriptAndExtractBool( 139 if (content::ExecuteScriptAndExtractBool(
132 display_host->GetOobeUI()->web_ui()->GetWebContents(), js, &result)) 140 display_host->GetOobeUI()->web_ui()->GetWebContents(), js, &result))
133 return result; 141 return result;
134 142
135 // Execution failed. 143 // Execution failed.
136 return false; 144 return false;
137 } 145 }
138 146
147 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.
148 std::string* out) {
149 chromeos::LoginDisplayHostImpl* display_host =
150 static_cast<chromeos::LoginDisplayHostImpl*>(
151 chromeos::LoginDisplayHostImpl::default_host());
152 const std::string js("window.domAutomationController.send(" + expression +
153 ");");
154
155 return content::ExecuteScriptAndExtractString(
156 display_host->GetOobeUI()->web_ui()->GetWebContents(), js, out);
157 }
158
139 void OobeLocalizationTest::VerifyInitialOptions(const char* select_id, 159 void OobeLocalizationTest::VerifyInitialOptions(const char* select_id,
140 const char* values, 160 const char* values,
141 bool check_separator) { 161 bool check_separator) {
142 const std::string expression = base::StringPrintf( 162 const std::string expression = base::StringPrintf(
143 "(function () {\n" 163 "(function () {\n"
144 " var select = document.querySelector('#%s');\n" 164 " var select = document.querySelector('#%s');\n"
145 " if (!select)\n" 165 " if (!select)\n"
146 " return false;\n" 166 " return false;\n"
147 " var values = '%s'.split(',');\n" 167 " var values = '%s'.split(',');\n"
148 " var correct = select.selectedIndex == 0;\n" 168 " var correct = select.selectedIndex == 0;\n"
(...skipping 17 matching lines...) Expand all
166 " return false;\n" 186 " return false;\n"
167 " for (var i = 0; i < select.options.length; i++) {\n" 187 " for (var i = 0; i < select.options.length; i++) {\n"
168 " if (select.options[i].value == '%s')\n" 188 " if (select.options[i].value == '%s')\n"
169 " return true;\n" 189 " return true;\n"
170 " }\n" 190 " }\n"
171 " return false;\n" 191 " return false;\n"
172 "})()", select_id, value); 192 "})()", select_id, value);
173 ASSERT_TRUE(JsExecute(expression)) << expression; 193 ASSERT_TRUE(JsExecute(expression)) << expression;
174 } 194 }
175 195
196 std::string OobeLocalizationTest::DumpOptions(const char* select_id) {
197 const std::string expression = base::StringPrintf(
198 "\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
199 "(function () {\n"
200 " var selector = '#%s';\n"
201 " var divider = ',';\n"
202 " var select = document.querySelector(selector);\n"
203 " if (!select)\n"
204 " 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.
205 " var dumpOptgroup = function(group) {\n"
206 " var result = '';\n"
207 " for (var i = 0; i < group.children.length; i++) {\n"
208 " if (i > 0) {\n"
209 " result += divider;\n"
210 " }\n"
211 " if (group.children[i].value) {\n"
212 " result += group.children[i].value;\n"
213 " } else {\n"
214 " result += '__NO_VALUE__';\n"
215 " }\n"
216 " }\n"
217 " return result;\n"
218 " };\n"
219 " var result = '';\n"
220 " var children = select.children;\n"
221 " for (var i = 0; i < children.length; i++) {\n"
222 " if (i > 0) {\n"
223 " result += divider;\n"
224 " }\n"
225 " if (children[i].value) {\n"
226 " result += children[i].value;\n"
227 " } else if (children[i].tagName === 'OPTGROUP') {\n"
228 " result += '[' + dumpOptgroup(children[i]) + ']';\n"
229 " } else {\n"
230 " result += '__NO_VALUE__';\n"
231 " }\n"
232 " }\n"
233 " return result;\n"
234 "})()\n",
235 select_id);
236 std::string result;
237 if (!JsExecute(expression, &result)) {
238 return std::string("Expression '") + expression + "' failed (result='" +
239 result + "').";
240 }
241 return result;
242 }
243
176 void OobeLocalizationTest::RunLocalizationTest( 244 void OobeLocalizationTest::RunLocalizationTest(
177 const std::string& initial_locale, 245 const std::string& initial_locale,
178 const std::string& keyboard_layout, 246 const std::string& keyboard_layout,
179 const std::string& expected_locale, 247 const std::string& expected_locale,
180 const std::string& expected_keyboard_layout) { 248 const std::string& expected_keyboard_layout,
249 const std::string& expected_keyboard_select_control) {
181 statistics_provider_->set_locale(initial_locale); 250 statistics_provider_->set_locale(initial_locale);
182 statistics_provider_->set_keyboard_layout(keyboard_layout); 251 statistics_provider_->set_keyboard_layout(keyboard_layout);
183 252
184 // Initialize StartupCustomizationDocument with fake statistics provider. 253 // Initialize StartupCustomizationDocument with fake statistics provider.
185 StartupCustomizationDocument::GetInstance()->Init( 254 StartupCustomizationDocument::GetInstance()->Init(
186 statistics_provider_.get()); 255 statistics_provider_.get());
187 256
188 // Bring up the OOBE network screen. 257 // Bring up the OOBE network screen.
189 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName); 258 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName);
190 content::WindowedNotificationObserver( 259 content::WindowedNotificationObserver(
191 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 260 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
192 content::NotificationService::AllSources()).Wait(); 261 content::NotificationService::AllSources()).Wait();
193 262
194 VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true); 263 VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true);
195 VerifyInitialOptions(kKeyboardSelect, 264 VerifyInitialOptions(kKeyboardSelect,
196 expected_keyboard_layout.c_str(), 265 expected_keyboard_layout.c_str(),
197 false); 266 false);
198 267
199 // Make sure we have a fallback keyboard. 268 // Make sure we have a fallback keyboard.
200 VerifyOptionExists(kKeyboardSelect, kUSLayout); 269 VerifyOptionExists(kKeyboardSelect, kUSLayout);
201 270
271 // Note, that sort order is locale-specific, but is unlikely to change.
272 // Especially for keyboard layouts.
273 EXPECT_EQ(expected_keyboard_select_control, DumpOptions(kKeyboardSelect));
274
202 // Shut down the display host. 275 // Shut down the display host.
203 chromeos::LoginDisplayHostImpl::default_host()->Finalize(); 276 chromeos::LoginDisplayHostImpl::default_host()->Finalize();
204 base::MessageLoopForUI::current()->RunUntilIdle(); 277 base::MessageLoopForUI::current()->RunUntilIdle();
205 278
206 // Clear the locale pref so the statistics provider is pinged next time. 279 // Clear the locale pref so the statistics provider is pinged next time.
207 g_browser_process->local_state()->SetString(prefs::kApplicationLocale, 280 g_browser_process->local_state()->SetString(prefs::kApplicationLocale,
208 std::string()); 281 std::string());
209 } 282 }
210 283
211 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenNonLatin) { 284 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenNonLatin) {
212 // For a non-Latin keyboard layout like Russian, we expect to see the US 285 // For a non-Latin keyboard layout like Russian, we expect to see the US
213 // keyboard. 286 // keyboard.
214 RunLocalizationTest("ru", "xkb:ru::rus", 287 RunLocalizationTest("ru", "xkb:ru::rus",
215 "ru", kUSLayout); 288 "ru", kUSLayout,
289 "xkb:us::eng");
290
291 RunLocalizationTest("ru", "xkb:us::eng,xkb:ru::rus",
292 "ru", kUSLayout,
293 "xkb:us::eng");
216 294
217 // IMEs do not load at OOBE, so we just expect to see the (Latin) Japanese 295 // IMEs do not load at OOBE, so we just expect to see the (Latin) Japanese
218 // keyboard. 296 // keyboard.
219 RunLocalizationTest("ja", "xkb:jp::jpn", 297 RunLocalizationTest("ja", "xkb:jp::jpn",
220 "ja", "xkb:jp::jpn"); 298 "ja", "xkb:jp::jpn",
299 "xkb:jp::jpn,[xkb:us::eng]");
221 } 300 }
222 301
223 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenKeyboardLayout) { 302 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenKeyboardLayout) {
224 // We don't use the Icelandic locale but the Icelandic keyboard layout 303 // We don't use the Icelandic locale but the Icelandic keyboard layout
225 // should still be selected when specified as the default. 304 // should still be selected when specified as the default.
226 RunLocalizationTest("en-US", "xkb:is::ice", 305 RunLocalizationTest("en-US", "xkb:is::ice",
227 "en-US", "xkb:is::ice"); 306 "en-US", "xkb:is::ice",
307 "xkb:is::ice,["
308 "xkb:us::eng,xkb:us:intl:eng,xkb:us:altgr-intl:eng,"
309 "xkb:us:dvorak:eng,xkb:us:colemak:eng]");
228 } 310 }
229 311
230 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenFullLatin) { 312 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenFullLatin) {
231 // French Swiss keyboard. 313 // French Swiss keyboard.
232 RunLocalizationTest("fr", "xkb:ch:fr:fra", 314 RunLocalizationTest("fr", "xkb:ch:fr:fra",
233 "fr", "xkb:ch:fr:fra"); 315 "fr", "xkb:ch:fr:fra",
316 "xkb:ch:fr:fra,["
317 "xkb:fr::fra,xkb:be::fra,xkb:ca::fra,"
318 "xkb:ca:multix:fra,xkb:us::eng]");
234 319
235 // German Swiss keyboard. 320 // German Swiss keyboard.
236 RunLocalizationTest("de", "xkb:ch::ger", 321 RunLocalizationTest("de", "xkb:ch::ger",
237 "de", "xkb:ch::ger"); 322 "de", "xkb:ch::ger",
323 "xkb:ch::ger,["
324 "xkb:de::ger,xkb:de:neo:ger,xkb:be::ger,xkb:us::eng"
325 "]");
238 } 326 }
239 327
240 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) { 328 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) {
241 RunLocalizationTest("es,en-US,nl", "xkb:be::nld", 329 RunLocalizationTest("es,en-US,nl", "xkb:be::nld",
242 "es,en-US,nl", "xkb:be::nld"); 330 "es,en-US,nl", "xkb:be::nld",
331 "xkb:be::nld,[xkb:es::spa,xkb:latam::spa,xkb:us::eng]");
243 332
244 RunLocalizationTest("ru,de", "xkb:ru::rus", 333 RunLocalizationTest("ru,de", "xkb:ru::rus",
245 "ru,de", kUSLayout); 334 "ru,de", kUSLayout
michaelpg 2014/02/17 22:39:10 comma
Alexander Alekseev 2014/02/18 13:38:43 Done.
335 "xkb:us::eng");
246 } 336 }
247 337
248 } // namespace chromeos 338 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698