Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: telemetry/telemetry/internal/backends/chrome/oobe.py

Issue 2692763002: Revert of [Telemetry] Switch clients to new JavaScript API (batch 5) (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: telemetry/telemetry/internal/backends/chrome/oobe.py
diff --git a/telemetry/telemetry/internal/backends/chrome/oobe.py b/telemetry/telemetry/internal/backends/chrome/oobe.py
index 356b8051c94ef1748b3e88bb4d1d313bdeaa2010..0a849263d2299057601148136c7654d9abace69d 100644
--- a/telemetry/telemetry/internal/backends/chrome/oobe.py
+++ b/telemetry/telemetry/internal/backends/chrome/oobe.py
@@ -4,6 +4,7 @@
from functools import partial
import logging
+import json
from telemetry.core import exceptions
from telemetry.internal.browser import web_contents
@@ -20,10 +21,10 @@
logging.debug('%d contexts in Gaia page' % max_context_id)
for gaia_iframe_context in range(max_context_id + 1):
try:
- if self.EvaluateJavaScript2(
+ if self.EvaluateJavaScriptInContext(
"document.readyState == 'complete' && "
"document.getElementById('Email') != null",
- context_id=gaia_iframe_context):
+ gaia_iframe_context):
return gaia_iframe_context
except exceptions.EvaluateException:
pass
@@ -37,17 +38,20 @@
def _ExecuteOobeApi(self, api, *args):
logging.info('Invoking %s' % api)
- self.WaitForJavaScriptCondition2("typeof Oobe == 'function'", timeout=120)
+ self.WaitForJavaScriptExpression("typeof Oobe == 'function'", 120)
- if self.EvaluateJavaScript2(
- "typeof {{ @api }} == 'undefined'", api=api):
+ # TODO(catapult:#3028): Fix interpolation of JavaScript values.
+ if self.EvaluateJavaScript("typeof %s == 'undefined'" % api):
raise exceptions.LoginException('%s js api missing' % api)
# Example values:
- # |api|: 'doLogin'
- # |args|: ['username', 'pass', True]
- # Executes: 'doLogin("username", "pass", true)'
- self.ExecuteJavaScript2('{{ @f }}({{ *args }})', f=api, args=args)
+ # |api|: 'doLogin'
+ # |args|: ['username', 'pass', True]
+ # js: '{}({},{},{})'
+ # js.format(...): 'doLogin("username","pass",true)'
+ js = '{}(' + ('{},' * len(args)).rstrip(',') + ')'
+ # TODO(catapult:#3028): Fix interpolation of JavaScript values.
+ self.ExecuteJavaScript(js.format(api, *map(json.dumps, args)))
def NavigateGuestLogin(self):
"""Logs in as guest."""
@@ -72,8 +76,8 @@
self._NavigateGaiaLogin(username, password, enterprise_enroll)
if enterprise_enroll:
- self.WaitForJavaScriptCondition2(
- 'Oobe.isEnrollmentSuccessfulForTest()', timeout=30)
+ self.WaitForJavaScriptExpression('Oobe.isEnrollmentSuccessfulForTest()',
+ 30)
self._ExecuteOobeApi('Oobe.enterpriseEnrollmentDone')
def _NavigateGaiaLogin(self, username, password, enterprise_enroll):
@@ -94,12 +98,13 @@
if add_user_for_testing:
self._ExecuteOobeApi('Oobe.showAddUserForTesting')
- self.ExecuteJavaScript2("""
- document.getElementById('Email').value= {{ username }};
- document.getElementById('Passwd').value= {{ password }};
- document.getElementById('signIn').click();""",
- username=username, password=password,
- context_id=gaia_iframe_context)
+ # TODO(catapult:#3028): Fix interpolation of JavaScript values.
+ self.ExecuteJavaScriptInContext("""
+ document.getElementById('Email').value='%s';
+ document.getElementById('Passwd').value='%s';
+ document.getElementById('signIn').click();"""
+ % (username, password),
+ gaia_iframe_context)
def _NavigateWebViewLogin(self, username, password, wait_for_close):
"""Logs into the webview-based GAIA screen"""
@@ -108,18 +113,19 @@
if wait_for_close:
py_utils.WaitFor(lambda: not self._GaiaWebviewContext(), 60)
- def _NavigateWebViewEntry(self, field, value, next_field):
+ def _NavigateWebViewEntry(self, field, value, nextField):
self._WaitForField(field)
- self._WaitForField(next_field)
+ self._WaitForField(nextField)
gaia_webview_context = self._GaiaWebviewContext()
- gaia_webview_context.EvaluateJavaScript2("""
- document.getElementById({{ field }}).value= {{ value }};
- document.getElementById({{ next_field }}).click()""",
- field=field, value=value, next_field=next_field)
+ # TODO(catapult:#3028): Fix interpolation of JavaScript values.
+ gaia_webview_context.EvaluateJavaScript("""
+ document.getElementById('%s').value='%s';
+ document.getElementById('%s').click()"""
+ % (field, value, nextField))
- def _WaitForField(self, field):
+ def _WaitForField(self, field_id):
gaia_webview_context = py_utils.WaitFor(self._GaiaWebviewContext, 5)
py_utils.WaitFor(gaia_webview_context.HasReachedQuiescence, 20)
- gaia_webview_context.WaitForJavaScriptCondition2(
- "document.getElementById({{ field }}) != null",
- field=field, timeout=20)
+ # TODO(catapult:#3028): Fix interpolation of JavaScript values.
+ gaia_webview_context.WaitForJavaScriptExpression(
+ "document.getElementById('%s') != null" % field_id, 20)

Powered by Google App Engine
This is Rietveld 408576698