| 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 |
| 11 # Add the telemetry directory to Python's search paths. | 11 # Add the telemetry directory to Python's search paths. |
| 12 current_directory = os.path.dirname(os.path.realpath(__file__)) | 12 current_directory = os.path.dirname(os.path.realpath(__file__)) |
| 13 telemetry_dir = os.path.realpath( | 13 telemetry_dir = os.path.realpath( |
| 14 os.path.join(current_directory, '..', '..', '..', 'tools', 'telemetry')) | 14 os.path.join(current_directory, '..', '..', '..', 'tools', 'telemetry')) |
| 15 if telemetry_dir not in sys.path: | 15 if telemetry_dir not in sys.path: |
| 16 sys.path.append(telemetry_dir) | 16 sys.path.append(telemetry_dir) |
| 17 | 17 |
| 18 from telemetry.core import browser_options | 18 from telemetry.internal.browser import browser_options |
| 19 from telemetry.core import browser_finder | 19 from telemetry.internal.browser import browser_finder |
| 20 from telemetry.core import exceptions | 20 from telemetry.core import exceptions |
| 21 from telemetry.core import util | 21 from telemetry.core import util |
| 22 from telemetry.core.platform import cros_interface | 22 from telemetry.core import cros_interface |
| 23 from telemetry.internal.browser import extension_to_load | 23 from telemetry.internal.browser import extension_to_load |
| 24 | 24 |
| 25 logger = logging.getLogger('proximity_auth.%s' % __name__) | 25 logger = logging.getLogger('proximity_auth.%s' % __name__) |
| 26 | 26 |
| 27 class AccountPickerScreen(object): | 27 class AccountPickerScreen(object): |
| 28 """ Wrapper for the ChromeOS account picker screen. | 28 """ Wrapper for the ChromeOS account picker screen. |
| 29 | 29 |
| 30 The account picker screen is the WebContents page used for both the lock | 30 The account picker screen is the WebContents page used for both the lock |
| 31 screen and signin screen. | 31 screen and signin screen. |
| 32 | 32 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 Note: This does not include the app's background page. | 211 Note: This does not include the app's background page. |
| 212 """ | 212 """ |
| 213 | 213 |
| 214 class PairingState: | 214 class PairingState: |
| 215 """ The current state of the setup flow. """ | 215 """ The current state of the setup flow. """ |
| 216 SCAN = 'scan' | 216 SCAN = 'scan' |
| 217 PAIR = 'pair' | 217 PAIR = 'pair' |
| 218 CLICK_FOR_TRIAL_RUN = 'click_for_trial_run' | 218 CLICK_FOR_TRIAL_RUN = 'click_for_trial_run' |
| 219 TRIAL_RUN_COMPLETED = 'trial_run_completed' | 219 TRIAL_RUN_COMPLETED = 'trial_run_completed' |
| 220 PROMOTE_SMARTLOCK_FOR_ANDROID = 'promote-smart-lock-for-android' |
| 220 | 221 |
| 221 def __init__(self, app_page, chromeos): | 222 def __init__(self, app_page, chromeos): |
| 222 """ | 223 """ |
| 223 Args: | 224 Args: |
| 224 app_page: Inspector page of the app window. | 225 app_page: Inspector page of the app window. |
| 225 chromeos: The parent Chrome wrapper. | 226 chromeos: The parent Chrome wrapper. |
| 226 """ | 227 """ |
| 227 self._app_page = app_page | 228 self._app_page = app_page |
| 228 self._chromeos = chromeos | 229 self._chromeos = chromeos |
| 229 | 230 |
| 230 @property | 231 @property |
| 231 def pairing_state(self): | 232 def pairing_state(self): |
| 232 ''' Returns the state the app is currently in. | 233 ''' Returns the state the app is currently in. |
| 233 | 234 |
| 234 Raises: | 235 Raises: |
| 235 ValueError: The current state is unknown. | 236 ValueError: The current state is unknown. |
| 236 ''' | 237 ''' |
| 237 state = self._app_page.EvaluateJavaScript( | 238 state = self._app_page.EvaluateJavaScript( |
| 238 'document.body.getAttribute("step")') | 239 'document.body.getAttribute("step")') |
| 239 if state == 'scan': | 240 if state == 'scan': |
| 240 return SmartLockApp.PairingState.SCAN | 241 return SmartLockApp.PairingState.SCAN |
| 241 elif state == 'pair': | 242 elif state == 'pair': |
| 242 return SmartLockApp.PairingState.PAIR | 243 return SmartLockApp.PairingState.PAIR |
| 244 elif state == 'promote-smart-lock-for-android': |
| 245 return SmartLockApp.PairingState.PROMOTE_SMARTLOCK_FOR_ANDROID |
| 243 elif state == 'complete': | 246 elif state == 'complete': |
| 244 button_text = self._app_page.EvaluateJavaScript( | 247 button_text = self._app_page.EvaluateJavaScript( |
| 245 'document.getElementById("pairing-button").textContent') | 248 'document.getElementById("pairing-button").textContent') |
| 246 button_text = button_text.strip().lower() | 249 button_text = button_text.strip().lower() |
| 247 if button_text == 'try it out': | 250 if button_text == 'try it out': |
| 248 return SmartLockApp.PairingState.CLICK_FOR_TRIAL_RUN | 251 return SmartLockApp.PairingState.CLICK_FOR_TRIAL_RUN |
| 249 elif button_text == 'done': | 252 elif button_text == 'done': |
| 250 return SmartLockApp.PairingState.TRIAL_RUN_COMPLETED | 253 return SmartLockApp.PairingState.TRIAL_RUN_COMPLETED |
| 251 else: | 254 else: |
| 252 raise ValueError('Unknown button text: %s', button_text) | 255 raise ValueError('Unknown button text: %s', button_text) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 275 def PairPhone(self): | 278 def PairPhone(self): |
| 276 """ Starts the step of finding nearby phones. | 279 """ Starts the step of finding nearby phones. |
| 277 | 280 |
| 278 The app must be in the PAIR state. | 281 The app must be in the PAIR state. |
| 279 | 282 |
| 280 Returns: | 283 Returns: |
| 281 True if pairing succeeded, else False. | 284 True if pairing succeeded, else False. |
| 282 """ | 285 """ |
| 283 assert(self.pairing_state == self.PairingState.PAIR) | 286 assert(self.pairing_state == self.PairingState.PAIR) |
| 284 self._ClickPairingButton() | 287 self._ClickPairingButton() |
| 288 if self.pairing_state == self.PairingState.PROMOTE_SMARTLOCK_FOR_ANDROID: |
| 289 self._ClickPairingButton() |
| 285 return self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN | 290 return self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN |
| 286 | 291 |
| 287 def StartTrialRun(self): | 292 def StartTrialRun(self): |
| 288 """ Starts the trial run. | 293 """ Starts the trial run. |
| 289 | 294 |
| 290 The app must be in the CLICK_FOR_TRIAL_RUN state. | 295 The app must be in the CLICK_FOR_TRIAL_RUN state. |
| 291 | 296 |
| 292 Raises: | 297 Raises: |
| 293 TimeoutException: Timed out starting the trial run. | 298 TimeoutException: Timed out starting the trial run. |
| 294 """ | 299 """ |
| 295 assert(self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN) | 300 assert(self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN) |
| 296 self._app_page.EvaluateJavaScript( | 301 self._app_page.EvaluateJavaScript( |
| 297 'document.getElementById("pairing-button").click()') | 302 'document.getElementById("pairing-button").click()') |
| 298 util.WaitFor(lambda: (self._chromeos.session_state == | 303 util.WaitFor(lambda: (self._chromeos.session_state == |
| 299 ChromeOS.SessionState.LOCK_SCREEN), | 304 ChromeOS.SessionState.LOCK_SCREEN), |
| 300 10) | 305 10) |
| 301 | 306 |
| 302 def DismissApp(self): | 307 def DismissApp(self): |
| 303 """ Dismisses the app after setup is completed. | 308 """ Dismisses the app after setup is completed. |
| 304 | 309 |
| 305 The app must be in the TRIAL_RUN_COMPLETED state. | 310 The app must be in the TRIAL_RUN_COMPLETED state. |
| 306 """ | 311 """ |
| 307 assert(self.pairing_state == self.PairingState.TRIAL_RUN_COMPLETED) | 312 assert(self.pairing_state == self.PairingState.TRIAL_RUN_COMPLETED) |
| 308 self._app_page.EvaluateJavaScript( | 313 self._app_page.EvaluateJavaScript( |
| 309 'document.getElementById("pairing-button").click()') | 314 'document.getElementById("pairing-button").click()') |
| 310 | 315 |
| 311 def _ClickPairingButton(self): | 316 def _ClickPairingButton(self): |
| 317 # Waits are needed because the clicks occur before the button label changes. |
| 318 time.sleep(1) |
| 312 self._app_page.EvaluateJavaScript( | 319 self._app_page.EvaluateJavaScript( |
| 313 'document.getElementById("pairing-button").click()') | 320 'document.getElementById("pairing-button").click()') |
| 321 time.sleep(1) |
| 314 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 322 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( |
| 315 '!document.getElementById("pairing-button").disabled'), 60) | 323 '!document.getElementById("pairing-button").disabled'), 60) |
| 324 time.sleep(1) |
| 316 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 325 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( |
| 317 '!document.getElementById("pairing-button-title")' | 326 '!document.getElementById("pairing-button-title")' |
| 318 '.classList.contains("animated-fade-out")'), 5) | 327 '.classList.contains("animated-fade-out")'), 5) |
| 319 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( | 328 util.WaitFor(lambda: self._app_page.EvaluateJavaScript( |
| 320 '!document.getElementById("pairing-button-title")' | 329 '!document.getElementById("pairing-button-title")' |
| 321 '.classList.contains("animated-fade-in")'), 5) | 330 '.classList.contains("animated-fade-in")'), 5) |
| 322 | 331 |
| 323 | 332 |
| 324 class ChromeOS(object): | 333 class ChromeOS(object): |
| 325 """ Wrapper for a remote ChromeOS device. | 334 """ Wrapper for a remote ChromeOS device. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 try: | 561 try: |
| 553 extensions = self._browser.extensions.GetByExtensionId( | 562 extensions = self._browser.extensions.GetByExtensionId( |
| 554 'mkaemigholebcgchlkbankmihknojeak') | 563 'mkaemigholebcgchlkbankmihknojeak') |
| 555 except KeyError: | 564 except KeyError: |
| 556 return None | 565 return None |
| 557 for extension_page in extensions: | 566 for extension_page in extensions: |
| 558 pathname = extension_page.EvaluateJavaScript('document.location.pathname') | 567 pathname = extension_page.EvaluateJavaScript('document.location.pathname') |
| 559 if pathname == page_name: | 568 if pathname == page_name: |
| 560 return extension_page | 569 return extension_page |
| 561 return None | 570 return None |
| OLD | NEW |