Support for normalizing email.
Remove dots from username, add @gmail.com if necessary.
Allow username, password to be specified for login_GaiaLogin.
BUG=chromium:618466
TEST=login_GaiaLogin
Change-Id: I8cd1340ec90e0d6d750cbde39cdbbcab3960ac0c
Reviewed-on: https://chromium-review.googlesource.com/351120
Commit-Ready: Achuith Bhandarkar <achuith@chromium.org>
Tested-by: Achuith Bhandarkar <achuith@chromium.org>
Reviewed-by: Jacob Dufault <jdufault@chromium.org>
diff --git a/client/common_lib/cros/chrome.py b/client/common_lib/cros/chrome.py
index 20c331a..4acc8be 100644
--- a/client/common_lib/cros/chrome.py
+++ b/client/common_lib/cros/chrome.py
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import logging, os
+import logging, os, re
from autotest_lib.client.cros import constants
from autotest_lib.client.bin import utils
@@ -41,6 +41,21 @@
from autotest_lib.client.common_lib.cros import arc_util
+def NormalizeEmail(username):
+ """Remove dots from username. Add @gmail.com if necessary.
+
+ TODO(achuith): Get rid of this when crbug.com/358427 is fixed.
+
+ @param username: username/email to be scrubbed.
+ """
+ parts = re.split('@', username)
+ parts[0] = re.sub('\.', '', parts[0])
+
+ if len(parts) == 1:
+ parts.append('gmail.com')
+ return '@'.join(parts)
+
+
class Chrome(object):
"""Wrapper for creating a telemetry browser instance with extensions."""
@@ -137,6 +152,7 @@
b_options.gaia_login = gaia_login
self.username = b_options.username if username is None else username
self.password = b_options.password if password is None else password
+ self.username = NormalizeEmail(self.username)
b_options.username = self.username
b_options.password = self.password
# gaia_id will be added to telemetry code in chromium repository later
diff --git a/client/site_tests/login_GaiaLogin/login_GaiaLogin.py b/client/site_tests/login_GaiaLogin/login_GaiaLogin.py
index dbd3458..66ac480 100644
--- a/client/site_tests/login_GaiaLogin/login_GaiaLogin.py
+++ b/client/site_tests/login_GaiaLogin/login_GaiaLogin.py
@@ -15,22 +15,28 @@
version = 1
- _USERNAME = 'powerloadtest@gmail.com'
- # TODO(achuith): Get rid of this when crbug.com/358427 is fixed.
- _USERNAME_DISPLAY = 'power.loadtest@gmail.com'
+ _USERNAME = 'power.loadtest@gmail.com'
_PLTP_URL = 'https://sites.google.com/a/chromium.org/dev/chromium-os' \
'/testing/power-testing/pltp/pltp'
- def run_once(self):
- with tempfile.NamedTemporaryFile() as pltp:
- file_utils.download_file(self._PLTP_URL, pltp.name)
- self._password = pltp.read().rstrip()
- with chrome.Chrome(gaia_login=True, username=self._USERNAME,
- password=self._password) as cr:
- if not cryptohome.is_vault_mounted(user=self._USERNAME):
+ def run_once(self, username=None, password=None):
+ if username is None:
+ username = self._USERNAME
+
+ if password is None:
+ with tempfile.NamedTemporaryFile() as pltp:
+ file_utils.download_file(self._PLTP_URL, pltp.name)
+ password = pltp.read().rstrip()
+
+ if not password:
+ raise error.TestFail('Password not set.')
+
+ with chrome.Chrome(gaia_login=True, username=username,
+ password=password) as cr:
+ if not cryptohome.is_vault_mounted(user=chrome.NormalizeEmail(username)):
raise error.TestFail('Expected to find a mounted vault for %s'
- % self._USERNAME)
+ % username)
tab = cr.browser.tabs.New()
# TODO(achuith): Use a better signal of being logged in, instead of
# parsing accounts.google.com.
@@ -46,8 +52,8 @@
}
}
res;
- ''' % self._USERNAME_DISPLAY)
+ ''' % username)
if not res:
raise error.TestFail('No references to %s on accounts page.'
- % self._USERNAME_DISPLAY)
+ % username)
tab.Close()