2016-01-15 18:35:51 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
|
|
|
)
|
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
Command,
|
2016-03-09 22:43:31 +03:00
|
|
|
CommandProvider,
|
2016-01-15 18:35:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-03-09 22:43:31 +03:00
|
|
|
def setup_argument_parser_functional():
|
2016-01-15 18:35:51 +03:00
|
|
|
from firefox_ui_harness.arguments.base import FirefoxUIArguments
|
2016-08-20 02:35:19 +03:00
|
|
|
from mozlog.structured import commandline
|
|
|
|
parser = FirefoxUIArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
return parser
|
2016-01-15 18:35:51 +03:00
|
|
|
|
|
|
|
|
2016-03-09 22:43:31 +03:00
|
|
|
def setup_argument_parser_update():
|
|
|
|
from firefox_ui_harness.arguments.update import UpdateArguments
|
2016-08-20 02:35:19 +03:00
|
|
|
from mozlog.structured import commandline
|
|
|
|
parser = UpdateArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
return parser
|
2016-01-15 18:35:51 +03:00
|
|
|
|
|
|
|
|
2016-03-09 22:43:31 +03:00
|
|
|
def run_firefox_ui_test(testtype=None, topsrcdir=None, **kwargs):
|
|
|
|
from mozlog.structured import commandline
|
2016-06-29 19:55:32 +03:00
|
|
|
from argparse import Namespace
|
2016-03-09 22:43:31 +03:00
|
|
|
import firefox_ui_harness
|
|
|
|
|
2016-04-02 03:30:56 +03:00
|
|
|
if testtype == 'functional':
|
|
|
|
parser = setup_argument_parser_functional()
|
|
|
|
else:
|
|
|
|
parser = setup_argument_parser_update()
|
|
|
|
|
2016-03-09 22:43:31 +03:00
|
|
|
test_types = {
|
|
|
|
'functional': {
|
|
|
|
'default_tests': [
|
2016-03-10 16:40:23 +03:00
|
|
|
os.path.join('puppeteer', 'manifest.ini'),
|
|
|
|
os.path.join('functional', 'manifest.ini'),
|
2016-03-09 22:43:31 +03:00
|
|
|
],
|
|
|
|
'cli_module': firefox_ui_harness.cli_functional,
|
|
|
|
},
|
|
|
|
'update': {
|
|
|
|
'default_tests': [
|
|
|
|
os.path.join('update', 'manifest.ini'),
|
|
|
|
],
|
|
|
|
'cli_module': firefox_ui_harness.cli_update,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 16:21:54 +03:00
|
|
|
fxui_dir = os.path.join(topsrcdir, 'testing', 'firefox-ui')
|
2016-03-09 22:43:31 +03:00
|
|
|
|
|
|
|
# Set the resources path which is used to serve test data via wptserve
|
|
|
|
if not kwargs['server_root']:
|
2016-03-10 16:21:54 +03:00
|
|
|
kwargs['server_root'] = os.path.join(fxui_dir, 'resources')
|
2016-03-09 22:43:31 +03:00
|
|
|
|
2016-09-21 11:31:05 +03:00
|
|
|
# If called via "mach test" a dictionary of tests is passed in
|
|
|
|
if 'test_objects' in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs['test_objects']:
|
|
|
|
tests.append(obj['file_relpath'])
|
|
|
|
kwargs['tests'] = tests
|
|
|
|
elif not kwargs.get('tests'):
|
|
|
|
# If no tests have been selected, set default ones
|
2016-04-15 01:17:40 +03:00
|
|
|
kwargs['tests'] = [os.path.join(fxui_dir, 'tests', test)
|
2016-03-09 22:43:31 +03:00
|
|
|
for test in test_types[testtype]['default_tests']]
|
|
|
|
|
2018-06-27 22:43:12 +03:00
|
|
|
kwargs['logger'] = kwargs.pop('log', None)
|
|
|
|
if not kwargs['logger']:
|
|
|
|
kwargs['logger'] = commandline.setup_logging('Firefox UI - {} Tests'.format(testtype),
|
|
|
|
{"mach": sys.stdout})
|
2016-03-09 22:43:31 +03:00
|
|
|
|
2016-06-29 19:55:32 +03:00
|
|
|
args = Namespace()
|
2016-04-02 03:30:56 +03:00
|
|
|
|
|
|
|
for k, v in kwargs.iteritems():
|
|
|
|
setattr(args, k, v)
|
|
|
|
|
|
|
|
parser.verify_usage(args)
|
|
|
|
|
|
|
|
failed = test_types[testtype]['cli_module'].cli(args=vars(args))
|
|
|
|
|
2016-01-15 18:35:51 +03:00
|
|
|
if failed > 0:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
2016-03-09 22:43:31 +03:00
|
|
|
"""Mach command provider for Firefox ui tests."""
|
|
|
|
|
|
|
|
@Command('firefox-ui-functional', category='testing',
|
|
|
|
conditions=[conditions.is_firefox],
|
|
|
|
description='Run the functional test suite of Firefox UI tests.',
|
|
|
|
parser=setup_argument_parser_functional,
|
|
|
|
)
|
|
|
|
def run_firefox_ui_functional(self, **kwargs):
|
|
|
|
kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app')
|
|
|
|
return run_firefox_ui_test(testtype='functional',
|
|
|
|
topsrcdir=self.topsrcdir, **kwargs)
|
|
|
|
|
|
|
|
@Command('firefox-ui-update', category='testing',
|
2016-01-15 18:35:51 +03:00
|
|
|
conditions=[conditions.is_firefox],
|
2016-03-09 22:43:31 +03:00
|
|
|
description='Run the update test suite of Firefox UI tests.',
|
|
|
|
parser=setup_argument_parser_update,
|
2016-01-15 18:35:51 +03:00
|
|
|
)
|
2016-03-09 22:43:31 +03:00
|
|
|
def run_firefox_ui_update(self, **kwargs):
|
2016-03-02 20:02:11 +03:00
|
|
|
kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app')
|
2016-03-09 22:43:31 +03:00
|
|
|
return run_firefox_ui_test(testtype='update',
|
|
|
|
topsrcdir=self.topsrcdir, **kwargs)
|