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 from autotest_lib.client.bin import test
      6 from autotest_lib.client.cros import cryptohome
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.common_lib.cros import chrome
      9 
     10 
     11 class login_GaiaLogin(test.test):
     12     """Sign into production gaia using Telemetry."""
     13     version = 1
     14 
     15 
     16     def run_once(self, username, password):
     17         """Test body."""
     18         if not username:
     19           raise error.TestFail('User not set.')
     20         if not password:
     21           raise error.TestFail('Password not set.')
     22 
     23         with chrome.Chrome(gaia_login=True,
     24                            username=username,
     25                            password=password) as cr:
     26             if not cryptohome.is_vault_mounted(
     27                     user=chrome.NormalizeEmail(username)):
     28                 raise error.TestFail('Expected to find a mounted vault for %s'
     29                                      % username)
     30             tab = cr.browser.tabs.New()
     31             # TODO(achuith): Use a better signal of being logged in, instead of
     32             # parsing accounts.google.com.
     33             tab.Navigate('http://accounts.google.com')
     34             tab.WaitForDocumentReadyStateToBeComplete()
     35             res = tab.EvaluateJavaScript('''
     36                     var res = '',
     37                         divs = document.getElementsByTagName('div');
     38                     for (var i = 0; i < divs.length; i++) {
     39                         res = divs[i].textContent;
     40                         if (res.search('%s') > 1) {
     41                             break;
     42                         }
     43                     }
     44                     res;
     45             ''' % username)
     46             if not res:
     47                 raise error.TestFail('No references to %s on accounts page.'
     48                                      % username)
     49             tab.Close()
     50