Exemplo n.º 1
0
def test_inner_package(err, package_contents, package):
    "Tests a package's inner content."
    
    # Iterate through each tier.
    for tier in sorted(decorator.get_tiers()):

        # Let the error bundler know what tier we're on
        err.tier = tier

        # Iterate through each test of our detected type
        for test in decorator.get_tests(tier, err.detected_type):
            test_func = test["test"]
            if test["simple"]:
                test_func(err)
            else:
                # Pass in:
                # - Error Bundler
                # - Package listing
                # - A copy of the package itself
                test_func(err, package_contents, package)
        
        # Return any errors at the end of the tier if undetermined.
        if err.failed(fail_on_warnings=False) and not err.determined:
            err.unfinished = True
            return err
            
    # Return the results.
    return err
Exemplo n.º 2
0
def test_assumedtype():
    """Tests to see if the decorator module can find tests for generic
    as well as specific types"""

    decorator.TEST_TIERS = {}

    decorator.register_test(tier=1)(lambda: None)
    decorator.register_test(tier=2, expected_type=5)(lambda: None)
    decorator.register_test(tier=2)(lambda: None)
    decorator.register_test(tier=2, simple=True)(lambda: None)

    tests = list(decorator.get_tests(2, 5))
    assert len(tests) == 3
Exemplo n.º 3
0
def test_specifictype():
    """Tests to make sure that the decorator module can return a test
    of a specific type."""

    decorator.TEST_TIERS = {}

    decorator.register_test(tier=1)(lambda: None)
    decorator.register_test(tier=2, expected_type=5)(lambda: None)
    decorator.register_test(tier=2)(lambda: None)
    decorator.register_test(tier=2, simple=True)(lambda: None)

    tests = list(decorator.get_tests(2, 1))
    assert len(tests) == 2
Exemplo n.º 4
0
def test_inner_package(err, xpi_package, for_appversions=None):
    "Tests a package's inner content."

    populate_chrome_manifest(err, xpi_package)

    # Iterate through each tier.
    for tier in sorted(decorator.get_tiers()):

        # Let the error bundler know what tier we're on.
        err.set_tier(tier)

        # Iterate through each test of our detected type.
        for test in decorator.get_tests(tier, err.detected_type):
            # Test whether the test is app/version specific.
            if test["versions"] is not None:
                # If the test's version requirements don't apply to the add-on,
                # then skip the test.
                if not err.supports_version(test["versions"]):
                    continue

                # If the user's version requirements don't apply to the test or
                # to the add-on, then skip the test.
                if (for_appversions and
                    not (err._compare_version(requirements=for_appversions,
                                              support=test["versions"]) and
                         err.supports_version(for_appversions))):
                    continue

            # Save the version requirements to the error bundler.
            err.version_requirements = test["versions"]

            test_func = test["test"]
            if test["simple"]:
                test_func(err)
            else:
                # Pass in:
                # - Error Bundler
                # - A copy of the package itself
                test_func(err, xpi_package)

        # Return any errors at the end of the tier if undetermined.
        if err.failed(fail_on_warnings=False) and not err.determined:
            err.unfinished = True
            err.discard_unused_messages(ending_tier=tier)
            return err

    # Return the results.
    return err
