# 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/.
import argparse import io import os import platform import sys
from mach.decorators import Command from mozbuild.base import BuildEnvironmentNotFoundException, MozbuildObject
with tarfile.open(fileobj=fileobj, mode="r") as tar_data:
tar_data.extractall(path=dest)
def unzip(fileobj, dest): import zipfile
with zipfile.ZipFile(fileobj) as zip_data:
zip_data.extractall(path=dest)
def writable_dir(path): ifnot os.path.isdir(path): raise argparse.ArgumentTypeError("{0} is not a valid dir".format(path)) if os.access(path, os.W_OK): return path else: raise argparse.ArgumentTypeError("{0} is not a writable dir".format(path))
def create_parser_interventions(): from mozlog import commandline
parser = argparse.ArgumentParser()
parser.add_argument("--webdriver-binary", help="Path to webdriver binary")
parser.add_argument( "--webdriver-port",
action="store",
default="4444",
help="Port on which to run WebDriver",
)
parser.add_argument( "--webdriver-ws-port",
action="store",
default="9222",
help="Port on which to run WebDriver BiDi websocket",
)
parser.add_argument("-b", "--bugs", nargs="*", help="Bugs to run tests for")
parser.add_argument( "--do2fa",
action="store_true",
default=False,
help="Do two-factor auth live in supporting tests",
)
parser.add_argument( "--config", help="Path to JSON file containing logins and other settings"
)
parser.add_argument( "--debug", action="store_true", default=False, help="Debug failing tests"
)
parser.add_argument( "-H", "--headless",
action="store_true",
default=False,
help="Run firefox in headless mode",
)
parser.add_argument( "--interventions",
action="store",
default="both",
choices=["enabled", "disabled", "both", "none"],
help="Enable webcompat interventions",
)
parser.add_argument( "--shims",
action="store",
default="none",
choices=["enabled", "disabled", "both", "none"],
help="Enable SmartBlock shims",
)
parser.add_argument( "--platform",
action="store",
choices=["android", "desktop"],
help="Platform to target",
)
parser.add_argument( "--failure-screenshots-dir",
action="store",
type=writable_dir,
help="Path to save failure screenshots",
)
parser.add_argument( "-s", "--no-failure-screenshots",
action="store_true",
default=False,
help="Do not save a screenshot for each test failure",
)
desktop_group = parser.add_argument_group("Desktop-specific arguments")
desktop_group.add_argument("--binary", help="Path to browser binary")
android_group = parser.add_argument_group("Android-specific arguments")
android_group.add_argument( "--device-serial",
action="store",
help="Running Android instances to connect to, if not emulator-5554",
)
android_group.add_argument( "--package-name",
action="store",
default=GVE,
help="Android package name to use",
)
class InterventionTest(MozbuildObject): def set_default_kwargs(self, logger, command_context, kwargs):
platform = kwargs["platform"]
binary = kwargs["binary"]
device_serial = kwargs["device_serial"] try:
is_gve_build = command_context.substs.get("MOZ_APP_NAME") == "fennec" except BuildEnvironmentNotFoundException: # If we don't have a build, just use the logic below to choose between # desktop and Android
is_gve_build = False
if platform == "android"or (
platform isNoneand binary isNoneand (device_serial or is_gve_build)
):
kwargs["platform"] = "android" else:
kwargs["platform"] = "desktop"
if kwargs["platform"] == "desktop"and kwargs["binary"] isNone:
kwargs["binary"] = self.get_binary_path()
if kwargs["webdriver_binary"] isNone:
webdriver_binary = self.get_binary_path( "geckodriver", validate_exists=False
)
# GVE does not have the webcompat addon by default. Add it. if app == GVE:
kwargs["addon"] = "/data/local/tmp/webcompat.xpi"
push_to_device(
command_context.substs["ADB"],
device_serial,
webcompat_addon(command_context),
kwargs["addon"],
)
log_level = "INFO" # It's not trivial to get a single log level out of mozlog, because we might have # different levels going to different outputs. We look for the maximum (i.e. most # verbose) level of any handler with an attached formatter.
configured_level_number = None for handler in logger.handlers: if hasattr(handler, "formatter") and hasattr(handler.formatter, "level"):
formatter_level = handler.formatter.level
configured_level_number = (
formatter_level if configured_level_number isNone else max(configured_level_number, formatter_level)
) if configured_level_number isnotNone: for level, number in mozlog.structuredlog.log_levels.items(): if number == configured_level_number:
log_level = level break
# We use #include directives in the system addon's moz.build (to inject our JSON config # into ua_overrides.js and injections.js), so we must do that here to make a working XPI.
tmpdir_kwargs = {} if sys.version_info.major >= 3 and sys.version_info.minor >= 10:
tmpdir_kwargs["ignore_cleanup_errors"] = True with tempfile.TemporaryDirectory(**tmpdir_kwargs) as src_copy:
def process_includes(path):
fullpath = os.path.join(src_copy, path)
in_lines = None with open(fullpath, "r") as f:
in_lines = f.readlines() with open(fullpath, "w") as f: for line in in_lines: ifnot line.startswith("#include"):
f.write(line) continue
include_path = line.split()[1]
include_fullpath = os.path.join(
os.path.dirname(fullpath), include_path
) with open(include_fullpath, "r") as inc:
f.write(inc.read())
f.write("\n")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.