• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8import time
9
10from typing import List, Optional
11
12from common import catch_sigterm, run_continuous_ffx_command
13from test_runner import TestRunner
14
15
16class WebpageTestRunner(TestRunner):
17    """Test runner for running GPU tests."""
18
19    def __init__(self, out_dir: str, test_args: List[str],
20                 target_id: Optional[str]) -> None:
21        parser = argparse.ArgumentParser()
22        parser.add_argument(
23            '--browser',
24            choices=['web-engine-shell', 'chrome'],
25            help='The browser to use for Telemetry based tests.')
26        args, _ = parser.parse_known_args(test_args)
27
28        if args.browser == 'web-engine-shell':
29            packages = ['web_engine_shell']
30        else:
31            packages = ['chrome']
32
33        super().__init__(out_dir, test_args, packages, target_id)
34
35    def run_test(self):
36        catch_sigterm()
37        browser_cmd = [
38            'test',
39            'run',
40            '-t',
41            '3600',  # Keep the webpage running for an hour.
42            f'fuchsia-pkg://fuchsia.com/{self._packages[0]}#meta/'
43            f'{self._packages[0]}.cm'
44        ]
45        browser_cmd.extend(
46            ['--', '--web-engine-package-name=web_engine_with_webui'])
47        if self._test_args:
48            browser_cmd.extend(self._test_args)
49        logging.info('Starting %s', self._packages[0])
50        try:
51            browser_proc = run_continuous_ffx_command(browser_cmd)
52            while True:
53                time.sleep(10000)
54        except KeyboardInterrupt:
55            logging.info('Ctrl-C received; shutting down the webpage.')
56            browser_proc.kill()
57        except SystemExit:
58            logging.info('SIGTERM received; shutting down the webpage.')
59            browser_proc.kill()
60        return browser_proc
61