Exemplo n.º 5
0
def test_inner_package(err, xpi_package, for_appversions=None):
    "Tests a package's inner content."

    populate_chrome_manifest(err, xpi_package)

    # Iterate through each tier.
    for tier in sorted(decorator.get_tiers()):

        # Let the error bundler know what tier we're on.
        err.set_tier(tier)

        # Iterate through each test of our detected type.
        for test in decorator.get_tests(tier, err.detected_type):
            # Test whether the test is app/version specific.
            if test["versions"] is not None:
                # If the test's version requirements don't apply to the add-on,
                # then skip the test.
                if not err.supports_version(test["versions"]):
                    continue

                # If the user's version requirements don't apply to the test or
                # to the add-on, then skip the test.
                if (for_appversions and
                        not (err._compare_version(requirements=for_appversions,
                                                  support=test["versions"])
                             and err.supports_version(for_appversions))):
                    continue

            # Save the version requirements to the error bundler.
            err.version_requirements = test["versions"]

            test_func = test["test"]
            if test["simple"]:
                test_func(err)
            else:
                # Pass in:
                # - Error Bundler
                # - A copy of the package itself
                test_func(err, xpi_package)

        # Return any errors at the end of the tier if undetermined.
        if err.failed(fail_on_warnings=False) and not err.determined:
            err.unfinished = True
            err.discard_unused_messages(ending_tier=tier)
            return err

    # Return the results.
    return err
Exemplo n.º 6
0
def test_assumedtype():
    """
    Test to see if the decorator module can find tests for generic as well as
    specific types.
    """

    dtt = decorator.TEST_TIERS
    decorator.TEST_TIERS = {}

    decorator.register_test(tier=1)(lambda: None)
    decorator.register_test(tier=2, expected_type=5)(lambda: None)
    decorator.register_test(tier=2)(lambda: None)
    decorator.register_test(tier=2, simple=True)(lambda: None)

    tests = list(decorator.get_tests(2, 5))
    assert len(tests) == 3
    decorator.TEST_TIERS = dtt
Exemplo n.º 7
0
def test_specifictype():
    """
    Test to make sure that the decorator module can return a test of a
    specific type.
    """

    dtt = decorator.TEST_TIERS
    decorator.TEST_TIERS = {}

    decorator.register_test(tier=1)(lambda: None)
    decorator.register_test(tier=2, expected_type=5)(lambda: None)
    decorator.register_test(tier=2)(lambda: None)
    decorator.register_test(tier=2, simple=True)(lambda: None)

    tests = list(decorator.get_tests(2, 1))
    assert len(tests) == 2
    decorator.TEST_TIERS = dtt
Exemplo n.º 8
0
def test_inner_package(err, xpi_package, for_appversions=None):
    "Tests a package's inner content."

    populate_chrome_manifest(err, xpi_package)

    # Iterate through each tier.
    for tier in sorted(decorator.get_tiers()):

        # Let the error bundler know what tier we're on.
        err.set_tier(tier)

        # Iterate through each test of our detected type.
        for test in decorator.get_tests(tier, err.detected_type):
            # Test whether the test is app/version specific.
            if test['versions'] is not None:
                # If the test's version requirements don't apply to the add-on,
                # then skip the test.
                if not err.supports_version(test['versions']):
                    continue

                # If the user's version requirements don't apply to the test or
                # to the add-on, then skip the test.
                if (for_appversions and
                        not (err._compare_version(requirements=for_appversions,
                                                  support=test['versions'])
                             and err.supports_version(for_appversions))):
                    continue

            # Save the version requirements to the error bundler.
            err.version_requirements = test['versions']

            test_func = test['test']
            if test['simple']:
                test_func(err)
            else:
                # Pass in:
                # - Error Bundler
                # - A copy of the package itself
                test_func(err, xpi_package)

        # Return any errors at the end of the tier if undetermined.
        if err.failed(fail_on_warnings=False) and not err.determined:
            err.unfinished = True
            err.discard_unused_messages(ending_tier=tier)
            return err

    supports = err.get_resource('supports') or []
    if (err.get_resource('has_install_rdf')
            and not err.get_resource('has_manifest_json')
            and not err.get_resource('is_multiprocess_compatible')
            and err.detected_type in (PACKAGE_EXTENSION, PACKAGE_SUBPACKAGE)
            and 'firefox' in supports):
        # If it's an old-style xpi, or a sdk extension, that supports Firefox,
        # but is not a Web Extension, then we raise a warning if multiprocess
        # compatible property was not found in install.rdf.
        format_args = {}
        if err.get_resource('has_package_json'):
            format_args['filename'] = 'package.json'
            format_args['field'] = 'multiprocess'
            format_args['link'] = (
                MDN_DOC %
                'Mozilla/Add-ons/SDK/Guides/Multiprocess_Firefox_and_the_SDK')
        else:
            format_args['filename'] = 'install.rdf'
            format_args['field'] = '<em:multiprocessCompatible>'
            format_args['link'] = (
                MDN_DOC % 'Mozilla/Add-ons/Working_with_multiprocess_Firefox')
        err.warning(
            ('submain', 'test_inner_package', 'not_multiprocess_compatible'),
            'Extension is not marked as compatible with Multi Process',
            "Your extension is not marked as compatible with "
            "Multi-Process Firefox and may not work in future versions "
            "of Firefox. Please review it, make changes if needed and "
            "set {field} to true in {filename} if it's compatible. "
            "See {link} for more information.".format(**format_args))

    # Return the results.
    return err
