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/.
11 from six
import iteritems
13 from mach
.decorators
import (
17 from mozbuild
.base
import (
18 MachCommandConditions
as conditions
,
19 BinaryNotFoundException
,
22 SUPPORTED_APPS
= ["firefox", "android", "thunderbird"]
25 def create_parser_tests():
26 from marionette_harness
.runtests
import MarionetteArguments
27 from mozlog
.structured
import commandline
29 parser
= MarionetteArguments()
30 commandline
.add_logging_group(parser
)
34 def run_marionette(tests
, binary
=None, topsrcdir
=None, **kwargs
):
35 from mozlog
.structured
import commandline
37 from marionette_harness
.runtests
import MarionetteTestRunner
, MarionetteHarness
39 parser
= create_parser_tests()
41 args
= argparse
.Namespace(tests
=tests
)
44 args
.logger
= kwargs
.pop("log", None)
46 for k
, v
in iteritems(kwargs
):
49 parser
.verify_usage(args
)
51 # Causes Firefox to crash when using non-local connections.
52 os
.environ
["MOZ_DISABLE_NONLOCAL_CONNECTIONS"] = "1"
55 args
.logger
= commandline
.setup_logging(
56 "Marionette Unit Tests", args
, {"mach": sys
.stdout
}
58 failed
= MarionetteHarness(MarionetteTestRunner
, args
=vars(args
)).run()
68 description
="Remote control protocol to Gecko, used for browser automation.",
69 conditions
=[functools
.partial(conditions
.is_buildapp_in
, apps
=SUPPORTED_APPS
)],
70 parser
=create_parser_tests
,
72 def marionette_test(command_context
, tests
, **kwargs
):
73 if "test_objects" in kwargs
:
75 for obj
in kwargs
["test_objects"]:
76 tests
.append(obj
["file_relpath"])
77 del kwargs
["test_objects"]
80 if conditions
.is_thunderbird(command_context
):
83 command_context
.topsrcdir
,
84 "comm/testing/marionette/unit-tests.ini",
90 command_context
.topsrcdir
,
91 "testing/marionette/harness/marionette_harness/tests/unit-tests.ini",
95 if not kwargs
.get("binary") and (
96 conditions
.is_firefox(command_context
)
97 or conditions
.is_thunderbird(command_context
)
100 kwargs
["binary"] = command_context
.get_binary_path("app")
101 except BinaryNotFoundException
as e
:
109 logging
.INFO
, "marionette-test", {"help": e
.help()}, "{help}"
113 return run_marionette(tests
, topsrcdir
=command_context
.topsrcdir
, **kwargs
)