| Index: components/proximity_auth/e2e_test/cros.py
|
| diff --git a/components/proximity_auth/e2e_test/cros.py b/components/proximity_auth/e2e_test/cros.py
|
| index bd7081b5ecc2b5e685f2a7fd133ca09b6a6aa872..a1ef76453239a50a028602c9990a9a2bbd80ba78 100644
|
| --- a/components/proximity_auth/e2e_test/cros.py
|
| +++ b/components/proximity_auth/e2e_test/cros.py
|
| @@ -71,22 +71,23 @@ class AccountPickerScreen(object):
|
|
|
| @property
|
| def is_lockscreen(self):
|
| - return self._oobe.EvaluateJavaScript(
|
| + return self._oobe.EvaluateJavaScript2(
|
| '!document.getElementById("sign-out-user-item").hidden')
|
|
|
| @property
|
| def auth_type(self):
|
| - return self._oobe.EvaluateJavaScript('%s.authType' % self._GET_POD_JS)
|
| + return self._oobe.EvaluateJavaScript2(
|
| + '{{ @pod }}.authType', pod=self._GET_POD_JS)
|
|
|
| @property
|
| def smart_lock_state(self):
|
| - icon_shown = self._oobe.EvaluateJavaScript(
|
| - '!%s.customIconElement.hidden' % self._GET_POD_JS)
|
| + icon_shown = self._oobe.EvaluateJavaScript2(
|
| + '!{{ @pod }}.customIconElement.hidden', pod=self._GET_POD_JS)
|
| if not icon_shown:
|
| return self.SmartLockState.NOT_SHOWN
|
| - class_list_dict = self._oobe.EvaluateJavaScript(
|
| - '%s.customIconElement.querySelector(".custom-icon")'
|
| - '.classList' % self._GET_POD_JS)
|
| + class_list_dict = self._oobe.EvaluateJavaScript2(
|
| + '{{ @pod }}.customIconElement.querySelector(".custom-icon").classList',
|
| + pod=self._GET_POD_JS)
|
| class_list = [v for k,v in class_list_dict.items() if k != 'length']
|
|
|
| if 'custom-icon-unlocked' in class_list:
|
| @@ -125,11 +126,11 @@ class AccountPickerScreen(object):
|
| assert(self.auth_type == self.AuthType.OFFLINE_PASSWORD or
|
| self.auth_type == self.AuthType.FORCE_OFFLINE_PASSWORD)
|
| oobe = self._oobe
|
| - oobe.EvaluateJavaScript(
|
| - '%s.passwordElement.value = "%s"' % (
|
| - self._GET_POD_JS, self._chromeos.password))
|
| - oobe.EvaluateJavaScript(
|
| - '%s.activate()' % self._GET_POD_JS)
|
| + oobe.EvaluateJavaScript2(
|
| + '{{ @pod }}.passwordElement.value = {{ password }}',
|
| + pod=self._GET_POD_JS, password=self._chromeos.password)
|
| + oobe.EvaluateJavaScript2(
|
| + '{{ @pod }}.activate()', pod=self._GET_POD_JS)
|
| util.WaitFor(lambda: (self._chromeos.session_state ==
|
| ChromeOS.SessionState.IN_SESSION),
|
| 5)
|
| @@ -137,7 +138,8 @@ class AccountPickerScreen(object):
|
| def UnlockWithClick(self):
|
| """ Clicks the user pod to unlock or sign-in. """
|
| assert(self.auth_type == self.AuthType.USER_CLICK)
|
| - self._oobe.EvaluateJavaScript('%s.activate()' % self._GET_POD_JS)
|
| + self._oobe.EvaluateJavaScript2(
|
| + '{{ @pod }}.activate()', pod=self._GET_POD_JS)
|
|
|
|
|
| class SmartLockSettings(object):
|
| @@ -155,7 +157,7 @@ class SmartLockSettings(object):
|
| @property
|
| def is_smart_lock_enabled(self):
|
| ''' Returns true if the settings show that Smart Lock is enabled. '''
|
| - return self._tab.EvaluateJavaScript(
|
| + return self._tab.EvaluateJavaScript2(
|
| '!document.getElementById("easy-unlock-enabled").hidden')
|
|
|
| def TurnOffSmartLock(self):
|
| @@ -169,22 +171,22 @@ class SmartLockSettings(object):
|
| """
|
| assert(self.is_smart_lock_enabled)
|
| tab = self._tab
|
| - tab.EvaluateJavaScript(
|
| + tab.EvaluateJavaScript2(
|
| 'document.getElementById("easy-unlock-turn-off-button").click()')
|
| - util.WaitFor(lambda: tab.EvaluateJavaScript(
|
| + tab.WaitForJavaScriptCondition2(
|
| '!document.getElementById("easy-unlock-turn-off-overlay").hidden && '
|
| - 'document.getElementById("easy-unlock-turn-off-confirm") != null'),
|
| - 10)
|
| - tab.EvaluateJavaScript(
|
| + 'document.getElementById("easy-unlock-turn-off-confirm") != null',
|
| + timeout=10)
|
| + tab.EvaluateJavaScript2(
|
| 'document.getElementById("easy-unlock-turn-off-confirm").click()')
|
| - util.WaitFor(lambda: tab.EvaluateJavaScript(
|
| - '!document.getElementById("easy-unlock-disabled").hidden'), 15)
|
| + tab.WaitForJavaScriptCondition2(
|
| + '!document.getElementById("easy-unlock-disabled").hidden', timeout=15)
|
|
|
| def StartSetup(self):
|
| """ Starts the Smart Lock setup flow by clicking the button.
|
| """
|
| assert(not self.is_smart_lock_enabled)
|
| - self._tab.EvaluateJavaScript(
|
| + self._tab.EvaluateJavaScript2(
|
| 'document.getElementById("easy-unlock-setup-button").click()')
|
|
|
| def StartSetupAndReturnApp(self):
|
| @@ -239,7 +241,7 @@ class SmartLockApp(object):
|
| Raises:
|
| ValueError: The current state is unknown.
|
| '''
|
| - state = self._app_page.EvaluateJavaScript(
|
| + state = self._app_page.EvaluateJavaScript2(
|
| 'document.body.getAttribute("step")')
|
| if state == 'scan':
|
| return SmartLockApp.PairingState.SCAN
|
| @@ -248,7 +250,7 @@ class SmartLockApp(object):
|
| elif state == 'promote-smart-lock-for-android':
|
| return SmartLockApp.PairingState.PROMOTE_SMARTLOCK_FOR_ANDROID
|
| elif state == 'complete':
|
| - button_text = self._app_page.EvaluateJavaScript(
|
| + button_text = self._app_page.EvaluateJavaScript2(
|
| 'document.getElementById("pairing-button").textContent')
|
| button_text = button_text.strip().lower()
|
| if button_text == 'try it out':
|
| @@ -302,7 +304,7 @@ class SmartLockApp(object):
|
| TimeoutException: Timed out starting the trial run.
|
| """
|
| assert(self.pairing_state == self.PairingState.CLICK_FOR_TRIAL_RUN)
|
| - self._app_page.EvaluateJavaScript(
|
| + self._app_page.EvaluateJavaScript2(
|
| 'document.getElementById("pairing-button").click()')
|
| util.WaitFor(lambda: (self._chromeos.session_state ==
|
| ChromeOS.SessionState.LOCK_SCREEN),
|
| @@ -314,24 +316,24 @@ class SmartLockApp(object):
|
| The app must be in the TRIAL_RUN_COMPLETED state.
|
| """
|
| assert(self.pairing_state == self.PairingState.TRIAL_RUN_COMPLETED)
|
| - self._app_page.EvaluateJavaScript(
|
| + self._app_page.EvaluateJavaScript2(
|
| 'document.getElementById("pairing-button").click()')
|
|
|
| def _ClickPairingButton(self):
|
| # Waits are needed because the clicks occur before the button label changes.
|
| time.sleep(1)
|
| - self._app_page.EvaluateJavaScript(
|
| + self._app_page.EvaluateJavaScript2(
|
| 'document.getElementById("pairing-button").click()')
|
| time.sleep(1)
|
| - util.WaitFor(lambda: self._app_page.EvaluateJavaScript(
|
| - '!document.getElementById("pairing-button").disabled'), 60)
|
| + self._app_page.WaitForJavaScriptCondition2(
|
| + '!document.getElementById("pairing-button").disabled', timeout=60)
|
| time.sleep(1)
|
| - util.WaitFor(lambda: self._app_page.EvaluateJavaScript(
|
| + self._app_page.WaitForJavaScriptCondition2(
|
| '!document.getElementById("pairing-button-title")'
|
| - '.classList.contains("animated-fade-out")'), 5)
|
| - util.WaitFor(lambda: self._app_page.EvaluateJavaScript(
|
| + '.classList.contains("animated-fade-out")', timeout=5)
|
| + self._app_page.WaitForJavaScriptCondition2(
|
| '!document.getElementById("pairing-button-title")'
|
| - '.classList.contains("animated-fade-in")'), 5)
|
| + '.classList.contains("animated-fade-in")', timeout=5)
|
|
|
|
|
| class ChromeOS(object):
|
| @@ -393,13 +395,13 @@ class ChromeOS(object):
|
| @property
|
| def cryptauth_access_token(self):
|
| try:
|
| - util.WaitFor(lambda: self._background_page.EvaluateJavaScript(
|
| + self._background_page.WaitForJavaScriptCondition2(
|
| 'var __token = __token || null; '
|
| 'chrome.identity.getAuthToken(function(token) {'
|
| ' __token = token;'
|
| '}); '
|
| - '__token != null'), 5)
|
| - return self._background_page.EvaluateJavaScript('__token');
|
| + '__token != null', timeout=5)
|
| + return self._background_page.EvaluateJavaScript2('__token');
|
| except exceptions.TimeoutException:
|
| logger.error('Failed to get access token.');
|
| return ''
|
| @@ -484,14 +486,14 @@ class ChromeOS(object):
|
| self.session_state == self.SessionState.SIGNIN_SCREEN)
|
| oobe = self._browser.oobe
|
| def IsLockScreenResponsive():
|
| - return (oobe.EvaluateJavaScript("typeof Oobe == 'function'") and
|
| - oobe.EvaluateJavaScript(
|
| + return (oobe.EvaluateJavaScript2("typeof Oobe == 'function'") and
|
| + oobe.EvaluateJavaScript2(
|
| "typeof Oobe.authenticateForTesting == 'function'"))
|
| util.WaitFor(IsLockScreenResponsive, 10)
|
| - util.WaitFor(lambda: oobe.EvaluateJavaScript(
|
| + oobe.WaitForJavaScriptCondition2(
|
| 'document.getElementById("pod-row") && '
|
| 'document.getElementById("pod-row").pods && '
|
| - 'document.getElementById("pod-row").pods.length > 0'), 10)
|
| + 'document.getElementById("pod-row").pods.length > 0', timeout=10)
|
| return AccountPickerScreen(oobe, self)
|
|
|
| def GetSmartLockSettings(self):
|
| @@ -506,16 +508,17 @@ class ChromeOS(object):
|
| if not len(self._browser.tabs):
|
| self._browser.New()
|
| tab = self._browser.tabs[0]
|
| - url = tab.EvaluateJavaScript('document.location.href')
|
| + url = tab.EvaluateJavaScript2('document.location.href')
|
| if url != self._SMART_LOCK_SETTINGS_URL:
|
| tab.Navigate(self._SMART_LOCK_SETTINGS_URL)
|
|
|
| # Wait for settings page to be responsive.
|
| - util.WaitFor(lambda: tab.EvaluateJavaScript(
|
| + tab.WaitForJavaScriptCondition2(
|
| 'document.getElementById("easy-unlock-disabled") && '
|
| 'document.getElementById("easy-unlock-enabled") && '
|
| '(!document.getElementById("easy-unlock-disabled").hidden || '
|
| - ' !document.getElementById("easy-unlock-enabled").hidden)'), 10)
|
| + ' !document.getElementById("easy-unlock-enabled").hidden)',
|
| + timeout=10)
|
| settings = SmartLockSettings(tab, self)
|
| logger.info('Started Smart Lock settings: enabled=%s' %
|
| settings.is_smart_lock_enabled)
|
| @@ -530,22 +533,23 @@ class ChromeOS(object):
|
| app_page = self._FindSmartLockAppPage('/pairing.html')
|
| if app_page is not None:
|
| # Wait for app window to be responsive.
|
| - util.WaitFor(lambda: app_page.EvaluateJavaScript(
|
| - 'document.getElementById("pairing-button") != null'), 10)
|
| + tab.WaitForJavaScriptCondition2(
|
| + 'document.getElementById("pairing-button") != null', timeout=10)
|
| return SmartLockApp(app_page, self)
|
| return None
|
|
|
| def SetCryptAuthStaging(self, cryptauth_staging_url):
|
| logger.info('Setting CryptAuth to Staging')
|
| try:
|
| - self._background_page.ExecuteJavaScript(
|
| - 'var key = app.CryptAuthClient.GOOGLE_API_URL_OVERRIDE_;'
|
| - 'var __complete = false;'
|
| - 'chrome.storage.local.set({key: "%s"}, function() {'
|
| - ' __complete = true;'
|
| - '});' % cryptauth_staging_url)
|
| - util.WaitFor(lambda: self._background_page.EvaluateJavaScript(
|
| - '__complete == true'), 10)
|
| + self._background_page.ExecuteJavaScript2("""
|
| + var key = app.CryptAuthClient.GOOGLE_API_URL_OVERRIDE_;
|
| + var __complete = false;
|
| + chrome.storage.local.set({key: {{ url }}}, function() {
|
| + __complete = true;
|
| + });""",
|
| + url=cryptauth_staging_url)
|
| + self._background_page.WaitForJavaScriptCondition2(
|
| + '__complete == true', timeout=10)
|
| except exceptions.TimeoutException:
|
| logger.error('Failed to override CryptAuth to staging url.')
|
|
|
| @@ -568,7 +572,8 @@ class ChromeOS(object):
|
| except KeyError:
|
| return None
|
| for extension_page in extensions:
|
| - pathname = extension_page.EvaluateJavaScript('document.location.pathname')
|
| + pathname = extension_page.EvaluateJavaScript2(
|
| + 'document.location.pathname')
|
| if pathname == page_name:
|
| return extension_page
|
| return None
|
|
|