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 = chrome.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 # Evaluate some javascript. 45 logging.info('Evaluating JavaScript.') 46 if cr.browser.tabs[0].EvaluateJavaScript('2+2') != 4: 47 raise TestFail('EvaluateJavaScript failed') 48 49 # ARC test. 50 if is_arc_available: 51 arc.wait_for_android_process('org.chromium.arc.intent_helper') 52 arc.wait_for_adb_ready() 53 logging.info('Android booted successfully.') 54 if not arc.is_package_installed('android'): 55 raise TestFail('"android" system package was not listed by ' 56 'Package Manager.') 57 58 if is_arc_available: 59 utils.poll_for_condition(lambda: not arc.is_adb_connected(), 60 timeout=15, 61 desc='Android container still running after ' 62 'Chrome shutdown.') 63 elapsed = datetime.datetime.now() - start 64 logging.info('Test succeeded in %s seconds.', elapsed.seconds) 65 66 67 if __name__ == '__main__': 68 sys.exit(main(sys.argv[1:])) 69