1# Lint as: python2, python3 2# Copyright 2021 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 6import logging 7import os 8import time 9 10from autotest_lib.client.bin import test 11from autotest_lib.client.bin import utils 12from autotest_lib.client.common_lib import error 13from autotest_lib.client.common_lib import ui_utils 14from autotest_lib.client.common_lib.cros import chrome 15 16 17class desktopui_RootfsLacros(test.test): 18 """Tests logging in, opening lacros, and verifying the version number.""" 19 version = 1 20 21 def is_lacros_running(self): 22 """ Return True if lacros is running. """ 23 process = utils.run('pgrep -f /run/lacros/chrome', 24 ignore_status=True).stdout 25 return len(process) > 0 26 27 def run_once(self, dont_override_profile=False): 28 """Check rootfs-lacros opens and its version number.""" 29 # Use args to keep test as hermetic as possible. 30 # See crbug.com/1268252 and crbug.com/1268743 for details. 31 browser_args = [ 32 '--lacros-selection=rootfs', '--enable-features=LacrosSupport', 33 '--enable-features=LacrosPrimary', 34 '--disable-lacros-keep-alive', '--disable-login-lacros-opening' 35 ] 36 37 with chrome.Chrome(autotest_ext=True, 38 dont_override_profile=dont_override_profile, 39 extra_browser_args=browser_args) as cr: 40 # Use chrome.automation API to drive UI. 41 self.ui = ui_utils.UI_Handler() 42 self.ui.start_ui_root(cr) 43 44 # Click the shelf button for lacors. 45 self.ui.wait_for_ui_obj('Lacros', role='button') 46 self.ui.doDefault_on_obj('Lacros', role='button') 47 48 # Check that lacros process is running. 49 try: 50 utils.poll_for_condition(condition=self.is_lacros_running) 51 except utils.TimeoutError: 52 raise error.TestFail( 53 'No Lacros processes running after clicking shelf icon' 54 ) 55 56 # Get lacros version 57 res = utils.run('/run/lacros/chrome -version').stdout 58 version = str(utils.parse_chrome_version(res)[0]) 59 logging.info('Lacros version is %s', version) 60 61 # Save lacros version for other uses. 62 save_file = os.path.join(self.resultsdir, 'lacros_version.txt') 63 tmp_file = '/tmp/lacros_version.txt' 64 utils.run(['echo', version, '>', save_file]) 65 utils.run(['echo', version, '>', tmp_file]) 66 67 # Wait to make sure lacros doesn't crash. 68 time.sleep(10) 69 try: 70 utils.poll_for_condition(condition=self.is_lacros_running) 71 except utils.TimeoutError: 72 raise error.TestFail('No Lacros processes running after 10s') 73