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

Unified Diff: tools/telemetry/telemetry/form_based_credentials_backend.py

Issue 11828048: [Telemetry] Fixing credentials login behaviour in case the user is already logged in and using --do… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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: tools/telemetry/telemetry/form_based_credentials_backend.py
diff --git a/tools/telemetry/telemetry/form_based_credentials_backend.py b/tools/telemetry/telemetry/form_based_credentials_backend.py
index 6a21cb80026cbea615b5deda3bdc39865f41ac3e..69c89ce8173486d988d710c3a70c95111e433a52 100644
--- a/tools/telemetry/telemetry/form_based_credentials_backend.py
+++ b/tools/telemetry/telemetry/form_based_credentials_backend.py
@@ -7,13 +7,21 @@ import logging
import telemetry
from telemetry import util
-def _WaitForFormToLoad(form_id, tab):
- def IsFormLoaded():
+
+def _IsAlreadyLoggedIn(already_logged_in_element_id, tab):
+ return tab.runtime.Evaluate(
+ 'document.getElementById("%s")!== null' % \
+ already_logged_in_element_id)
+
+def _WaitForLoginFormToLoad(login_form_id, already_logged_in_element_id, tab):
+ def IsFormLoadedOrAlreadyLoggedIn():
return tab.runtime.Evaluate(
- 'document.querySelector("#%s")!== null' % form_id)
+ 'document.querySelector("#%s")!== null' % login_form_id) or \
+ _IsAlreadyLoggedIn(already_logged_in_element_id, tab)
# Wait until the form is submitted and the page completes loading.
- util.WaitFor(lambda: IsFormLoaded(), 60) # pylint: disable=W0108
+ util.WaitFor(lambda: IsFormLoadedOrAlreadyLoggedIn(), # pylint: disable=W0108
+ 60)
def _SubmitFormAndWait(form_id, tab):
js = 'document.getElementById("%s").submit();' % form_id
@@ -39,7 +47,7 @@ class FormBasedCredentialsBackend(object):
raise NotImplementedError()
@property
- def form_id(self):
+ def login_form_id(self):
raise NotImplementedError()
@property
@@ -47,6 +55,10 @@ class FormBasedCredentialsBackend(object):
raise NotImplementedError()
@property
+ def already_logged_in_element_id(self):
+ raise NotImplementedError()
+
+ @property
def password_input_id(self):
raise NotImplementedError()
@@ -69,7 +81,14 @@ class FormBasedCredentialsBackend(object):
try:
logging.info('Loading %s...', self.url)
tab.page.Navigate(self.url)
- _WaitForFormToLoad(self.form_id, tab)
+ _WaitForLoginFormToLoad(self.login_form_id,
+ self.already_logged_in_element_id,
+ tab)
+
+ if _IsAlreadyLoggedIn(self.already_logged_in_element_id, tab):
+ self._logged_in = True
+ return True
+
tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
logging.info('Loaded page: %s', self.url)
@@ -80,7 +99,7 @@ class FormBasedCredentialsBackend(object):
tab.runtime.Execute(email_id)
tab.runtime.Execute(password)
- _SubmitFormAndWait(self.form_id, tab)
+ _SubmitFormAndWait(self.login_form_id, tab)
self._logged_in = True
return True

Powered by Google App Engine
This is Rietveld 408576698