1# Lint as: python2, python3 2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6from autotest_lib.client.bin import test, utils 7from autotest_lib.client.cros import cryptohome 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.common_lib.cros import chrome 10 11 12class login_GaiaLogin(test.test): 13 """Sign into production gaia using Telemetry.""" 14 version = 1 15 16 17 def run_once(self, username, password): 18 """Test body.""" 19 if not username: 20 raise error.TestFail('User not set.') 21 if not password: 22 raise error.TestFail('Password not set.') 23 24 with chrome.Chrome(gaia_login=True, 25 username=username, 26 password=password) as cr: 27 if not cryptohome.is_vault_mounted( 28 user=chrome.NormalizeEmail(username)): 29 raise error.TestFail('Expected to find a mounted vault for %s' 30 % username) 31 32 tab = cr.browser.tabs.New() 33 tab.Navigate('https://google.com') 34 tab.WaitForDocumentReadyStateToBeComplete() 35 36 def _userLoggedIn(tab, username): 37 # TODO(achuith): Use a better signal of being logged in, instead 38 # of parsing google.com. 39 res = tab.EvaluateJavaScript(''' 40 var res = '', 41 divs = document.getElementsByTagName('div'); 42 for (var i = 0; i < divs.length; i++) { 43 res = divs[i].textContent; 44 if (res.search('%s') > 1) { 45 break; 46 } 47 } 48 res; 49 ''' % username) 50 return res 51 52 utils.poll_for_condition(lambda: _userLoggedIn(tab, username), 53 timeout=20) 54