1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__
import absolute_import
, print_function
, unicode_literals
11 from mach
.decorators
import (
16 from mozbuild
.base
import (
18 MachCommandConditions
as conditions
,
21 SUPPORTED_APPS
= ['firefox', 'android', 'thunderbird']
23 def create_parser_tests():
24 from marionette_harness
.runtests
import MarionetteArguments
25 from mozlog
.structured
import commandline
27 parser
= MarionetteArguments()
28 commandline
.add_logging_group(parser
)
32 def run_marionette(tests
, binary
=None, topsrcdir
=None, **kwargs
):
33 from mozlog
.structured
import commandline
35 from marionette_harness
.runtests
import (
40 parser
= create_parser_tests()
42 args
= argparse
.Namespace(tests
=tests
)
45 args
.logger
= kwargs
.pop('log', None)
47 for k
, v
in kwargs
.iteritems():
50 parser
.verify_usage(args
)
53 args
.logger
= commandline
.setup_logging("Marionette Unit Tests",
56 failed
= MarionetteHarness(MarionetteTestRunner
, args
=vars(args
)).run()
63 def is_buildapp_in(*apps
):
64 def is_buildapp_supported(cls
):
66 c
= getattr(conditions
, 'is_{}'.format(a
), None)
71 is_buildapp_supported
.__doc
__ = 'Must have a {} build.'.format(
73 return is_buildapp_supported
77 class MarionetteTest(MachCommandBase
):
78 @Command("marionette-test",
80 description
="Remote control protocol to Gecko, used for browser automation.",
81 conditions
=[is_buildapp_in(*SUPPORTED_APPS
)],
82 parser
=create_parser_tests
,
84 def marionette_test(self
, tests
, **kwargs
):
85 if "test_objects" in kwargs
:
87 for obj
in kwargs
["test_objects"]:
88 tests
.append(obj
["file_relpath"])
89 del kwargs
["test_objects"]
92 if conditions
.is_thunderbird(self
):
93 tests
= [os
.path
.join(self
.topsrcdir
,
94 "comm/testing/marionette/unit-tests.ini")]
96 tests
= [os
.path
.join(self
.topsrcdir
,
97 "testing/marionette/harness/marionette_harness/tests/unit-tests.ini")]
99 # Force disable e10s because it is not supported in Fennec
100 if kwargs
.get("app") == "fennec":
101 kwargs
["e10s"] = False
103 if not kwargs
.get("binary") and \
104 (conditions
.is_firefox(self
) or conditions
.is_thunderbird(self
)):
105 kwargs
["binary"] = self
.get_binary_path("app")
107 return run_marionette(tests
, topsrcdir
=self
.topsrcdir
, **kwargs
)