Exemplo n.º 9
0
def test_inner_package(err, xpi_package, for_appversions=None):
    "Tests a package's inner content."

    populate_chrome_manifest(err, xpi_package)

    # Iterate through each tier.
    for tier in sorted(decorator.get_tiers()):

        # Let the error bundler know what tier we're on.
        err.set_tier(tier)

        # Iterate through each test of our detected type.
        for test in decorator.get_tests(tier, err.detected_type):
            # Test whether the test is app/version specific.
            if test["versions"] is not None:
                # If the test's version requirements don't apply to the add-on,
                # then skip the test.
                if not err.supports_version(test["versions"]):
                    continue

                # If the user's version requirements don't apply to the test or
                # to the add-on, then skip the test.
                if for_appversions and not (
                    err._compare_version(requirements=for_appversions, support=test["versions"])
                    and err.supports_version(for_appversions)
                ):
                    continue

            # Save the version requirements to the error bundler.
            err.version_requirements = test["versions"]

            test_func = test["test"]
            if test["simple"]:
                test_func(err)
            else:
                # Pass in:
                # - Error Bundler
                # - A copy of the package itself
                test_func(err, xpi_package)

        # Return any errors at the end of the tier if undetermined.
        if err.failed(fail_on_warnings=False) and not err.determined:
            err.unfinished = True
            err.discard_unused_messages(ending_tier=tier)
            return err

    supports = err.get_resource("supports") or []
    if (
        err.get_resource("has_install_rdf")
        and not err.get_resource("has_manifest_json")
        and not err.get_resource("is_multiprocess_compatible")
        and err.detected_type in (PACKAGE_EXTENSION, PACKAGE_SUBPACKAGE)
        and "firefox" in supports
    ):
        # If it's an old-style xpi, or a sdk extension, that supports Firefox,
        # but is not a Web Extension, then we raise a warning if multiprocess
        # compatible property was not found in install.rdf.
        format_args = {}
        if err.get_resource("has_package_json"):
            format_args["filename"] = "package.json"
            format_args["field"] = "multiprocess"
            format_args["link"] = MDN_DOC % "Mozilla/Add-ons/SDK/Guides/Multiprocess_Firefox_and_the_SDK"
        else:
            format_args["filename"] = "install.rdf"
            format_args["field"] = "<em:multiprocessCompatible>"
            format_args["link"] = MDN_DOC % "Mozilla/Add-ons/Working_with_multiprocess_Firefox"
        err.warning(
            ("submain", "test_inner_package", "not_multiprocess_compatible"),
            "Extension is not marked as compatible with Multi Process",
            "Your extension is not marked as compatible with "
            "Multi-Process Firefox and may not work in future versions "
            "of Firefox. Please review it, make changes if needed and "
            "set {field} to true in {filename} if it's compatible. "
            "See {link} for more information.".format(**format_args),
        )

    # Return the results.
    return err