| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 import time | 9 import time |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 """ | 64 """ |
| 65 Args: | 65 Args: |
| 66 oobe: Inspector page of the OOBE WebContents. | 66 oobe: Inspector page of the OOBE WebContents. |
| 67 chromeos: The parent Chrome wrapper. | 67 chromeos: The parent Chrome wrapper. |
| 68 """ | 68 """ |
| 69 self._oobe = oobe | 69 self._oobe = oobe |
| 70 self._chromeos = chromeos | 70 self._chromeos = chromeos |
| 71 | 71 |
| 72 @property | 72 @property |
| 73 def is_lockscreen(self): | 73 def is_lockscreen(self): |
| 74 return self._oobe.EvaluateJavaScript( | 74 return self._oobe.EvaluateJavaScript2( |
| 75 '!document.getElementById("sign-out-user-item").hidden') | 75 '!document.getElementById("sign-out-user-item").hidden') |
| 76 | 76 |
| 77 @property | 77 @property |
| 78 def auth_type(self): | 78 def auth_type(self): |
| 79 return self._oobe.EvaluateJavaScript('%s.authType' % self._GET_POD_JS) | 79 return self._oobe.EvaluateJavaScript2( |
| 80 '{{ @pod }}.authType', pod=self._GET_POD_JS) |
| 80 | 81 |
| 81 @property | 82 @property |
| 82 def smart_lock_state(self): | 83 def smart_lock_state(self): |
| 83 icon_shown = self._oobe.EvaluateJavaScript( | 84 icon_shown = self._oobe.EvaluateJavaScript2( |
| 84 '!%s.customIconElement.hidden' % self._GET_POD_JS) | 85 '!{{ @pod }}.customIconElement.hidden', pod=self._GET_POD_JS) |
| 85 if not icon_shown: | 86 if not icon_shown: |
| 86 return self.SmartLockState.NOT_SHOWN | 87 return self.SmartLockState.NOT_SHOWN |
| 87 class_list_dict = self._oobe.EvaluateJavaScript( | 88 class_list_dict = self._oobe.EvaluateJavaScript2( |
| 88 '%s.customIconElement.querySelector(".custom-icon")' | 89 '{{ @pod }}.customIconElement.querySelector(".custom-icon").classList', |
| 89 '.classList' % self._GET_POD_JS) | 90 pod=self._GET_POD_JS) |
| 90 class_list = [v for k,v in class_list_dict.items() if k != 'length'] | 91 class_list = [v for k,v in class_list_dict.items() if k != 'length'] |
| 91 | 92 |
| 92 if 'custom-icon-unlocked' in class_list: | 93 if 'custom-icon-unlocked' in class_list: |
| 93 return self.SmartLockState.AUTHENTICATED | 94 return self.SmartLockState.AUTHENTICATED |
| 94 if 'custom-icon-locked' in class_list: | 95 if 'custom-icon-locked' in class_list: |
| 95 return self.SmartLockState.LOCKED | 96 return self.SmartLockState.LOCKED |
| 96 if 'custom-icon-hardlocked' in class_list: | 97 if 'custom-icon-hardlocked' in class_list: |
| 97 return self.SmartLockState.HARD_LOCKED | 98 return self.SmartLockState.HARD_LOCKED |
| 98 if 'custom-icon-locked-to-be-activated' in class_list: | 99 if 'custom-icon-locked-to-be-activated' in class_list: |
| 99 return self.SmartLockState.TO_BE_ACTIVATED | 100 return self.SmartLockState.TO_BE_ACTIVATED |
| (...skipping 18 matching lines...) Expand all Loading... |
| 118 def EnterPassword(self): | 119 def EnterPassword(self): |
| 119 """ Enters the password to unlock or sign-in. | 120 """ Enters the password to unlock or sign-in. |
| 120 | 121 |
| 121 Raises: | 122 Raises: |
| 122 TimeoutException: entering the password fails to enter/resume the user | 123 TimeoutException: entering the password fails to enter/resume the user |
| 123 session. | 124 session. |
| 124 """ | 125 """ |
| 125 assert(self.auth_type == self.AuthType.OFFLINE_PASSWORD or | 126 assert(self.auth_type == self.AuthType.OFFLINE_PASSWORD or |
| 126 self.auth_type == self.AuthType.FORCE_OFFLINE_PASSWORD) | 127 self.auth_type == self.AuthType.FORCE_OFFLINE_PASSWORD) |
| 127 oobe = self._oobe | 128 oobe = self._oobe |
| 128 oobe.EvaluateJavaScript( | 129 oobe.EvaluateJavaScript2( |
| 129 '%s.passwordElement.value = "%s"' % ( | 130 '{{ @pod }}.passwordElement.value = {{ password }}', |
| 130 self._GET_POD_JS, self._chromeos.password)) | 131 pod=self._GET_POD_JS, password=self._chromeos.password) |
| 131 oobe.EvaluateJavaScript( | 132 oobe.EvaluateJavaScript2( |
| 132 '%s.activate()' % self._GET_POD_JS) | 133 '{{ @pod }}.activate()', pod=self._GET_POD_JS) |
| 133 util.WaitFor(lambda: (self._chromeos.session_state == | 134 util.WaitFor(lambda: (self._chromeos.session_state == |
| 134 ChromeOS.SessionState.IN_SESSION), | 135 ChromeOS.SessionState.IN_SESSION), |
| 135 5) | 136 5) |
| 136 | 137 |
| 137 def UnlockWithClick(self): | 138 def UnlockWithClick(self): |
| 138 """ Clicks the user pod to unlock or sign-in. """ | 139 """ Clicks the user pod to unlock or sign-in. """ |
| 139 assert(self.auth_type == self.AuthType.USER_CLICK) | 140 assert(self.auth_type == self.AuthType.USER_CLICK) |
| 140 self._oobe.EvaluateJavaScript('%s.activate()' % self._GET_POD_JS) | 141 self._oobe.EvaluateJavaScript2( |
| 142 '{{ @pod }}.activate()', pod=self._GET_POD_JS) |
| 141 | 143 |
| 142 | 144 |
| 143 class SmartLockSettings(object): | 145 class SmartLockSettings(object): |
| 144 """ Wrapper for the Smart Lock settings in chromeos://settings. | 146 """ Wrapper for the Smart Lock settings in chromeos://settings. |
| 145 """ | 147 """ |
| 146 def __init__(self, tab, chromeos): | 148 def __init__(self, tab, chromeos): |
| 147 """ | 149 """ |
| 148 Args: | 150 Args: |
| 149 tab: Inspector page of the chromeos://settings tag. | 151 tab: Inspector page of the chromeos://settings tag. |
| 150 chromeos: The parent Chrome wrapper. | 152 chromeos: The parent Chrome wrapper. |
| 151 """ | 153 """ |
| 152 self._tab = tab | 154 self._tab = tab |
| 153 self._chromeos = chromeos | 155 self._chromeos = chromeos |
| 154 | 156 |
| 155 @property | 157 @property |
| 156 def is_smart_lock_enabled(self): | 158 def is_smart_lock_enabled(self): |
| 157 ''' Returns true if the settings show that Smart Lock is enabled. ''' | 159 ''' Returns true if the settings show that Smart Lock is enabled. ''' |
| 158 return self._tab.EvaluateJavaScript( | 160 return self._tab.EvaluateJavaScript2( |
| 159 '!document.getElementById("easy-unlock-enabled").hidden') | 161 '!document.getElementById("easy-unlock-enabled").hidden') |
| 160 | 162 |
| 161 def TurnOffSmartLock(self): | 163 def TurnOffSmartLock(self): |
| 162 """ Turns off Smart Lock. | 164 """ Turns off Smart Lock. |
| 163 | 165 |
| 164 Smart Lock is turned off by clicking the turn-off button and navigating | 166 Smart Lock is turned off by clicking the turn-off button and navigating |
| 165 through the resulting overlay. | 167 through the resulting overlay. |
| 166 | 168 |
| 167 Raises: | 169 Raises: |
| 168 TimeoutException: Timed out waiting for Smart Lock to be turned off. | 170 TimeoutException: Timed out waiting for Smart Lock to be turned off. |
| 169 """ | 171 """ |
| 170 assert(self.is_smart_lock_enabled) | 172 assert(self.is_smart_lock_enabled) |
| 171 tab = self._tab | 173 tab = self._tab |
| 172 tab.EvaluateJavaScript( | 174 tab.EvaluateJavaScript2( |
| 173 'document.getElementById("easy-unlock-turn-off-button").click()') | 175 'document.getElementById("easy-unlock-turn-off-button").click()') |
| 174 util.WaitFor(lambda: tab.EvaluateJavaScript( | 176 tab.WaitForJavaScriptCondition2( |
| 175 '!document.getElementById("easy-unlock-turn-off-overlay").hidden && ' | 177 '!document.getElementById("easy-unlock-turn-off-overlay").hidden && ' |
| 176 'document.getElementById("easy-unlock-turn-off-confirm") != null'), | 178 'document.getElementById("easy-unlock-turn-off-confirm") != null', |
| 177 10) | 179 timeout=10) |
| 178 tab.EvaluateJavaScript( | 180 tab.EvaluateJavaScript2( |
| 179 'document.getElementById("easy-unlock-turn-off-confirm").click()') | 181 'document.getElementById("easy-unlock-turn-off-confirm").click()') |
| 180 util.WaitFor(lambda: tab.EvaluateJavaScript( | 182 tab.WaitForJavaScriptCondition2( |
| 181 '!document.getElementById("easy-unlock-disabled").hidden'), 15) | 183 '!document.getElementById("easy-unlock-disabled").hidden', timeout=15) |
| 182 | 184 |
| 183 def StartSetup(self): | 185 def StartSetup(self): |
| 184 """ Starts the Smart Lock setup flow by clicking the button. | 186 """ Starts the Smart Lock setup flow by clicking the button. |
| 185 """ | 187 """ |
| 186 assert(not self.is_smart_lock_enabled) | 188 assert(not self.is_smart_lock_enabled) |
| 187 self._tab.EvaluateJavaScript( | 189 self._tab.EvaluateJavaScript2( |
| 188 'document.getElementById("easy-unlock-setup-button").click()') | 190 'document.getElementById("easy-unlock-setup-button").click()') |
| 189 | 191 |
| 190 def StartSetupAndReturnApp(self): | 192 def StartSetupAndReturnApp(self): |
| 191 """ Runs the setup and returns the wrapper to the setup app. | 193 """ Runs the setup and returns the wrapper to the setup app. |
| 192 | 194 |
| 193 After clicking the setup button in the settings page, enter the password to | 195 After clicking the setup button in the settings page, enter the password to |
| 194 reauthenticate the user before the app launches. | 196 reauthenticate the user before the app launches. |
| 195 | 197 |
| 196 Returns: | 198 Returns: |
| 197 A SmartLockApp object of the app that was launched. | 199 A SmartLockApp object of the app that was launched. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 self._app_page = app_page | 234 self._app_page = app_page |
| 233 self._chromeos = chromeos | 235 self._chromeos = chromeos |
| 234 | 236 |
| 235 @property | 237 @property |
| 236 def pairing_state(self): | 238 def pairing_state(self): |
| 237 ''' Returns the state the app is currently in. | 239 ''' Returns the state the app is currently in. |
| 238 | 240 |
| 239 Raises: | 241 Raises: |
| 240 ValueError: The current state is unknown. | 242 ValueError: The current state is unknown. |
| 241 ''' | 243 ''' |
| 242 state = self._app_page.EvaluateJavaScript( | 244 state = self._app_page.EvaluateJavaScript2( |
| 243 'document.body.getAttribute("step")') | 245 'document.body.getAttribute("step")') |
| 244 if state == 'scan': | 246 if state == 'scan': |
| 245 return SmartLockApp.PairingState.SCAN | 247 return SmartLockApp.PairingState.SCAN |
| 246 elif state == 'pair': | 248 elif state == 'pair': |
| 247 return SmartLockApp.PairingState.PAIR | 249 return SmartLockApp.PairingState.PAIR |
| 248 elif state == 'promote-smart-lock-for-android': | 250 elif state == 'promote-smart-lock-for-android': |
| 249 return SmartLockApp.PairingState.PROMOTE_SMARTLOCK_FOR_ANDROID | 251 return SmartLockApp.PairingState.PROMOTE_SMARTLOCK_FOR_ANDROID |
| 250 elif state == 'complete': | 252 elif state == 'complete': |
| 251 button_text = self._app_page.EvaluateJavaScript( | 253 button_text = self._app_page.EvaluateJavaScript2( |
| 252 'document.getElementById("pairing-button").textContent') | 254 'document.getElementById("pairing-button").textContent') |
| 253 button_text = button_text.strip().lower() | 255 button_text = button_text.strip().lower() |
| 254 if button_text == 'try it out': | 256 if button_text == 'try it out': |
| 255 return SmartLockApp.PairingState.CLICK_FOR_TRIAL_RUN | 257 return SmartLockApp.PairingState.CLICK_FOR_TRIAL_RUN |
| 256 elif button_text == 'done': | 258 elif button_text == 'done': |
| 257 return SmartLockApp.PairingState.TRIAL_RUN_COMPLETED | 259 return SmartLockApp.PairingState.TRIAL_RUN_COMPLETED |
| 258 else: | 260 else: |
| 259 raise ValueError('Unknown button text: %s', button_text) | 261 raise ValueError('Unknown button text: %s', button_text) |
| 260 else: | 262 else: |
| 261 raise ValueError('Unknown pairing state: %s' % state) | 263 raise ValueError('Unknown pairing state: %s' % state) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 297 |
| 296 def StartTrialRun(self): | 298 def StartTrialRun(self): |
| 297 """ Starts the trial run. | 299 """ Starts the trial run. |
| 298 | 300 |
| 299 The app must be in the CLICK_FOR_TRIAL_RUN state. | 301 The app must be in the CLICK_FOR_TRIAL_RUN state. |
| 300 | 302 |
| 301 Raises: | 303 Raises: |
| 302 TimeoutException: Timed out starting the trial run. | 304 TimeoutException: Timed out starting the trial run. |
| 303 """ | 305 """ |
| 304 assert(self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN) | 306 assert(self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN) |
| 305 self._app_page.EvaluateJavaScript( | 307 self._app_page.EvaluateJavaScript2( |
| 306 'document.getElementById("pairing-button").click()') | 308 'document.getElementById("pairing-button").click()') |
| 307 util.WaitFor(lambda: (self._chromeos.session_state == | 309 util.WaitFor(lambda: (self._chromeos.session_state == |
| 308 ChromeOS.SessionState.LOCK_SCREEN), | 310 ChromeOS.SessionState.LOCK_SCREEN), |
| 309 10) | 311 10) |
| 310 | 312 |
| 311 def DismissApp(self): | 313 def DismissApp(self): |
| 312 """ Dismisses the app after setup is completed. | 314 """ Dismisses the app after setup is completed. |
| 313 | 315 |
| 314 The app must be in the TRIAL_RUN_COMPLETED state. | 316 The app must be in the TRIAL_RUN_COMPLETED state. |
| 315 """ | 317 """ |
| 316 assert(self.pairing_state == self.PairingState.TRIAL_RUN_COMPLETED) | 318 assert(self.pairing_state == self.PairingState.TRIAL_RUN_COMPLETED) |
| 317 self._app_page.EvaluateJavaScript( | 319 self._app_page.EvaluateJavaScript2( |
| 318 'document.getElementById("pairing-button").click()') | 320 'document.getElementById("pairing-button").click()') |
| 319 | 321 |
| 320 def _ClickPairingButton(self): | 322 def _ClickPairingButton(self): |
| 321 # Waits are needed because the clicks occur before the button label changes. | 323 # Waits are needed because the clicks occur before the button label changes. |
| 322 time.sleep(1) | 324 time.sleep(1) |
| 323 self._app_page.EvaluateJavaScript( | 325 self._app_page.EvaluateJavaScript2( |
| 324 'document.getElementById("pairing-button").click()') | 326 'document.getElementById("pairing-button").click()') |
| 325 time.sleep(1) | 327 time.sleep(1) |
| 326 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 328 self._app_page.WaitForJavaScriptCondition2( |
| 327 '!document.getElementById("pairing-button").disabled'), 60) | 329 '!document.getElementById("pairing-button").disabled', timeout=60) |
| 328 time.sleep(1) | 330 time.sleep(1) |
| 329 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 331 self._app_page.WaitForJavaScriptCondition2( |
| 330 '!document.getElementById("pairing-button-title")' | 332 '!document.getElementById("pairing-button-title")' |
| 331 '.classList.contains("animated-fade-out")'), 5) | 333 '.classList.contains("animated-fade-out")', timeout=5) |
| 332 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 334 self._app_page.WaitForJavaScriptCondition2( |
| 333 '!document.getElementById("pairing-button-title")' | 335 '!document.getElementById("pairing-button-title")' |
| 334 '.classList.contains("animated-fade-in")'), 5) | 336 '.classList.contains("animated-fade-in")', timeout=5) |
| 335 | 337 |
| 336 | 338 |
| 337 class ChromeOS(object): | 339 class ChromeOS(object): |
| 338 """ Wrapper for a remote ChromeOS device. | 340 """ Wrapper for a remote ChromeOS device. |
| 339 | 341 |
| 340 Operations performed through this wrapper are sent through the network to | 342 Operations performed through this wrapper are sent through the network to |
| 341 Chrome using the Chrome DevTools API. Therefore, any function may throw an | 343 Chrome using the Chrome DevTools API. Therefore, any function may throw an |
| 342 exception if the communication to the remote device is severed. | 344 exception if the communication to the remote device is severed. |
| 343 """ | 345 """ |
| 344 | 346 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if self._cros_interface.IsCryptohomeMounted(self.username, False): | 388 if self._cros_interface.IsCryptohomeMounted(self.username, False): |
| 387 return self.SessionState.LOCK_SCREEN | 389 return self.SessionState.LOCK_SCREEN |
| 388 else: | 390 else: |
| 389 return self.SessionState.SIGNIN_SCREEN | 391 return self.SessionState.SIGNIN_SCREEN |
| 390 else: | 392 else: |
| 391 return self.SessionState.IN_SESSION; | 393 return self.SessionState.IN_SESSION; |
| 392 | 394 |
| 393 @property | 395 @property |
| 394 def cryptauth_access_token(self): | 396 def cryptauth_access_token(self): |
| 395 try: | 397 try: |
| 396 util.WaitFor(lambda: self._background_page.EvaluateJavaScript( | 398 self._background_page.WaitForJavaScriptCondition2( |
| 397 'var __token = __token || null; ' | 399 'var __token = __token || null; ' |
| 398 'chrome.identity.getAuthToken(function(token) {' | 400 'chrome.identity.getAuthToken(function(token) {' |
| 399 ' __token = token;' | 401 ' __token = token;' |
| 400 '}); ' | 402 '}); ' |
| 401 '__token != null'), 5) | 403 '__token != null', timeout=5) |
| 402 return self._background_page.EvaluateJavaScript('__token'); | 404 return self._background_page.EvaluateJavaScript2('__token'); |
| 403 except exceptions.TimeoutException: | 405 except exceptions.TimeoutException: |
| 404 logger.error('Failed to get access token.'); | 406 logger.error('Failed to get access token.'); |
| 405 return '' | 407 return '' |
| 406 | 408 |
| 407 def __enter__(self): | 409 def __enter__(self): |
| 408 return self | 410 return self |
| 409 | 411 |
| 410 def __exit__(self, *args): | 412 def __exit__(self, *args): |
| 411 if self._browser is not None: | 413 if self._browser is not None: |
| 412 self._browser.Close() | 414 self._browser.Close() |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 Return: | 479 Return: |
| 478 An instance of AccountPickerScreen. | 480 An instance of AccountPickerScreen. |
| 479 Raises: | 481 Raises: |
| 480 TimeoutException: Timed out waiting for account picker screen to load. | 482 TimeoutException: Timed out waiting for account picker screen to load. |
| 481 """ | 483 """ |
| 482 assert(self._browser is not None) | 484 assert(self._browser is not None) |
| 483 assert(self.session_state == self.SessionState.LOCK_SCREEN or | 485 assert(self.session_state == self.SessionState.LOCK_SCREEN or |
| 484 self.session_state == self.SessionState.SIGNIN_SCREEN) | 486 self.session_state == self.SessionState.SIGNIN_SCREEN) |
| 485 oobe = self._browser.oobe | 487 oobe = self._browser.oobe |
| 486 def IsLockScreenResponsive(): | 488 def IsLockScreenResponsive(): |
| 487 return (oobe.EvaluateJavaScript("typeof Oobe == 'function'") and | 489 return (oobe.EvaluateJavaScript2("typeof Oobe == 'function'") and |
| 488 oobe.EvaluateJavaScript( | 490 oobe.EvaluateJavaScript2( |
| 489 "typeof Oobe.authenticateForTesting == 'function'")) | 491 "typeof Oobe.authenticateForTesting == 'function'")) |
| 490 util.WaitFor(IsLockScreenResponsive, 10) | 492 util.WaitFor(IsLockScreenResponsive, 10) |
| 491 util.WaitFor(lambda: oobe.EvaluateJavaScript( | 493 oobe.WaitForJavaScriptCondition2( |
| 492 'document.getElementById("pod-row") && ' | 494 'document.getElementById("pod-row") && ' |
| 493 'document.getElementById("pod-row").pods && ' | 495 'document.getElementById("pod-row").pods && ' |
| 494 'document.getElementById("pod-row").pods.length > 0'), 10) | 496 'document.getElementById("pod-row").pods.length > 0', timeout=10) |
| 495 return AccountPickerScreen(oobe, self) | 497 return AccountPickerScreen(oobe, self) |
| 496 | 498 |
| 497 def GetSmartLockSettings(self): | 499 def GetSmartLockSettings(self): |
| 498 """ Returns the wrapper for the Smart Lock settings. | 500 """ Returns the wrapper for the Smart Lock settings. |
| 499 A tab will be navigated to chrome://settings if it does not exist. | 501 A tab will be navigated to chrome://settings if it does not exist. |
| 500 | 502 |
| 501 Return: | 503 Return: |
| 502 An instance of SmartLockSettings. | 504 An instance of SmartLockSettings. |
| 503 Raises: | 505 Raises: |
| 504 TimeoutException: Timed out waiting for settings page. | 506 TimeoutException: Timed out waiting for settings page. |
| 505 """ | 507 """ |
| 506 if not len(self._browser.tabs): | 508 if not len(self._browser.tabs): |
| 507 self._browser.New() | 509 self._browser.New() |
| 508 tab = self._browser.tabs[0] | 510 tab = self._browser.tabs[0] |
| 509 url = tab.EvaluateJavaScript('document.location.href') | 511 url = tab.EvaluateJavaScript2('document.location.href') |
| 510 if url != self._SMART_LOCK_SETTINGS_URL: | 512 if url != self._SMART_LOCK_SETTINGS_URL: |
| 511 tab.Navigate(self._SMART_LOCK_SETTINGS_URL) | 513 tab.Navigate(self._SMART_LOCK_SETTINGS_URL) |
| 512 | 514 |
| 513 # Wait for settings page to be responsive. | 515 # Wait for settings page to be responsive. |
| 514 util.WaitFor(lambda: tab.EvaluateJavaScript( | 516 tab.WaitForJavaScriptCondition2( |
| 515 'document.getElementById("easy-unlock-disabled") && ' | 517 'document.getElementById("easy-unlock-disabled") && ' |
| 516 'document.getElementById("easy-unlock-enabled") && ' | 518 'document.getElementById("easy-unlock-enabled") && ' |
| 517 '(!document.getElementById("easy-unlock-disabled").hidden || ' | 519 '(!document.getElementById("easy-unlock-disabled").hidden || ' |
| 518 ' !document.getElementById("easy-unlock-enabled").hidden)'), 10) | 520 ' !document.getElementById("easy-unlock-enabled").hidden)', |
| 521 timeout=10) |
| 519 settings = SmartLockSettings(tab, self) | 522 settings = SmartLockSettings(tab, self) |
| 520 logger.info('Started Smart Lock settings: enabled=%s' % | 523 logger.info('Started Smart Lock settings: enabled=%s' % |
| 521 settings.is_smart_lock_enabled) | 524 settings.is_smart_lock_enabled) |
| 522 return settings | 525 return settings |
| 523 | 526 |
| 524 def GetSmartLockApp(self): | 527 def GetSmartLockApp(self): |
| 525 """ Returns the wrapper for the Smart Lock setup app. | 528 """ Returns the wrapper for the Smart Lock setup app. |
| 526 | 529 |
| 527 Return: | 530 Return: |
| 528 An instance of SmartLockApp or None if the app window does not exist. | 531 An instance of SmartLockApp or None if the app window does not exist. |
| 529 """ | 532 """ |
| 530 app_page = self._FindSmartLockAppPage('/pairing.html') | 533 app_page = self._FindSmartLockAppPage('/pairing.html') |
| 531 if app_page is not None: | 534 if app_page is not None: |
| 532 # Wait for app window to be responsive. | 535 # Wait for app window to be responsive. |
| 533 util.WaitFor(lambda: app_page.EvaluateJavaScript( | 536 tab.WaitForJavaScriptCondition2( |
| 534 'document.getElementById("pairing-button") != null'), 10) | 537 'document.getElementById("pairing-button") != null', timeout=10) |
| 535 return SmartLockApp(app_page, self) | 538 return SmartLockApp(app_page, self) |
| 536 return None | 539 return None |
| 537 | 540 |
| 538 def SetCryptAuthStaging(self, cryptauth_staging_url): | 541 def SetCryptAuthStaging(self, cryptauth_staging_url): |
| 539 logger.info('Setting CryptAuth to Staging') | 542 logger.info('Setting CryptAuth to Staging') |
| 540 try: | 543 try: |
| 541 self._background_page.ExecuteJavaScript( | 544 self._background_page.ExecuteJavaScript2(""" |
| 542 'var key = app.CryptAuthClient.GOOGLE_API_URL_OVERRIDE_;' | 545 var key = app.CryptAuthClient.GOOGLE_API_URL_OVERRIDE_; |
| 543 'var __complete = false;' | 546 var __complete = false; |
| 544 'chrome.storage.local.set({key: "%s"}, function() {' | 547 chrome.storage.local.set({key: {{ url }}}, function() { |
| 545 ' __complete = true;' | 548 __complete = true; |
| 546 '});' % cryptauth_staging_url) | 549 });""", |
| 547 util.WaitFor(lambda: self._background_page.EvaluateJavaScript( | 550 url=cryptauth_staging_url) |
| 548 '__complete == true'), 10) | 551 self._background_page.WaitForJavaScriptCondition2( |
| 552 '__complete == true', timeout=10) |
| 549 except exceptions.TimeoutException: | 553 except exceptions.TimeoutException: |
| 550 logger.error('Failed to override CryptAuth to staging url.') | 554 logger.error('Failed to override CryptAuth to staging url.') |
| 551 | 555 |
| 552 def RunBtmon(self): | 556 def RunBtmon(self): |
| 553 """ Runs the btmon command. | 557 """ Runs the btmon command. |
| 554 Return: | 558 Return: |
| 555 A subprocess.Popen object of the btmon process. | 559 A subprocess.Popen object of the btmon process. |
| 556 """ | 560 """ |
| 557 assert(self._cros_interface) | 561 assert(self._cros_interface) |
| 558 cmd = self._cros_interface.FormSSHCommandLine(['btmon']) | 562 cmd = self._cros_interface.FormSSHCommandLine(['btmon']) |
| 559 process = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, | 563 process = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, |
| 560 stderr=subprocess.PIPE) | 564 stderr=subprocess.PIPE) |
| 561 self._processes.append(process) | 565 self._processes.append(process) |
| 562 return process | 566 return process |
| 563 | 567 |
| 564 def _FindSmartLockAppPage(self, page_name): | 568 def _FindSmartLockAppPage(self, page_name): |
| 565 try: | 569 try: |
| 566 extensions = self._browser.extensions.GetByExtensionId( | 570 extensions = self._browser.extensions.GetByExtensionId( |
| 567 'mkaemigholebcgchlkbankmihknojeak') | 571 'mkaemigholebcgchlkbankmihknojeak') |
| 568 except KeyError: | 572 except KeyError: |
| 569 return None | 573 return None |
| 570 for extension_page in extensions: | 574 for extension_page in extensions: |
| 571 pathname = extension_page.EvaluateJavaScript('document.location.pathname') | 575 pathname = extension_page.EvaluateJavaScript2( |
| 576 'document.location.pathname') |
| 572 if pathname == page_name: | 577 if pathname == page_name: |
| 573 return extension_page | 578 return extension_page |
| 574 return None | 579 return None |
| OLD | NEW |