OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import json | 4 import json |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import unittest | 7 import unittest |
8 | 8 |
9 from telemetry.core import browser_finder | 9 from telemetry.core import browser_finder |
10 from telemetry.core import exceptions | 10 from telemetry.core import exceptions |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 util.WaitFor(lambda: not browser.oobe, 10) | 145 util.WaitFor(lambda: not browser.oobe, 10) |
146 self.assertFalse(self._IsScreenLocked(browser)) | 146 self.assertFalse(self._IsScreenLocked(browser)) |
147 | 147 |
148 def testScreenLock(self): | 148 def testScreenLock(self): |
149 """Tests autotestPrivate.screenLock""" | 149 """Tests autotestPrivate.screenLock""" |
150 with self._CreateBrowser(autotest_ext=True) as browser: | 150 with self._CreateBrowser(autotest_ext=True) as browser: |
151 self._LockScreen(browser) | 151 self._LockScreen(browser) |
152 self._AttemptUnlockBadPassword(browser) | 152 self._AttemptUnlockBadPassword(browser) |
153 self._UnlockScreen(browser) | 153 self._UnlockScreen(browser) |
154 | 154 |
155 | |
156 def testLogout(self): | 155 def testLogout(self): |
157 """Tests autotestPrivate.logout""" | 156 """Tests autotestPrivate.logout""" |
158 with self._CreateBrowser(autotest_ext=True) as b: | 157 with self._CreateBrowser(autotest_ext=True) as b: |
159 extension = self._GetAutotestExtension(b) | 158 extension = self._GetAutotestExtension(b) |
160 try: | 159 try: |
161 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();') | 160 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();') |
162 except (exceptions.BrowserConnectionGoneException, | 161 except (exceptions.BrowserConnectionGoneException, |
163 exceptions.BrowserGoneException): | 162 exceptions.BrowserGoneException): |
164 pass | 163 pass |
165 util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) | 164 util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20) |
| 165 |
| 166 def _SwitchRegion(self, region): |
| 167 self._cri.RunCmdOnDevice(['stop', 'ui']) |
| 168 |
| 169 # Change VPD (requires RW-enabled firmware). |
| 170 # To save time, region and initial_timezone are not set. |
| 171 vpd = {'initial_locale': region.language_code, |
| 172 'keyboard_layout': region.keyboard} |
| 173 |
| 174 for (key, value) in vpd.items(): |
| 175 self._cri.RunCmdOnDevice(['vpd', '-s', '"%s"="%s"' % (key, value)]) |
| 176 |
| 177 # Remove cached files to clear initial locale info and force regeneration. |
| 178 self._cri.RunCmdOnDevice(['rm', '/home/chronos/Local\ State']) |
| 179 self._cri.RunCmdOnDevice(['rm', '/home/chronos/.oobe_completed']) |
| 180 self._cri.RunCmdOnDevice(['dump_vpd_log', '--force']) |
| 181 |
| 182 self._cri.RunCmdOnDevice(['start', 'ui']) |
| 183 |
| 184 def _OobeHasOption(self, browser, selectId, value): |
| 185 hasOptionJs = ''' |
| 186 // Check that the option is present, and selected if it is the default. |
| 187 (function hasOption(selectId, value, isDefault) { |
| 188 var options = document.getElementById(selectId).options; |
| 189 for (var i = 0; i < options.length; i++) { |
| 190 if (options[i].value == value) { |
| 191 // The option is present. Make sure it's selected if necessary. |
| 192 return !isDefault || options.selectedIndex == i; |
| 193 } |
| 194 } |
| 195 return false; |
| 196 })("%s", "%s", %s); |
| 197 ''' |
| 198 return browser.oobe.EvaluateJavaScript( |
| 199 hasOptionJs % (selectId, value, 'true')) |
| 200 |
| 201 def _ResolveLanguage(self, locale): |
| 202 # If the locale matches a language but not the country, fall back to |
| 203 # an existing locale. See ui/base/l10n/l10n_util.cc. |
| 204 lang, _, region = map(str.lower, locale.partition('-')) |
| 205 if not region: |
| 206 return "" |
| 207 |
| 208 # Map from other countries to a localized country |
| 209 if lang == 'es' and region == 'es': |
| 210 return 'es-419' |
| 211 if lang == 'zh': |
| 212 if region in ('hk', 'mo'): |
| 213 return 'zh-TW' |
| 214 return 'zh-CN' |
| 215 if lang == 'en': |
| 216 if region in ('au', 'ca', 'nz', 'za'): |
| 217 return 'en-GB' |
| 218 return 'en-US' |
| 219 |
| 220 # No mapping found |
| 221 return "" |
| 222 |
| 223 def testOobeLocalization(self): |
| 224 """Tests different region configurations at OOBE""" |
| 225 # Save the original device localization settings. |
| 226 # To save time, only read initial_locale and keyboard_layout. |
| 227 initial_region = self.Region('', '', '', '', '') |
| 228 initial_region.language_code, _ = self._cri.RunCmdOnDevice( |
| 229 ['vpd', '-g', 'initial_locale']) |
| 230 initial_region.keyboard, _ = self._cri.RunCmdOnDevice( |
| 231 ['vpd', '-g', 'keyboard_layout']) |
| 232 |
| 233 for region in self.REGIONS_LIST: |
| 234 self._SwitchRegion(region) |
| 235 with self._CreateBrowser(auto_login=False) as browser: |
| 236 # Ensure the dropdown lists have been created. |
| 237 util.WaitFor(lambda: browser.oobe.EvaluateJavaScript( |
| 238 'document.getElementById("language-select") != null'), |
| 239 10) |
| 240 |
| 241 # Find the language, or an acceptable fallback value. |
| 242 languageFound = self._OobeHasOption(browser, |
| 243 'language-select', |
| 244 region.language_code) |
| 245 if not languageFound: |
| 246 fallback = self._ResolveLanguage(region.language_code) |
| 247 self.assertTrue(fallback and |
| 248 self._OobeHasOption(browser, |
| 249 'language-select', |
| 250 fallback)) |
| 251 |
| 252 # Find the keyboard layout. |
| 253 self.assertTrue(self._OobeHasOption( |
| 254 browser, 'keyboard-select', region.keyboard)) |
| 255 |
| 256 # Test is finished. Restore original region settings. |
| 257 self._SwitchRegion(initial_region) |
| 258 |
| 259 # The Region class and region list will be available in regions.py. |
| 260 class Region(object): |
| 261 def __init__(self, region_code, keyboard, time_zone, language_code, |
| 262 keyboard_mechanical_layout, description=None, notes=None): |
| 263 self.region_code = region_code |
| 264 self.keyboard = keyboard |
| 265 self.time_zone = time_zone |
| 266 self.language_code = language_code |
| 267 self.keyboard_mechanical_layout = keyboard_mechanical_layout |
| 268 self.description = description or region_code |
| 269 self.notes = notes |
| 270 |
| 271 class Enum(frozenset): |
| 272 def __getattr__(self, name): |
| 273 if name in self: |
| 274 return name |
| 275 raise AttributeError |
| 276 |
| 277 KeyboardMechanicalLayout = Enum(['ANSI', 'ISO', 'JIS', 'ABNT2']) |
| 278 _KML = KeyboardMechanicalLayout |
| 279 REGIONS_LIST = [ |
| 280 Region('au', 'xkb:us::eng', 'Australia/Sydney', 'en-AU', _KML.ANSI, |
| 281 'Australia'), |
| 282 Region('ca.ansi', 'xkb:us::eng', 'America/Toronto', 'en-CA', _KML.ANSI, |
| 283 'Canada (US keyboard)', |
| 284 'Canada with US (ANSI) keyboard; see http://goto/cros-canada'), |
| 285 Region('ca.fr', 'xkb:ca::fra', 'America/Toronto', 'fr-CA', _KML.ISO, |
| 286 'Canada (French keyboard)', |
| 287 ('Canadian French (ISO) keyboard. The most common configuration for ' |
| 288 'Canadian French SKUs. See http://goto/cros-canada')), |
| 289 Region('ca.hybrid', 'xkb:ca:eng:eng', 'America/Toronto', 'en-CA', _KML.ISO, |
| 290 'Canada (hybrid)', |
| 291 ('Canada with hybrid xkb:ca:eng:eng + xkb:ca::fra keyboard (ISO), ' |
| 292 'defaulting to English language and keyboard. Used only if there ' |
| 293 'needs to be a single SKU for all of Canada. See ' |
| 294 'http://goto/cros-canada')), |
| 295 Region('ca.multix', 'xkb:ca:multix:fra', 'America/Toronto', 'fr-CA', |
| 296 _KML.ISO, 'Canada (multilingual)', |
| 297 ("Canadian Multilingual keyboard; you probably don't want this. See " |
| 298 "http://goto/cros-canada")), |
| 299 Region('de', 'xkb:de::ger', 'Europe/Berlin', 'de', _KML.ISO, 'Germany'), |
| 300 Region('fi', 'xkb:fi::fin', 'Europe/Helsinki', 'fi', _KML.ISO, 'Finland'), |
| 301 Region('fr', 'xkb:fr::fra', 'Europe/Paris', 'fr', _KML.ISO, 'France'), |
| 302 Region('gb', 'xkb:gb:extd:eng', 'Europe/London', 'en-GB', _KML.ISO, 'UK'), |
| 303 Region('ie', 'xkb:gb:extd:eng', 'Europe/Dublin', 'en-GB', _KML.ISO, |
| 304 'Ireland'), |
| 305 Region('in', 'xkb:us::eng', 'Asia/Calcutta', 'en-US', _KML.ANSI, 'India'), |
| 306 Region('my', 'xkb:us::eng', 'Asia/Kuala_Lumpur', 'ms', _KML.ANSI, |
| 307 'Malaysia'), |
| 308 Region('nl', 'xkb:us:intl:eng', 'Europe/Amsterdam', 'nl', _KML.ANSI, |
| 309 'Netherlands'), |
| 310 Region('nordic', 'xkb:se::swe', 'Europe/Stockholm', 'en-US', _KML.ISO, |
| 311 'Nordics', |
| 312 ('Unified SKU for Sweden, Norway, and Denmark. This defaults ' |
| 313 'to Swedish keyboard layout, but starts with US English language ' |
| 314 'for neutrality. Use if there is a single combined SKU for Nordic ' |
| 315 'countries.')), |
| 316 Region('se', 'xkb:se::swe', 'Europe/Stockholm', 'sv', _KML.ISO, 'Sweden', |
| 317 ("Use this if there separate SKUs for Nordic countries (Sweden, " |
| 318 "Norway, and Denmark), or the device is only shipping to Sweden. " |
| 319 "If there is a single unified SKU, use 'nordic' instead.")), |
| 320 Region('sg', 'xkb:us::eng', 'Asia/Singapore', 'en-GB', _KML.ANSI, |
| 321 'Singapore'), |
| 322 Region('us', 'xkb:us::eng', 'America/Los_Angeles', 'en-US', _KML.ANSI, |
| 323 'United States'), |
| 324 ] |
OLD | NEW |