author Nicholas Nethercote <nnethercote@mozilla.com>
Wed, 27 Apr 2016 14:16:50 +1000
changeset 336387 3d67e45f994a3ae1ae43479c32c2ed63bbf1a7c8
parent 333533 865e124224cd54ec70adbefbcb8a750f5e1d985c
child 345344 d218260e3e524040e7e712af2f7fbcba04073cd9
permissions -rw-r--r--
Bug 1267550 (part 2) - Rename MOZ_WARN_UNUSED_RESULT as MOZ_MUST_USE. r=froydnj. It's an annotation that is used a lot, and should be used even more, so a shorter name is better. MozReview-Commit-ID: 1VS4Dney4WX

# 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 (
    MachCommandConditions as conditions,

from mach.decorators import (

def setup_argument_parser_functional():
    from firefox_ui_harness.arguments.base import FirefoxUIArguments
    return FirefoxUIArguments()

def setup_argument_parser_update():
    from firefox_ui_harness.arguments.update import UpdateArguments
    return UpdateArguments()

def run_firefox_ui_test(testtype=None, topsrcdir=None, **kwargs):
    from mozlog.structured import commandline
    import firefox_ui_harness

    if testtype == 'functional':
        parser = setup_argument_parser_functional()
        parser = setup_argument_parser_update()

    test_types = {
        'functional': {
            'default_tests': [
                os.path.join('puppeteer', 'manifest.ini'),
                os.path.join('functional', 'manifest.ini'),
            'cli_module': firefox_ui_harness.cli_functional,
        'update': {
            'default_tests': [
                os.path.join('update', 'manifest.ini'),
            'cli_module': firefox_ui_harness.cli_update,

    fxui_dir = os.path.join(topsrcdir, 'testing', 'firefox-ui')

    # Set the resources path which is used to serve test data via wptserve
    if not kwargs['server_root']:
        kwargs['server_root'] = os.path.join(fxui_dir, 'resources')

    # If no tests have been selected, set default ones
    if not kwargs.get('tests'):
        kwargs['tests'] = [os.path.join(fxui_dir, 'tests', test)
                           for test in test_types[testtype]['default_tests']]

    kwargs['logger'] = commandline.setup_logging('Firefox UI - {} Tests'.format(testtype),
                                                 {"mach": sys.stdout})

    # pass tests to parse_args to avoid rereading sys.argv
    args = parser.parse_args(args=kwargs['tests'])

    for k, v in kwargs.iteritems():
        setattr(args, k, v)


    failed = test_types[testtype]['cli_module'].cli(args=vars(args))

    if failed > 0:
        return 1
        return 0

class MachCommands(MachCommandBase):
    """Mach command provider for Firefox ui tests."""

    @Command('firefox-ui-functional', category='testing',
             description='Run the functional test suite of Firefox UI tests.',
    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',
             description='Run the update test suite of Firefox UI tests.',
    def run_firefox_ui_update(self, **kwargs):
        kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app')
        return run_firefox_ui_test(testtype='update',
                                   topsrcdir=self.topsrcdir, **kwargs)