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

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

Issue 153473004: OOBE localization browser test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test multiple locales 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/customization_document.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/message_loop/message_loop.h"
6 #include "base/prefs/pref_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/task_runner.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/chromeos/customization_document.h"
12 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/login_wizard.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chromeos/system/statistics_provider.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/test_utils.h"
21
22 namespace base {
23 class TaskRunner;
24 }
25
26 namespace chromeos {
27
28 namespace {
29
30 // OOBE constants.
31 const char* kLocaleSelect = "language-select";
32 const char* kKeyboardSelect = "keyboard-select";
33
34 const char* kUSLayout = "xkb:us::eng";
35
36 }
37
38 namespace system {
39
40 // Custom StatisticsProvider that will return each set of region settings.
41 class FakeStatisticsProvider : public StatisticsProvider {
42 public:
43 virtual ~FakeStatisticsProvider() {}
44
45 void set_locale(const std::string& locale) {
46 initial_locale_ = locale;
47 }
48
49 void set_keyboard_layout(const std::string& keyboard_layout) {
50 keyboard_layout_ = keyboard_layout;
51 }
52
53 private:
54 virtual void StartLoadingMachineStatistics(
achuithb 2014/02/12 21:49:41 nit: Please add a comment like: // StatisticsProvi
michaelpg 2014/02/12 23:06:25 Done.
55 const scoped_refptr<base::TaskRunner>& file_task_runner,
56 bool load_oem_manifest) OVERRIDE {
57 }
58
59 // Populates the named machine statistic for initial_locale and
60 // keyboard_layout only.
61 virtual bool GetMachineStatistic(const std::string& name,
62 std::string* result) OVERRIDE {
63 if (name == "initial_locale")
64 *result = initial_locale_;
65 else if (name == "keyboard_layout")
66 *result = keyboard_layout_;
67 else
68 return false;
69
70 return true;
71 }
72
73 virtual bool GetMachineFlag(const std::string& name, bool* result) OVERRIDE {
74 return false;
75 }
76
77 virtual void Shutdown() OVERRIDE {
78 }
79
80 std::string initial_locale_;
81 std::string keyboard_layout_;
82 };
83
84 } // namespace system
85
86 class OobeLocalizationTest : public InProcessBrowserTest {
87 public:
88 OobeLocalizationTest();
89
90 // Returns true if the expression was successfully executed and returned true.
91 bool JsExecute(const std::string& expression);
92
93 // Verifies that the comma-separated |values| corresponds with the first
94 // values in |select_id|, optionally checking for an options group label after
95 // the first set of options.
96 void VerifyInitialOptions(const char* select_id,
97 const char* values,
98 bool check_separator);
99
100 // Verifies that |value| exists in |select_id|.
101 void VerifyOptionExists(const char* select_id, const char* value);
102
103 protected:
104 // Runs the test for the given locale and keyboard layout.
105 void RunLocalizationTest(const std::string& initial_locale,
106 const std::string& keyboard_layout,
107 const std::string& expected_locale,
108 const std::string& expected_keyboard_layout);
109
110 private:
111 scoped_ptr<system::FakeStatisticsProvider> statistics_provider_;
112
113 DISALLOW_COPY_AND_ASSIGN(OobeLocalizationTest);
114 };
115
116 OobeLocalizationTest::OobeLocalizationTest() {
117 statistics_provider_.reset(new system::FakeStatisticsProvider());
118 // Set the instance returned by GetInstance() for testing.
119 system::StatisticsProvider::SetTestProvider(statistics_provider_.get());
120 }
121
122 bool OobeLocalizationTest::JsExecute(const std::string& expression) {
123 bool result;
124 chromeos::LoginDisplayHostImpl* display_host =
125 static_cast<chromeos::LoginDisplayHostImpl*>(
126 chromeos::LoginDisplayHostImpl::default_host());
127 return content::ExecuteScriptAndExtractBool(
128 display_host->GetOobeUI()->web_ui()->GetWebContents(),
129 "window.domAutomationController.send(!!(" + expression + "));",
achuithb 2014/02/12 21:49:41 nit: could you pull this out into a separate varia
michaelpg 2014/02/12 23:06:25 Done.
130 &result) && result;
131 }
132
133 void OobeLocalizationTest::VerifyInitialOptions(const char* select_id,
134 const char* values,
135 bool check_separator) {
136 std::string expression = base::StringPrintf(
achuithb 2014/02/12 21:49:41 nit: const
michaelpg 2014/02/12 23:06:25 Done.
137 "(function () {\n"
138 " var select = document.querySelector('#%s');\n"
139 " if (!select)\n"
140 " return false;\n"
141 " var values = '%s'.split(',');\n"
142 " var correct = select.selectedIndex == 0;\n"
143 " for (var i = 0; i < values.length && correct; i++) {\n"
144 " if (select.options[i].value != values[i])\n"
145 " correct = false;\n"
146 " }\n"
147 " if (%d && correct)\n"
148 " correct = select.children[values.length].tagName === 'OPTGROUP';\n"
149 " return correct;\n"
150 "})()", select_id, values, check_separator);
151 ASSERT_TRUE(JsExecute(expression)) << expression;
152 }
153
154 void OobeLocalizationTest::VerifyOptionExists(const char* select_id,
155 const char* value) {
156 std::string expression = base::StringPrintf(
achuithb 2014/02/12 21:49:41 nit: const
michaelpg 2014/02/12 23:06:25 Done.
157 "(function () {\n"
158 " var select = document.querySelector('#%s');\n"
159 " if (!select)\n"
160 " return false;\n"
161 " for (var i = 0; i < select.options.length; i++) {\n"
162 " if (select.options[i].value == '%s')\n"
163 " return true;\n"
164 " }\n"
165 " return false;\n"
166 "})()", select_id, value);
167 ASSERT_TRUE(JsExecute(expression)) << expression;
168 }
169
170 void OobeLocalizationTest::RunLocalizationTest(
171 const std::string& initial_locale,
172 const std::string& keyboard_layout,
173 const std::string& expected_locale,
174 const std::string& expected_keyboard_layout) {
175 statistics_provider_->set_locale(initial_locale);
176 statistics_provider_->set_keyboard_layout(keyboard_layout);
177
178 // Initialize StartupCustomizationDocument with fake statistics provider
achuithb 2014/02/12 21:49:41 nit: period at the end of the comment.
michaelpg 2014/02/12 23:06:25 Done.
179 StartupCustomizationDocument::GetInstance()->Init(
180 statistics_provider_.get());
181
182 // Bring up the OOBE network screen
achuithb 2014/02/12 21:49:41 nit: period at the end of comment.
michaelpg 2014/02/12 23:06:25 Done.
183 chromeos::ShowLoginWizard(chromeos::WizardController::kNetworkScreenName);
184 content::WindowedNotificationObserver(
185 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
186 content::NotificationService::AllSources()).Wait();
187
188 VerifyInitialOptions(kLocaleSelect, expected_locale.c_str(), true);
189 VerifyInitialOptions(kKeyboardSelect,
190 expected_keyboard_layout.c_str(),
191 false);
192
193 // Make sure we have a fallback keyboard.
194 VerifyOptionExists(kKeyboardSelect, kUSLayout);
195
196 // Shut down the display host.
197 chromeos::LoginDisplayHostImpl::default_host()->Finalize();
198 base::MessageLoopForUI::current()->RunUntilIdle();
199
200 // Clear the locale pref so the statistics provider is pinged next time.
201 g_browser_process->local_state()->SetString(prefs::kApplicationLocale,
202 std::string());
203 }
204
205 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenNonLatin) {
206 // For a non-Latin keyboard layout like Russian, we expect to see the US
207 // keyboard.
208 RunLocalizationTest("ru", "xkb:ru::rus",
209 "ru", kUSLayout);
210
211 // IMEs do not load at OOBE, so we just expect to see the (Latin) Japanese
212 // keyboard.
213 RunLocalizationTest("ja", "xkb:jp::jpn",
214 "ja", "xkb:jp::jpn");
215 }
216
217 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenKeyboardLayout) {
218 // We don't use the Icelandic locale but the Icelandic keyboard layout
219 // should still be selected when specified as the default.
220 RunLocalizationTest("en-US", "xkb:is::ice",
221 "en-US", "xkb:is::ice");
222 }
223
224 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenFullLatin) {
225 // French Swiss keyboard.
226 RunLocalizationTest("fr", "xkb:ch:fr:fra",
227 "fr", "xkb:ch:fr:fra");
228
229 // German Swiss keyboard.
230 RunLocalizationTest("de", "xkb:ch::ger",
231 "de", "xkb:ch::ger");
232 }
233
234 IN_PROC_BROWSER_TEST_F(OobeLocalizationTest, NetworkScreenMultipleLocales) {
235 RunLocalizationTest("es,en-US,nl", "xkb:be::nld",
236 "es,en-US,nl", "xkb:be::nld");
237
238 RunLocalizationTest("ru,de", "xkb:ru::rus",
239 "ru,de", kUSLayout);
240 }
241
242 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/customization_document.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698