xref: /aosp_15_r20/external/cronet/testing/scripts/run_chromedriver_tests.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env python
2# Copyright 2018 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Runs chrome driver tests.
7
8This script attempts to emulate the contract of gtest-style tests
9invoked via recipes.
10
11If optional argument --isolated-script-test-output=[FILENAME] is passed
12to the script, json is written to that file in the format detailed in
13//docs/testing/json-test-results-format.md.
14
15If optional argument --isolated-script-test-filter=[TEST_NAMES] is passed to
16the script, it should be a  double-colon-separated ("::") list of test names,
17to run just that subset of tests. This list is forwarded to the chrome driver
18test runner.  """
19
20import argparse
21import json
22import os
23import shutil
24import sys
25import tempfile
26import traceback
27
28# Add src/testing/ into sys.path for importing common without pylint errors.
29sys.path.append(
30    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
31from scripts import common
32
33
34class ChromeDriverAdapter(common.BaseIsolatedScriptArgsAdapter):
35
36  def generate_test_output_args(self, output):
37    return ['--isolated-script-test-output', output]
38
39  def generate_test_filter_args(self, test_filter_str):
40    if any('--filter' in arg for arg in self.rest_args):
41      self.parser.error(
42          'can\'t have the test call filter with the'
43          '--isolated-script-test-filter argument to the wrapper script')
44
45    return ['--filter', test_filter_str.replace('::', ':')]
46
47
48def main():
49  adapter = ChromeDriverAdapter()
50  return adapter.run_test()
51
52
53# This is not really a "script test" so does not need to manually add
54# any additional compile targets.
55def main_compile_targets(args):
56  json.dump([], args.output)
57
58
59if __name__ == '__main__':
60  # Conform minimally to the protocol defined by ScriptTest.
61  if 'compile_targets' in sys.argv:
62    funcs = {
63      'run': None,
64      'compile_targets': main_compile_targets,
65    }
66    sys.exit(common.run_script(sys.argv[1:], funcs))
67  sys.exit(main())
68