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