Home | History | Annotate | Download | only in bin
      1 #!/usr/bin/python
      2 #
      3 # Copyright 2016 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 '''A simple sanity test for Chrome.
      8 
      9 This script logs in, ensures that the cryptohome is mounted,
     10 and checks that the browser is functional.
     11 '''
     12 
     13 from __future__ import print_function
     14 
     15 import datetime
     16 import logging
     17 import os
     18 import sys
     19 
     20 # This sets up import paths for autotest.
     21 import common
     22 from autotest_lib.client.bin import utils
     23 from autotest_lib.client.common_lib.cros import arc, arc_common, chrome
     24 from autotest_lib.client.common_lib.error import TestFail
     25 from autotest_lib.client.cros import cryptohome
     26 
     27 
     28 def main(args):
     29     '''The main function.'''
     30     if args:
     31         print('No args for vm_sanity.py')
     32         return os.EX_USAGE
     33 
     34 
     35     start = datetime.datetime.now()
     36     logging.info('Starting chrome and logging in.')
     37     is_arc_available = utils.is_arc_available()
     38     arc_mode = arc_common.ARC_MODE_ENABLED if is_arc_available else None
     39     with chrome.Chrome(arc_mode=arc_mode) as cr:
     40         # Check that the cryptohome is mounted.
     41         # is_vault_mounted throws an exception if it fails.
     42         logging.info('Checking mounted cryptohome.')
     43         cryptohome.is_vault_mounted(user=cr.username, allow_fail=False)
     44         # Navigate to about:blank.
     45         tab = cr.browser.tabs[0]
     46         tab.Navigate('about:blank')
     47 
     48         # Evaluate some javascript.
     49         logging.info('Evaluating JavaScript.')
     50         if tab.EvaluateJavaScript('2+2') != 4:
     51             raise TestFail('EvaluateJavaScript failed')
     52 
     53         # ARC test.
     54         if is_arc_available:
     55             arc.wait_for_android_process('org.chromium.arc.intent_helper')
     56             arc.wait_for_adb_ready()
     57             logging.info('Android booted successfully.')
     58             if not arc.is_package_installed('android'):
     59                 raise TestFail('"android" system package was not listed by '
     60                                'Package Manager.')
     61 
     62     if is_arc_available:
     63         utils.poll_for_condition(lambda: not arc.is_adb_connected(),
     64                                  timeout=15,
     65                                  desc='Android container still running after '
     66                                       'Chrome shutdown.')
     67     elapsed = datetime.datetime.now() - start
     68     logging.info('Test succeeded in %s seconds.', elapsed.seconds)
     69 
     70 
     71 if __name__ == '__main__':
     72     sys.exit(main(sys.argv[1:]))
     73