1# Copyright 2023 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4"""Implements commands for running webpage tests.""" 5 6import argparse 7import logging 8 9from typing import List, Optional 10 11from common import catch_sigterm, run_continuous_ffx_command, wait_for_sigterm 12from test_runner import TestRunner 13 14 15class WebpageTestRunner(TestRunner): 16 """Test runner for running GPU tests.""" 17 18 def __init__(self, out_dir: str, test_args: List[str], 19 target_id: Optional[str]) -> None: 20 parser = argparse.ArgumentParser() 21 parser.add_argument( 22 '--browser', 23 choices=['web-engine-shell', 'chrome'], 24 help='The browser to use for Telemetry based tests.') 25 args, _ = parser.parse_known_args(test_args) 26 27 if args.browser == 'web-engine-shell': 28 packages = ['web_engine_shell'] 29 else: 30 packages = ['chrome'] 31 32 super().__init__(out_dir, test_args, packages, target_id) 33 34 def run_test(self): 35 catch_sigterm() 36 browser_cmd = [ 37 'test', 38 'run', 39 '-t', 40 '3600', # Keep the webpage running for an hour. 41 f'fuchsia-pkg://fuchsia.com/{self._packages[0]}#meta/' 42 f'{self._packages[0]}.cm' 43 ] 44 browser_cmd.extend( 45 ['--', '--web-engine-package-name=web_engine_with_webui']) 46 if self._test_args: 47 browser_cmd.extend(self._test_args) 48 logging.info('Starting %s', self._packages[0]) 49 browser_proc = run_continuous_ffx_command(browser_cmd) 50 try: 51 wait_for_sigterm('shutting down the webpage.') 52 finally: 53 browser_proc.kill() 54