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

Unified Diff: tools/chrome_remote_control/chrome_remote_control/google_credentials_backend.py

Issue 10914237: Port perf.py's _LoginToGoogleAccount to chrome_remote_control (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/chrome_remote_control/chrome_remote_control/google_credentials_backend.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/google_credentials_backend.py b/tools/chrome_remote_control/chrome_remote_control/google_credentials_backend.py
new file mode 100644
index 0000000000000000000000000000000000000000..daea914eb6ac498ab74d408e7bb875f81c2e49e0
--- /dev/null
+++ b/tools/chrome_remote_control/chrome_remote_control/google_credentials_backend.py
@@ -0,0 +1,86 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys
+import time
+import logging
+import os
+import chrome_remote_control
+from credentials_backend import CredentialsBackend
+
+class GoogleCredentialsBackend(CredentialsBackend):
+ label = 'google'
+
+ def __init__(self, tab):
+ self._tab = tab
+ self._logged_in = False
+
+ def LoginNeeded(self):
+ if not self._logged_in:
+ self._logged_in = self._LoginToGoogleAccount()
+
+ def LoginNoLongerNeeded(self):
dtu 2012/09/24 21:35:10 This is a placeholder for the future, right? What
hartmanng 2012/09/26 22:06:15 I added this in response to http://codereview.chro
+ pass
+
+ def GoogleAccountsLogin(self, username, password, url=None):
+ """Log into Google Accounts.
+
+ Attempts to login to Google by entering the username/password into the
+ google login page and click submit button.
+
+ Args:
+ username: users login input.
+ password: users login password input.
+ url: an alternative url for login page, if None, original one will be
+ used.
+ """
+ url = url or 'https://accounts.google.com/'
+
+ try:
+ logging.info('Loading %s...', url)
+ self._tab.page.Navigate(url)
+ time.sleep(2) # Wait for unpredictable redirects.
tonyg 2012/09/24 20:41:01 Looks brittle. Is there anything better to WaitFor
hartmanng 2012/09/26 22:06:15 Done.
+ self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
+ logging.info('Loaded page: %s', url)
+
+ email_id = 'document.getElementById("Email").value = "%s"; ' % username
+ password = 'document.getElementById("Passwd").value = "%s"; ' % password
+ self._tab.runtime.Execute(email_id)
+ self._tab.runtime.Execute(password)
+
+ self.SubmitFormAndWait('gaia_loginform')
+
+ return True
+ except chrome_remote_control.TimeoutException:
+ logging.warning('Timed out while loading: %s', url)
+ print 'Timed out while loading: ', url
+ return False
+
+
+ def _LoginToGoogleAccount(self):
+ """Logs in to a test Google account.
+
+ Login with user-defined credentials if they exist.
+ Else fail.
+
+ Raises:
+ RuntimeError: if could not get credential information.
+ """
+ config = CredentialsBackend._GetConfig(
+ {'google_username': None,
+ 'google_password': None,
+ 'google_account_url': 'https://accounts.google.com/'})
+ google_account_url = config.get('google_account_url')
+ username = config.get('google_username')
+ password = config.get('google_password')
+ if username and password:
+ logging.info(
+ 'Using google account credential from %s',
+ self._config_file, 'credentials.json')
+ else:
+ message = 'No credentials could be found. ' \
+ 'Please specify credential information in %s.' \
+ % self._config_file
+ raise RuntimeError(message)
+ return self.GoogleAccountsLogin(username, password, url=google_account_url)

Powered by Google App Engine
This is Rietveld 408576698