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