DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (8506e87cec50)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
# 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/.


"""
This module contains a set of shortcut methods that create runners for commonly
used Mozilla applications, such as Firefox, Firefox for Android or Thunderbird.
"""

from __future__ import absolute_import

from .application import get_app_context
from .base import GeckoRuntimeRunner, FennecRunner, BlinkRuntimeRunner
from .devices import EmulatorAVD


def Runner(*args, **kwargs):
    """
    Create a generic GeckoRuntime runner.

    :param binary: Path to binary.
    :param cmdargs: Arguments to pass into binary.
    :param profile: Profile object to use.
    :param env: Environment variables to pass into the gecko process.
    :param clean_profile: If True, restores profile back to original state.
    :param process_class: Class used to launch the binary.
    :param process_args: Arguments to pass into process_class.
    :param symbols_path: Path to symbol files used for crash analysis.
    :param show_crash_reporter: allow the crash reporter window to pop up.
        Defaults to False.
    :returns: A generic GeckoRuntimeRunner.
    """
    return GeckoRuntimeRunner(*args, **kwargs)


def FirefoxRunner(*args, **kwargs):
    """
    Create a desktop Firefox runner.

    :param binary: Path to Firefox binary.
    :param cmdargs: Arguments to pass into binary.
    :param profile: Profile object to use.
    :param env: Environment variables to pass into the gecko process.
    :param clean_profile: If True, restores profile back to original state.
    :param process_class: Class used to launch the binary.
    :param process_args: Arguments to pass into process_class.
    :param symbols_path: Path to symbol files used for crash analysis.
    :param show_crash_reporter: allow the crash reporter window to pop up.
        Defaults to False.
    :returns: A GeckoRuntimeRunner for Firefox.
    """
    kwargs['app_ctx'] = get_app_context('firefox')()
    return GeckoRuntimeRunner(*args, **kwargs)


def ThunderbirdRunner(*args, **kwargs):
    """
    Create a desktop Thunderbird runner.

    :param binary: Path to Thunderbird binary.
    :param cmdargs: Arguments to pass into binary.
    :param profile: Profile object to use.
    :param env: Environment variables to pass into the gecko process.
    :param clean_profile: If True, restores profile back to original state.
    :param process_class: Class used to launch the binary.
    :param process_args: Arguments to pass into process_class.
    :param symbols_path: Path to symbol files used for crash analysis.
    :param show_crash_reporter: allow the crash reporter window to pop up.
        Defaults to False.
    :returns: A GeckoRuntimeRunner for Thunderbird.
    """
    kwargs['app_ctx'] = get_app_context('thunderbird')()
    return GeckoRuntimeRunner(*args, **kwargs)


def ChromeRunner(*args, **kwargs):
    """
    Create a desktop Google Chrome runner.

    :param binary: Path to Chrome binary.
    :param cmdargs: Arguments to pass into the binary.
    """
    kwargs['app_ctx'] = get_app_context('chrome')()
    return BlinkRuntimeRunner(*args, **kwargs)


def ChromiumRunner(*args, **kwargs):
    """
    Create a desktop Google Chromium runner.

    :param binary: Path to Chromium binary.
    :param cmdargs: Arguments to pass into the binary.
    """
    kwargs['app_ctx'] = get_app_context('chromium')()
    return BlinkRuntimeRunner(*args, **kwargs)


def FennecEmulatorRunner(avd='mozemulator-4.3',
                         adb_path=None,
                         avd_home=None,
                         logdir=None,
                         serial=None,
                         binary=None,
                         app='org.mozilla.fennec',
                         **kwargs):
    """
    Create a Fennec emulator runner. This can either start a new emulator
    (which will use an avd), or connect to  an already-running emulator.

    :param avd: name of an AVD available in your environment.
        Typically obtained via tooltool: either 'mozemulator-4.3' or 'mozemulator-x86'.
        Defaults to 'mozemulator-4.3'
    :param avd_home: Path to avd parent directory
    :param logdir: Path to save logfiles such as qemu output.
    :param serial: Serial of emulator to connect to as seen in `adb devices`.
        Defaults to the first entry in `adb devices`.
    :param binary: Path to emulator binary.
        Defaults to None, which causes the device_class to guess based on PATH.
    :param app: Name of Fennec app (often org.mozilla.fennec_$USER)
        Defaults to 'org.mozilla.fennec'
    :param cmdargs: Arguments to pass into binary.
    :returns: A DeviceRunner for Android emulators.
    """
    kwargs['app_ctx'] = get_app_context('fennec')(app, adb_path=adb_path,
                                                  avd_home=avd_home,
                                                  device_serial=serial)
    device_args = {'app_ctx': kwargs['app_ctx'],
                   'avd': avd,
                   'binary': binary,
                   'logdir': logdir}
    return FennecRunner(device_class=EmulatorAVD,
                        device_args=device_args,
                        **kwargs)


runners = {
    'chrome': ChromeRunner,
    'chromium': ChromiumRunner,
    'default': Runner,
    'firefox': FirefoxRunner,
    'fennec': FennecEmulatorRunner,
    'thunderbird': ThunderbirdRunner,
}